public function testSubmitNonCritical()
 {
     $super = User::getByUsername('super');
     $emailAddress = new Email();
     $emailAddress->emailAddress = '*****@*****.**';
     $super->primaryEmail = $emailAddress;
     $saved = $super->save();
     $this->assertTrue($saved);
     $billy = User::getByUsername('billy');
     $emailAddress = new Email();
     $emailAddress->emailAddress = '*****@*****.**';
     $billy->primaryEmail = $emailAddress;
     $saved = $billy->save();
     $this->assertTrue($saved);
     $notifications = Notification::getAll();
     $this->assertEquals(0, count($notifications));
     $message = new NotificationMessage();
     $message->textContent = 'text content';
     $message->htmlContent = 'html content';
     $rules = new SimpleNotificationRules();
     $rules->addUser($super);
     $rules->addUser($billy);
     NotificationsUtil::submit($message, $rules);
     //It should not send an email because it is non-critical
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $notifications = Notification::getAll();
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
 }
 /**
  * This method replaces previous usage of throwing an exception when a game model like gamePoint was retrieved
  * for a person and there was more than one.  For a given person/type there should only be one.  It is possible
  * though that 2 endRequestBehaviors occur simultaneously for the same user. An example is if the user is using
  * 2 browser tabs at once and submits a page request simultaneously.  Currently there is not much that can be done
  * to avoid this so instead of failing we will now log this to the application.log and notify the super user
  * that the Repair Gamification tool should be run. This tool is located under developer tools.
  * @param $logContent
  */
 public static function logAndNotifyOnDuplicateGameModel($logContent)
 {
     assert('is_string($logContent)');
     $logContent .= "\n Use developer tools 'Repair Gamification' to resolve";
     Yii::log($logContent, CLogger::LEVEL_WARNING);
     $message = new NotificationMessage();
     $message->textContent = Zurmo::t('GamificationModule', "Run 'Repair Gamification' under developer tools");
     $rules = new RepairGamificationNotificationRules();
     NotificationsUtil::submit($message, $rules);
 }
 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);
 }
 /**
  * @param RedBeanModel $relatedModel
  * @param Comment $comment
  * @param array $peopleToSendNotification
  */
 public static function sendNotificationOnNewComment(RedBeanModel $relatedModel, Comment $comment, $peopleToSendNotification)
 {
     if (count($peopleToSendNotification) > 0) {
         $notificationRulesClassName = static::resolveNotificationRulesClassByModel($relatedModel);
         $rules = new $notificationRulesClassName();
         foreach ($peopleToSendNotification as $people) {
             $rules->addUser($people);
             $rules->setModel($relatedModel);
         }
         $notificationMessage = static::createNotificationMessage($relatedModel, $comment);
         NotificationsUtil::submit($notificationMessage, $rules);
     } else {
         return;
     }
 }
 public function actionCreateMultipleLineTest()
 {
     $message = new NotificationMessage();
     $message->textContent = 'As a result of some fields recently becoming required, at least 1 ' . 'workflow rule will no longer work properly.';
     $message->textContent .= "\n";
     $message->textContent .= "<a href=''>Workflow #1</a>";
     $message->textContent .= "\n";
     $message->textContent .= "<a href=''>Workflow #2</a>";
     $message->htmlContent = 'As a result of some fields recently becoming required, at least 1 ' . 'workflow rule will no longer work properly.';
     $message->htmlContent .= "<div><ul><li>";
     $message->htmlContent .= "<a href=''>Workflow #1</a>";
     $message->htmlContent .= "</li><li>";
     $message->htmlContent .= "<a href=''>Workflow #2</a>";
     $message->htmlContent .= "</li></ul></div>";
     $rules = new SimpleDuplicateNotificationRules();
     $rules->addUser(Yii::app()->user->userModel);
     NotificationsUtil::submit($message, $rules);
     echo 'Test notification created';
 }
 /**
  * @see BaseJob::run()
  */
 public function run()
 {
     $workflows = WorkflowActionsUtil::getWorkflowsMissingRequiredActionAttributes();
     if (count($workflows) > 0) {
         $message = new NotificationMessage();
         $message->htmlContent = Zurmo::t('WorkflowsModule', 'As a result of a field or fields recently ' . 'becoming required, at least 1 workflow rule will no longer work properly.');
         $message->htmlContent .= "<div><ul>";
         foreach ($workflows as $workflow) {
             $message->htmlContent .= "<li>";
             $url = Yii::app()->createUrl('workflows/default/details', array('id' => $workflow->getId()));
             $message->htmlContent .= ZurmoHtml::link(strval($workflow), $url);
             $message->htmlContent .= "</li>";
         }
         $message->htmlContent .= "</ul></div>";
         $rules = new WorkflowValidityCheckNotificationRules();
         NotificationsUtil::submit($message, $rules);
     }
     return true;
 }
 /**
  * @see BaseJob::run()
  */
 public function run()
 {
     $workflowsWithInvalidActions = WorkflowActionsUtil::getWorkflowsMissingRequiredActionAttributes();
     if (count($workflowsWithInvalidActions) > 0) {
         $commonMessage = Zurmo::t('WorkflowsModule', 'As a result of a field or fields recently ' . 'becoming required, at least 1 workflow action rule will no longer work properly:');
         $message = new NotificationMessage();
         $message = $this->updateNotificationMessage($workflowsWithInvalidActions, $message, $commonMessage);
     }
     $workflowsWithInvalidTriggers = WorkflowTriggersUtil::getWorkflowsWithInvalidTriggerCustomFieldValue();
     if (count($workflowsWithInvalidTriggers) > 0) {
         if (!isset($message)) {
             $message = new NotificationMessage();
         }
         $commonMessage = Zurmo::t('WorkflowsModule', 'As a result of modifying picklist data recently, ' . 'at least 1 workflow trigger rule will no longer work properly:');
         $message = $this->updateNotificationMessage($workflowsWithInvalidTriggers, $message, $commonMessage);
     }
     if (count($workflowsWithInvalidActions) > 0 || count($workflowsWithInvalidTriggers) > 0) {
         $rules = new WorkflowValidityCheckNotificationRules();
         NotificationsUtil::submit($message, $rules);
     }
     return true;
 }
Example #8
0
 /**
  * Check if available zurmo updates has been checked within the last 7 days. If not, then perform
  * update and update the lastAttemptedInfoUpdateTimeStamp and lastZurmoStableVersion global configuration properties.
  * @param boolean $forceCheck - If true, it will ignore the last time the check was made
  */
 public static function checkAndUpdateZurmoInfo($forceCheck = false)
 {
     $lastAttemptedInfoUpdateTimeStamp = self::getLastAttemptedInfoUpdateTimeStamp();
     if ($forceCheck || $lastAttemptedInfoUpdateTimeStamp == null || time() - $lastAttemptedInfoUpdateTimeStamp > 7 * 24 * 60 * 60) {
         $headers = array('Accept: application/json', 'ZURMO_API_REQUEST_TYPE: REST');
         $data = array('zurmoToken' => ZURMO_TOKEN, 'zurmoVersion' => VERSION, 'serializedData' => '');
         if (isset($_SERVER['SERVER_ADDR'])) {
             $data['serverIpAddress'] = $_SERVER['SERVER_ADDR'];
         }
         if (isset($_SERVER['SERVER_NAME'])) {
             $data['serverName'] = $_SERVER['SERVER_NAME'];
         }
         if (isset($_SERVER['SERVER_SOFTWARE'])) {
             $data['serverSoftware'] = $_SERVER['SERVER_SOFTWARE'];
         }
         $sandboxMode = Yii::app()->isApplicationInSandboxMode();
         $data['sandboxMode'] = $sandboxMode;
         $response = ApiRestHelper::createApiCall('http://updates.zurmo.com/app/index.php/updatesManager/api/create', 'POST', $headers, array('data' => $data));
         $response = json_decode($response, true);
         if (ApiResponse::STATUS_SUCCESS == $response['status']) {
             if (isset($response['data']['latestStableZurmoVersion']) && $response['data']['latestStableZurmoVersion'] != '') {
                 self::setLastZurmoStableVersion($response['data']['latestStableZurmoVersion']);
             }
             $zurmoServiceHelper = new ZurmoServiceHelper();
             if (!$zurmoServiceHelper->runCheckAndGetIfSuccessful()) {
                 $message = new NotificationMessage();
                 $message->textContent = $zurmoServiceHelper->getMessage();
                 $rules = new NewZurmoVersionAvailableNotificationRules();
                 NotificationsUtil::submit($message, $rules);
             }
         }
         self::setLastAttemptedInfoUpdateTimeStamp();
     }
 }
 /**
  * Given a event, process any workflow rules
  * @param CEvent $event
  */
 public function processWorkflowAfterSave(CEvent $event)
 {
     $model = $event->sender;
     if ($this->depth < 11 && $model->shouldProcessWorkflowOnSave()) {
         try {
             $this->depth = $this->depth + 1;
             $triggeredByUser = Yii::app()->user->userModel;
             Yii::app()->user->userModel = BaseControlUserConfigUtil::getUserToRunAs();
             $model->setDoNotProcessWorkflowOnSave();
             SavedWorkflowsUtil::resolveAfterSaveByModel($model, $triggeredByUser);
             $model->setProcessWorkflowOnSave();
             Yii::app()->user->userModel = $triggeredByUser;
         } catch (MissingASuperAdministratorException $e) {
             //skip running workflow, since no super administrators are available.
         }
         $this->depth = $this->depth - 1;
     } elseif ($this->depth > 10) {
         $message = new NotificationMessage();
         $message->htmlContent = Zurmo::t('WorkflowsModule', 'The combination of workflow rules setup caused ' . 'an infinite loop and processing was stopped prematurely while saving the ' . 'following record: {modelName}', array('{modelName}' => strval($model)));
         $url = Yii::app()->createAbsoluteUrl('workflows/default/list');
         $message->htmlContent .= "<br/>" . ZurmoHtml::link(Zurmo::t('WorkflowsModule', 'Manage Workflows'), $url);
         $rules = new WorkflowMaximumDepthNotificationRules();
         NotificationsUtil::submit($message, $rules);
     }
 }
 /**
  * Send notification messages based on list of added required attributes
  * @param $addedRequiredAttributesViaDesigner
  */
 protected function sendNotificationMessages($addedRequiredAttributesViaDesigner)
 {
     $message = '';
     foreach ($addedRequiredAttributesViaDesigner as $modelClassName => $attributes) {
         foreach ($attributes as $attributeName) {
             $message .= $modelClassName::getModelLabelByTypeAndLanguage('Singular', Yii::app()->language) . ':' . $modelClassName::getAnAttributeLabel($attributeName) . '<br />';
         }
     }
     $notificationMessage = new NotificationMessage();
     $notificationMessage->htmlContent = static::getNotificationMessage() . '<br />' . $message;
     $notificationRulesClassName = static::getNotificationRulesClassName();
     $rules = new $notificationRulesClassName();
     $superAdminGroup = Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME);
     foreach ($superAdminGroup->users as $user) {
         Notification::deleteByTypeAndUser(static::getNotificationType(), $user);
         $rules->addUser($user);
         NotificationsUtil::submit($notificationMessage, $rules);
     }
 }
 /**
  * From the command line, run the autobuild method which will effectively update
  * the database schema.
  */
 public static function runAutoBuildFromUpdateSchemaCommand($messageLogger)
 {
     assert('$messageLogger instanceof MessageLogger');
     ForgetAllCacheUtil::forgetAllCaches();
     static::autoBuildDatabase($messageLogger);
     // Send notification to super admin to clean assets folder(optional).
     $message = new NotificationMessage();
     $message->textContent = Zurmo::t('InstallModule', 'Please delete all files from assets folder on server.');
     $rules = new ClearAssetsFolderNotificationRules();
     NotificationsUtil::submit($message, $rules);
     return true;
 }
Example #12
0
 public function run()
 {
     $exportItems = ExportItem::getUncompletedItems();
     if (count($exportItems) > 0) {
         foreach ($exportItems as $exportItem) {
             if (isset($exportItem->exportFileModel)) {
                 //continue;
             }
             $unserializedData = unserialize($exportItem->serializedData);
             if ($unserializedData instanceof RedBeanModelDataProvider) {
                 $formattedData = $unserializedData->getData();
             } else {
                 $formattedData = array();
                 foreach ($unserializedData as $idToExport) {
                     $model = call_user_func(array($exportItem->modelClassName, 'getById'), intval($idToExport));
                     $formattedData[] = $model;
                 }
             }
             if ($exportItem->exportFileType == 'csv') {
                 $headerData = array();
                 foreach ($formattedData as $model) {
                     if (ControllerSecurityUtil::doesCurrentUserHavePermissionOnSecurableItem($model, Permission::READ)) {
                         $modelToExportAdapter = new ModelToExportAdapter($model);
                         if (count($headerData) == 0) {
                             $headerData = $modelToExportAdapter->getHeaderData();
                         }
                         $data[] = $modelToExportAdapter->getData();
                     }
                 }
                 $output = ExportItemToCsvFileUtil::export($data, $headerData);
                 $fileContent = new FileContent();
                 $fileContent->content = $output;
                 $exportFileModel = new ExportFileModel();
                 $exportFileModel->fileContent = $fileContent;
                 $exportFileModel->name = $exportItem->exportFileName . ".csv";
                 $exportFileModel->type = 'application/octet-stream';
                 $exportFileModel->size = strlen($output);
                 $saved = $exportFileModel->save();
                 if ($saved) {
                     $exportItem->isCompleted = 1;
                     $exportItem->exportFileModel = $exportFileModel;
                     $exportItem->save();
                     $message = new NotificationMessage();
                     $message->htmlContent = Zurmo::t('ExportModule', 'Export of {fileName} requested on {dateTime} is completed. <a href="{url}">Click here</a> to download file!', array('{fileName}' => $exportItem->exportFileName, '{url}' => Yii::app()->createUrl('export/default/download', array('id' => $exportItem->id)), '{dateTime}' => DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($exportItem->createdDateTime, 'long')));
                     $rules = new ExportProcessCompletedNotificationRules();
                     NotificationsUtil::submit($message, $rules);
                 }
             }
         }
     } else {
         return true;
     }
     return true;
 }
 protected function logAndNotifyOnMissingMarketingListModel($type)
 {
     assert('$type == ActionForWorkflowForm::TYPE_SUBSCRIBE_TO_LIST ||
                 $type == ActionForWorkflowForm::TYPE_UNSUBSCRIBE_FROM_LIST');
     if ($type == ActionForWorkflowForm::TYPE_SUBSCRIBE_TO_LIST) {
         $logContent = "\n Workflow model with id: " . $this->workflowId . ' is malformed. Subscribe action references invalid marketing list';
         Yii::log($logContent, CLogger::LEVEL_WARNING);
     } else {
         $logContent = "\n Workflow model with id: " . $this->workflowId . ' is malformed. Unsubscribe action references invalid marketing list';
         Yii::log($logContent, CLogger::LEVEL_WARNING);
     }
     $message = new NotificationMessage();
     $message->textContent = "Repair the workflow rule named '" . $this->workflowName . "' because it is referencing an invalid marketing list";
     $rules = new MalformedWorkflowMissingMarketingListNotificationRules();
     NotificationsUtil::submit($message, $rules);
 }
Example #14
0
 /**
  * @param array $jobTitleLabels
  */
 public static function makeJobStuckNotification(array $jobTitleLabels)
 {
     $message = new NotificationMessage();
     $prefixContent = Zurmo::t('JobsManagerModule', 'Stuck Job| Stuck Jobs', array(count($jobTitleLabels)));
     $url = Yii::app()->createAbsoluteUrl('jobsManager/default/list/');
     $message->textContent = $prefixContent;
     $message->htmlContent = $prefixContent;
     $textContent = null;
     $htmlContent = null;
     foreach ($jobTitleLabels as $label) {
         if ($textContent != null) {
             $textContent .= ', ';
         }
         if ($htmlContent != null) {
             $htmlContent .= ', ';
         }
         $textContent .= $label;
         $htmlContent .= $label;
     }
     $message->textContent .= ': ' . $textContent;
     $message->htmlContent .= ': ' . $htmlContent;
     $message->textContent .= "\n" . Zurmo::t('Core', 'View Job Manager') . ': ' . ShortUrlUtil::createShortUrl($url);
     $message->htmlContent .= "<br/>" . ZurmoHtml::link(Zurmo::t('Core', 'View Job Manager'), $url, array('target' => '_blank'));
     $rules = new StuckJobsNotificationRules();
     NotificationsUtil::submit($message, $rules);
 }
 /**
  * Save email message
  * This method should be protected, but we made it public for unit testing, so don't call it outside this class.
  * @param ImapMessage $message
  * @throws NotSupportedException
  * @return boolean
  */
 public function saveEmailMessage(ImapMessage $message)
 {
     // Get owner for message
     try {
         $emailOwner = EmailArchivingUtil::resolveOwnerOfEmailMessage($message);
     } catch (CException $e) {
         // User not found, so inform user about issue and continue with next email.
         $this->resolveMessageSubjectAndContentAndSendSystemMessage('OwnerNotExist', $message);
         return false;
     }
     $emailSenderOrRecipientEmailFoundInSystem = false;
     $userCanAccessContacts = RightsUtil::canUserAccessModule('ContactsModule', $emailOwner);
     $userCanAccessLeads = RightsUtil::canUserAccessModule('LeadsModule', $emailOwner);
     $userCanAccessAccounts = RightsUtil::canUserAccessModule('AccountsModule', $emailOwner);
     $senderInfo = EmailArchivingUtil::resolveEmailSenderFromEmailMessage($message);
     if (!$senderInfo) {
         $this->resolveMessageSubjectAndContentAndSendSystemMessage('SenderNotExtracted', $message);
         return false;
     } else {
         $sender = EmailArchivingUtil::createEmailMessageSender($senderInfo, $userCanAccessContacts, $userCanAccessLeads, $userCanAccessAccounts);
         if ($sender->personsOrAccounts->count() > 0) {
             $emailSenderOrRecipientEmailFoundInSystem = true;
         }
     }
     try {
         $recipientsInfo = EmailArchivingUtil::resolveEmailRecipientsFromEmailMessage($message);
     } catch (NotSupportedException $exception) {
         $this->resolveMessageSubjectAndContentAndSendSystemMessage('RecipientNotExtracted', $message);
         return false;
     }
     $emailMessage = new EmailMessage();
     $emailMessage->owner = $emailOwner;
     $emailMessage->subject = $message->subject;
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = $message->textBody;
     $emailContent->htmlContent = $message->htmlBody;
     $emailMessage->content = $emailContent;
     $emailMessage->sender = $sender;
     $emailRecipientFoundInSystem = false;
     foreach ($recipientsInfo as $recipientInfo) {
         $recipient = EmailArchivingUtil::createEmailMessageRecipient($recipientInfo, $userCanAccessContacts, $userCanAccessLeads, $userCanAccessAccounts);
         $emailMessage->recipients->add($recipient);
         // Check if at least one recipient email can't be found in Contacts, Leads, Account and User emails
         // so we will save email message in EmailFolder::TYPE_ARCHIVED_UNMATCHED folder, and user will
         // be able to match emails with items(Contacts, Accounts...) emails in systems
         if ($recipient->personsOrAccounts->count() > 0) {
             $emailRecipientFoundInSystem = true;
         }
     }
     // Override $emailSenderOrRecipientEmailFoundInSystem only if there are no errors
     if ($emailSenderOrRecipientEmailFoundInSystem == true) {
         $emailSenderOrRecipientEmailFoundInSystem = $emailRecipientFoundInSystem;
     }
     if ($emailOwner instanceof User) {
         $box = EmailBoxUtil::getDefaultEmailBoxByUser($emailOwner);
     } else {
         $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     }
     if (!$emailSenderOrRecipientEmailFoundInSystem) {
         $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_ARCHIVED_UNMATCHED);
         $notificationMessage = new NotificationMessage();
         $notificationMessage->textContent = Zurmo::t('EmailMessagesModule', 'At least one archived email message does ' . 'not match any records in the system. ' . 'To manually match them use this link: {url}.', array('{url}' => Yii::app()->createUrl('emailMessages/default/matchingList')));
         $notificationMessage->htmlContent = Zurmo::t('EmailMessagesModule', 'At least one archived email message does ' . 'not match any records in the system. ' . '<a href="{url}" target="_blank">Click here</a> to manually match them.', array('{url}' => Yii::app()->createUrl('emailMessages/default/matchingList')));
         if ($emailOwner instanceof User) {
             $rules = new EmailMessageArchivingEmailAddressNotMatchingNotificationRules();
             $rules->addUser($emailOwner);
             NotificationsUtil::submit($notificationMessage, $rules);
         }
     } else {
         $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_ARCHIVED);
     }
     if (!empty($message->attachments)) {
         foreach ($message->attachments as $attachment) {
             if (!$attachment['is_attachment']) {
                 continue;
             }
             $file = EmailArchivingUtil::createEmailAttachment($attachment);
             if ($file instanceof FileModel) {
                 $emailMessage->files->add($file);
             }
         }
     }
     $emailMessage->sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $validated = $emailMessage->validate();
     if (!$validated) {
         // Email message couldn't be validated(some related models can't be validated). Email user.
         $this->resolveMessageSubjectAndContentAndSendSystemMessage('EmailMessageNotValidated', $message);
         return false;
     }
     EmailArchivingUtil::resolveSanitizeFromImapToUtf8($emailMessage);
     $saved = $emailMessage->save();
     try {
         if (!$saved) {
             throw new NotSupportedException();
         }
         if (isset($message->uid)) {
             $this->imapManager->deleteMessage($message->uid);
             $this->getMessageLogger()->addDebugMessage('Deleted Message id: ' . $message->uid);
         }
     } catch (NotSupportedException $e) {
         // Email message couldn't be saved. Email user.
         $this->resolveMessageSubjectAndContentAndSendSystemMessage('EmailMessageNotSaved', $message);
         return false;
     }
     return true;
 }
 public static function makeMonitorStuckJobNotification()
 {
     $message = new NotificationMessage();
     $message->textContent = MonitorJob::getStuckStringContent();
     $message->htmlContent = MonitorJob::getStuckStringContent();
     $rules = new StuckMonitorJobNotificationRules();
     NotificationsUtil::submit($message, $rules);
 }
Example #17
0
 /**
  * @param array $jobTitleLabels
  */
 public static function makeJobStuckNotification(array $jobTitleLabels)
 {
     $message = new NotificationMessage();
     $prefixContent = Zurmo::t('JobsManagerModule', 'Stuck Job| Stuck Jobs', array(count($jobTitleLabels)));
     $message->textContent = $prefixContent;
     $message->htmlContent = $prefixContent;
     $textContent = null;
     $htmlContent = null;
     foreach ($jobTitleLabels as $label) {
         if ($textContent != null) {
             $textContent .= ', ';
         }
         if ($htmlContent != null) {
             $htmlContent .= ', ';
         }
         $textContent .= $label;
         $htmlContent .= $label;
     }
     $message->textContent .= ': ' . $textContent;
     $message->htmlContent .= ': ' . $htmlContent;
     $rules = new StuckJobsNotificationRules();
     NotificationsUtil::submit($message, $rules);
 }
 public function actionRedeemReward($id)
 {
     $gameReward = static::getModelAndCatchNotFoundAndDisplayError('GameReward', intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($gameReward);
     $gameCoin = GameCoin::resolveByPerson(Yii::app()->user->userModel);
     if ($gameCoin->value < $gameReward->cost) {
         $message = Zurmo::t('GameRewardsModule', 'You do not have enough coins to redeem this reward');
         echo CJSON::encode(array('message' => $message));
         Yii::app()->end(0, false);
     }
     if ($gameReward->quantity <= 0) {
         $message = Zurmo::t('GameRewardsModule', 'This reward is no longer available');
         echo CJSON::encode(array('message' => $message));
         Yii::app()->end(0, false);
     }
     $gameRewardTransaction = new GameRewardTransaction();
     $gameRewardTransaction->quantity = 1;
     $gameRewardTransaction->person = Yii::app()->user->userModel;
     $gameReward->transactions->add($gameRewardTransaction);
     $gameCoin->removeValue((int) $gameReward->cost);
     if (!$gameCoin->save()) {
         throw new FailedToSaveModelException();
     }
     $gameReward->quantity = $gameReward->quantity - 1;
     if (!$gameReward->save()) {
         throw new FailedToSaveModelException();
     }
     //Notify the owner of the game reward
     $message = new NotificationMessage();
     $message->htmlContent = Zurmo::t('JobsManagerModule', '{name} was redeemed by {personFullName}.', array('{name}' => strval($gameReward), '{personFullName}' => strval(Yii::app()->user->userModel)));
     $url = Yii::app()->createAbsoluteUrl('gameRewards/default/details/', array('id' => $gameReward->id));
     $message->htmlContent .= "<br/>" . ZurmoHtml::link(Zurmo::t('Core', 'Click Here'), $url);
     $rules = new GameRewardRedeemedNotificationRules();
     $rules->addUser($gameReward->owner);
     NotificationsUtil::submit($message, $rules);
     $message = Zurmo::t('GameRewardsModule', '{name} has been redeemed.', array('{name}' => strval($gameReward)));
     echo CJSON::encode(array('message' => $message));
     Yii::app()->end(0, false);
 }
Example #19
0
 /**
  * @param ExportItem $exportItem
  * @throws FailedToSaveModelException
  */
 protected function processCompletedWithSecurityExceptionExportItem(ExportItem $exportItem)
 {
     $exportItem->isCompleted = true;
     $saved = $exportItem->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     $message = new NotificationMessage();
     $message->htmlContent = Zurmo::t('ExportModule', 'Export requested on {dateTime} was unable to be completed due to a permissions error.', array('{dateTime}' => DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($exportItem->createdDateTime, 'long')));
     $message->textContent = $message->htmlContent;
     $rules = $this->getExportProcessCompletedNotificationRulesForExportItem($exportItem);
     NotificationsUtil::submit($message, $rules);
 }
 /**
  * @param Mission $mission
  */
 public static function makeAndSubmitNewMissionNotificationMessage(Mission $mission)
 {
     $rules = new NewMissionNotificationRules();
     $rules->setModel($mission);
     $notificationMessage = new NotificationMessage();
     $notificationMessage->textContent = static::getTextContentForNotificationMessage($mission);
     $notificationMessage->htmlContent = static::getHtmlContentForNotificationMessage($mission);
     $peopleToSendNotification = static::resolvePeopleToSendNotificationToOnNewMission($mission);
     if (count($peopleToSendNotification) > 0) {
         foreach ($peopleToSendNotification as $person) {
             $rules->addUser($person);
         }
         NotificationsUtil::submit($notificationMessage, $rules);
     }
 }
 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 actionRecentNotifcations()
 {
     echo NotificationsUtil::getRecentAjaxContentByUser(Yii::app()->user->userModel, 10);
     $linkHtmlOptions = array('class' => 'view-all-notifications');
     echo ZurmoHtml::link(Zurmo::t('NotificationsModule', 'View All Notifications'), array('/notifications/default'), $linkHtmlOptions);
 }
 /**
  * Send notification about unmatched email messages to email owner
  * @param mixed $emailOwner
  * @return void
  */
 protected function sendArchivedUnmatchedNotificationToEmailOwner($emailOwner)
 {
     $notificationMessage = new NotificationMessage();
     $notificationMessage->textContent = Zurmo::t('EmailMessagesModule', 'At least one archived email message does ' . 'not match any records in the system. ' . 'To manually match them use this link: {url}.', array('{url}' => Yii::app()->createUrl('emailMessages/default/matchingList')));
     $notificationMessage->htmlContent = Zurmo::t('EmailMessagesModule', 'At least one archived email message does ' . 'not match any records in the system. ' . '<a href="{url}">Click here</a> to manually match them.', array('{url}' => Yii::app()->createUrl('emailMessages/default/matchingList')));
     if ($emailOwner instanceof User) {
         $rules = new EmailMessageArchivingEmailAddressNotMatchingNotificationRules();
         $rules->addUser($emailOwner);
         NotificationsUtil::submit($notificationMessage, $rules);
     }
 }
Example #24
0
 /**
  * Create at most one notification for a user when there are new unread comments.
  * @param User $userToReceiveMessage
  * @param integer $missionId
  * @param string $messageContent
  */
 public static function makeAndSubmitNewCommentNotificationMessage(User $userToReceiveMessage)
 {
     assert('$userToReceiveMessage->id > 0');
     $message = new NotificationMessage();
     $url = Yii::app()->createAbsoluteUrl('missions/default/list/');
     $message->htmlContent = ZurmoHtml::link(Zurmo::t('Core', 'Click Here'), $url);
     $rules = new MissionUnreadCommentNotificationRules();
     $rules->addUser($userToReceiveMessage);
     NotificationsUtil::submit($message, $rules);
 }
 /**
  * @param Conversation $conversation
  * @param array $people
  */
 public static function resolveEmailInvitesByPeople($conversation, $people)
 {
     assert('$conversation instanceof Conversation && $conversation->id > 0');
     if (count($people) == 0) {
         return;
     }
     $rules = new ConversationInvitesNotificationRules();
     $message = new NotificationMessage();
     $message->textContent = static::getParticipantInviteEmailTextContent($conversation);
     $message->htmlContent = static::getParticipantInviteEmailHtmlContent($conversation);
     foreach ($people as $personOrUserModel) {
         if ($personOrUserModel instanceof User) {
             $rules->addUser($personOrUserModel);
         } else {
             static::sendEmailInviteToParticipant($conversation, $personOrUserModel);
         }
     }
     NotificationsUtil::submit($message, $rules);
 }
 protected function createWorkflowTriggerUserPrimaryEmailAddressRequiredNotificationForUser(User $user)
 {
     $notificationMessage = new NotificationMessage();
     $notificationMessage->htmlContent = Zurmo::t('WorkflowsModule', 'Please configure your primary email address to be able to receive workflow notifications from Zurmo.');
     $rules = new WorkflowTriggerUserPrimaryEmailAddressRequiredNotificationRules();
     $rules->addUser($user);
     NotificationsUtil::submit($notificationMessage, $rules);
 }