/** * Given a UserConfigurationForm and user, save the configuration values for the specified user. */ public static function setConfigurationFromForm(UserNotificationConfigurationForm $form, User $user) { assert('$user instanceOf User && $user->id > 0'); $notificationSettingsNames = UserNotificationUtil::getAllNotificationSettingAttributes(); foreach ($notificationSettingsNames as $setting) { $form->{$setting} = (bool) $form->{$setting}; $form->{$setting} = (bool) $form->{$setting}; } UserNotificationUtil::setValue($user, $form->inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false); }
public static function setNotificationSettingsForUser(User $user, $notificationType, $inbox = true, $email = true) { assert('is_string($notificationType)'); assert('is_bool($inbox)'); assert('is_bool($email)'); $inboxAndEmailNotificationSettings = UserNotificationUtil::getNotificationSettingsByUser($user); $settingName = NotificationsUtil::resolveNotificationSettingNameFromType($notificationType); $inboxAndEmailNotificationSettings[$settingName]['inbox'] = $inbox; $inboxAndEmailNotificationSettings[$settingName]['email'] = $email; UserNotificationUtil::setValue($user, $inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false); }
protected function resolveNotificationConfigurationViewContentByUserType($user) { $userPanels = array(); foreach (UserNotificationUtil::getNotificationRulesTypesForCurrentUserByModule() as $module => $panel) { $tableHeadRow = array(array('cells' => array(array('elements' => array(array('attributeName' => 'notificationConfigurationTableHead' . $module, 'type' => 'NotificationConfigurationTableHead')))))); $userRows = array(); foreach ($panel as $type => $label) { $userRows[] = array('cells' => array(array('elements' => array(array('attributeName' => UserNotificationUtil::getConfigurationAttributeByNotificationType($type), 'type' => UserNotificationUtil::getConfigurationElementTypeByNotificationType($type)))))); } $userPanels[] = array('title' => $module, 'rows' => array_merge($tableHeadRow, $userRows)); } return $userPanels; }
public function testSubmitWithInboxNotificationSettingDisabledAndEmailNotificationSettingDisabled() { $initialNotificationCount = Notification::getCount(); $initialEmailMessageCount = EmailMessage::getCount(); $rules = new SimpleNotificationRules(); $rules->setAllowDuplicates(true); $rules->addUser($this->user); $inboxAndEmailNotificationSettings = UserTestHelper::getDefaultNotificationSettingsValuesForTestUser(); $inboxAndEmailNotificationSettings['enableSimpleNotification']['email'] = false; $inboxAndEmailNotificationSettings['enableSimpleNotification']['inbox'] = false; UserNotificationUtil::setValue($this->user, $inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false); $this->assertFalse(UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($this->user, 'enableSimpleNotification', 'email')); $this->assertFalse(UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($this->user, 'enableSimpleNotification', 'inbox')); $message = new NotificationMessage(); $message->textContent = 'text content for' . __FUNCTION__; $message->htmlContent = 'html content for' . __FUNCTION__; NotificationsUtil::submit($message, $rules); $this->assertEquals($initialNotificationCount, Notification::getCount()); $this->assertEquals($initialEmailMessageCount, EmailMessage::getCount()); }
public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Test all default controller actions that do not require any POST/GET variables to be passed. //This does not include portlet controller actions. $this->runControllerWithNoExceptionsAndGetContent('users/default'); $this->runControllerWithNoExceptionsAndGetContent('users/default/index'); $this->runControllerWithNoExceptionsAndGetContent('users/default/list'); $this->runControllerWithNoExceptionsAndGetContent('users/default/create'); $this->runControllerWithNoExceptionsAndGetContent('users/default/profile'); //Access to admin configuration should be allowed. $this->runControllerWithNoExceptionsAndGetContent('configuration'); //Default Controller actions requiring some sort of parameter via POST or GET //Load Model Edit Views $users = User::getAll(); $this->assertEquals(5, count($users)); $aUser = User::getByUsername('auser'); $bUser = User::getByUsername('buser'); $cUser = User::getByUsername('cuser'); $dUser = User::getByUsername('duser'); $super = User::getByUsername('super'); $this->setGetArray(array('id' => $super->id)); //Access to allowed to view Audit Trail. $this->runControllerWithNoExceptionsAndGetContent('users/default/auditEventsModalList'); $this->setGetArray(array('id' => $aUser->id)); //Access to allowed to view Audit Trail. $this->runControllerWithNoExceptionsAndGetContent('users/default/auditEventsModalList'); $this->setGetArray(array('id' => $bUser->id)); //Access to allowed to view Audit Trail. $this->runControllerWithNoExceptionsAndGetContent('users/default/auditEventsModalList'); $this->setGetArray(array('id' => $super->id)); //Access to User Role edit link and control available. $content = $this->runControllerWithNoExceptionsAndGetContent('users/default/edit'); $this->assertContains('User_role_SelectLink', $content); $this->assertContains('User_role_name', $content); $this->setGetArray(array('id' => $aUser->id)); //Access to User Role edit link and control available. $content = $this->runControllerWithNoExceptionsAndGetContent('users/default/edit'); $this->assertContains('User_role_SelectLink', $content); $this->assertContains('User_role_name', $content); $users = User::getAll(); $this->assertEquals(5, count($users)); //Save user. $this->assertTrue($aUser->id > 0); $this->assertEquals('aUserson', $aUser->lastName); $this->assertEquals(null, $aUser->officePhone); $this->setGetArray(array('id' => $aUser->id)); $this->setPostArray(array('User' => array('officePhone' => '456765421'))); $this->runControllerWithRedirectExceptionAndGetContent('users/default/edit'); $users = User::getAll(); $this->assertEquals(5, count($users)); $aUser = User::getById($aUser->id); $this->assertEquals('456765421', $aUser->officePhone); $this->assertEquals('aUserson', $aUser->lastName); //Test having a failed validation on the user during save. $this->setGetArray(array('id' => $aUser->id)); $this->setPostArray(array('User' => array('lastName' => ''))); $content = $this->runControllerWithNoExceptionsAndGetContent('users/default/edit'); $this->assertContains('Name cannot be blank', $content); $users = User::getAll(); $this->assertEquals(5, count($users)); //LastName for aUser should still be aUserson. //Need to forget aUser, since it has lastName = '' from the setAttributes called in actionEdit. //Retrieve aUser and confirm the lastName is still aUserson. $aUser->forget(); $aUser = User::getByUsername('auser'); $this->assertEquals('aUserson', $aUser->lastName); //Load Model Detail View $this->setGetArray(array('id' => $aUser->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('users/default/details'); //Load game dashboard view $this->setGetArray(array('id' => $aUser->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('users/default/gameDashboard'); //Load Model Security Detail View $this->setGetArray(array('id' => $aUser->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('users/default/securityDetails'); //Load Model Security Detail View for super user $this->setGetArray(array('id' => $super->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('users/default/securityDetails'); //Load Model MassEdit Views. //MassEdit view for single selected ids $this->setGetArray(array('selectedIds' => '4,5,6,7', 'selectAll' => '')); // Not Coding Standard $this->resetPostArray(); $content = $this->runControllerWithNoExceptionsAndGetContent('users/default/massEdit'); $this->assertContains('<strong>4</strong> records selected for updating', $content); //MassEdit view for all result selected ids $users = User::getAll(); $this->assertEquals(5, count($users)); $this->setGetArray(array('selectAll' => '1')); $this->resetPostArray(); $content = $this->runControllerWithNoExceptionsAndGetContent('users/default/massEdit'); $this->assertContains('<strong>5</strong> records selected for updating', $content); //save Model MassEdit for selected Ids //Test that the 4 contacts do not have the office phone number we are populating them with. $user1 = User::getById($aUser->id); $user2 = User::getById($bUser->id); $user3 = User::getById($cUser->id); $user4 = User::getById($dUser->id); $this->assertNotEquals('7788', $user1->officePhone); $this->assertNotEquals('7788', $user2->officePhone); $this->assertNotEquals('7788', $user3->officePhone); $this->assertNotEquals('7788', $user4->officePhone); $this->setGetArray(array('selectedIds' => $aUser->id . ',' . $bUser->id, 'selectAll' => '', 'User_page' => 1)); $this->setPostArray(array('User' => array('officePhone' => '7788'), 'MassEdit' => array('officePhone' => 1))); $this->runControllerWithRedirectExceptionAndGetContent('users/default/massEdit'); //Test that the 2 contacts have the new office phone number and the other contacts do not. $user1 = User::getById($aUser->id); $user2 = User::getById($bUser->id); $user3 = User::getById($cUser->id); $user4 = User::getById($dUser->id); $this->assertEquals('7788', $user1->officePhone); $this->assertEquals('7788', $user2->officePhone); $this->assertNotEquals('7788', $user3->officePhone); $this->assertNotEquals('7788', $user4->officePhone); //save Model MassEdit for entire search result $this->setGetArray(array('selectAll' => '1', 'User_page' => 1)); $this->setPostArray(array('User' => array('officePhone' => '1234'), 'MassEdit' => array('officePhone' => 1))); $this->runControllerWithRedirectExceptionAndGetContent('users/default/massEdit'); //Test that all accounts have the new phone number. $user1 = User::getById($aUser->id); $user2 = User::getById($bUser->id); $user3 = User::getById($cUser->id); $user4 = User::getById($dUser->id); $this->assertEquals('1234', $user1->officePhone); $this->assertEquals('1234', $user2->officePhone); $this->assertEquals('1234', $user3->officePhone); $this->assertEquals('1234', $user4->officePhone); //Run Mass Update using progress save. $pageSize = Yii::app()->pagination->getForCurrentUserByType('massEditProgressPageSize'); $this->assertEquals(5, $pageSize); Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', 1); //The page size is smaller than the result set, so it should exit. $this->runControllerWithExitExceptionAndGetContent('users/default/massEdit'); //save Modal MassEdit using progress load for page 2, 3, 4 and 5. $this->setGetArray(array('selectAll' => '1', 'User_page' => 2)); $content = $this->runControllerWithNoExceptionsAndGetContent('users/default/massEditProgressSave'); $this->assertContains('"value":40', $content); $this->setGetArray(array('selectAll' => '1', 'User_page' => 3)); $content = $this->runControllerWithNoExceptionsAndGetContent('users/default/massEditProgressSave'); $this->assertContains('"value":60', $content); $this->setGetArray(array('selectAll' => '1', 'User_page' => 4)); $content = $this->runControllerWithNoExceptionsAndGetContent('users/default/massEditProgressSave'); $this->assertContains('"value":80', $content); $this->setGetArray(array('selectAll' => '1', 'User_page' => 5)); $content = $this->runControllerWithNoExceptionsAndGetContent('users/default/massEditProgressSave'); $this->assertContains('"value":100', $content); //Set page size back to old value. Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', $pageSize); //Autocomplete for User $this->setGetArray(array('term' => 'auser')); $this->runControllerWithNoExceptionsAndGetContent('users/default/autoComplete'); //actionModalList $this->setGetArray(array('modalTransferInformation' => array('sourceIdFieldId' => 'x', 'sourceNameFieldId' => 'y', 'modalId' => 'z'))); $this->runControllerWithNoExceptionsAndGetContent('users/default/modalList'); //Change password view. $this->setGetArray(array('id' => $aUser->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('users/default/changePassword'); //Failed change password validation $this->setPostArray(array('ajax' => 'edit-form', 'UserPasswordForm' => array('newPassword' => '', 'newPassword_repeat' => ''))); $content = $this->runControllerWithExitExceptionAndGetContent('users/default/changePassword'); $this->assertTrue(strlen($content) > 50); //approximate, but should definetely be larger than 50. //Successful change password validation $this->setPostArray(array('ajax' => 'edit-form', 'UserPasswordForm' => array('newPassword' => 'aNewPassword', 'newPassword_repeat' => 'aNewPassword'))); $content = $this->runControllerWithExitExceptionAndGetContent('users/default/changePassword'); $this->assertEquals('[]', $content); //Successful saved password change. $this->setPostArray(array('save' => 'Save', 'UserPasswordForm' => array('newPassword' => 'bNewPassword', 'newPassword_repeat' => 'bNewPassword'))); $this->runControllerWithRedirectExceptionAndGetContent('users/default/changePassword'); //Login using new password successfully. $identity = new UserIdentity('auser', 'bNewPassword'); $authenticated = $identity->authenticate(); $this->assertEquals(0, $identity->errorCode); $this->assertTrue($authenticated); //User Configuration UI. Change aUser configuration values. //First make sure settings are not what we are setting them too. $this->assertNotEquals(9, Yii::app()->pagination->getByUserAndType($aUser, 'listPageSize')); $this->assertNotEquals(4, Yii::app()->pagination->getByUserAndType($aUser, 'subListPageSize')); //Load up configuration page. $this->setGetArray(array('id' => $aUser->id)); $this->runControllerWithNoExceptionsAndGetContent('users/default/configurationEdit'); //Post fake save that will fail validation. $this->setGetArray(array('id' => $aUser->id)); $this->setPostArray(array('UserConfigurationForm' => array('listPageSize' => 0, 'subListPageSize' => 4))); $this->runControllerWithNoExceptionsAndGetContent('users/default/configurationEdit'); //Post fake save that will pass validation. $this->setGetArray(array('id' => $aUser->id)); $this->setPostArray(array('UserConfigurationForm' => array('listPageSize' => 9, 'subListPageSize' => 4))); $this->runControllerWithRedirectExceptionAndGetContent('users/default/configurationEdit'); $this->assertEquals('User configuration saved successfully.', Yii::app()->user->getFlash('notification')); //Check to make sure user configuration is actually changed. $this->assertEquals(9, Yii::app()->pagination->getByUserAndType($aUser, 'listPageSize')); $this->assertEquals(4, Yii::app()->pagination->getByUserAndType($aUser, 'subListPageSize')); //Confirm current user has certain session values $this->assertNotEquals(7, Yii::app()->user->getState('listPageSize')); $this->assertNotEquals(4, Yii::app()->user->getState('subListPageSize')); //Change current user configuration values. (Yii::app()->user->userModel) //First make sure settings are not what we are setting them too. $this->assertNotEquals(7, Yii::app()->pagination->getForCurrentUserByType('listPageSize')); //Load up configuration page. $this->setGetArray(array('id' => Yii::app()->user->userModel->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('users/default/configurationEdit'); //Post fake save that will fail validation. $this->setGetArray(array('id' => Yii::app()->user->userModel->id)); $this->setPostArray(array('UserConfigurationForm' => array('listPageSize' => 0, 'subListPageSize' => 4))); $this->runControllerWithNoExceptionsAndGetContent('users/default/configurationEdit'); //Post fake save that will pass validation. $this->setGetArray(array('id' => Yii::app()->user->userModel->id)); $this->setPostArray(array('UserConfigurationForm' => array('listPageSize' => 7, 'subListPageSize' => 4))); $this->runControllerWithRedirectExceptionAndGetContent('users/default/configurationEdit'); $this->assertEquals('User configuration saved successfully.', Yii::app()->user->getFlash('notification')); //Check to make sure user configuration is actually changed. $this->assertEquals(7, Yii::app()->pagination->getForCurrentUserByType('listPageSize')); //Check getState data. since it should be updated for current user. $this->assertEquals(7, Yii::app()->user->getState('listPageSize')); $this->assertEquals(4, Yii::app()->user->getState('subListPageSize')); //User Notification Configuration UI. Change aUser notification configuration values. //First make sure settings all default values are true $notificationSettings = UserNotificationUtil::getNotificationSettingsByUser($aUser); $notificationSettingsNames = UserNotificationUtil::getAllNotificationSettingAttributes(); foreach ($notificationSettingsNames as $setting) { list($settingName, $type) = UserNotificationUtil::getSettingNameAndTypeBySuffixedConfigurationAttribute($setting); $this->assertTrue((bool) $notificationSettings[$settingName][$type]); } //Load up notification configuration page. $this->setGetArray(array('id' => $aUser->id)); $this->runControllerWithNoExceptionsAndGetContent('users/default/notificationConfiguration'); //Post fake save that will pass validation. $this->setGetArray(array('id' => $aUser->id)); $this->setPostArray(array('UserNotificationConfigurationForm' => array('enableConversationInvitesNotificationInbox' => 0))); $this->runControllerWithRedirectExceptionAndGetContent('users/default/notificationConfiguration'); $this->assertEquals('User notifications configuration saved successfully.', Yii::app()->user->getFlash('notification')); //Check to make sure user notification configuration is actually changed. $this->assertFalse((bool) UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($aUser, 'enableConversationInvitesNotification', 'inbox')); }
/** * Resolve and get notifications * @param NotificationMessage $message * @param $rules * @throws NotSupportedException * @return Notification */ protected static function resolveAndGetNotifications(NotificationMessage $message, NotificationRules $rules) { $notifications = array(); foreach ($rules->getUsers() as $user) { //todo: !!!process duplication check if ($rules->allowDuplicates() || Notification::getCountByTypeAndUser($rules->getType(), $user) == 0) { $notification = new Notification(); $notification->owner = $user; $notification->type = $rules->getType(); $notification->notificationMessage = $message; $notificationSettingName = static::resolveNotificationSettingNameFromType($rules->getType()); if (static::resolveToSaveNotification() && UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($user, $notificationSettingName, 'inbox')) { $saved = $notification->save(); if (!$saved) { throw new NotSupportedException(); } } $notifications[] = $notification; } } return $notifications; }
protected function renderTooltipContentForNotification() { $title = UserNotificationUtil::getTooltipTitleByAttribute($this->attribute); $content = ZurmoHtml::tag('span', array('id' => UserNotificationUtil::getTooltipIdByAttribute($this->attribute), 'class' => 'tooltip', 'title' => $title), '?'); $qtip = new ZurmoTip(array('options' => array('position' => array('my' => 'bottom right', 'at' => 'top left'), 'hide' => array('event' => 'unfocus'), 'show' => array('event' => 'click')))); $qtip->addQTip("#" . UserNotificationUtil::getTooltipIdByAttribute($this->attribute)); return $content; }
/** * @depends testClosingConversations */ public function testSendEmailInNewComment() { if (!SECURITY_OPTIMIZED) { return; } $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $steven = User::getByUsername('steven'); $sally = User::getByUsername('sally'); $mary = User::getByUsername('mary'); $conversations = Conversation::getAll(); $this->assertEquals(2, count($conversations)); $this->assertEquals(0, $conversations[0]->comments->count()); foreach (EmailMessage::getAll() as $emailMessage) { $emailMessage->delete(); } $initialQueued = 0; $conversation = $conversations[0]; $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $steven; $conversation->conversationParticipants->add($conversationParticipant); $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $sally; $conversation->conversationParticipants->add($conversationParticipant); $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $mary; $conversation->conversationParticipants->add($conversationParticipant); $inboxAndEmailNotificationSettings = UserTestHelper::getDefaultNotificationSettingsValuesForTestUser(); $inboxAndEmailNotificationSettings['enableConversationNewCommentNotification'] = array('inbox' => false, 'email' => false); UserNotificationUtil::setValue($mary, $inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false); //Save a new comment $this->setGetArray(array('relatedModelId' => $conversation->id, 'relatedModelClassName' => 'Conversation', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name'))); $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave'); $this->assertEquals(1, $conversation->comments->count()); $this->assertEquals($initialQueued + 2, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[$initialQueued]; $this->assertEquals(1, count($emailMessage->recipients)); $emailMessage = $emailMessages[$initialQueued + 1]; $this->assertEquals(1, count($emailMessage->recipients)); $this->assertContains('conversation', $emailMessage->subject); $this->assertContains(strval($conversation), $emailMessage->subject); $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->htmlContent); $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->textContent); }
/** * @param DemoDataHelper $demoDataHelper */ public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); assert('$demoDataHelper->isSetRange("Group")'); assert('$demoDataHelper->isSetRange("Role")'); $super = User::getByUsername('super'); $email = new Email(); $email->emailAddress = static::resolveDemoEmailAddress('Super.test'); $super->primaryEmail = $email; $saved = $super->save(); assert('$saved'); UserNotificationUtil::setEmailNotificationSettingsAllDisabledForUser($super); $userAvatarForm = new UserAvatarForm($super); $userAvatarForm->avatarType = User::AVATAR_TYPE_PRIMARY_EMAIL; $saved = $userAvatarForm->save(); assert('$saved'); $user = new User(); $this->populateModel($user); $user->username = '******'; $user->title->value = 'Sir'; $user->firstName = 'Jason'; $user->lastName = 'Blue'; $user->lastLoginDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $email = new Email(); $email->emailAddress = static::resolveDemoEmailAddress('Jason.Blue'); $user->primaryEmail = $email; $user->setPassword($user->username); $saved = $user->save(); assert('$saved'); UserNotificationUtil::setEmailNotificationSettingsAllDisabledForUser($user); $userAvatarForm = new UserAvatarForm($user); $userAvatarForm->avatarType = User::AVATAR_TYPE_PRIMARY_EMAIL; $saved = $userAvatarForm->save(); assert('$saved'); $userStartId = $user->id; $roleIdRange = $demoDataHelper->getRangeByModelName('Role'); $role = Role::getById($roleIdRange['startId']); assert('$role instanceof Role'); $role->users->add($user); $saved = $role->save(); assert('$saved'); foreach (array('jim' => 'Mr.', 'john' => 'Mr.', 'sally' => 'Dr.', 'mary' => 'Mrs.', 'katie' => 'Ms.', 'jill' => 'Ms.', 'sam' => 'Mr.') as $username => $title) { $user = new User(); $this->populateModel($user); $user->username = $username; $user->setPassword($user->username); $user->title->value = $title; $user->firstName = ucfirst($username); $user->lastName = 'Smith'; $email = new Email(); $email->emailAddress = static::resolveDemoEmailAddress($user->firstName); $user->primaryEmail = $email; $user->lastLoginDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $saved = $user->save(); assert('$saved'); UserNotificationUtil::setEmailNotificationSettingsAllDisabledForUser($user); $userAvatarForm = new UserAvatarForm($user); $userAvatarForm->avatarType = User::AVATAR_TYPE_PRIMARY_EMAIL; $saved = $userAvatarForm->save(); assert('$saved'); $roleIdRange = $demoDataHelper->getRangeByModelName('Role'); $role = Role::getById($roleIdRange['startId'] + 1); assert('$role instanceof Role'); $role->users->add($user); $saved = $role->save(); assert('$saved'); } $demoDataHelper->setRangeByModelName('User', $userStartId, $user->id); }
/** * Send task email * @param Notification $notification * @param TaskNotificationRules $rule * @param string $action */ protected static function sendTaskEmail(Notification $notification, TaskNotificationRules $rule, $action) { assert('is_string($action)'); $notificationSettingName = static::resolveNotificationSettingNameFromType($rule->getType()); if ($notification->owner->primaryEmail->emailAddress !== null && UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($notification->owner, $notificationSettingName, 'email')) { $emailMessage = static::makeEmailMessage(); $emailMessage->subject = static::getEmailSubject($notification, $rule); $emailMessage->content = static::makeEmailContent($notification); $emailMessage->sender = static::makeSender(); $emailMessage->recipients->add(static::makeRecipient($notification)); $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT); try { Yii::app()->emailHelper->send($emailMessage); } catch (CException $e) { //Not sure what to do yet when catching an exception here. Currently ignoring gracefully. } } }
/** * Set default notifications settings to be all enabled * * @param User $user */ public static function setDefaultNotificationSettingsForUser($user) { $defaultNotificationSettings = static::getDefaultNotificationSettingsValuesForTestUser(); UserNotificationUtil::setValue($user, $defaultNotificationSettings, 'inboxAndEmailNotificationSettings', false); }
public function attributeLabels() { $labels = array(); foreach ($this->attributeNames() as $name) { list($settingName, $type) = UserNotificationUtil::getSettingNameAndTypeBySuffixedConfigurationAttribute($name); $notificationRulesClassName = str_replace('enable', '', $settingName) . 'Rules'; if (@class_exists($notificationRulesClassName)) { $rule = NotificationRulesFactory::createNotificationRulesByType(str_replace('NotificationRules', '', $notificationRulesClassName)); $labels[$settingName] = $rule->getDisplayName(); } } return $labels; }
/** * Set email notifications settings to be all disabled * * @param User $user */ public static function setEmailNotificationSettingsAllDisabledForUser($user) { $notificationSettingsAttributes = UserNotificationUtil::getAllNotificationSettingAttributes(); $defaultNotificationSettings = array(); foreach ($notificationSettingsAttributes as $attribute) { list($settingName, $type) = UserNotificationUtil::getSettingNameAndTypeBySuffixedConfigurationAttribute($attribute); if ($type == 'email') { $defaultNotificationSettings[$settingName][$type] = false; } else { $defaultNotificationSettings[$settingName][$type] = true; } } static::setValue($user, $defaultNotificationSettings, 'inboxAndEmailNotificationSettings', false); }