Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
TocGridHandler.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.grid.CategoryGridHandler');
17 import('controllers.grid.toc.TocGridCategoryRow');
18 import('controllers.grid.toc.TocGridRow');
19 
21  var $publishedArticlesBySectionId;
22 
26  function TocGridHandler() {
27  parent::CategoryGridHandler();
28  $this->addRoleAssignment(
29  array(ROLE_ID_EDITOR, ROLE_ID_MANAGER),
30  array('fetchGrid', 'fetchCategory', 'fetchRow', 'saveSequence', 'removeArticle')
31  );
32  $this->publishedArticlesBySectionId = array();
33  }
34 
35 
36  //
37  // Implement template methods from PKPHandler.
38  //
42  function authorize($request, &$args, $roleAssignments) {
43  import('lib.pkp.classes.security.authorization.PkpContextAccessPolicy');
44  $this->addPolicy(new PkpContextAccessPolicy($request, $roleAssignments));
45 
46  import('classes.security.authorization.OjsIssueRequiredPolicy');
47  $this->addPolicy(new OjsIssueRequiredPolicy($request, $args));
48 
49  return parent::authorize($request, $args, $roleAssignments);
50  }
51 
55  function initialize($request) {
56  parent::initialize($request);
57 
58  AppLocale::requireComponents(LOCALE_COMPONENT_APP_EDITOR, LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_APP_SUBMISSION);
59 
60  //
61  // Grid columns.
62  //
63  import('controllers.grid.toc.TocGridCellProvider');
64  $tocGridCellProvider = new TocGridCellProvider();
65 
66  // Article title
67  $this->addColumn(
68  new GridColumn(
69  'title',
70  'article.title',
71  null,
72  'controllers/grid/gridCell.tpl',
73  $tocGridCellProvider
74  )
75  );
76  }
77 
81  function initFeatures($request, $args) {
82  return array(new OrderCategoryGridItemsFeature(ORDER_CATEGORY_GRID_CATEGORIES_AND_ROWS));
83  }
84 
89  return 'sectionId';
90  }
91 
95  function getRequestArgs() {
96  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
97  return array_merge(
98  parent::getRequestArgs(),
99  array('issueId' => $issue->getId())
100  );
101  }
102 
107  function getRowInstance() {
108  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
109  return new TocGridRow($issue->getId());
110  }
111 
116  return new TocGridCategoryRow();
117  }
118 
122  function getCategoryData($section) {
123  return $this->publishedArticlesBySectionId[$section->getId()];
124  }
125 
129  function loadData($request, $filter) {
130  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
131 
132  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
133  $sectionDao = DAORegistry::getDAO('SectionDAO');
134  $publishedArticles = $publishedArticleDao->getPublishedArticles($issue->getId());
135 
136  $sections = array();
137  foreach ($publishedArticles as $article) {
138  $sectionId = $article->getSectionId();
139  if (!isset($sections[$sectionId])) {
140  $sections[$sectionId] = $sectionDao->getById($sectionId);
141  }
142  $this->publishedArticlesBySectionId[$sectionId][$article->getId()] = $article;
143  }
144  return $sections;
145  }
146 
150  function getDataElementSequence($section) {
151  $sectionDao = DAORegistry::getDAO('SectionDAO');
152  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
153  $customOrdering = $sectionDao->getCustomSectionOrder($issue->getId(), $section->getId());
154  if ($customOrdering === null) { // No custom ordering specified; use default section ordering
155  return $section->getSequence();
156  } else { // Custom ordering specified.
157  return $customOrdering;
158  }
159  }
160 
164  function setDataElementSequence($request, $sectionId, $section, $newSequence) {
165  $sectionDao = DAORegistry::getDAO('SectionDAO');
166  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
167  if (!$sectionDao->customSectionOrderingExists($issue->getId())) {
168  $sectionDao->setDefaultCustomSectionOrders($issue->getId());
169  }
170  $sectionDao->moveCustomSectionOrder($issue->getId(), $sectionId, $newSequence);
171  }
172 
176  function getDataElementInCategorySequence($categoryId, $publishedArticle) {
177  return $publishedArticle->getSeq();
178  }
179 
183  function setDataElementInCategorySequence($sectionId, $publishedArticle, $newSequence) {
184  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
185  if ($sectionId != $publishedArticle->getSectionId()) {
186  $publishedArticle->setSectionId($sectionId);
187  }
188  $publishedArticle->setSeq($newSequence);
189  $publishedArticleDao->updatePublishedArticle($publishedArticle);
190  }
191 
192  //
193  // Public handler functions
194  //
200  function removeArticle($args, $request) {
201  $journal = $request->getJournal();
202  $articleId = (int) $request->getUserVar('articleId');
203  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
204  $issueDao = DAORegistry::getDAO('IssueDAO');
205  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
206  $article = $publishedArticleDao->getPublishedArticleByArticleId($articleId);
207  import('classes.article.ArticleTombstoneManager');
208  $articleTombstoneManager = new ArticleTombstoneManager();
209  if ($article && $article->getIssueId() == $issue->getId()) {
210  if ($issue->getPublished()) {
211  $articleTombstoneManager->insertArticleTombstone($article, $journal);
212  }
213  $article->setStatus(STATUS_QUEUED);
214  $article->stampStatusModified();
215  // If the article is the only one in the section, delete the section from custom issue ordering
216  $sectionId = $article->getSectionId();
217  $publishedArticleArray = $publishedArticleDao->getPublishedArticlesBySectionId($sectionId, $issue->getId());
218  if (sizeof($publishedArticleArray) == 1) {
219  $sectionDao = DAORegistry::getDAO('SectionDAO');
220  $sectionDao->deleteCustomSection($issue->getId(), $sectionId);
221  }
222  $publishedArticleDao->deletePublishedArticleByArticleId($articleId);
223  $publishedArticleDao->resequencePublishedArticles($article->getSectionId(), $issue->getId());
224  return DAO::getDataChangedEvent();
225  }
226 
227  // If we've fallen through, it must be a badly-specified article
228  $json = new JSONMessage(false);
229  return $json->getString();
230  }
231 }
232 
233 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
System Info grid category row definition.
Policy that ensures that the request contains a valid issue.
Grid cell provider for the TOC (Table of Contents) category grid.
Handle TOC (table of contents) grid requests.
Implements category grid ordering functionality.
static requireComponents()
addColumn($column)
loadData($request, $filter)
removeArticle($args, $request)
Class to control access to PKP applications&#39; setup components.
addRoleAssignment($roleIds, $operations)
Class to represent a JSON (Javascript Object Notation) message.
Class defining basic operations for handling HTML grids with categories.
getDataElementInCategorySequence($categoryId, $publishedArticle)
getDataElementSequence($section)
setDataElementInCategorySequence($sectionId, $publishedArticle, $newSequence)
Class defining basic operations for article tombstones.
Handle issue grid row requests.
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:632
initFeatures($request, $args)
setDataElementSequence($request, $sectionId, $section, $newSequence)
& getAuthorizedContextObject($assocType)
authorize($request, &$args, $roleAssignments)