/ojs/ojs-2.3.1-2/pages/rtadmin/RTSearchHandler.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite · PHP · 196 lines · 133 code · 43 blank · 20 comment · 45 complexity · 91267e77d9f6e5b2a4bd8c36f45c8922 MD5 · raw file

  1. <?php
  2. /**
  3. * @file RTSearchHandler.inc.php
  4. *
  5. * Copyright (c) 2003-2009 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @class RTSearchHandler
  9. * @ingroup pages_rtadmin
  10. *
  11. * @brief Handle Reading Tools administration requests -- contexts section.
  12. */
  13. // $Id: RTSearchHandler.inc.php,v 1.27 2009/09/22 21:20:36 asmecher Exp $
  14. import('rt.ojs.JournalRTAdmin');
  15. import('pages.rtadmin.RTAdminHandler');
  16. class RTSearchHandler extends RTAdminHandler {
  17. /**
  18. * Constructor
  19. **/
  20. function RTSearchHandler() {
  21. parent::RTAdminHandler();
  22. }
  23. function createSearch($args) {
  24. $this->validate();
  25. $journal = Request::getJournal();
  26. $rtDao =& DAORegistry::getDAO('RTDAO');
  27. $versionId = isset($args[0])?$args[0]:0;
  28. $version =& $rtDao->getVersion($versionId, $journal->getJournalId());
  29. $contextId = isset($args[1])?$args[1]:0;
  30. $context =& $rtDao->getContext($contextId);
  31. import('rt.ojs.form.SearchForm');
  32. $searchForm = new SearchForm(null, $contextId, $versionId);
  33. if (isset($args[2]) && $args[2]=='save') {
  34. $searchForm->readInputData();
  35. $searchForm->execute();
  36. Request::redirect(null, null, 'searches', array($versionId, $contextId));
  37. } else {
  38. $this->setupTemplate(true, $version, $context);
  39. $searchForm->display();
  40. }
  41. }
  42. function searches($args) {
  43. $this->validate();
  44. $journal = Request::getJournal();
  45. $rtDao =& DAORegistry::getDAO('RTDAO');
  46. $rangeInfo = Handler::getRangeInfo('searches');
  47. $versionId = isset($args[0])?$args[0]:0;
  48. $version =& $rtDao->getVersion($versionId, $journal->getJournalId());
  49. $contextId = isset($args[1])?$args[1]:0;
  50. $context =& $rtDao->getContext($contextId);
  51. if ($context && $version && $context->getVersionId() == $version->getVersionId()) {
  52. $this->setupTemplate(true, $version, $context);
  53. $templateMgr =& TemplateManager::getManager();
  54. $templateMgr->assign_by_ref('version', $version);
  55. $templateMgr->assign_by_ref('context', $context);
  56. import('core.ArrayItemIterator');
  57. $templateMgr->assign_by_ref('searches', new ArrayItemIterator($context->getSearches(), $rangeInfo->getPage(), $rangeInfo->getCount()));
  58. $templateMgr->assign('helpTopicId', 'journal.managementPages.readingTools.contexts');
  59. $templateMgr->display('rtadmin/searches.tpl');
  60. }
  61. else Request::redirect(null, null, 'versions');
  62. }
  63. function editSearch($args) {
  64. $this->validate();
  65. $rtDao =& DAORegistry::getDAO('RTDAO');
  66. $journal = Request::getJournal();
  67. $versionId = isset($args[0])?$args[0]:0;
  68. $version =& $rtDao->getVersion($versionId, $journal->getJournalId());
  69. $contextId = isset($args[1])?$args[1]:0;
  70. $context =& $rtDao->getContext($contextId);
  71. $searchId = isset($args[2])?$args[2]:0;
  72. $search =& $rtDao->getSearch($searchId);
  73. if (isset($version) && isset($context) && isset($search) && $context->getVersionId() == $version->getVersionId() && $search->getContextId() == $context->getContextId()) {
  74. import('rt.ojs.form.SearchForm');
  75. $this->setupTemplate(true, $version, $context, $search);
  76. $searchForm = new SearchForm($searchId, $contextId, $versionId);
  77. $searchForm->initData();
  78. $searchForm->display();
  79. }
  80. else Request::redirect(null, null, 'searches', array($versionId, $contextId));
  81. }
  82. function deleteSearch($args) {
  83. $this->validate();
  84. $rtDao =& DAORegistry::getDAO('RTDAO');
  85. $journal = Request::getJournal();
  86. $versionId = isset($args[0])?$args[0]:0;
  87. $version =& $rtDao->getVersion($versionId, $journal->getJournalId());
  88. $contextId = isset($args[1])?$args[1]:0;
  89. $context =& $rtDao->getContext($contextId);
  90. $searchId = isset($args[2])?$args[2]:0;
  91. $search =& $rtDao->getSearch($searchId);
  92. if (isset($version) && isset($context) && isset($search) && $context->getVersionId() == $version->getVersionId() && $search->getContextId() == $context->getContextId()) {
  93. $rtDao->deleteSearch($searchId, $contextId);
  94. }
  95. Request::redirect(null, null, 'searches', array($versionId, $contextId));
  96. }
  97. function saveSearch($args) {
  98. $this->validate();
  99. $rtDao =& DAORegistry::getDAO('RTDAO');
  100. $journal = Request::getJournal();
  101. $versionId = isset($args[0])?$args[0]:0;
  102. $version =& $rtDao->getVersion($versionId, $journal->getJournalId());
  103. $contextId = isset($args[1])?$args[1]:0;
  104. $context =& $rtDao->getContext($contextId);
  105. $searchId = isset($args[2])?$args[2]:0;
  106. $search =& $rtDao->getSearch($searchId);
  107. if (isset($version) && isset($context) && isset($search) && $context->getVersionId() == $version->getVersionId() && $search->getContextId() == $context->getContextId()) {
  108. import('rt.ojs.form.SearchForm');
  109. $searchForm = new SearchForm($searchId, $contextId, $versionId);
  110. $searchForm->readInputData();
  111. $searchForm->execute();
  112. }
  113. Request::redirect(null, null, 'searches', array($versionId, $contextId));
  114. }
  115. function moveSearch($args) {
  116. $this->validate();
  117. $rtDao =& DAORegistry::getDAO('RTDAO');
  118. $journal = Request::getJournal();
  119. $versionId = isset($args[0])?$args[0]:0;
  120. $version =& $rtDao->getVersion($versionId, $journal->getJournalId());
  121. $contextId = isset($args[1])?$args[1]:0;
  122. $context =& $rtDao->getContext($contextId);
  123. $searchId = Request::getUserVar('id');
  124. $search =& $rtDao->getSearch($searchId);
  125. if (isset($version) && isset($context) && isset($search) && $context->getVersionId() == $version->getVersionId() && $search->getContextId() == $context->getContextId()) {
  126. $direction = Request::getUserVar('dir');
  127. if ($direction != null) {
  128. // moving with up or down arrow
  129. $isDown = $direction =='d';
  130. $search->setOrder($search->getOrder()+($isDown?1.5:-1.5));
  131. } else {
  132. // drag and drop
  133. $prevId = Request::getUserVar('prevId');
  134. if ($prevId == null)
  135. $prevSeq = 0;
  136. else {
  137. $prevSearch = $rtDao->getSearch($prevId);
  138. $prevSeq = $prevSearch->getOrder();
  139. }
  140. $search->setOrder($prevSeq + .5);
  141. }
  142. $rtDao->updateSearch($search);
  143. $rtDao->resequenceSearches($context->getContextId());
  144. }
  145. // Moving up or down with the arrows requires a page reload.
  146. // In the case of a drag and drop move, the display has been
  147. // updated on the client side, so no reload is necessary.
  148. if ($direction != null) {
  149. Request::redirect(null, null, 'searches', array($versionId, $contextId));
  150. }
  151. }
  152. }
  153. ?>