/** * Creates notification message for new comment * @param $model * @param Comment $comment * @return NotificationMessage */ protected static function createNotificationMessage($model, Comment $comment) { $notificationMessage = new NotificationMessage(); $url = static::getUrlToEmail($model); $shortUrl = ShortUrlUtil::createShortUrl($url); $textContent = Zurmo::t('CommentsModule', 'Hello, {lineBreak} {updaterName} added a new comment to the ' . '{strongStartTag}{modelName}{strongEndTag}: {lineBreak}' . '"{commentDescription}." {lineBreak}{lineBreak} {url} ', array('{lineBreak}' => "\n", '{strongStartTag}' => null, '{strongEndTag}' => null, '{updaterName}' => strval($comment->createdByUser), '{modelName}' => $model->getModelLabelByTypeAndLanguage('SingularLowerCase'), '{commentDescription}' => strval($comment), '{url}' => $shortUrl)); $notificationMessage->textContent = $textContent; $htmlContent = Zurmo::t('CommentsModule', 'Hello, {lineBreak} {updaterName} added a new comment to the ' . '{strongStartTag}{url}{strongEndTag}: {lineBreak}' . '"{commentDescription}."', array('{lineBreak}' => "<br/>", '{strongStartTag}' => '<strong>', '{strongEndTag}' => '</strong>', '{updaterName}' => strval($comment->createdByUser), '{commentDescription}' => strval($comment), '{url}' => ZurmoHtml::link($model->getModelLabelByTypeAndLanguage('SingularLowerCase'), $url, array('target' => '_blank')))); $notificationMessage->htmlContent = DataUtil::purifyHtml($htmlContent); return $notificationMessage; }
/** * @param RedBeanModel $model * @param Comment $comment * @param User $user * @return EmailMessageContent */ public static function getEmailContent(RedBeanModel $model, Comment $comment, User $user) { $emailContent = new EmailMessageContent(); $url = static::getUrlToEmail($model); $shortUrl = ShortUrlUtil::createShortUrl($url); $textContent = Zurmo::t('CommentsModule', 'Hello, {lineBreak} {updaterName} added a new comment to the ' . '{strongStartTag}{modelName}{strongEndTag}: {lineBreak}' . '"{commentDescription}." {lineBreak}{lineBreak} {url} ', array('{lineBreak}' => "\n", '{strongStartTag}' => null, '{strongEndTag}' => null, '{updaterName}' => strval($comment->createdByUser), '{modelName}' => $model->getModelLabelByTypeAndLanguage('SingularLowerCase'), '{commentDescription}' => strval($comment), '{url}' => $shortUrl)); $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate($textContent); $htmlContent = Zurmo::t('CommentsModule', 'Hello, {lineBreak} {updaterName} added a new comment to the ' . '{strongStartTag}{url}{strongEndTag}: {lineBreak}' . '"{commentDescription}."', array('{lineBreak}' => "<br/>", '{strongStartTag}' => '<strong>', '{strongEndTag}' => '</strong>', '{updaterName}' => strval($comment->createdByUser), '{commentDescription}' => strval($comment), '{url}' => ZurmoHtml::link($model->getModelLabelByTypeAndLanguage('SingularLowerCase'), $url))); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate($htmlContent); return $emailContent; }
/** * @see BaseJob::run() */ public function run() { $workflows = WorkflowActionsUtil::getWorkflowsMissingRequiredActionAttributes(); if (count($workflows) > 0) { $message = new NotificationMessage(); $commonMessage = 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 = $commonMessage; $message->htmlContent .= "<div><ul>"; $message->textContent = $commonMessage; 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, array('target' => '_blank')); $message->htmlContent .= "</li>"; $message->textContent .= "\n" . strval($workflow) . ': ' . ShortUrlUtil::createShortUrl($url); } $message->htmlContent .= "</ul></div>"; $rules = new WorkflowValidityCheckNotificationRules(); NotificationsUtil::submit($message, $rules); } return true; }
protected static function getParticipantInviteEmailTextContent(Conversation $conversation) { $url = ShortUrlUtil::createShortUrl(static::getUrlToConversationDetailAndRelationsView($conversation->id)); $content = Zurmo::t('ConversationsModule', '{headerStartTag}Join the Conversation{headerEndTag}{headerLineBreak}{ownerName} ' . 'would like you to join a conversation {strongStartTag}"{conversationSubject}"{strongEndTag}', array('{headerStartTag}' => null, '{headerEndTag}' => null, '{headerLineBreak}' => "\n\n", '{strongStartTag}' => null, '{strongEndTag}' => null, '{ownerName}' => $conversation->owner, '{conversationSubject}' => $conversation->subject)); $content .= "\n\n"; $content .= $url; return $content; }
/** * @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); }
/** * Based on the current theme, retrieve the email notification template for text content and replace the * content tags with the appropriate strings * @param string $bodyContent * @param User $user * @return string */ public static function resolveNotificationTextTemplate($bodyContent, User $user = null) { assert('is_string($bodyContent)'); if ($user === null) { $user = Yii::app()->user->userModel; } $url = ShortUrlUtil::createShortUrl(Yii::app()->createAbsoluteUrl('users/default/configurationEdit', array('id' => $user->id))); $textTemplate = self::getNotificationTextTemplate(); $textContent = array(); $textContent['{bodyContent}'] = $bodyContent; $textContent['{preferenceContent}'] = Zurmo::t('EmailMessagesModule', 'Manage your email preferences') . ': ' . $url; $textContent['{sourceContent}'] = Zurmo::t('EmailMessagesModule', 'Powered By Zurmo', LabelUtil::getTranslationParamsForAllModules()); $textContent['{sourceContent}'] .= PHP_EOL . self::resolveWebsiteUrlForNotificationMessage(); return strtr($textTemplate, $textContent); }
/** * @param array $textContent * @param User|null $user * @param $isTestNotification * @return array */ protected static function resolvePreferenceAndSourceContentForTextTemplate(array $textContent, User $user = null, $isTestNotification) { if ($user === null) { $user = Yii::app()->user->userModel; } if (isset($isTestNotification) && $isTestNotification) { $textContent['{preferenceContent}'] = ''; } else { $url = ShortUrlUtil::createShortUrl(Yii::app()->createAbsoluteUrl('users/default/configurationEdit', array('id' => $user->id))); $textContent['{preferenceContent}'] = Zurmo::t('EmailMessagesModule', 'Manage your email preferences') . ': ' . $url; } $textContent['{sourceContent}'] = Zurmo::t('EmailMessagesModule', 'Powered By Zurmo', LabelUtil::getTranslationParamsForAllModules()); $textContent['{sourceContent}'] .= PHP_EOL . self::resolveWebsiteUrlForNotificationMessage(); return $textContent; }
protected function updateNotificationMessage($workflows, $message, $commonMessage) { if ($message->htmlContent == '') { $message->htmlContent = $commonMessage; } else { $message->htmlContent = '<br /><br /><br />' . $commonMessage; } $message->htmlContent .= "<div><ul>"; if ($message->textContent == '') { $message->textContent = $commonMessage; } else { $message->textContent = "\n\n\n" . $commonMessage; } 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, array('target' => '_blank')); $message->htmlContent .= "</li>"; $message->textContent .= "\n" . strval($workflow) . ': ' . ShortUrlUtil::createShortUrl($url); } $message->htmlContent .= "</ul></div>"; return $message; }
/** * 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(); $commonContent = 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))); $message->htmlContent = $commonContent; $url = Yii::app()->createAbsoluteUrl('workflows/default/list'); $message->htmlContent .= "<br/>" . ZurmoHtml::link(Zurmo::t('WorkflowsModule', 'Manage Workflows'), $url, array('target' => '_blank')); $message->textContent = $commonContent; $message->textContent .= "\n" . Zurmo::t('WorkflowsModule', 'Manage Workflows') . ': ' . ShortUrlUtil::createShortUrl($url); $rules = new WorkflowMaximumDepthNotificationRules(); NotificationsUtil::submit($message, $rules); } }
/** * @param ExportItem $exportItem * @param ExportFileModel $exportFileModel * @throws FailedToSaveModelException */ protected function processCompletedExportItem(ExportItem $exportItem, ExportFileModel $exportFileModel) { $exportItem->isCompleted = true; $exportItem->exportFileModel = $exportFileModel; $saved = $exportItem->save(); if (!$saved) { throw new FailedToSaveModelException(); } $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()->createAbsoluteUrl('export/default/download', array('id' => $exportItem->id)), '{dateTime}' => DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($exportItem->createdDateTime, 'long'))); $message->textContent = Zurmo::t('ExportModule', 'Export of {fileName} requested on {dateTime} is completed. Use this {url} to download file!', array('{fileName}' => $exportItem->exportFileName, '{url}' => ShortUrlUtil::createShortUrl(Yii::app()->createAbsoluteUrl('export/default/download', array('id' => $exportItem->id))), '{dateTime}' => DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($exportItem->createdDateTime, 'long'))); $rules = $this->getExportProcessCompletedNotificationRulesForExportItem($exportItem); 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(); $commonMessage = Zurmo::t('JobsManagerModule', '{name} was redeemed by {personFullName}.', array('{name}' => strval($gameReward), '{personFullName}' => strval(Yii::app()->user->userModel))); $message->htmlContent = $commonMessage; $url = Yii::app()->createAbsoluteUrl('gameRewards/default/details/', array('id' => $gameReward->id)); $message->htmlContent .= "<br/>" . ZurmoHtml::link(Zurmo::t('Core', 'Click Here'), $url, array('target' => '_blank')); $message->textContent = $commonMessage . "\n"; $message->textContent .= Zurmo::t('GameRewardsModule', 'Use this link to get more details: {url}', array('{url}' => ShortUrlUtil::createShortUrl($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); }
/** * @param Mission $mission * @param User $user * @return EmailMessageContent */ public static function getEmailContent(Mission $mission, User $user) { $emailContent = new EmailMessageContent(); $url = CommentsUtil::getUrlToEmail($mission); $shortUrl = ShortUrlUtil::createShortUrl($url); $textContent = Zurmo::t('MissionsModule', 'Hello, {lineBreak}There is a new mission. ' . 'Be the first one to start it and get this great reward: {reward}.' . '{lineBreak}{lineBreak} {url}', array('{lineBreak}' => "\n", '{reward}' => $mission->reward, '{url}' => $shortUrl)); $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate($textContent, $user); $htmlContent = Zurmo::t('MissionsModule', 'Hello, {lineBreak}There is a new {url}. ' . 'Be the first one to start it and get this great reward: {reward}.', array('{lineBreak}' => "<br/>", '{strongStartTag}' => '<strong>', '{strongEndTag}' => '</strong>', '{reward}' => $mission->reward, '{url}' => ZurmoHtml::link($mission->getModelLabelByTypeAndLanguage('SingularLowerCase'), $url))); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate($htmlContent, $user); return $emailContent; }
/** * @param Mission $mission * @return string */ protected static function getTextContentForNotificationMessage(Mission $mission) { $url = CommentsUtil::getUrlToEmail($mission); $shortUrl = ShortUrlUtil::createShortUrl($url); $textContent = Zurmo::t('MissionsModule', 'Hello, {lineBreak}There is a new mission. ' . 'Be the first one to start it and get this great reward: {reward}.' . '{lineBreak}{lineBreak} {url}', array('{lineBreak}' => "\n", '{reward}' => $mission->reward, '{url}' => $shortUrl)); return $textContent; }