/
JournalSiteSettingsForm.inc.php
190 lines (158 loc) · 6.34 KB
/
JournalSiteSettingsForm.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
* @file classes/manager/form/JournalSiteSettingsForm.inc.php
*
* Copyright (c) 2003-2010 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class JournalSiteSettingsForm
* @ingroup admin_form
*
* @brief Form for site administrator to edit basic journal settings.
*/
// $Id$
import('lib.pkp.classes.db.DBDataXMLParser');
import('lib.pkp.classes.form.Form');
class JournalSiteSettingsForm extends Form {
/** The ID of the journal being edited */
var $journalId;
/**
* Constructor.
* @param $journalId omit for a new journal
*/
function JournalSiteSettingsForm($journalId = null) {
parent::Form('admin/journalSettings.tpl');
$this->journalId = isset($journalId) ? (int) $journalId : null;
// Validation checks for this form
$this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'admin.journals.form.titleRequired'));
$this->addCheck(new FormValidator($this, 'journalPath', 'required', 'admin.journals.form.pathRequired'));
$this->addCheck(new FormValidatorAlphaNum($this, 'journalPath', 'required', 'admin.journals.form.pathAlphaNumeric'));
$this->addCheck(new FormValidatorCustom($this, 'journalPath', 'required', 'admin.journals.form.pathExists', create_function('$path,$form,$journalDao', 'return !$journalDao->journalExistsByPath($path) || ($form->getData(\'oldPath\') != null && $form->getData(\'oldPath\') == $path);'), array(&$this, DAORegistry::getDAO('JournalDAO'))));
$this->addCheck(new FormValidatorPost($this));
}
/**
* Display the form.
*/
function display() {
$templateMgr =& TemplateManager::getManager();
$templateMgr->assign('journalId', $this->journalId);
$templateMgr->assign('helpTopicId', 'site.siteManagement');
parent::display();
}
/**
* Initialize form data from current settings.
*/
function initData() {
if (isset($this->journalId)) {
$journalDao =& DAORegistry::getDAO('JournalDAO');
$journal =& $journalDao->getJournal($this->journalId);
if ($journal != null) {
$this->_data = array(
'title' => $journal->getSetting('title', null), // Localized
'description' => $journal->getSetting('description', null), // Localized
'journalPath' => $journal->getPath(),
'enabled' => $journal->getEnabled()
);
} else {
$this->journalId = null;
}
}
if (!isset($this->journalId)) {
$this->_data = array(
'enabled' => 1
);
}
}
/**
* Assign form data to user-submitted data.
*/
function readInputData() {
$this->readUserVars(array('title', 'description', 'journalPath', 'enabled'));
$this->setData('enabled', (int)$this->getData('enabled'));
if (isset($this->journalId)) {
$journalDao =& DAORegistry::getDAO('JournalDAO');
$journal =& $journalDao->getJournal($this->journalId);
$this->setData('oldPath', $journal->getPath());
}
}
/**
* Get a list of field names for which localized settings are used
* @return array
*/
function getLocaleFieldNames() {
return array('title', 'description');
}
/**
* Save journal settings.
*/
function execute() {
$journalDao =& DAORegistry::getDAO('JournalDAO');
if (isset($this->journalId)) {
$journal =& $journalDao->getJournal($this->journalId);
}
if (!isset($journal)) {
$journal = new Journal();
}
$journal->setPath($this->getData('journalPath'));
$journal->setEnabled($this->getData('enabled'));
if ($journal->getId() != null) {
$isNewJournal = false;
$journalDao->updateJournal($journal);
$section = null;
} else {
$isNewJournal = true;
$site =& Request::getSite();
// Give it a default primary locale
$journal->setPrimaryLocale ($site->getPrimaryLocale());
$journalId = $journalDao->insertJournal($journal);
$journalDao->resequenceJournals();
// Make the site administrator the journal manager of newly created journals
$sessionManager =& SessionManager::getManager();
$userSession =& $sessionManager->getUserSession();
if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($journalId)) {
$role = new Role();
$role->setJournalId($journalId);
$role->setUserId($userSession->getUserId());
$role->setRoleId(ROLE_ID_JOURNAL_MANAGER);
$roleDao =& DAORegistry::getDAO('RoleDAO');
$roleDao->insertRole($role);
}
// Make the file directories for the journal
import('lib.pkp.classes.file.FileManager');
FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId);
FileManager::mkdir(Config::getVar('files', 'files_dir'). '/journals/' . $journalId . '/articles');
FileManager::mkdir(Config::getVar('files', 'files_dir'). '/journals/' . $journalId . '/issues');
FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/journals/' . $journalId);
// Install default journal settings
$journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
$titles = $this->getData('title');
Locale::requireComponents(array(LOCALE_COMPONENT_OJS_DEFAULT, LOCALE_COMPONENT_APPLICATION_COMMON));
$journalSettingsDao->installSettings($journalId, 'registry/journalSettings.xml', array(
'indexUrl' => Request::getIndexUrl(),
'journalPath' => $this->getData('journalPath'),
'primaryLocale' => $site->getPrimaryLocale(),
'journalName' => $titles[$site->getPrimaryLocale()]
));
// Install the default RT versions.
import('classes.rt.ojs.JournalRTAdmin');
$journalRtAdmin = new JournalRTAdmin($journalId);
$journalRtAdmin->restoreVersions(false);
// Create a default "Articles" section
$sectionDao =& DAORegistry::getDAO('SectionDAO');
$section = new Section();
$section->setJournalId($journal->getId());
$section->setTitle(Locale::translate('section.default.title'), $journal->getPrimaryLocale());
$section->setAbbrev(Locale::translate('section.default.abbrev'), $journal->getPrimaryLocale());
$section->setMetaIndexed(true);
$section->setMetaReviewed(true);
$section->setPolicy(Locale::translate('section.default.policy'), $journal->getPrimaryLocale());
$section->setEditorRestricted(false);
$section->setHideTitle(false);
$sectionDao->insertSection($section);
}
$journal->updateSetting('title', $this->getData('title'), 'string', true);
$journal->updateSetting('description', $this->getData('description'), 'string', true);
HookRegistry::call('JournalSiteSettingsForm::execute', array(&$this, &$journal, &$section, &$isNewJournal));
}
}
?>