Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
AnnouncementForm.inc.php
1 <?php
16 import('lib.pkp.classes.manager.form.PKPAnnouncementForm');
17 
19 
21  var $_readOnly;
22 
29  function AnnouncementForm($journalId, $announcementId = null, $readOnly = false) {
30  parent::PKPAnnouncementForm($journalId, $announcementId);
31 
32  $this->_readOnly = $readOnly;
33 
34  // Validate date expire.
35  $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);')));
36 
37  // If provided, announcement type is valid
38  $this->addCheck(new FormValidatorCustom($this, 'typeId', 'optional', 'manager.announcements.form.typeIdValid', create_function('$typeId, $journalId', '$announcementTypeDao = DAORegistry::getDAO(\'AnnouncementTypeDAO\'); if((int)$typeId === 0) { return true; } else { return $announcementTypeDao->announcementTypeExistsByTypeId($typeId, ASSOC_TYPE_JOURNAL, $journalId);}'), array($journalId)));
39  }
40 
41 
42  //
43  // Getters and Setters
44  //
48  function isReadOnly() {
49  return $this->_readOnly;
50  }
51 
52 
53  //
54  // Extended methods from Form
55  //
59  function fetch($request) {
60  $templateMgr = TemplateManager::getManager($request);
61  $templateMgr->assign('readOnly', $this->isReadOnly());
62  $templateMgr->assign('selectedTypeId', $this->getData('typeId'));
63 
64  $announcementDao = DAORegistry::getDAO('AnnouncementDAO');
65  $announcement = $announcementDao->getById($this->announcementId);
66  $templateMgr->assign('announcement', $announcement);
67 
68  $announcementTypeDao = DAORegistry::getDAO('AnnouncementTypeDAO');
69  list($assocType, $assocId) = $this->_getAnnouncementTypesAssocId();
70  $announcementTypeFactory = $announcementTypeDao->getByAssoc($assocType, $assocId);
71 
72  $announcementTypeOptions = array();
73  if (!$announcementTypeFactory->wasEmpty()) {
74  $announcementTypeOptions = array(0 => __('common.none'));
75  }
76  while ($announcementType = $announcementTypeFactory->next()) {
77  $announcementTypeOptions[$announcementType->getId()] = $announcementType->getLocalizedTypeName();
78  }
79  $templateMgr->assign('announcementTypes', $announcementTypeOptions);
80 
81 
82  return parent::fetch($request, 'controllers/grid/announcements/form/announcementForm.tpl');
83  }
84 
85  //
86  // Extended methods from PKPAnnouncementForm
87  //
91  function readInputData() {
92  parent::readInputData();
93  $this->readUserVars(array('dateExpire'));
94  }
95 
99  function execute($request) {
100  $announcement = parent::execute();
101  $journalId = $this->getContextId();
103  // Send a notification to associated users
104  import('classes.notification.NotificationManager');
105  $notificationManager = new NotificationManager();
106  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
107  $notificationUsers = array();
108  $allUsers = $userGroupDao->getUsersByContextId($journalId);
109  while ($user = $allUsers->next()) {
110  $notificationUsers[] = array('id' => $user->getId());
111  }
112  foreach ($notificationUsers as $userRole) {
113  $notificationManager->createNotification(
114  $request, $userRole['id'], NOTIFICATION_TYPE_NEW_ANNOUNCEMENT,
115  $journalId, ASSOC_TYPE_ANNOUNCEMENT, $announcement->getId()
116  );
117  }
118  $notificationManager->sendToMailingList($request,
119  $notificationManager->createNotification(
120  $request, UNSUBSCRIBED_USER_NOTIFICATION, NOTIFICATION_TYPE_NEW_ANNOUNCEMENT,
121  $journalId, ASSOC_TYPE_ANNOUNCEMENT, $announcement->getId()
122  )
123  );
124  return $announcement->getId();
125  }
126 
127 
128  //
129  // Implement protected methods from PKPAnnouncementForm.
130  //
134  function setDateExpire(&$announcement) {
135  /* @var $announcement Announcement */
136  $dateExpire = $this->getData('dateExpire');
137  if ($dateExpire) {
138  $announcement->setDateExpire(DAO::formatDateToDB($dateExpire, null, false));
139  } else {
140  // No date passed but null is acceptable for
141  // announcements.
142  $announcement->setDateExpire(null);
143  }
144  return true;
145  }
146 
147 
148  //
149  // Private helper methdos.
150  //
154  function _getAnnouncementTypesAssocId() {
155  return array(ASSOC_TYPE_JOURNAL, $this->getContextId());
156  }
161  function _setAnnouncementAssocId($announcement) {
162  $announcement->setAssocType(ASSOC_TYPE_JOURNAL);
163  $announcement->setAssocId($this->getContextId());
164  }
165 }
166 
167 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:397
formatDateToDB($date, $defaultNumWeeks=null, $acceptPastDate=true)
Definition: DAO.inc.php:635
Form validation check with a custom user function performing the validation check.
setDateExpire(&$announcement)
readUserVars($vars)
Definition: Form.inc.php:365
AnnouncementForm($journalId, $announcementId=null, $readOnly=false)
getData($key)
Definition: Form.inc.php:211
_setAnnouncementAssocId($announcement)
Form for to read/create/edit announcements.
Form for managers to create/edit announcements.