Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ProjectsNotificationUtil.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
49  public static function submitProjectNotificationMessage(Project $project, $action, Task $task = null,
50  User $relatedUser = null)
51  {
52  assert('is_string($action)');
53  $message = static::getNotificationMessageByAction($project, $action, $task, $relatedUser);
54  $notificationRulesClassName = static::resolveNotificationRulesClassByAction($action);
55  $rule = new $notificationRulesClassName();
56  $peopleToSendNotification = static::resolvePeopleToSendNotification($project, $action);
57  foreach ($peopleToSendNotification as $person)
58  {
59  $rule->addUser($person);
60  }
61  $rule->setModel($project);
62  $rule->setAdditionalModel($task);
63  $rule->setAllowDuplicates(true);
64  static::processProjectNotification($message, $rule, $action);
65  }
66 
73  protected static function processProjectNotification(NotificationMessage $message, ProjectNotificationRules $rule, $action)
74  {
75  assert('is_string($action)');
76  $users = $rule->getUsers();
77  //This scenario would be there when there is only one subscriber. In that case users would
78  //be zero
79  if (count($users) == 0)
80  {
81  return;
82  }
83  $notifications = static::resolveAndGetNotifications($message, $rule);
84  if (static::resolveShouldSendEmailIfCritical())
85  {
86  foreach ($notifications as $notification)
87  {
88  static::sendProjectEmail($notification, $rule, $action);
89  }
90  }
91  }
92 
101  protected static function getNotificationMessageByAction(Project $project, $action, Task $task = null,
102  User $relatedUser = null)
103  {
104  assert('is_string($action)');
105  $message = new NotificationMessage();
106  $messageContent = static::getEmailMessageContent($project, $action, $task, $relatedUser);
107  $url = Yii::app()->createAbsoluteUrl('projects/default/details/',
108  array('id' => $project->id));
109  $message->textContent = $messageContent . "\n";
110  $message->textContent .= ZurmoHtml::link(Zurmo::t('Core', 'Click Here'), $url, array('target' => '_blank'));
111  $message->htmlContent = $messageContent . "<br/>";
112  $message->htmlContent .= ZurmoHtml::link(Zurmo::t('Core', 'Click Here'), $url, array('target' => '_blank'));
113  return $message;
114  }
115 
122  public static function resolvePeopleToSendNotification(Project $project, $action)
123  {
124  assert('is_string($action)');
125  $peopleToSendNotification = array();
126  if ($action == ProjectAuditEvent::PROJECT_CREATED ||
127  $action == ProjectAuditEvent::TASK_ADDED ||
128  $action == ProjectAuditEvent::PROJECT_ARCHIVED)
129  {
130  $peopleToSendNotification[] = $project->owner;
131  }
132  return $peopleToSendNotification;
133  }
134 
143  public static function getEmailMessageContent(Project $project, $action, Task $task = null, User $relatedUser = null)
144  {
145  assert('is_string($action)');
146  if ($action == ProjectAuditEvent::PROJECT_CREATED)
147  {
148  return Zurmo::t('ProjectsModule', "The project, '{project}', is now owned by you.",
149  array('{project}' => strval($project)));
150  }
151  elseif ($action == ProjectAuditEvent::TASK_ADDED)
152  {
153  return Zurmo::t('ProjectsModule', "New task, {task}, was created for project, '{project}'. Created by {user}",
154  array('{task}' => strval($task),
155  '{project}' => strval($project),
156  '{user}' => strval($relatedUser)));
157  }
158  elseif ($action == ProjectAuditEvent::PROJECT_ARCHIVED)
159  {
160  return Zurmo::t('ProjectsModule', "The project, '{project}', is now archived.",
161  array('{project}' => strval($project)));
162  }
163  }
164 
171  protected static function sendProjectEmail(Notification $notification, ProjectNotificationRules $rule, $action)
172  {
173  assert('is_string($action)');
174  $notificationSettingName = static::resolveNotificationSettingNameFromType($rule->getType());
175  if ($notification->owner->primaryEmail->emailAddress !== null &&
176  UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($notification->owner,
177  $notificationSettingName, 'email'))
178  {
179  $emailMessage = static::makeEmailMessage();
180  $emailMessage->subject = static::getEmailSubject($notification, $rule);
181  $emailMessage->content = static::makeEmailContent($notification);
182  $emailMessage->sender = static::makeSender();
183  $emailMessage->recipients->add(static::makeRecipient($notification));
184  $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
185  $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
186  try
187  {
188  Yii::app()->emailHelper->sendImmediately($emailMessage);
189  }
190  catch (CException $e)
191  {
192  //Not sure what to do yet when catching an exception here. Currently ignoring gracefully.
193  }
194  }
195  }
196 
202  protected static function resolveNotificationRulesClassByAction($action)
203  {
204  assert('is_string($action)');
205  switch ($action)
206  {
207  case ProjectAuditEvent::PROJECT_CREATED:
208  return 'NewProjectNotificationRules';
209  break;
210  case ProjectAuditEvent::TASK_ADDED:
211  return 'ProjectTaskAddedNotificationRules';
212  break;
213  case ProjectAuditEvent::PROJECT_ARCHIVED:
214  return 'ArchivedProjectNotificationRules';
215  break;
216  default:
217  throw new NotFoundException();
218  }
219  }
220  }
221 ?>
Definition: User.php:37
static getEmailMessageContent(Project $project, $action, Task $task=null, User $relatedUser=null)
static getNotificationMessageByAction(Project $project, $action, Task $task=null, User $relatedUser=null)
Definition: Task.php:37
static resolveNotificationRulesClassByAction($action)
static sendProjectEmail(Notification $notification, ProjectNotificationRules $rule, $action)
static resolvePeopleToSendNotification(Project $project, $action)
static processProjectNotification(NotificationMessage $message, ProjectNotificationRules $rule, $action)
static submitProjectNotificationMessage(Project $project, $action, Task $task=null, User $relatedUser=null)
Generated on Fri Jul 3 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.