addCheck(new FormValidatorCustom($this, 'typeId', 'optional', 'manager.announcements.form.typeIdValid', create_function('$typeId, $journalId', '$announcementTypeDao =& DAORegistry::getDAO(\'AnnouncementTypeDAO\'); return $announcementTypeDao->announcementTypeExistsByTypeId($typeId, ASSOC_TYPE_JOURNAL, $journalId);'), array($journalId))); } /** * Display the form. */ function display() { $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('helpTopicId', 'journal.managementPages.announcements'); parent::display(); } function _getAnnouncementTypesAssocId() { $journalId = $this->getContextId(); return array(ASSOC_TYPE_JOURNAL, $journalId); } /** * Helper function to assign the AssocType and the AssocId * @param Announcement the announcement to be modified */ function _setAnnouncementAssocId(&$announcement) { $journalId = $this->getContextId(); $announcement->setAssocType(ASSOC_TYPE_JOURNAL); $announcement->setAssocId($journalId); } /** * Save announcement. * @param $request Request */ function execute(&$request) { $announcement = parent::execute(); $journalId = $this->getContextId(); if ($this->getData('notificationToggle')) { // Send a notification to associated users import('classes.notification.NotificationManager'); $notificationManager = new NotificationManager(); $roleDao =& DAORegistry::getDAO('RoleDAO'); $notificationUsers = array(); $allUsers = $roleDao->getUsersByJournalId($journalId); while (!$allUsers->eof()) { $user =& $allUsers->next(); $notificationUsers[] = array('id' => $user->getId()); unset($user); } foreach ($notificationUsers as $userRole) { $notificationManager->createNotification( $request, $userRole['id'], NOTIFICATION_TYPE_NEW_ANNOUNCEMENT, $journalId, ASSOC_TYPE_ANNOUNCEMENT, $announcement->getId() ); } $notificationManager->sendToMailingList($request, $notificationManager->createNotification( $request, UNSUBSCRIBED_USER_NOTIFICATION, NOTIFICATION_TYPE_NEW_ANNOUNCEMENT, $journalId, ASSOC_TYPE_ANNOUNCEMENT, $announcement->getId() ) ); } } } ?>