Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ManageCatalogHandler.inc.php
1 <?php
2 
16 import('classes.handler.Handler');
17 
18 // import UI base classes
19 import('lib.pkp.classes.linkAction.LinkAction');
20 import('lib.pkp.classes.core.JSONMessage');
21 
26  function ManageCatalogHandler() {
27  parent::Handler();
28 
29  $this->addRoleAssignment(
30  array(ROLE_ID_SUB_EDITOR, ROLE_ID_MANAGER),
31  array(
32  'index', // Container
33  'homepage', 'search',
34  'getCategories', 'category', // By category
35  'getSeries', 'series', // By series
36  'toggle'
37  )
38  );
39  }
40 
41 
42  //
43  // Implement template methods from PKPHandler
44  //
51  function authorize($request, &$args, $roleAssignments) {
52  import('lib.pkp.classes.security.authorization.PKPSiteAccessPolicy');
53  $this->addPolicy(new PKPSiteAccessPolicy($request, null, $roleAssignments));
54  return parent::authorize($request, $args, $roleAssignments);
55  }
56 
60  function initialize($request, $args) {
61  $this->setupTemplate($request);
62 
63  // Call parent method.
64  parent::initialize($request, $args);
65  }
66 
67 
68  //
69  // Public handler methods
70  //
76  function index($args, $request) {
77  // Render the view.
78  $templateMgr = TemplateManager::getManager($request);
79 
80  import('controllers.modals.submissionMetadata.linkAction.MonographlessCatalogEntryLinkAction');
81  $catalogEntryAction = new MonographlessCatalogEntryLinkAction($request);
82  $templateMgr->assign('catalogEntryAction', $catalogEntryAction);
83 
84  import('lib.pkp.classes.linkAction.LinkAction');
85  import('lib.pkp.classes.linkAction.request.AjaxModal');
86 
87  $dispatcher = $request->getDispatcher();
88 
89  $manageCategoriesLinkAction =
90  new LinkAction(
91  'manageCategories',
92  new AjaxModal(
93  $dispatcher->url($request, ROUTE_PAGE, null, 'management', 'categories'),
94  __('catalog.manage.manageCategories'),
95  'modal_manage',
96  true
97  ),
98  __('catalog.manage.manageCategories'),
99  'manage'
100  );
101 
102  $manageSeriesLinkAction =
103  new LinkAction(
104  'manageSeries',
105  new AjaxModal(
106  $dispatcher->url($request, ROUTE_PAGE, null, 'management', 'series'),
107  __('catalog.manage.manageSeries'),
108  'modal_manage',
109  true
110  ),
111  __('catalog.manage.manageSeries'),
112  'manage'
113  );
114 
115  $templateMgr->assign('manageCategoriesLinkAction', $manageCategoriesLinkAction);
116  $templateMgr->assign('manageSeriesLinkAction', $manageSeriesLinkAction);
117  $templateMgr->display('manageCatalog/index.tpl');
118  }
119 
125  function homepage($args, $request) {
126  // Set up the monograph list template
127  $press = $request->getPress();
129  $request,
130  true, 'homepage', 'catalog.manage.homepageDescription',
131  ASSOC_TYPE_PRESS, $press->getId()
132  );
133 
134  $templateMgr = TemplateManager::getManager($request);
135 
136  // Fetch the monographs to display
137  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
138  $publishedMonographs =& $publishedMonographDao->getByPressId($press->getId());
139  $templateMgr->assign('publishedMonographs', $publishedMonographs);
140 
141  // Display the monograph list
142  $templateMgr->display('manageCatalog/monographs.tpl');
143  }
144 
151  function getCategories($args, $request) {
152  $press = $request->getPress();
153  $categoryDao = DAORegistry::getDAO('CategoryDAO');
154  $categoryIterator = $categoryDao->getByPressId($press->getId());
155  $categoryArray = array();
156  while ($category = $categoryIterator->next()) {
157  $categoryArray[$category->getPath()] = $category->getLocalizedTitle();
158  }
159  $json = new JSONMessage(true, $categoryArray);
160  return $json->getString();
161  }
162 
169  function getSeries($args, $request) {
170  $press = $request->getPress();
171  $seriesDao = DAORegistry::getDAO('SeriesDAO');
172  $seriesIterator = $seriesDao->getByPressId($press->getId());
173  $seriesArray = array();
174  while ($series = $seriesIterator->next()) {
175  $seriesArray[$series->getPath()] = $series->getLocalizedTitle();
176  }
177  $json = new JSONMessage(true, $seriesArray);
178  return $json->getString();
179  }
180 
187  function category($args, $request) {
188  $templateMgr = TemplateManager::getManager($request);
189  $press = $request->getPress();
190 
191  // Get the category
192  $categoryDao = DAORegistry::getDAO('CategoryDAO');
193  $categoryPath = array_shift($args);
194  $category = $categoryDao->getByPath($categoryPath, $press->getId());
195  $templateMgr->assign('category', $category);
196 
197  // Set up the monograph list template
199  $request,
200  true, 'category', 'catalog.manage.categoryDescription',
201  ASSOC_TYPE_CATEGORY, $category->getId()
202  );
203 
204  // Fetch the monographs to display
205  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
206  $publishedMonographs = $publishedMonographDao->getByCategoryId($category->getId(), $press->getId());
207  $templateMgr->assign('publishedMonographs', $publishedMonographs);
208 
209  // Fetch the current features
210  $featureDao = DAORegistry::getDAO('FeatureDAO');
211  $features = $featureDao->getSequencesByAssoc(ASSOC_TYPE_CATEGORY, $category->getId());
212  $templateMgr->assign('features', $features);
213 
214  // Return the monograph list as a JSON message
215  $json = new JSONMessage(true, $templateMgr->fetch('manageCatalog/monographs.tpl'));
216  return $json->getString();
217  }
218 
225  function series($args, $request) {
226  $templateMgr = TemplateManager::getManager($request);
227  $press = $request->getPress();
228 
229  // Get the series
230  $seriesDao = DAORegistry::getDAO('SeriesDAO');
231  $seriesPath = array_shift($args);
232  $series =& $seriesDao->getByPath($seriesPath, $press->getId());
233  $templateMgr->assign('series', $series);
234 
235  // Set up the monograph list template
237  $request,
238  true, 'series', 'catalog.manage.seriesDescription',
239  ASSOC_TYPE_SERIES, $series->getId()
240  );
241 
242  // Fetch the monographs to display
243  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
244  $publishedMonographs =& $publishedMonographDao->getBySeriesId($series->getId(), $press->getId());
245  $templateMgr->assign('publishedMonographs', $publishedMonographs);
246 
247  // Return the monograph list as a JSON message
248  $json = new JSONMessage(true, $templateMgr->fetch('manageCatalog/monographs.tpl'));
249  return $json->getString();
250  }
251 
257  function search($args, $request) {
258  $searchText = array_shift($args);
259  $this->_setupMonographsTemplate($request, false, 'search');
260 
261  $templateMgr = TemplateManager::getManager($request);
262  $press = $request->getPress();
263 
264  // Fetch the monographs to display
265  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
266  $publishedMonographs = $publishedMonographDao->getByPressId($press->getId(), $searchText);
267  $templateMgr->assign('publishedMonographs', $publishedMonographs);
268 
269  // Display the monograph list
270  $templateMgr->display('manageCatalog/monographs.tpl');
271  }
272 
279  function toggle($args, $request) {
280  $press = $request->getPress();
281 
282  // Identification of item to set new state state on
283  $monographId = (int) array_shift($args);
284  $assocType = (int) array_shift($args);
285  $assocId = (int) array_shift($args);
286 
287  // toggle type
288  $toggleType = array_shift($args);
289 
290  // Description of new state
291  $newState = (int) array_shift($args);
292  $newSeq = (int) array_shift($args);
293 
294  // Validate the monograph ID
295  // FIXME: Can this be done with the auth framework without
296  // needing the policy throughout?
297  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
298  $publishedMonograph = $publishedMonographDao->getById($monographId, $press->getId());
299  if (!$publishedMonograph) fatalError('Invalid monograph!');
300 
301  // Determine the assoc type and ID to be used.
302  switch ($assocType) {
303  case ASSOC_TYPE_PRESS:
304  // Force assocId to press
305  $assocId = $press->getId();
306  break;
307  case ASSOC_TYPE_CATEGORY:
308  // Validate specified assocId
309  $categoryDao = DAORegistry::getDAO('CategoryDAO');
310  $category = $categoryDao->getById($assocId, $press->getId());
311  if (!$category) fatalError('Invalid category!');
312  break;
313  case ASSOC_TYPE_SERIES:
314  // Validate specified assocId
315  $seriesDao = DAORegistry::getDAO('SeriesDAO');
316  $series = $seriesDao->getById($assocId, $press->getId());
317  if (!$series) fatalError('Invalid series!');
318  break;
319  default:
320  fatalError('Invalid feature specified.');
321  }
322 
323  $returner = null;
324 
325  switch ($toggleType) {
326  case 'setFeatured':
327  $featureDao = DAORegistry::getDAO('FeatureDAO');
328  $featureDao->deleteFeature($monographId, $assocType, $assocId);
329 
330  // If necessary, insert the new featured state and resequence.
331  if ($newState) {
332  $featureDao->insertFeature($monographId, $assocType, $assocId, $newSeq);
333  $returner = $featureDao->resequenceByAssoc($assocType, $assocId);
334  } else {
335  $returner = null;
336  }
337  break;
338  case 'setNewRelease':
339  $newReleaseDao = DAORegistry::getDAO('NewReleaseDAO');
340  $newReleaseDao->deleteNewRelease($monographId, $assocType, $assocId);
341  if ($newState) {
342  $newReleaseDao->insertNewRelease($monographId, $assocType, $assocId);
343  $returner = true;
344  }
345  break;
346  default:
347  fatalError('Invalid toggle type specified.');
348  }
349 
350  $json = new JSONMessage(true, $returner);
351  return $json->getString();
352  }
353 
354  //
355  // Private functions
356  //
368  function _setupMonographsTemplate($request, $includeFeatureAction, $listName, $messageKey = null, $assocType = null, $assocId = null) {
369  // Loadubmission locale content for monograph listing
370  AppLocale::requireComponents(LOCALE_COMPONENT_APP_SUBMISSION, LOCALE_COMPONENT_PKP_SUBMISSION);
371 
372  $templateMgr = TemplateManager::getManager($request);
373  import('lib.pkp.classes.linkAction.request.NullAction');
374 
375  // Feature action (if enabled)
376  $templateMgr->assign('includeFeatureAction', $includeFeatureAction);
377 
378  // Add the list name, for ID differentiation
379  $templateMgr->assign('listName', $listName);
380 
381  // Include the message locale key displayed at the top of the tab
382  $templateMgr->assign('messageKey', $messageKey);
383 
384  // Expose the featured monograph IDs and associated params
385  if ($assocType) {
386  $featureDao = DAORegistry::getDAO('FeatureDAO');
387  $featuredMonographIds = $featureDao->getSequencesByAssoc($assocType, $assocId);
388  $templateMgr->assign('featuredMonographIds', $featuredMonographIds);
389 
390  $newReleaseDao = DAORegistry::getDAO('NewReleaseDAO');
391  $newReleaseMonographIds = $newReleaseDao->getMonographIdsByAssoc($assocType, $assocId);
392  $templateMgr->assign('newReleaseMonographIds', $newReleaseMonographIds);
393  }
394 
395  $templateMgr->assign('assocType', $assocType);
396  $templateMgr->assign('assocId', $assocId);
397  }
398 }
399 
400 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
static requireComponents()
setupTemplate($request)
addRoleAssignment($roleIds, $operations)
A modal that retrieves its content from via AJAX.
Class to represent a JSON (Javascript Object Notation) message.
Handle requests for catalog management.
_setupMonographsTemplate($request, $includeFeatureAction, $listName, $messageKey=null, $assocType=null, $assocId=null)
Base request handler application class.
Definition: Handler.inc.php:20
Class to that makes sure that a user is logged in.
Add a catalog entry, including first selecting a monograph.
authorize($request, &$args, $roleAssignments)
Base class defining an action that can be performed by the user in the user interface.