pages/director/DirectorHandler.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 
00019 import('trackDirector.TrackDirectorHandler');
00020 
00021 define('DIRECTOR_TRACK_HOME', 0);
00022 define('DIRECTOR_TRACK_SUBMISSIONS', 1);
00023 
00024 // Filter director
00025 define('FILTER_DIRECTOR_ALL', 0);
00026 define('FILTER_DIRECTOR_ME', 1);
00027 
00028 import ('submission.director.DirectorAction');
00029 import('handler.validation.HandlerValidatorRoles');
00030 
00031 class DirectorHandler extends TrackDirectorHandler {
00035    function DirectorHandler() {
00036       parent::TrackDirectorHandler();
00037 
00038       $this->addCheck(new HandlerValidatorConference($this));
00039       $this->addCheck(new HandlerValidatorSchedConf($this));
00040       $this->addCheck(new HandlerValidatorRoles($this, true, null, null, array(ROLE_ID_DIRECTOR)));      
00041    }
00042 
00047    function index($args) {
00048       $this->validate();
00049       $this->setupTemplate(DIRECTOR_TRACK_HOME);
00050 
00051       $templateMgr =& TemplateManager::getManager();
00052       $schedConf =& Request::getSchedConf();
00053       $directorSubmissionDao =& DAORegistry::getDAO('DirectorSubmissionDAO');
00054       $submissionsCount =& $directorSubmissionDao->getDirectorSubmissionsCount($schedConf->getId());
00055       $templateMgr->assign('submissionsCount', $submissionsCount);
00056       $templateMgr->assign('helpTopicId', 'editorial.directorsRole');
00057       $templateMgr->display('director/index.tpl');
00058    }
00059 
00063    function submissions($args) {
00064       $this->validate();
00065       $this->setupTemplate(DIRECTOR_TRACK_SUBMISSIONS);
00066 
00067       $schedConf =& Request::getSchedConf();
00068       $schedConfId = $schedConf->getId();
00069       $user =& Request::getUser();
00070 
00071       $directorSubmissionDao =& DAORegistry::getDAO('DirectorSubmissionDAO');
00072       $trackDao =& DAORegistry::getDAO('TrackDAO');
00073 
00074       $page = isset($args[0]) ? $args[0] : '';
00075       $tracks =& $trackDao->getTrackTitles($schedConfId);
00076 
00077       $filterDirectorOptions = array(
00078          FILTER_DIRECTOR_ALL => AppLocale::Translate('director.allDirectors'),
00079          FILTER_DIRECTOR_ME => AppLocale::Translate('director.me')
00080       );
00081 
00082       $filterTrackOptions = array(
00083          FILTER_TRACK_ALL => AppLocale::Translate('director.allTracks')
00084       ) + $tracks;
00085 
00086       // Get the user's search conditions, if any
00087       $searchField = Request::getUserVar('searchField');
00088       $searchMatch = Request::getUserVar('searchMatch');
00089       $search = Request::getUserVar('search');
00090 
00091       $sort = Request::getUserVar('sort');
00092       $sortDirection = Request::getUserVar('sortDirection');
00093 
00094       switch($page) {
00095          case 'submissionsUnassigned':
00096             $functionName = 'getDirectorSubmissionsUnassigned';
00097             $helpTopicId = 'editorial.directorsRole.submissions.unassigned';
00098             $sort = isset($sort) ? $sort : 'id';
00099             break;
00100          case 'submissionsAccepted':
00101             $functionName = 'getDirectorSubmissionsAccepted';
00102             $helpTopicId = 'editorial.directorsRole.submissions.presentations';
00103             $sort = isset($sort) ? $sort : 'seq';
00104             break;
00105          case 'submissionsArchives':
00106             $functionName = 'getDirectorSubmissionsArchives';
00107             $helpTopicId = 'editorial.directorsRole.submissions.archives';
00108             $sort = isset($sort) ? $sort : 'id';
00109             break;
00110          default:
00111             $page = 'submissionsInReview';
00112             $functionName = 'getDirectorSubmissionsInReview';
00113             $helpTopicId = 'editorial.directorsRole.submissions.inReview';
00114             $sort = isset($sort) ? $sort : 'id';
00115       }
00116 
00117       $filterDirector = Request::getUserVar('filterDirector');
00118       if ($filterDirector != '' && array_key_exists($filterDirector, $filterDirectorOptions)) {
00119          $user->updateSetting('filterDirector', $filterDirector, 'int', $schedConfId);
00120       } else {
00121          $filterDirector = $user->getSetting('filterDirector', $schedConfId);
00122          if ($filterDirector == null) {
00123             $filterDirector = FILTER_DIRECTOR_ALL;
00124             $user->updateSetting('filterDirector', $filterDirector, 'int', $schedConfId);
00125          }  
00126       }
00127 
00128       if ($filterDirector == FILTER_DIRECTOR_ME) {
00129          $directorId = $user->getId();
00130       } else {
00131          $directorId = FILTER_DIRECTOR_ALL;
00132       }
00133 
00134       $filterTrack = Request::getUserVar('filterTrack');
00135       if ($filterTrack != '' && array_key_exists($filterTrack, $filterTrackOptions)) {
00136          $user->updateSetting('filterTrack', $filterTrack, 'int', $schedConfId);
00137       } else {
00138          $filterTrack = $user->getSetting('filterTrack', $schedConfId);
00139          if ($filterTrack == null) {
00140             $filterTrack = FILTER_TRACK_ALL;
00141             $user->updateSetting('filterTrack', $filterTrack, 'int', $schedConfId);
00142          }  
00143       }
00144 
00145       $rangeInfo =& Handler::getRangeInfo('submissions', array($functionName, (string) $searchField, (string) $searchMatch, (string) $search));
00146       while (true) {
00147          $submissions =& $directorSubmissionDao->$functionName(
00148             $schedConfId,
00149             $filterTrack,
00150             $directorId,
00151             $searchField,
00152             $searchMatch,
00153             $search,
00154             null,
00155             null,
00156             null,
00157             $rangeInfo,
00158             $sort,
00159             $sortDirection
00160          );
00161          if ($submissions->isInBounds()) break;
00162          unset($rangeInfo);
00163          $rangeInfo =& $submissions->getLastPageRangeInfo();
00164          unset($submissions);
00165       }
00166 
00167       if ($sort == 'status') {
00168          // Sort all submissions by status, which is too complex to do in the DB
00169          $submissionsArray = $submissions->toArray();
00170          $compare = create_function('$s1, $s2', 'return strcmp($s1->getSubmissionStatus(), $s2->getSubmissionStatus());');
00171          usort ($submissionsArray, $compare);
00172          if($sortDirection == 'DESC') {
00173             $submissionsArray = array_reverse($submissionsArray);
00174          }
00175          // Convert submission array back to an ItemIterator class
00176          import('core.ArrayItemIterator');
00177          $submissions =& ArrayItemIterator::fromRangeInfo($submissionsArray, $rangeInfo);
00178       }
00179 
00180       $templateMgr =& TemplateManager::getManager();
00181       $templateMgr->assign('pageToDisplay', $page);
00182       $templateMgr->assign('director', $user->getFullName());
00183       $templateMgr->assign('directorOptions', $filterDirectorOptions);
00184       $templateMgr->assign('trackOptions', $filterTrackOptions);
00185       $templateMgr->assign_by_ref('submissions', $submissions);
00186       $templateMgr->assign('filterDirector', $filterDirector);
00187       $templateMgr->assign('filterTrack', $filterTrack);
00188       $templateMgr->assign('yearOffsetFuture', SCHED_CONF_DATE_YEAR_OFFSET_FUTURE);
00189       $templateMgr->assign('durationOptions', TrackDirectorHandler::getDurationOptions());
00190 
00191       // Set search parameters
00192       $duplicateParameters = array(
00193          'searchField', 'searchMatch', 'search'
00194       );
00195       foreach ($duplicateParameters as $param)
00196          $templateMgr->assign($param, Request::getUserVar($param));
00197 
00198       $templateMgr->assign('reviewType', Array(
00199          REVIEW_STAGE_ABSTRACT => __('submission.abstract'),
00200          REVIEW_STAGE_PRESENTATION => __('submission.paper')
00201       ));
00202 
00203       $templateMgr->assign('fieldOptions', Array(
00204          SUBMISSION_FIELD_TITLE => 'paper.title',
00205          SUBMISSION_FIELD_AUTHOR => 'user.role.author',
00206          SUBMISSION_FIELD_DIRECTOR => 'user.role.director',
00207          SUBMISSION_FIELD_REVIEWER => 'user.role.reviewer'
00208       ));
00209 
00210       $templateMgr->assign('helpTopicId', $helpTopicId);
00211       $templateMgr->assign('sort', $sort);
00212       $templateMgr->assign('sortDirection', $sortDirection);
00213       $templateMgr->display('director/submissions.tpl');
00214    }
00215 
00219    function deleteEditAssignment($args) {
00220       $this->validate();
00221 
00222       $schedConf =& Request::getSchedConf();
00223       $editId = (int) (isset($args[0])?$args[0]:0);
00224 
00225       $editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00226       $editAssignment =& $editAssignmentDao->getEditAssignment($editId);
00227 
00228       if ($editAssignment) {
00229          $paperDao =& DAORegistry::getDAO('PaperDAO');
00230          $paper =& $paperDao->getPaper($editAssignment->getPaperId());
00231 
00232          if ($paper && $paper->getSchedConfId() === $schedConf->getId()) {
00233             $editAssignmentDao->deleteEditAssignmentById($editAssignment->getEditId());
00234             Request::redirect(null, null, null, 'submission', $paper->getId());
00235          }
00236       }
00237 
00238       Request::redirect(null, null, null, 'submissions');
00239    }
00240 
00244    function assignDirector($args) {
00245       $this->validate();
00246       AppLocale::requireComponents(array(LOCALE_COMPONENT_PKP_MANAGER)); // manager.people.noneEnrolled
00247 
00248       $schedConf =& Request::getSchedConf();
00249       $paperId = Request::getUserVar('paperId');
00250       $directorId = Request::getUserVar('directorId');
00251       $roleDao =& DAORegistry::getDAO('RoleDAO');
00252 
00253       $isDirector = $roleDao->roleExists($schedConf->getConferenceId(), $schedConf->getId(), $directorId, ROLE_ID_DIRECTOR) || $roleDao->roleExists($schedConf->getConferenceId(), 0, $directorId, ROLE_ID_DIRECTOR);
00254       $isTrackDirector = $roleDao->roleExists($schedConf->getConferenceId(), $schedConf->getId(), $directorId, ROLE_ID_TRACK_DIRECTOR) || $roleDao->roleExists($schedConf->getConferenceId(), 0, $directorId, ROLE_ID_TRACK_DIRECTOR);
00255 
00256       if (isset($directorId) && $directorId != null && ($isDirector || $isTrackDirector)) {
00257          // A valid track director has already been chosen;
00258          // either prompt with a modifiable email or, if this
00259          // has been done, send the email and store the director
00260          // selection.
00261 
00262          $this->setupTemplate(DIRECTOR_TRACK_SUBMISSIONS, $paperId, 'summary');
00263 
00264          // FIXME: Prompt for due date.
00265          if (DirectorAction::assignDirector($paperId, $directorId, $isDirector, Request::getUserVar('send'))) {
00266             Request::redirect(null, null, null, 'submission', $paperId);
00267          }
00268       } else {
00269          // Allow the user to choose a track director or director.
00270          $this->setupTemplate(DIRECTOR_TRACK_SUBMISSIONS, $paperId, 'summary');
00271 
00272          $searchType = null;
00273          $searchMatch = null;
00274          $search = Request::getUserVar('search');
00275          $searchInitial = Request::getUserVar('searchInitial');
00276          if (!empty($search)) {
00277             $searchType = Request::getUserVar('searchField');
00278             $searchMatch = Request::getUserVar('searchMatch');
00279 
00280          } elseif (!empty($searchInitial)) {
00281             $searchInitial = String::strtoupper($searchInitial);
00282             $searchType = USER_FIELD_INITIAL;
00283             $search = $searchInitial;
00284          }
00285 
00286          $forDirectors = isset($args[0]) && $args[0] === 'director';
00287          $rangeInfo =& Handler::getRangeInfo('directors', array($forDirectors, (string) $searchType, (string) $search, (string) $searchMatch));
00288          $directorSubmissionDao =& DAORegistry::getDAO('DirectorSubmissionDAO');
00289 
00290          if ($forDirectors) {
00291             $roleName = 'user.role.director';
00292             $rolePath = 'director';
00293             while (true) {
00294                $directors =& $directorSubmissionDao->getUsersNotAssignedToPaper($schedConf->getId(), $paperId, RoleDAO::getRoleIdFromPath('director'), $searchType, $search, $searchMatch, $rangeInfo);
00295                if ($directors->isInBounds()) break;
00296                unset($rangeInfo);
00297                $rangeInfo =& $directors->getLastPageRangeInfo();
00298                unset($directors);
00299             }
00300          } else {
00301             $roleName = 'user.role.trackDirector';
00302             $rolePath = 'trackDirector';
00303             while (true) {
00304                $directors =& $directorSubmissionDao->getUsersNotAssignedToPaper($schedConf->getId(), $paperId, RoleDAO::getRoleIdFromPath('trackDirector'), $searchType, $search, $searchMatch, $rangeInfo);
00305                if ($directors->isInBounds()) break;
00306                unset($rangeInfo);
00307                $rangeInfo =& $directors->getLastPageRangeInfo();
00308                unset($directors);
00309             }
00310          }
00311 
00312          $templateMgr =& TemplateManager::getManager();
00313 
00314          $templateMgr->assign_by_ref('directors', $directors);
00315          $templateMgr->assign('roleName', $roleName);
00316          $templateMgr->assign('rolePath', $rolePath);
00317          $templateMgr->assign('paperId', $paperId);
00318 
00319          $trackDao =& DAORegistry::getDAO('TrackDAO');
00320          $trackDirectorTracks =& $trackDao->getDirectorTracks($schedConf->getId());
00321 
00322          $editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00323          $directorStatistics = $editAssignmentDao->getDirectorStatistics($schedConf->getId());
00324 
00325          $templateMgr->assign_by_ref('directorTracks', $trackDirectorTracks);
00326          $templateMgr->assign('directorStatistics', $directorStatistics);
00327 
00328          $templateMgr->assign('searchField', $searchType);
00329          $templateMgr->assign('searchMatch', $searchMatch);
00330          $templateMgr->assign('search', $search);
00331          $templateMgr->assign('searchInitial', Request::getUserVar('searchInitial'));
00332 
00333          $templateMgr->assign('fieldOptions', Array(
00334             USER_FIELD_FIRSTNAME => 'user.firstName',
00335             USER_FIELD_LASTNAME => 'user.lastName',
00336             USER_FIELD_USERNAME => 'user.username',
00337             USER_FIELD_EMAIL => 'user.email'
00338          ));
00339          $templateMgr->assign('alphaList', explode(' ', __('common.alphaList')));
00340          $templateMgr->assign('helpTopicId', 'editorial.directorsRole.summaryPage.submissionManagement');
00341          $templateMgr->display('director/selectTrackDirector.tpl');
00342       }
00343    }
00344 
00348    function deleteSubmission($args) {
00349       $paperId = isset($args[0]) ? (int) $args[0] : 0;
00350       $this->validate();
00351 
00352       $schedConf =& Request::getSchedConf();
00353 
00354       $paperDao =& DAORegistry::getDAO('PaperDAO');
00355       $paper =& $paperDao->getPaper($paperId);
00356 
00357       $status = $paper->getStatus();
00358       $progress = $paper->getSubmissionProgress();
00359       $stage = $paper->getCurrentStage();
00360 
00361       if ($paper->getSchedConfId() == $schedConf->getId() && ($status == STATUS_DECLINED || $status == STATUS_ARCHIVED
00362          || ($progress != 0 && ($stage == REVIEW_STAGE_ABSTRACT || ($stage == REVIEW_STAGE_PRESENTATION && $progress < 3))))) {
00363          // Delete paper files
00364          import('file.PaperFileManager');
00365          $paperFileManager = new PaperFileManager($paperId);
00366          $paperFileManager->deletePaperTree();
00367 
00368          // Delete paper database entries
00369          $paperDao->deletePaperById($paperId);
00370       }
00371 
00372       Request::redirect(null, null, null, 'submissions', 'submissionsArchives');
00373    }
00374 
00378    function movePaper($args) {
00379       $paperId = Request::getUserVar('paperId');
00380       $schedConf =& Request::getSchedConf();
00381       $this->validate();
00382 
00383       $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00384       $publishedPaper =& $publishedPaperDao->getPublishedPaperByPaperId($paperId);
00385 
00386       if ($publishedPaper != null && $publishedPaper->getSchedConfId() == $schedConf->getId()) {
00387          $publishedPaper->setSeq($publishedPaper->getSeq() + (Request::getUserVar('d') == 'u' ? -1.5 : 1.5));
00388          $publishedPaperDao->updatePublishedPaper($publishedPaper);
00389          $publishedPaperDao->resequencePublishedPapers($publishedPaper->getTrackId(), $schedConf->getId());
00390       }
00391 
00392       Request::redirect(null, null, null, 'submissions', 'submissionsAccepted');
00393    }
00394 
00398    function notifyUsers($args) {
00399       $this->validate();
00400       $this->setupTemplate(DIRECTOR_TRACK_HOME);
00401 
00402       $userDao =& DAORegistry::getDAO('UserDAO');
00403       $roleDao =& DAORegistry::getDAO('RoleDAO');
00404       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00405       $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00406 
00407       $conference =& Request::getConference();
00408       $conferenceId = $conference->getId();
00409       $schedConf =& Request::getSchedConf();
00410       $schedConfId = $schedConf->getId();
00411 
00412       $user =& Request::getUser();
00413       $templateMgr =& TemplateManager::getManager();
00414 
00415       import('mail.MassMail');
00416       $email = new MassMail('PUBLISH_NOTIFY');
00417 
00418       if (Request::getUserVar('send') && !$email->hasErrors()) {
00419          $email->addRecipient($user->getEmail(), $user->getFullName());
00420 
00421          switch (Request::getUserVar('whichUsers')) {
00422             case 'allPaidRegistrants':
00423                $recipients =& $registrationDao->getRegisteredUsers($schedConfId);
00424                break;
00425             case 'allRegistrants':
00426                $recipients =& $registrationDao->getRegisteredUsers($schedConfId, false);
00427                break;
00428             case 'allAuthors':
00429                $recipients =& $authorDao->getAuthorsAlphabetizedBySchedConf($schedConfId, null, null, true);
00430                break;
00431             case 'allUsers':
00432                $recipients =& $roleDao->getUsersBySchedConfId($schedConfId);
00433                break;
00434             case 'allReaders':
00435             default:
00436                $recipients =& $roleDao->getUsersByRoleId(
00437                   ROLE_ID_READER,
00438                   $conferenceId,
00439                   $schedConfId
00440                );
00441                break;
00442          }
00443          while (!$recipients->eof()) {
00444             $recipient =& $recipients->next();
00445             $email->addRecipient($recipient->getEmail(), $recipient->getFullName());
00446             unset($recipient);
00447          }
00448 
00449          if (Request::getUserVar('includeToc')=='1') {
00450             $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00451             $publishedPapers =& $publishedPaperDao->getPublishedPapersInTracks($schedConfId);
00452 
00453             $templateMgr->assign_by_ref('conference', $conference);
00454             $templateMgr->assign_by_ref('schedConf', $schedConf);
00455             $templateMgr->assign('body', $email->getBody());
00456             $templateMgr->assign_by_ref('publishedPapers', $publishedPapers);
00457 
00458             $email->setBody($templateMgr->fetch('director/notifyUsersEmail.tpl'));
00459          }
00460 
00461          $callback = array(&$email, 'send');
00462          $templateMgr->setProgressFunction($callback);
00463          unset($callback);
00464 
00465          $email->setFrequency(10); // 10 emails per callback
00466          $callback = array('TemplateManager', 'updateProgressBar');
00467          $email->setCallback($callback);
00468          unset($callback);
00469 
00470          $templateMgr->assign('message', 'common.inProgress');
00471          $templateMgr->display('common/progress.tpl');
00472          echo '<script type="text/javascript">window.location = "' . Request::url(null, null, 'director') . '";</script>';
00473       } else {
00474          if (!Request::getUserVar('continued')) {
00475             $email->assignParams(array(
00476                'editorialContactSignature' => $user->getContactSignature()
00477             ));
00478          }
00479 
00480          // FIXME: There should be a better way of doing this.
00481          $authors =& $authorDao->getAuthorsAlphabetizedBySchedConf($schedConfId);
00482          $authorCount = $authors->getCount();
00483 
00484          $email->displayEditForm(
00485             Request::url(null, null, null, 'notifyUsers'),
00486             array(),
00487             'director/notifyUsers.tpl',
00488             array(
00489                'allReadersCount' => $roleDao->getSchedConfUsersCount($schedConfId, ROLE_ID_READER),
00490                'allAuthorsCount' => $authorCount,
00491                'allPaidRegistrantsCount' => $registrationDao->getRegisteredUserCount($schedConfId),
00492                'allRegistrantsCount' => $registrationDao->getRegisteredUserCount($schedConfId, false),
00493                'allUsersCount' => $roleDao->getSchedConfUsersCount($schedConfId)
00494             )
00495          );
00496       }
00497    }
00498 
00503    function setupTemplate($level = DIRECTOR_TRACK_HOME, $paperId = 0, $parentPage = null) {
00504       parent::setupTemplate();
00505       $templateMgr =& TemplateManager::getManager();
00506 
00507       $conference =& Request::getConference();
00508       $schedConf =& Request::getSchedConf();
00509       $pageHierarchy = array();
00510 
00511       if ($schedConf) {
00512          $pageHierarchy[] = array(Request::url(null, null, 'index'), $schedConf->getFullTitle(), true);
00513       } elseif ($conference) {
00514          $pageHierarchy[] = array(Request::url(null, 'index', 'index'), $conference->getConferenceTitle(), true);
00515       }
00516 
00517       $pageHierarchy[] = array(Request::url(null, null, 'user'), 'navigation.user');
00518       if ($level==DIRECTOR_TRACK_SUBMISSIONS) {
00519          $pageHierarchy[] = array(Request::url(null, null, 'director'), 'user.role.director');
00520          $pageHierarchy[] = array(Request::url(null, null, 'director', 'submissions'), 'paper.submissions');
00521       }
00522 
00523       import('submission.trackDirector.TrackDirectorAction');
00524       $submissionCrumb = TrackDirectorAction::submissionBreadcrumb($paperId, $parentPage, 'director');
00525       if (isset($submissionCrumb)) {
00526          $pageHierarchy = array_merge($pageHierarchy, $submissionCrumb);
00527       }
00528       $templateMgr->assign('pageHierarchy', $pageHierarchy);
00529    }
00530 }
00531 
00532 ?>

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