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

controllers/grid/content/announcements/form/AnnouncementForm.inc.php

00001 <?php
00015 import('lib.pkp.classes.manager.form.PKPAnnouncementForm');
00016 
00017 class AnnouncementForm extends PKPAnnouncementForm {
00018 
00020    var $_readOnly;
00021 
00028    function AnnouncementForm($pressId, $announcementId = null, $readOnly = false) {
00029       parent::PKPAnnouncementForm($pressId, $announcementId);
00030 
00031       $this->_readOnly = $readOnly;
00032 
00033       // Validate date expire.
00034       $this->addCheck(new FormValidatorCustom($this, 'dateExpire', 'optional', 'manager.announcements.form.dateExpireValid', create_function('$dateExpire', '$today = getDate(); $todayTimestamp = mktime(0, 0, 0, $today[\'mon\'], $today[\'mday\'], $today[\'year\']); return (strtotime($dateExpire) > $todayTimestamp);')));
00035 
00036       // If provided, announcement type is valid
00037       $this->addCheck(new FormValidatorCustom($this, 'typeId', 'optional', 'manager.announcements.form.typeIdValid', create_function('$typeId, $pressId', '$announcementTypeDao =& DAORegistry::getDAO(\'AnnouncementTypeDAO\'); if((int)$typeId === 0) { return true; } else { return $announcementTypeDao->announcementTypeExistsByTypeId($typeId, ASSOC_TYPE_PRESS, $pressId);}'), array($pressId)));
00038    }
00039 
00040 
00041    //
00042    // Getters and Setters
00043    //
00047    function isReadOnly() {
00048       return $this->_readOnly;
00049    }
00050 
00051 
00052    //
00053    // Extended methods from Form
00054    //
00058    function fetch($request) {
00059       $templateMgr =& TemplateManager::getManager();
00060       $templateMgr->assign('readOnly', $this->isReadOnly());
00061       $templateMgr->assign('selectedTypeId', $this->getData('typeId'));
00062 
00063       $announcementDao =& DAORegistry::getDAO('AnnouncementDAO');
00064       $announcement =& $announcementDao->getById($this->announcementId);
00065       $templateMgr->assign_by_ref('announcement', $announcement);
00066 
00067       $announcementTypeDao =& DAORegistry::getDAO('AnnouncementTypeDAO');
00068       list($assocType, $assocId) = $this->_getAnnouncementTypesAssocId();
00069       $announcementTypeFactory =& $announcementTypeDao->getByAssoc($assocType, $assocId);
00070 
00071       $announcementTypeOptions = array();
00072       if (!$announcementTypeFactory->wasEmpty()) {
00073          $announcementTypeOptions = array(0 => __('common.none'));
00074       }
00075       while ($announcementType =& $announcementTypeFactory->next()) {
00076          $announcementTypeOptions[$announcementType->getId()] = $announcementType->getLocalizedTypeName();
00077          unset($announcementType);
00078       }
00079       $templateMgr->assign('announcementTypes', $announcementTypeOptions);
00080 
00081 
00082       return parent::fetch($request, 'controllers/grid/content/announcements/form/announcementForm.tpl');
00083    }
00084 
00085    //
00086    // Extended methods from PKPAnnouncementForm
00087    //
00091    function readInputData() {
00092       parent::readInputData();
00093       $this->readUserVars(array('dateExpire'));
00094    }
00095 
00099    function execute(&$request) {
00100       $announcement = parent::execute();
00101       $pressId = $this->getContextId();
00102 
00103       // Send a notification to associated users
00104       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00105       $notificationUsers = array();
00106       $allUsers = $userGroupDao->getUsersByContextId($pressId);
00107       while (!$allUsers->eof()) {
00108          $user =& $allUsers->next();
00109          $notificationUsers[] = array('id' => $user->getId());
00110          unset($user);
00111       }
00112       $notificationManager = new NotificationManager();
00113       foreach ($notificationUsers as $userRole) {
00114          $notificationManager->createNotification(
00115             $request, $userRole['id'], NOTIFICATION_TYPE_NEW_ANNOUNCEMENT,
00116             $pressId, ASSOC_TYPE_ANNOUNCEMENT, $announcement->getId()
00117          );
00118       }
00119       $notificationManager->sendToMailingList($request,
00120          $notificationManager->createNotification(
00121             $request, UNSUBSCRIBED_USER_NOTIFICATION, NOTIFICATION_TYPE_NEW_ANNOUNCEMENT,
00122             $pressId, ASSOC_TYPE_ANNOUNCEMENT, $announcement->getId()
00123          )
00124       );
00125    }
00126 
00127 
00128    //
00129    // Implement protected methods from PKPAnnouncementForm.
00130    //
00134    function setDateExpire(&$announcement) {
00135       /* @var $announcement Announcement */
00136       $dateExpire = $this->getData('dateExpire');
00137       if ($dateExpire) {
00138          $announcement->setDateExpire(DAO::formatDateToDB($dateExpire, null, false));
00139       } else {
00140          // No date passed but null is acceptable for
00141          // announcements.
00142          $announcement->setDateExpire(null);
00143       }
00144       return true;
00145    }
00146 
00147 
00148    //
00149    // Private helper methdos.
00150    //
00154    function _getAnnouncementTypesAssocId() {
00155       $pressId = $this->getContextId();
00156       return array(ASSOC_TYPE_PRESS, $pressId);
00157    }
00158 
00163    function _setAnnouncementAssocId(&$announcement) {
00164       $pressId = $this->getContextId();
00165       $announcement->setAssocType(ASSOC_TYPE_PRESS);
00166       $announcement->setAssocId($pressId);
00167    }
00168 }
00169 
00170 ?>

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