Open Journal Systems  3.0.0
 All Data Structures Namespaces Functions Variables Groups Pages
IssueGridHandler.inc.php
1 <?php
21 import('lib.pkp.classes.controllers.grid.GridHandler');
22 import('controllers.grid.issues.IssueGridRow');
23 
28  function IssueGridHandler() {
29  parent::GridHandler();
30  $this->addRoleAssignment(
31  array(ROLE_ID_MANAGER),
32  array(
33  'fetchGrid', 'fetchRow',
34  'addIssue', 'editIssue', 'editIssueData', 'updateIssue',
35  'uploadFile',
36  'editCover', 'updateCover',
37  'issueToc',
38  'issueGalleys',
39  'deleteIssue', 'publishIssue', 'unpublishIssue',
40  )
41  );
42  }
43 
44 
45  //
46  // Implement template methods from PKPHandler
47  //
51  function authorize($request, &$args, $roleAssignments) {
52  import('lib.pkp.classes.security.authorization.ContextAccessPolicy');
53  $this->addPolicy(new ContextAccessPolicy($request, $roleAssignments));
54 
55  // If a signoff ID was specified, authorize it.
56  if ($request->getUserVar('issueId')) {
57  import('classes.security.authorization.OjsIssueRequiredPolicy');
58  $this->addPolicy(new OjsIssueRequiredPolicy($request, $args));
59  }
60 
61  return parent::authorize($request, $args, $roleAssignments);
62  }
63 
67  function initialize($request, $args) {
68  parent::initialize($request, $args);
69 
70  AppLocale::requireComponents(LOCALE_COMPONENT_APP_EDITOR);
71 
72  // Grid columns.
73  import('controllers.grid.issues.IssueGridCellProvider');
74  $issueGridCellProvider = new IssueGridCellProvider();
75 
76  // Issue identification
77  $this->addColumn(
78  new GridColumn(
79  'identification',
80  'issue.issue',
81  null,
82  null,
83  $issueGridCellProvider
84  )
85  );
86 
87  $this->_addCenterColumns($issueGridCellProvider);
88 
89  // Number of articles
90  $this->addColumn(
91  new GridColumn(
92  'numArticles',
93  'editor.issues.numArticles',
94  null,
95  null,
96  $issueGridCellProvider
97  )
98  );
99  }
100 
106  protected function _addCenterColumns($issueGridCellProvider) {
107  // Default implementation does nothing.
108  }
109 
114  protected function getRowInstance() {
115  return new IssueGridRow();
116  }
117 
118  //
119  // Public operations
120  //
126  function addIssue($args, $request) {
127  // Calling editIssueData with an empty ID will add
128  // a new issue.
129  return $this->editIssueData($args, $request);
130  }
131 
138  function editIssue($args, $request) {
139  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
140  $templateMgr = TemplateManager::getManager($request);
141  if ($issue) $templateMgr->assign('issueId', $issue->getId());
142  return new JSONMessage(true, $templateMgr->fetch('controllers/grid/issues/issue.tpl'));
143  }
144 
151  function editIssueData($args, $request) {
152  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
153 
154  import('controllers.grid.issues.form.IssueForm');
155  $issueForm = new IssueForm($issue);
156  $issueForm->initData($request);
157  return new JSONMessage(true, $issueForm->fetch($request));
158  }
159 
166  function uploadFile($args, $request) {
167  $user = $request->getUser();
168 
169  import('lib.pkp.classes.file.TemporaryFileManager');
170  $temporaryFileManager = new TemporaryFileManager();
171  $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
172  if ($temporaryFile) {
173  $json = new JSONMessage(true);
174  $json->setAdditionalAttributes(array(
175  'temporaryFileId' => $temporaryFile->getId()
176  ));
177  return $json;
178  } else {
179  return new JSONMessage(false, __('common.uploadFailed'));
180  }
181  }
182 
189  function updateIssue($args, $request) {
190  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
191 
192  import('controllers.grid.issues.form.IssueForm');
193  $issueForm = new IssueForm($issue);
194  $issueForm->readInputData();
195 
196  if ($issueForm->validate($request)) {
197  $issueId = $issueForm->execute($request);
198  return DAO::getDataChangedEvent($issueId);
199  } else {
200  return new JSONMessage(true, $issueForm->fetch($request));
201  }
202  }
203 
210  function editCover($args, $request) {
211  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
212 
213  import('controllers.grid.issues.form.CoverForm');
214  $coverForm = new CoverForm($issue);
215  $coverForm->initData($request);
216  return new JSONMessage(true, $coverForm->fetch($request));
217  }
218 
225  function updateCover($args, $request) {
226  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
227 
228  import('controllers.grid.issues.form.CoverForm');
229  $coverForm = new CoverForm($issue);
230  $coverForm->readInputData();
231 
232  if ($coverForm->validate($request)) {
233  $coverForm->execute($request);
234  return DAO::getDataChangedEvent($issue->getId());
235  } else {
236  return new JSONMessage(false);
237  }
238  }
239 
245  function deleteIssue($args, $request) {
246  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
247  $issueId = $issue->getId();
248  $journal = $request->getJournal();
249  $isBackIssue = $issue->getPublished() > 0 ? true: false;
250 
251  // remove all published articles and return original articles to editing queue
252  $articleDao = DAORegistry::getDAO('ArticleDAO');
253  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
254  $publishedArticles = $publishedArticleDao->getPublishedArticles($issueId);
255  if (isset($publishedArticles) && !empty($publishedArticles)) {
256  // Insert article tombstone if the issue is published
257  import('classes.article.ArticleTombstoneManager');
258  $articleTombstoneManager = new ArticleTombstoneManager();
259  foreach ($publishedArticles as $article) {
260  if ($isBackIssue) {
261  $articleTombstoneManager->insertArticleTombstone($article, $journal);
262  }
263  $articleDao->changeStatus($article->getId(), STATUS_QUEUED);
264  $publishedArticleDao->deletePublishedArticleById($article->getPublishedArticleId());
265  }
266  }
267 
268  $issueDao = DAORegistry::getDAO('IssueDAO');
269  $issueDao->deleteObject($issue);
270  if ($issue->getCurrent()) {
271  $issues = $issueDao->getPublishedIssues($journal->getId());
272  if (!$issues->eof()) {
273  $issue = $issues->next();
274  $issue->setCurrent(1);
275  $issueDao->updateObject($issue);
276  }
277  }
278 
279  return DAO::getDataChangedEvent($issueId);
280  }
281 
288  function issueToc($args, $request) {
289  $templateMgr = TemplateManager::getManager($request);
290  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
291  $templateMgr->assign('issue', $issue);
292  return new JSONMessage(true, $templateMgr->fetch('controllers/grid/issues/issueToc.tpl'));
293  }
294 
301  function issueGalleys($args, $request) {
302  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
303  $templateMgr = TemplateManager::getManager($request);
304  $dispatcher = $request->getDispatcher();
305  return $templateMgr->fetchAjax(
306  'issueGalleysGridContainer',
307  $dispatcher->url(
308  $request, ROUTE_COMPONENT, null,
309  'grid.issueGalleys.IssueGalleyGridHandler', 'fetchGrid', null,
310  array('issueId' => $issue->getId())
311  )
312  );
313  }
314 
320  function publishIssue($args, $request) {
321  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
322  $issueId = $issue->getId();
323 
324  $journal = $request->getJournal();
325  $journalId = $journal->getId();
326 
327  $articleSearchIndex = null;
328  if (!$issue->getPublished()) {
329  // Set the status of any attendant queued articles to STATUS_PUBLISHED.
330  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
331  $articleDao = DAORegistry::getDAO('ArticleDAO');
332  $publishedArticles = $publishedArticleDao->getPublishedArticles($issueId);
333  foreach ($publishedArticles as $publishedArticle) {
334  $article = $articleDao->getById($publishedArticle->getId());
335  if ($article && $article->getStatus() == STATUS_QUEUED) {
336  $article->setStatus(STATUS_PUBLISHED);
337  $article->stampStatusModified();
338  $articleDao->updateObject($article);
339  if (!$articleSearchIndex) {
340  import('classes.search.ArticleSearchIndex');
341  $articleSearchIndex = new ArticleSearchIndex();
342  }
343  $articleSearchIndex->articleMetadataChanged($publishedArticle);
344  }
345  // delete article tombstone
346  $tombstoneDao = DAORegistry::getDAO('DataObjectTombstoneDAO');
347  $tombstoneDao->deleteByDataObjectId($article->getId());
348  }
349  }
350 
351  $issue->setCurrent(1);
352  $issue->setPublished(1);
353  $issue->setDatePublished(Core::getCurrentDate());
354 
355  // If subscriptions with delayed open access are enabled then
356  // update open access date according to open access delay policy
357  if ($journal->getSetting('publishingMode') == PUBLISHING_MODE_SUBSCRIPTION && $journal->getSetting('enableDelayedOpenAccess')) {
358 
359  $delayDuration = $journal->getSetting('delayedOpenAccessDuration');
360  $delayYears = (int)floor($delayDuration/12);
361  $delayMonths = (int)fmod($delayDuration,12);
362 
363  $curYear = date('Y');
364  $curMonth = date('n');
365  $curDay = date('j');
366 
367  $delayOpenAccessYear = $curYear + $delayYears + (int)floor(($curMonth+$delayMonths)/12);
368  $delayOpenAccessMonth = (int)fmod($curMonth+$delayMonths,12);
369 
370  $issue->setAccessStatus(ISSUE_ACCESS_SUBSCRIPTION);
371  $issue->setOpenAccessDate(date('Y-m-d H:i:s',mktime(0,0,0,$delayOpenAccessMonth,$curDay,$delayOpenAccessYear)));
372  }
373 
374  $issueDao = DAORegistry::getDAO('IssueDAO');
375  $issueDao->updateCurrent($journalId,$issue);
376 
377  if ($articleSearchIndex) $articleSearchIndex->articleChangesFinished();
378 
379  // Send a notification to associated users
380  import('classes.notification.NotificationManager');
381  $notificationManager = new NotificationManager();
382  $notificationUsers = array();
383  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
384  $allUsers = $userGroupDao->getUsersByContextId($journalId);
385  while ($user = $allUsers->next()) {
386  $notificationUsers[] = array('id' => $user->getId());
387  }
388  foreach ($notificationUsers as $userRole) {
389  $notificationManager->createNotification(
390  $request, $userRole['id'], NOTIFICATION_TYPE_PUBLISHED_ISSUE,
391  $journalId
392  );
393  }
394  $notificationManager->sendToMailingList($request,
395  $notificationManager->createNotification(
396  $request, UNSUBSCRIBED_USER_NOTIFICATION, NOTIFICATION_TYPE_PUBLISHED_ISSUE,
397  $journalId
398  )
399  );
400 
401  return DAO::getDataChangedEvent();
402  }
403 
409  function unpublishIssue($args, $request) {
410  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
411  $journal = $request->getJournal();
412 
413  $issue->setCurrent(0);
414  $issue->setPublished(0);
415  $issue->setDatePublished(null);
416 
417  $issueDao = DAORegistry::getDAO('IssueDAO');
418  $issueDao->updateObject($issue);
419 
420  // insert article tombstones for all articles
421  import('classes.article.ArticleTombstoneManager');
422  $articleTombstoneManager = new ArticleTombstoneManager();
423  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
424  $publishedArticles = $publishedArticleDao->getPublishedArticles($issue->getId());
425  foreach ($publishedArticles as $article) {
426  $articleTombstoneManager->insertArticleTombstone($article, $journal);
427  }
428 
429  $dispatcher = $request->getDispatcher();
430  $json = new JSONMessage();
431  $json->setEvent('containerReloadRequested', array('tabsUrl' => $dispatcher->url($request, ROUTE_PAGE, null, 'manageIssues', 'index')));
432  return $json;
433  }
434 }
435 
436 ?>
static & getDAO($name, $dbconn=null)
addIssue($args, $request)
Grid cell provider for the issue management grid.
addPolicy($authorizationPolicy, $addToTop=false)
deleteIssue($args, $request)
Policy that ensures that the request contains a valid issue.
Form to create or edit an issue.
issueGalleys($args, $request)
Form to create or edit an issue.
static requireComponents()
addColumn($column)
This class defines basic operations for handling HTML grids. Grids are used to implement a standardiz...
publishIssue($args, $request)
initialize($request, $args)
unpublishIssue($args, $request)
addRoleAssignment($roleIds, $operations)
Class to represent a JSON (Javascript Object Notation) message.
updateIssue($args, $request)
authorize($request, &$args, $roleAssignments)
_addCenterColumns($issueGridCellProvider)
Class to control access to PKP applications&#39; setup components.
uploadFile($args, $request)
issueToc($args, $request)
editCover($args, $request)
static & getManager($request=null)
Class defining basic operations for article tombstones.
Handle issue grid row requests.
updateCover($args, $request)
editIssue($args, $request)
The GridColumn class represents a column within a grid. It is used to format the data presented in a ...
static getDataChangedEvent($elementId=null, $parentElementId=null, $content= '')
Definition: DAO.inc.php:633
& getAuthorizedContextObject($assocType)
Handle issues grid requests.
editIssueData($args, $request)
static getCurrentDate($ts=null)
Definition: Core.inc.php:95