Open Journal Systems  3.0.0
 All Data Structures 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 
22 
26  function TocGridHandler() {
27  parent::CategoryGridHandler();
28  $this->addRoleAssignment(
29  array(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.ContextAccessPolicy');
44  $this->addPolicy(new ContextAccessPolicy($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  null,
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  protected function getRowInstance() {
108  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
109  return new TocGridRow($issue->getId());
110  }
111 
115  protected function getCategoryRowInstance() {
116  return new TocGridCategoryRow();
117  }
118 
122  function loadCategoryData($request, $section) {
123  return $this->publishedArticlesBySectionId[$section->getId()];
124  }
125 
129  protected 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->getSequence();
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->setSequence($newSequence);
189  $publishedArticleDao->updatePublishedArticle($publishedArticle);
190  }
191 
192  //
193  // Public handler functions
194  //
201  function removeArticle($args, $request) {
202  $journal = $request->getJournal();
203  $articleId = (int) $request->getUserVar('articleId');
204  $issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);
205  $issueDao = DAORegistry::getDAO('IssueDAO');
206  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
207  $article = $publishedArticleDao->getPublishedArticleByArticleId($articleId);
208  import('classes.article.ArticleTombstoneManager');
209  $articleTombstoneManager = new ArticleTombstoneManager();
210  if ($article && $article->getIssueId() == $issue->getId()) {
211  if ($issue->getPublished()) {
212  $articleTombstoneManager->insertArticleTombstone($article, $journal);
213  }
214  $article->setStatus(STATUS_QUEUED);
215  $article->stampStatusModified();
216  // If the article is the only one in the section, delete the section from custom issue ordering
217  $sectionId = $article->getSectionId();
218  $publishedArticleArray = $publishedArticleDao->getPublishedArticlesBySectionId($sectionId, $issue->getId());
219  if (sizeof($publishedArticleArray) == 1) {
220  $sectionDao = DAORegistry::getDAO('SectionDAO');
221  $sectionDao->deleteCustomSection($issue->getId(), $sectionId);
222  }
223  $publishedArticleDao->deletePublishedArticleByArticleId($articleId);
224  $publishedArticleDao->resequencePublishedArticles($article->getSectionId(), $issue->getId());
225  return DAO::getDataChangedEvent();
226  }
227 
228  // If we've fallen through, it must be a badly-specified article
229  return new JSONMessage(false);
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)
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)
Class to control access to PKP applications&#39; setup components.
setDataElementInCategorySequence($sectionId, $publishedArticle, $newSequence)
Class defining basic operations for article tombstones.
Handle issue grid row requests.
loadCategoryData($request, $section)
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
initFeatures($request, $args)
setDataElementSequence($request, $sectionId, $section, $newSequence)
& getAuthorizedContextObject($assocType)
authorize($request, &$args, $roleAssignments)