Open Journal Systems  3.3.0
ContextService.inc.php
1 <?php
15 namespace APP\Services;
16 
19  var $contextsFileDirName = 'journals';
20 
24  public function __construct() {
25  $this->installFileDirs = array(
26  \Config::getVar('files', 'files_dir') . '/%s/%d',
27  \Config::getVar('files', 'files_dir'). '/%s/%d/articles',
28  \Config::getVar('files', 'files_dir'). '/%s/%d/issues',
29  \Config::getVar('files', 'public_files_dir') . '/%s/%d',
30  );
31 
32  \HookRegistry::register('Context::add', array($this, 'afterAddContext'));
33  \HookRegistry::register('Context::edit', array($this, 'afterEditContext'));
34  \HookRegistry::register('Context::delete', array($this, 'afterDeleteContext'));
35  \HookRegistry::register('Context::validate', array($this, 'validateContext'));
36  }
37 
47  public function afterAddContext($hookName, $args) {
48  $context = $args[0];
49  $request = $args[1];
50 
51  // Create a default section
52  $sectionDao = \DAORegistry::getDAO('SectionDAO'); // constants
53  $section = new \Section();
54  $section->setTitle(__('section.default.title'), $context->getPrimaryLocale());
55  $section->setAbbrev(__('section.default.abbrev'), $context->getPrimaryLocale());
56  $section->setMetaIndexed(true);
57  $section->setMetaReviewed(true);
58  $section->setPolicy(__('section.default.policy'), $context->getPrimaryLocale());
59  $section->setEditorRestricted(false);
60  $section->setHideTitle(false);
61 
62  \Services::get('section')->addSection($section, $context);
63  }
64 
76  public function afterEditContext($hookName, $args) {
77  $newContext = $args[0];
78  $params = $args[2];
79  $request = $args[3];
80 
81  // Move an uploaded journal thumbnail and set the updated data
82  if (!empty($params['journalThumbnail'])) {
83  $supportedLocales = $newContext->getSupportedFormLocales();
84  foreach ($supportedLocales as $localeKey) {
85  if (!array_key_exists($localeKey, $params['journalThumbnail'])) {
86  continue;
87  }
88  $localeValue = $this->_saveFileParam(
89  $newContext,
90  $params['journalThumbnail'][$localeKey],
91  'journalThumbnail',
92  $request->getUser()->getId(),
93  $localeKey,
94  true
95  );
96  $newContext->setData('journalThumbnail', $localeValue, $localeKey);
97  }
98  }
99  }
100 
110  public function afterDeleteContext($hookName, $args) {
111  $context = $args[0];
112 
113  $sectionDao = \DAORegistry::getDAO('SectionDAO');
114  $sectionDao->deleteByJournalId($context->getId());
115 
116  $issueDao = \DAORegistry::getDAO('IssueDAO');
117  $issueDao->deleteByJournalId($context->getId());
118 
119  $subscriptionDao = \DAORegistry::getDAO('IndividualSubscriptionDAO');
120  $subscriptionDao->deleteByJournalId($context->getId());
121  $subscriptionDao = \DAORegistry::getDAO('InstitutionalSubscriptionDAO');
122  $subscriptionDao->deleteByJournalId($context->getId());
123 
124  $subscriptionTypeDao = \DAORegistry::getDAO('SubscriptionTypeDAO');
125  $subscriptionTypeDao->deleteByJournal($context->getId());
126 
127  $submissionDao = \DAORegistry::getDAO('SubmissionDAO');
128  $submissionDao->deleteByContextId($context->getId());
129 
130  import('classes.file.PublicFileManager');
131  $publicFileManager = new \PublicFileManager();
132  $publicFileManager->rmtree($publicFileManager->getContextFilesPath($context->getId()));
133  }
134 
144  public function validateContext($hookName, $args) {
145  $errors =& $args[0];
146  $props = $args[2];
147  $allowedLocales = $args[3];
148 
149  if (!isset($props['journalThumbnail'])) {
150  return;
151  }
152 
153  // If a journal thumbnail is passed, check that the temporary file exists
154  // and the current user owns it
155  $user = \Application::get()->getRequest()->getUser();
156  $userId = $user ? $user->getId() : null;
157  import('lib.pkp.classes.file.TemporaryFileManager');
158  $temporaryFileManager = new \TemporaryFileManager();
159  if (isset($props['journalThumbnail']) && empty($errors['journalThumbnail'])) {
160  foreach ($allowedLocales as $localeKey) {
161  if (empty($props['journalThumbnail'][$localeKey]) || empty($props['journalThumbnail'][$localeKey]['temporaryFileId'])) {
162  continue;
163  }
164  if (!$temporaryFileManager->getFile($props['journalThumbnail'][$localeKey]['temporaryFileId'], $userId)) {
165  if (!is_array($errors['journalThumbnail'])) {
166  $errors['journalThumbnail'] = [];
167  }
168  $errors['journalThumbnail'][$localeKey] = [__('common.noTemporaryFile')];
169  }
170  }
171  }
172  }
173 }
APP\Services\ContextService\afterDeleteContext
afterDeleteContext($hookName, $args)
Definition: ContextService.inc.php:110
APP\Services\ContextService\afterAddContext
afterAddContext($hookName, $args)
Definition: ContextService.inc.php:47
PKP\Services\PKPContextService\_saveFileParam
_saveFileParam($context, $value, $settingName, $userId, $localeKey='', $isImage=false)
Definition: PKPContextService.inc.php:614
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PKP\Services\PKPContextService
Definition: PKPContextService.inc.php:30
Config\getVar
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
APP\Services\ContextService\$contextsFileDirName
$contextsFileDirName
Definition: ContextService.inc.php:19
APP\Services
Definition: ContextService.inc.php:15
APP\Services\ContextService
Definition: ContextService.inc.php:17
APP\Services\ContextService\__construct
__construct()
Definition: ContextService.inc.php:24
APP\Services\ContextService\afterEditContext
afterEditContext($hookName, $args)
Definition: ContextService.inc.php:76
HookRegistry\register
static register($hookName, $callback, $hookSequence=HOOK_SEQUENCE_NORMAL)
Definition: HookRegistry.inc.php:70
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
APP\Services\ContextService\validateContext
validateContext($hookName, $args)
Definition: ContextService.inc.php:144
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49