• Main Page
  • Modules
  • Classes
  • Files
  • File List

controllers/informationCenter/form/InformationCenterNotifyForm.inc.php

00001 <?php
00002 
00017 import('lib.pkp.classes.form.Form');
00018 
00019 class InformationCenterNotifyForm extends Form {
00021    var $itemId;
00022 
00024    var $itemType;
00025 
00029    function InformationCenterNotifyForm($itemId, $itemType) {
00030       parent::Form('controllers/informationCenter/notify.tpl');
00031       $this->itemId = $itemId;
00032       $this->itemType = $itemType;
00033 
00034       $this->addCheck(new FormValidatorListbuilder($this, 'users', 'informationCenter.notify.warning'));
00035       $this->addCheck(new FormValidator($this, 'message', 'required', 'informationCenter.notify.warning'));
00036       $this->addCheck(new FormValidatorPost($this));
00037    }
00038 
00043    function fetch(&$request) {
00044       $templateMgr =& TemplateManager::getManager();
00045       if($this->itemType == ASSOC_TYPE_MONOGRAPH) {
00046          $monographId = $this->itemId;
00047       } else {
00048          $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
00049          $monographFile =& $submissionFileDao->getLatestRevision($this->itemId);
00050          $monographId = $monographFile->getMonographId();
00051       }
00052 
00053       $templateMgr->assign_by_ref('monographId', $monographId);
00054       $templateMgr->assign_by_ref('itemId', $this->itemId);
00055 
00056       // All stages can choose the default template
00057       $templateKeys = array('NOTIFICATION_CENTER_DEFAULT');
00058 
00059       // template keys indexed by stageId
00060       $stageTemplates = array(
00061          WORKFLOW_STAGE_ID_SUBMISSION => array(),
00062          WORKFLOW_STAGE_ID_INTERNAL_REVIEW => array('EDITOR_ASSIGN'),
00063          WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => array('EDITOR_ASSIGN'),
00064          WORKFLOW_STAGE_ID_EDITING => array('COPYEDIT_REQUEST'),
00065          WORKFLOW_STAGE_ID_PRODUCTION => array('LAYOUT_REQUEST', 'LAYOUT_COMPLETE', 'INDEX_REQUEST', 'INDEX_COMPLETE', 'EDITOR_ASSIGN')
00066       );
00067 
00068       $monographDao =& DAORegistry::getDAO('MonographDAO');
00069       $monograph =& $monographDao->getById($monographId);
00070       $currentStageId = $monograph->getStageId();
00071 
00072       $templateKeys = array_merge($templateKeys, $stageTemplates[$currentStageId]);
00073 
00074       import('classes.mail.MonographMailTemplate');
00075 
00076       foreach ($templateKeys as $templateKey) {
00077          $template = new MonographMailTemplate($monograph, $templateKey);
00078          $template->assignParams(array());
00079          $templates[$templateKey] = $template->getSubject();
00080       }
00081 
00082       unset($templateKeys);
00083       $templateMgr->assign_by_ref('templates', $templates);
00084 
00085       // check to see if we were handed a userId from the stage participants grid.  If so,
00086       // pass that in so the list builder can pre-populate. The Listbuilder validates this.
00087 
00088       $templateMgr->assign('userId', (int) $request->getUserVar('userId'));
00089 
00090       return parent::fetch($request);
00091    }
00092 
00097    function readInputData() {
00098       $this->readUserVars(array('message', 'users', 'template'));
00099       import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
00100       $userData = $this->getData('users');
00101       ListbuilderHandler::unpack($request, $userData);
00102    }
00103 
00108    function execute(&$request) {
00109       return parent::execute($request);
00110    }
00111 
00116    function insertEntry(&$request, $newRowId) {
00117 
00118       $userDao =& DAORegistry::getDAO('UserDAO');
00119       $application =& Application::getApplication();
00120       $request =& $application->getRequest(); // need to do this because the method version is null.
00121       $fromUser =& $request->getUser();
00122 
00123       $monographDao =& DAORegistry::getDAO('MonographDAO');
00124       import('classes.mail.MonographMailTemplate');
00125 
00126       if($this->itemType == ASSOC_TYPE_MONOGRAPH) {
00127          $monographId = $this->itemId;
00128       } else {
00129          $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
00130          $monographFile =& $submissionFileDao->getLatestRevision($this->itemId);
00131          $monographId = $monographFile->getMonographId();
00132       }
00133 
00134       $monograph =& $monographDao->getById($monographId);
00135       $template = $this->getData('template');
00136 
00137       $email = new MonographMailTemplate($monograph, $template, null, null, null, false);
00138       $email->setFrom($fromUser->getEmail(), $fromUser->getFullName());
00139 
00140       import('controllers.grid.submissions.SubmissionsListGridCellProvider');
00141       $dispatcher =& $request->getDispatcher();
00142 
00143       foreach ($newRowId as $id) {
00144          $user = $userDao->getById($id);
00145          if (isset($user)) {
00146             $email->addRecipient($user->getEmail(), $user->getFullName());
00147             $email->setBody($this->getData('message'));
00148             list($page, $operation) = SubmissionsListGridCellProvider::getPageAndOperationByUserRoles($request, $monograph, $user->getId());
00149             $submissionUrl = $dispatcher->url($request, ROUTE_PAGE, null, $page, $operation, array('monographId' => $monograph->getId()));
00150 
00151             // these are for *_REQUEST emails
00152             $email->assignParams(array(
00153                // COPYEDIT_REQUEST
00154                'copyeditorName' => $user->getFullName(),
00155                'copyeditorUsername' => $user->getUsername(),
00156                'submissionCopyeditingUrl' => $submissionUrl,
00157                // LAYOUT_REQUEST
00158                'layoutEditorName' => $user->getFullName(),
00159                'submissionUrl' => $submissionUrl,
00160                'layoutEditorUsername' => $user->getUsername(),
00161                // LAYOUT_COMPLETE, INDEX_COMPLETE, EDITOR_ASSIGN
00162                'editorialContactName' => $user->getFullname(),
00163                // INDEX_REQUEST
00164                'indexerName' => $user->getFullName(),
00165                'indexerUsername' => $user->getUsername(),
00166                // EDITOR_ASSIGN
00167                'editorUsername' => $user->getUsername(),
00168             ));
00169 
00170             $this->_createNotifications($request, $monograph, $user, $template);
00171             $email->send($request);
00172             // remove the INDEX_ and LAYOUT_ tasks if a user has sent the appropriate _COMPLETE email
00173             switch ($template) {
00174                case 'LAYOUT_COMPLETE':
00175                   $this->_removeUploadTaskNotification($monograph, NOTIFICATION_TYPE_LAYOUT_ASSIGNMENT, $request);
00176                   break;
00177                case 'INDEX_COMPLETE':
00178                   $this->_removeUploadTaskNotification($monograph, NOTIFICATION_TYPE_INDEX_ASSIGNMENT, $request);
00179                   break;
00180             }
00181          }
00182       }
00183    }
00184 
00190    function deleteEntry(&$request, $rowId) {
00191       return true;
00192    }
00193 
00201    function _createNotifications(&$request, $monograph, $user, $template) {
00202 
00203       $currentStageId = $monograph->getStageId();
00204       $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00205       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00206       $stageAssignments =& $stageAssignmentDao->getBySubmissionAndStageId($monograph->getId(), $monograph->getStageId(), null, $user->getId());
00207       $notificationMgr = new NotificationManager();
00208 
00209       switch ($template) {
00210          case 'COPYEDIT_REQUEST':
00211             while ($stageAssignment =& $stageAssignments->next()) {
00212                $userGroup =& $userGroupDao->getById($stageAssignment->getUserGroupId());
00213                if (in_array($userGroup->getRoleId(), array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT))) {
00214                   import('classes.monograph.MonographFile');
00215                   $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00216                   $monographFileSignoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO');
00217                   $monographFiles =& $submissionFileDao->getLatestRevisions($monograph->getId(), MONOGRAPH_FILE_COPYEDIT);
00218                   foreach ($monographFiles as $monographFile) {
00219                      $signoffFactory =& $monographFileSignoffDao->getAllBySymbolic('SIGNOFF_COPYEDITING', $monographFile->getFileId());
00220                      while ($signoff =& $signoffFactory->next()) {
00221                         $notificationMgr->updateCopyeditRequestNotification($signoff, $user, $request);
00222                         unset($signoff);
00223                      }
00224                   }
00225                   return;
00226                }
00227             }
00228             // User not in valid role for this task/notification.
00229             break;
00230          case 'LAYOUT_REQUEST':
00231             while ($stageAssignment =& $stageAssignments->next()) {
00232                $userGroup =& $userGroupDao->getById($stageAssignment->getUserGroupId());
00233                if (in_array($userGroup->getRoleId(), array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT))) {
00234                   $notificationMgr->updateProductionRequestNotification($monograph, $user, NOTIFICATION_TYPE_LAYOUT_ASSIGNMENT, $request);
00235                   return;
00236                }
00237             }
00238             // User not in valid role for this task/notification.
00239             break;
00240          case 'INDEX_REQUEST':
00241             while ($stageAssignment =& $stageAssignments->next()) {
00242                $userGroup =& $userGroupDao->getById($stageAssignment->getUserGroupId());
00243                if (in_array($userGroup->getRoleId(), array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT))) {
00244                   $notificationMgr->updateProductionRequestNotification($monograph, $user, NOTIFICATION_TYPE_INDEX_ASSIGNMENT, $request);
00245                   return;
00246                }
00247             }
00248             // User not in valid role for this task/notification.
00249             break;
00250       }
00251    }
00252 
00260    function _removeUploadTaskNotification(&$monograph, $task, &$request) {
00261 
00262       // if this is a submission by a LAYOUT_EDITOR for a monograph in production, check
00263       // to see if there is a task notification for that and if so, clear it.
00264       $currentStageId = $monograph->getStageId();
00265       $notificationMgr = new NotificationManager();
00266 
00267       if ($currentStageId == WORKFLOW_STAGE_ID_PRODUCTION) {
00268 
00269          $user =& $request->getUser();
00270          $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00271          $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00272          $stageAssignments =& $stageAssignmentDao->getBySubmissionAndStageId($monograph->getId(), $monograph->getStageId(), null, $user->getId());
00273 
00274          while ($stageAssignment =& $stageAssignments->next()) {
00275             $userGroup =& $userGroupDao->getById($stageAssignment->getUserGroupId());
00276             if (in_array($userGroup->getRoleId(), array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT))) {
00277                $notificationMgr->deleteProductionRequestNotification($monograph, $user, $task, $request);
00278                return;
00279             }
00280          }
00281       }
00282    }
00283 }
00284 
00285 ?>

Generated on Mon Sep 17 2012 13:58:56 for Open Monograph Press by  doxygen 1.7.1