pages/manager/ReviewFormHandler.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 import('pages.manager.ManagerHandler');
00017 
00018 class ReviewFormHandler extends ManagerHandler {
00022    function ReviewFormHandler() {
00023       parent::ManagerHandler();
00024    }
00025 
00029    function reviewForms() {
00030       $this->validate();
00031       $this->setupTemplate();
00032 
00033       $conference =& Request::getConference();
00034       $rangeInfo =& Handler::getRangeInfo('reviewForms');
00035       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00036       $reviewForms =& $reviewFormDao->getByAssocId(ASSOC_TYPE_CONFERENCE, $conference->getId(), $rangeInfo);
00037       $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00038 
00039       $templateMgr =& TemplateManager::getManager();
00040       $templateMgr->assign_by_ref('reviewForms', $reviewForms);
00041       $templateMgr->assign('helpTopicId','conference.managementPages.reviewForms');
00042       $templateMgr->display('manager/reviewForms/reviewForms.tpl');
00043    }
00044 
00048    function createReviewForm() {
00049       $this->editReviewForm();
00050    }
00051 
00056    function editReviewForm($args = array()) {
00057       $this->validate();
00058 
00059       $reviewFormId = isset($args[0]) ? (int)$args[0] : null;
00060 
00061       $conference =& Request::getConference();
00062       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00063       $reviewForm =& $reviewFormDao->getReviewForm($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId());
00064 
00065       if ($reviewFormId != null && (!isset($reviewForm) || $reviewForm->getCompleteCount() != 0 || $reviewForm->getIncompleteCount() != 0)) {
00066          Request::redirect(null, null, null, 'reviewForms');
00067       } else {
00068          $this->setupTemplate(true, $reviewForm);
00069          $templateMgr =& TemplateManager::getManager();
00070 
00071          if ($reviewFormId == null) {
00072             $templateMgr->assign('pageTitle', 'manager.reviewForms.create');
00073          } else {
00074             $templateMgr->assign('pageTitle', 'manager.reviewForms.edit');
00075          }
00076 
00077          import('manager.form.ReviewFormForm');
00078          $reviewFormForm = new ReviewFormForm($reviewFormId);
00079 
00080          if ($reviewFormForm->isLocaleResubmit()) {
00081             $reviewFormForm->readInputData();
00082          } else {
00083             $reviewFormForm->initData();
00084          }
00085          $reviewFormForm->display();
00086       }
00087    }
00088 
00092    function updateReviewForm() {
00093       $this->validate();
00094       $this->setupTemplate(true, $reviewForm);
00095 
00096       $reviewFormId = Request::getUserVar('reviewFormId') === null? null : (int) Request::getUserVar('reviewFormId');
00097 
00098       $conference =& Request::getConference();
00099       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00100       $reviewForm =& $reviewFormDao->getReviewForm($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId());
00101 
00102       if ($reviewFormId != null && (!isset($reviewForm) || $reviewForm->getCompleteCount() != 0 || $reviewForm->getIncompleteCount() != 0)) {
00103          Request::redirect(null, null, null, 'reviewForms');
00104       }
00105 
00106       import('manager.form.ReviewFormForm');
00107       $reviewFormForm = new ReviewFormForm($reviewFormId);
00108       $reviewFormForm->readInputData();
00109 
00110       if ($reviewFormForm->validate()) {
00111          $reviewFormForm->execute();
00112          Request::redirect(null, null, null, 'reviewForms');
00113       } else {
00114          $templateMgr =& TemplateManager::getManager();
00115 
00116          if ($reviewFormId == null) {
00117             $templateMgr->assign('pageTitle', 'manager.reviewForms.create');
00118          } else {
00119             $templateMgr->assign('pageTitle', 'manager.reviewForms.edit');
00120          }
00121 
00122          $reviewFormForm->display();
00123       }
00124    }
00125 
00130    function previewReviewForm($args) {
00131       $this->validate();
00132 
00133       $reviewFormId = isset($args[0]) ? (int)$args[0] : null;
00134 
00135       $conference =& Request::getConference();
00136       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00137       $reviewForm =& $reviewFormDao->getReviewForm($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId());
00138       $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
00139       $reviewFormElements =& $reviewFormElementDao->getReviewFormElements($reviewFormId);
00140 
00141       if (!isset($reviewForm)) {
00142          Request::redirect(null, null, null, 'reviewForms');
00143       }
00144 
00145       if ($reviewForm->getCompleteCount() != 0 || $reviewForm->getIncompleteCount() != 0) {
00146          $this->setupTemplate(true);
00147       } else {
00148          $this->setupTemplate(true, $reviewForm);
00149       }
00150 
00151       $templateMgr =& TemplateManager::getManager();
00152 
00153       $templateMgr->assign('pageTitle', 'manager.reviewForms.preview');
00154       $templateMgr->assign_by_ref('reviewForm', $reviewForm);
00155       $templateMgr->assign('reviewFormElements', $reviewFormElements);
00156       $templateMgr->register_function('form_language_chooser', array('ReviewFormHandler', 'smartyFormLanguageChooser'));
00157       $templateMgr->assign('helpTopicId','conference.managementPages.reviewForms');
00158       $templateMgr->display('manager/reviewForms/previewReviewForm.tpl');
00159    }
00160 
00165    function deleteReviewForm($args) {
00166       $this->validate();
00167 
00168       $reviewFormId = isset($args[0]) ? (int)$args[0] : null;
00169 
00170       $conference =& Request::getConference();
00171       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00172       $reviewForm =& $reviewFormDao->getReviewForm($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId());
00173 
00174       if (isset($reviewForm) && $reviewForm->getCompleteCount() == 0 && $reviewForm->getIncompleteCount() == 0) {
00175          $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00176          $reviewAssignments =& $reviewAssignmentDao->getReviewAssignmentsByReviewFormId($reviewFormId);
00177 
00178          foreach ($reviewAssignments as $reviewAssignment) {
00179             $reviewAssignment->setReviewFormId('');
00180             $reviewAssignmentDao->updateReviewAssignment($reviewAssignment);
00181          }
00182 
00183          $reviewFormDao->deleteById($reviewFormId);
00184       }
00185 
00186       Request::redirect(null, null, null, 'reviewForms');
00187    }
00188 
00193    function activateReviewForm($args) {
00194       $this->validate();
00195 
00196       $reviewFormId = isset($args[0]) ? (int)$args[0] : null;
00197 
00198       $conference =& Request::getConference();
00199       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00200       $reviewForm =& $reviewFormDao->getReviewForm($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId());
00201 
00202       if (isset($reviewForm) && !$reviewForm->getActive()) {
00203          $reviewForm->setActive(1);
00204          $reviewFormDao->updateObject($reviewForm);
00205       }
00206 
00207       Request::redirect(null, null, null, 'reviewForms');
00208    }
00209 
00214    function deactivateReviewForm($args) {
00215       $this->validate();
00216 
00217       $reviewFormId = isset($args[0]) ? (int)$args[0] : null;
00218 
00219       $conference =& Request::getConference();
00220       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00221       $reviewForm =& $reviewFormDao->getReviewForm($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId());
00222 
00223       if (isset($reviewForm) && $reviewForm->getActive()) {
00224          $reviewForm->setActive(0);
00225          $reviewFormDao->updateObject($reviewForm);
00226       }
00227 
00228       Request::redirect(null, null, null, 'reviewForms');
00229    }
00230 
00234    function copyReviewForm($args) {
00235       $this->validate();
00236 
00237       $reviewFormId = isset($args[0]) ? (int)$args[0] : null;
00238 
00239       $conference =& Request::getConference();
00240       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00241       $reviewForm =& $reviewFormDao->getReviewForm($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId());
00242 
00243       if (isset($reviewForm)) {
00244          $reviewForm->setActive(0);
00245          $reviewForm->setSequence(REALLY_BIG_NUMBER);
00246          $newReviewFormId = $reviewFormDao->insertObject($reviewForm);
00247          $reviewFormDao->resequenceReviewForms(ASSOC_TYPE_CONFERENCE, $conference->getId());
00248 
00249          $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
00250          $reviewFormElements =& $reviewFormElementDao->getReviewFormElements($reviewFormId);
00251          foreach ($reviewFormElements as $reviewFormElement) {
00252             $reviewFormElement->setReviewFormId($newReviewFormId);
00253             $reviewFormElement->setSequence(REALLY_BIG_NUMBER);
00254             $reviewFormElementDao->insertObject($reviewFormElement);
00255             $reviewFormElementDao->resequenceReviewFormElements($newReviewFormId);
00256          }
00257 
00258       }
00259 
00260       Request::redirect(null, null, null, 'reviewForms');
00261    }
00262 
00266    function moveReviewForm() {
00267       $this->validate();
00268 
00269       $conference =& Request::getConference();
00270       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00271       $reviewForm =& $reviewFormDao->getReviewForm(Request::getUserVar('reviewFormId'), ASSOC_TYPE_CONFERENCE, $conference->getId());
00272 
00273       if (isset($reviewForm)) {
00274          $reviewForm->setSequence($reviewForm->getSequence() + (Request::getUserVar('d') == 'u' ? -1.5 : 1.5));
00275          $reviewFormDao->updateObject($reviewForm);
00276          $reviewFormDao->resequenceReviewForms(ASSOC_TYPE_CONFERENCE, $conference->getId());
00277       }
00278 
00279       Request::redirect(null, null, null, 'reviewForms');
00280    }
00281 
00285    function reviewFormElements($args) {
00286       $this->validate();
00287 
00288       $reviewFormId = isset($args[0]) ? $args[0] : null;
00289 
00290       $conference =& Request::getConference();
00291       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00292       $reviewForm =& $reviewFormDao->getReviewForm($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId());
00293 
00294       if (!isset($reviewForm) || $reviewForm->getCompleteCount() != 0 || $reviewForm->getIncompleteCount() != 0) {
00295          Request::redirect(null, null, null, 'reviewForms');
00296       }
00297 
00298       $rangeInfo =& Handler::getRangeInfo('reviewFormElements');
00299       $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
00300       $reviewFormElements =& $reviewFormElementDao->getReviewFormElementsByReviewForm($reviewFormId, $rangeInfo);
00301 
00302       $unusedReviewFormTitles =& $reviewFormDao->getTitlesByAssocId(ASSOC_TYPE_CONFERENCE, $conference->getId(), 0);
00303 
00304       $this->setupTemplate(true, $reviewForm);
00305       $templateMgr =& TemplateManager::getManager();
00306 
00307       $templateMgr->assign_by_ref('unusedReviewFormTitles', $unusedReviewFormTitles);
00308       $templateMgr->assign_by_ref('reviewFormElements', $reviewFormElements);
00309       $templateMgr->assign('reviewFormId', $reviewFormId);
00310       import('reviewForm.ReviewFormElement');
00311       $templateMgr->assign_by_ref('reviewFormElementTypeOptions', ReviewFormElement::getReviewFormElementTypeOptions());
00312       $templateMgr->assign('helpTopicId','conference.managementPages.reviewForms');
00313       $templateMgr->display('manager/reviewForms/reviewFormElements.tpl');
00314    }
00315 
00319    function createReviewFormElement($args) {
00320       $this->editReviewFormElement($args);
00321    }
00322 
00327    function editReviewFormElement($args) {
00328       $this->validate();
00329 
00330       $reviewFormId = isset($args[0]) ? (int)$args[0] : null;
00331       $reviewFormElementId = isset($args[1]) ? (int) $args[1] : null;
00332 
00333       $conference =& Request::getConference();
00334       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00335       $reviewForm =& $reviewFormDao->getReviewForm($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId());
00336       $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
00337 
00338       if (!isset($reviewForm) || $reviewForm->getCompleteCount() != 0 || $reviewForm->getIncompleteCount() != 0 || ($reviewFormElementId != null && !$reviewFormElementDao->reviewFormElementExists($reviewFormElementId, $reviewFormId))) {
00339          Request::redirect(null, null, null, 'reviewFormElements', array($reviewFormId));
00340       }
00341 
00342       $this->setupTemplate(true, $reviewForm);
00343       $templateMgr =& TemplateManager::getManager();
00344 
00345       if ($reviewFormElementId == null) {
00346          $templateMgr->assign('pageTitle', 'manager.reviewFormElements.create');
00347       } else {
00348          $templateMgr->assign('pageTitle', 'manager.reviewFormElements.edit');
00349       }
00350 
00351       import('manager.form.ReviewFormElementForm');
00352       $reviewFormElementForm = new ReviewFormElementForm($reviewFormId, $reviewFormElementId);
00353       if ($reviewFormElementForm->isLocaleResubmit()) {
00354          $reviewFormElementForm->readInputData();
00355       } else {
00356          $reviewFormElementForm->initData();
00357       }
00358 
00359       $reviewFormElementForm->display();
00360    }
00361 
00365    function updateReviewFormElement() {
00366       $this->validate();
00367 
00368       $reviewFormId = Request::getUserVar('reviewFormId') === null? null : (int) Request::getUserVar('reviewFormId');
00369       $reviewFormElementId = Request::getUserVar('reviewFormElementId') === null? null : (int) Request::getUserVar('reviewFormElementId');
00370 
00371       $conference =& Request::getConference();
00372       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00373       $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
00374 
00375       $reviewForm =& $reviewFormDao->getReviewForm($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId());
00376       $this->setupTemplate(true, $reviewForm);
00377 
00378       if (!$reviewFormDao->unusedReviewFormExists($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId()) || ($reviewFormElementId != null && !$reviewFormElementDao->reviewFormElementExists($reviewFormElementId, $reviewFormId))) {
00379          Request::redirect(null, null, null, 'reviewFormElements', array($reviewFormId));
00380       }
00381 
00382       import('manager.form.ReviewFormElementForm');
00383       $reviewFormElementForm = new ReviewFormElementForm($reviewFormId, $reviewFormElementId);
00384       $reviewFormElementForm->readInputData();
00385       $formLocale = $reviewFormElementForm->getFormLocale();
00386 
00387       // Reorder response items
00388       $response = $reviewFormElementForm->getData('possibleResponses');
00389       if (isset($response[$formLocale]) && is_array($response[$formLocale])) {
00390          usort($response[$formLocale], create_function('$a,$b','return $a[\'order\'] == $b[\'order\'] ? 0 : ($a[\'order\'] < $b[\'order\'] ? -1 : 1);'));
00391       }
00392       $reviewFormElementForm->setData('possibleResponses', $response);
00393 
00394       if (Request::getUserVar('addResponse')) {
00395          // Add a response item
00396          $editData = true;
00397          $response = $reviewFormElementForm->getData('possibleResponses');
00398          if (!isset($response[$formLocale]) || !is_array($response[$formLocale])) {
00399             $response[$formLocale] = array();
00400             $lastOrder = 0;
00401          } else {
00402             $lastOrder = $response[$formLocale][count($response[$formLocale])-1]['order'];
00403          }
00404          array_push($response[$formLocale], array('order' => $lastOrder+1));
00405          $reviewFormElementForm->setData('possibleResponses', $response);
00406 
00407       } else if (($delResponse = Request::getUserVar('delResponse')) && count($delResponse) == 1) {
00408          // Delete a response item
00409          $editData = true;
00410          list($delResponse) = array_keys($delResponse);
00411          $delResponse = (int) $delResponse;
00412          $response = $reviewFormElementForm->getData('possibleResponses');
00413          if (!isset($response[$formLocale])) $response[$formLocale] = array();
00414          array_splice($response[$formLocale], $delResponse, 1);
00415          $reviewFormElementForm->setData('possibleResponses', $response);
00416       }
00417 
00418       if (!isset($editData) && $reviewFormElementForm->validate()) {
00419          $reviewFormElementForm->execute();
00420          Request::redirect(null, null, null, 'reviewFormElements', array($reviewFormId));
00421       } else {
00422          $conference =& Request::getConference();
00423          $templateMgr =& TemplateManager::getManager();
00424          if ($reviewFormElementId == null) {
00425             $templateMgr->assign('pageTitle', 'manager.reviewFormElements.create');
00426          } else {
00427             $templateMgr->assign('pageTitle', 'manager.reviewFormElements.edit');
00428          }
00429 
00430          $reviewFormElementForm->display();
00431       }
00432    }
00433 
00438    function deleteReviewFormElement($args) {
00439       $this->validate();
00440 
00441       $reviewFormId = isset($args[0]) ? (int)$args[0] : null;
00442       $reviewFormElementId = isset($args[1]) ? (int) $args[1] : null;
00443 
00444       $conference =& Request::getConference();
00445       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00446 
00447       if ($reviewFormDao->unusedReviewFormExists($reviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId())) {
00448          $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
00449          $reviewFormElementDao->deleteById($reviewFormElementId);
00450       }
00451       Request::redirect(null, null, null, 'reviewFormElements', array($reviewFormId));
00452    }
00453 
00457    function moveReviewFormElement() {
00458       $this->validate();
00459 
00460       $conference =& Request::getConference();
00461       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00462       $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
00463       $reviewFormElement =& $reviewFormElementDao->getReviewFormElement(Request::getUserVar('reviewFormElementId'));
00464 
00465       if (isset($reviewFormElement) && $reviewFormDao->unusedReviewFormExists($reviewFormElement->getReviewFormId(), ASSOC_TYPE_CONFERENCE, $conference->getId())) {
00466          $reviewFormElement->setSequence($reviewFormElement->getSequence() + (Request::getUserVar('d') == 'u' ? -1.5 : 1.5));
00467          $reviewFormElementDao->updateObject($reviewFormElement);
00468          $reviewFormElementDao->resequenceReviewFormElements($reviewFormElement->getReviewFormId());
00469       }
00470 
00471       Request::redirect(null, null, null, 'reviewFormElements', array($reviewFormElement->getReviewFormId()));
00472    }
00473 
00477    function copyReviewFormElement() {
00478       $this->validate();
00479 
00480       $copy = Request::getUserVar('copy');
00481       $targetReviewFormId = Request::getUserVar('targetReviewForm');
00482 
00483       $conference =& Request::getConference();
00484       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00485 
00486       if (is_array($copy) && $reviewFormDao->unusedReviewFormExists($targetReviewFormId, ASSOC_TYPE_CONFERENCE, $conference->getId())) {
00487          $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
00488          foreach ($copy as $reviewFormElementId) {
00489             $reviewFormElement =& $reviewFormElementDao->getReviewFormElement($reviewFormElementId);
00490             if (isset($reviewFormElement) && $reviewFormDao->unusedReviewFormExists($reviewFormElement->getReviewFormId(), ASSOC_TYPE_CONFERENCE, $conference->getId())) {
00491                $reviewFormElement->setReviewFormId($targetReviewFormId);
00492                $reviewFormElement->setSequence(REALLY_BIG_NUMBER);
00493                $reviewFormElementDao->insertObject($reviewFormElement);
00494                $reviewFormElementDao->resequenceReviewFormElements($targetReviewFormId);
00495             }
00496             unset($reviewFormElement);
00497          }
00498       }
00499 
00500       Request::redirect(null, null, null, 'reviewFormElements', array($targetReviewFormId));
00501    }
00502 
00503    function setupTemplate($subclass = false, $reviewForm = null) {
00504       parent::setupTemplate(true);
00505       if ($subclass) {
00506          $templateMgr =& TemplateManager::getManager();
00507          $templateMgr->append('pageHierarchy', array(Request::url(null, null, 'manager', 'reviewForms'), 'manager.reviewForms'));
00508       }
00509       if ($reviewForm) {
00510          $templateMgr->append('pageHierarchy', array(Request::url(null, null, 'manager', 'editReviewForm', $reviewForm->getId()), $reviewForm->getLocalizedTitle(), true));
00511       }
00512    }
00513 }
00514 
00515 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7