Open Journal Systems  3.0.0
 All Classes 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_EDITOR, 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.PkpContextAccessPolicy');
53  $this->addPolicy(new PkpContextAccessPolicy($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  'controllers/grid/gridCell.tpl',
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  'controllers/grid/gridCell.tpl',
96  $issueGridCellProvider
97  )
98  );
99  }
100 
106  protected function _addCenterColumns($issueGridCellProvider) {
107  // Default implementation does nothing.
108  }
109 
114  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  $json = new JSONMessage(true, $templateMgr->fetch('controllers/grid/issues/issue.tpl'));
143  return $json->getString();
144  }
145 
152  function editIssueData($args, $request) {
153  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
154 
155  import('controllers.grid.issues.form.IssueForm');
156  $issueForm = new IssueForm($issue);
157  $issueForm->initData($request);
158  $json = new JSONMessage(true, $issueForm->fetch($request));
159  return $json->getString();
160  }
161 
168  function uploadFile($args, $request) {
169  $user = $request->getUser();
170 
171  import('lib.pkp.classes.file.TemporaryFileManager');
172  $temporaryFileManager = new TemporaryFileManager();
173  $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
174  if ($temporaryFile) {
175  $json = new JSONMessage(true);
176  $json->setAdditionalAttributes(array(
177  'temporaryFileId' => $temporaryFile->getId()
178  ));
179  } else {
180  $json = new JSONMessage(false, __('common.uploadFailed'));
181  }
182 
183  return $json->getString();
184  }
185 
192  function updateIssue($args, $request) {
193  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
194 
195  import('controllers.grid.issues.form.IssueForm');
196  $issueForm = new IssueForm($issue);
197  $issueForm->readInputData();
198 
199  if ($issueForm->validate($request)) {
200  $issueId = $issueForm->execute($request);
201  return DAO::getDataChangedEvent($issueId);
202  } else {
203  $json = new JSONMessage(true, $issueForm->fetch($request));
204  return $json->getString();
205  }
206  }
207 
214  function editCover($args, $request) {
215  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
216 
217  import('controllers.grid.issues.form.CoverForm');
218  $coverForm = new CoverForm($issue);
219  $coverForm->initData($request);
220  $json = new JSONMessage(true, $coverForm->fetch($request));
221  return $json->getString();
222  }
223 
230  function updateCover($args, $request) {
231  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
232 
233  import('controllers.grid.issues.form.CoverForm');
234  $coverForm = new CoverForm($issue);
235  $coverForm->readInputData();
236 
237  if ($coverForm->validate($request)) {
238  $coverForm->execute($request);
239  return DAO::getDataChangedEvent($issue->getId());
240  } else {
241  $json = new JSONMessage(false);
242  return $json->getString();
243  }
244  }
245 
251  function deleteIssue($args, $request) {
252  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
253  $issueId = $issue->getId();
254  $journal = $request->getJournal();
255  $isBackIssue = $issue->getPublished() > 0 ? true: false;
256 
257  // remove all published articles and return original articles to editing queue
258  $articleDao = DAORegistry::getDAO('ArticleDAO');
259  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
260  $publishedArticles = $publishedArticleDao->getPublishedArticles($issueId);
261  if (isset($publishedArticles) && !empty($publishedArticles)) {
262  // Insert article tombstone if the issue is published
263  import('classes.article.ArticleTombstoneManager');
264  $articleTombstoneManager = new ArticleTombstoneManager();
265  foreach ($publishedArticles as $article) {
266  if ($isBackIssue) {
267  $articleTombstoneManager->insertArticleTombstone($article, $journal);
268  }
269  $articleDao->changeStatus($article->getId(), STATUS_QUEUED);
270  $publishedArticleDao->deletePublishedArticleById($article->getPublishedArticleId());
271  }
272  }
273 
274  $issueDao = DAORegistry::getDAO('IssueDAO');
275  $issueDao->deleteObject($issue);
276  if ($issue->getCurrent()) {
277  $issues = $issueDao->getPublishedIssues($journal->getId());
278  if (!$issues->eof()) {
279  $issue = $issues->next();
280  $issue->setCurrent(1);
281  $issueDao->updateObject($issue);
282  }
283  }
284 
285  return DAO::getDataChangedEvent($issueId);
286  }
287 
292  function issueToc($args, $request) {
293  $templateMgr = TemplateManager::getManager($request);
294  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
295  $templateMgr->assign('issue', $issue);
296  $json = new JSONMessage(true, $templateMgr->fetch('controllers/grid/issues/issueToc.tpl'));
297  return $json->getString();
298  }
299 
305  function issueGalleys($args, $request) {
306  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
307  $issueId = $issue->getId();
308 
309  $templateMgr = TemplateManager::getManager($request);
310  import('classes.issue.IssueAction');
311  $templateMgr->assign('issueId', $issueId);
312  $templateMgr->assign('unpublished',!$issue->getPublished());
313  $templateMgr->assign('issue', $issue);
314 
315  $issueGalleyDao = DAORegistry::getDAO('IssueGalleyDAO');
316  $templateMgr->assign('issueGalleys', $issueGalleyDao->getByIssueId($issue->getId()));
317 
318  $json = new JSONMessage(true, $templateMgr->fetch('controllers/grid/issues/issueGalleys.tpl'));
319  return $json->getString();
320  }
321 
327  function publishIssue($args, $request) {
328  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
329  $issueId = $issue->getId();
330 
331  $journal = $request->getJournal();
332  $journalId = $journal->getId();
333 
334  $articleSearchIndex = null;
335  if (!$issue->getPublished()) {
336  // Set the status of any attendant queued articles to STATUS_PUBLISHED.
337  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
338  $articleDao = DAORegistry::getDAO('ArticleDAO');
339  $publishedArticles = $publishedArticleDao->getPublishedArticles($issueId);
340  foreach ($publishedArticles as $publishedArticle) {
341  $article = $articleDao->getById($publishedArticle->getId());
342  if ($article && $article->getStatus() == STATUS_QUEUED) {
343  $article->setStatus(STATUS_PUBLISHED);
344  $article->stampStatusModified();
345  $articleDao->updateObject($article);
346  if (!$articleSearchIndex) {
347  import('classes.search.ArticleSearchIndex');
348  $articleSearchIndex = new ArticleSearchIndex();
349  }
350  $articleSearchIndex->articleMetadataChanged($publishedArticle);
351  }
352  // delete article tombstone
353  $tombstoneDao = DAORegistry::getDAO('DataObjectTombstoneDAO');
354  $tombstoneDao->deleteByDataObjectId($article->getId());
355  }
356  }
357 
358  $issue->setCurrent(1);
359  $issue->setPublished(1);
360  $issue->setDatePublished(Core::getCurrentDate());
361 
362  // If subscriptions with delayed open access are enabled then
363  // update open access date according to open access delay policy
364  if ($journal->getSetting('publishingMode') == PUBLISHING_MODE_SUBSCRIPTION && $journal->getSetting('enableDelayedOpenAccess')) {
365 
366  $delayDuration = $journal->getSetting('delayedOpenAccessDuration');
367  $delayYears = (int)floor($delayDuration/12);
368  $delayMonths = (int)fmod($delayDuration,12);
369 
370  $curYear = date('Y');
371  $curMonth = date('n');
372  $curDay = date('j');
373 
374  $delayOpenAccessYear = $curYear + $delayYears + (int)floor(($curMonth+$delayMonths)/12);
375  $delayOpenAccessMonth = (int)fmod($curMonth+$delayMonths,12);
376 
377  $issue->setAccessStatus(ISSUE_ACCESS_SUBSCRIPTION);
378  $issue->setOpenAccessDate(date('Y-m-d H:i:s',mktime(0,0,0,$delayOpenAccessMonth,$curDay,$delayOpenAccessYear)));
379  }
380 
381  $issueDao = DAORegistry::getDAO('IssueDAO');
382  $issueDao->updateCurrent($journalId,$issue);
383 
384  if ($articleSearchIndex) $articleSearchIndex->articleChangesFinished();
385 
386  // Send a notification to associated users
387  import('classes.notification.NotificationManager');
388  $notificationManager = new NotificationManager();
389  $notificationUsers = array();
390  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
391  $allUsers = $userGroupDao->getUsersByContextId($journalId);
392  while ($user = $allUsers->next()) {
393  $notificationUsers[] = array('id' => $user->getId());
394  }
395  foreach ($notificationUsers as $userRole) {
396  $notificationManager->createNotification(
397  $request, $userRole['id'], NOTIFICATION_TYPE_PUBLISHED_ISSUE,
398  $journalId
399  );
400  }
401  $notificationManager->sendToMailingList($request,
402  $notificationManager->createNotification(
403  $request, UNSUBSCRIBED_USER_NOTIFICATION, NOTIFICATION_TYPE_PUBLISHED_ISSUE,
404  $journalId
405  )
406  );
407 
408  $dispatcher = $request->getDispatcher();
409  // FIXME: Find a better way to reload the containing tabs.
410  // Without this, issues don't move between tabs properly.
411  return $request->redirectUrlJson($dispatcher->url($request, ROUTE_PAGE, null, 'manageIssues'));
412  }
413 
419  function unpublishIssue($args, $request) {
420  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
421  $journal = $request->getJournal();
422 
423  $issue->setCurrent(0);
424  $issue->setPublished(0);
425  $issue->setDatePublished(null);
426 
427  $issueDao = DAORegistry::getDAO('IssueDAO');
428  $issueDao->updateObject($issue);
429 
430  // insert article tombstones for all articles
431  import('classes.article.ArticleTombstoneManager');
432  $articleTombstoneManager = new ArticleTombstoneManager();
433  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
434  $publishedArticles = $publishedArticleDao->getPublishedArticles($issue->getId());
435  foreach ($publishedArticles as $article) {
436  $articleTombstoneManager->insertArticleTombstone($article, $journal);
437  }
438 
439  $dispatcher = $request->getDispatcher();
440  // FIXME: Find a better way to reload the containing tabs.
441  // Without this, issues don't move between tabs properly.
442  return $request->redirectUrlJson($dispatcher->url($request, ROUTE_PAGE, null, 'manageIssues'));
443  }
444 }
445 
446 ?>
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)
Class defining basic operations for handling HTML grids.
publishIssue($args, $request)
initialize($request, $args)
unpublishIssue($args, $request)
Class to control access to PKP applications&#39; setup components.
addRoleAssignment($roleIds, $operations)
Class to represent a JSON (Javascript Object Notation) message.
static getDataChangedEvent($elementId=null, $parentElementId=null)
Definition: DAO.inc.php:606
updateIssue($args, $request)
authorize($request, &$args, $roleAssignments)
_addCenterColumns($issueGridCellProvider)
uploadFile($args, $request)
issueToc($args, $request)
editCover($args, $request)
Class defining basic operations for article tombstones.
Handle issue grid row requests.
Class to maintain the article search index.
updateCover($args, $request)
editIssue($args, $request)
Represents a column within a grid. It is used to configure the way cells within a column are displaye...
& getAuthorizedContextObject($assocType)
Handle issues grid requests.
editIssueData($args, $request)
static getCurrentDate($ts=null)
Definition: Core.inc.php:95