addCheck(new \PKP\form\validation\FormValidatorPost($this)); $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this)); $this->_notification = $notification; $this->_validationToken = $validationToken; } /** * Assign form data to user-submitted data. */ public function readInputData() { $userVars = []; foreach ($this->getNotificationSettingsMap() as $notificationSetting) { $userVars[] = $notificationSetting['emailSettingName']; } $this->readUserVars($userVars); } /** * Get all notification settings form names and their setting type values * * @return array */ protected function getNotificationSettingsMap() { $notificationManager = new NotificationManager(); return $notificationManager->getNotificationSettingsMap(); } /** * @copydoc Form::fetch * * @param null|mixed $template */ public function fetch($request, $template = null, $display = false) { $userId = $this->_notification->getUserId(); $contextId = $this->_notification->getContextId(); if ($contextId != $request->getContext()->getId()) { $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } $emailSettings = $this->getNotificationSettingsMap(); $user = Repo::user()->get($userId); $context = $request->getContext(); $templateMgr = TemplateManager::getManager($request); $templateMgr->assign([ 'contextName' => $context->getLocalizedName(), 'userEmail' => $user->getEmail(), 'emailSettings' => $emailSettings, 'validationToken' => $this->_validationToken, 'notificationId' => $this->_notification->getId(), ]); return parent::fetch($request, $template, $display); } /** * @copydoc Form::execute */ public function execute(...$functionArgs) { $emailSettings = []; foreach ($this->getNotificationSettingsMap() as $settingId => $notificationSetting) { // Get notifications that the user wants to be notified of by email if ($this->getData($notificationSetting['emailSettingName'])) { $emailSettings[] = $settingId; } } /** @var NotificationSubscriptionSettingsDAO */ $notificationSubscriptionSettingsDao = DAORegistry::getDAO('NotificationSubscriptionSettingsDAO'); $notificationSubscriptionSettingsDao->updateNotificationSubscriptionSettings('blocked_emailed_notification', $emailSettings, $this->_notification->getUserId(), $this->_notification->getContextId()); return true; } } if (!PKP_STRICT_MODE) { class_alias('\PKP\notification\form\PKPNotificationsUnsubscribeForm', '\PKPNotificationsUnsubscribeForm'); }