Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
Mission.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 
42  {
43  const STATUS_AVAILABLE = 1;
44 
45  const STATUS_TAKEN = 2;
46 
47  const STATUS_COMPLETED = 3;
48 
49  const STATUS_REJECTED = 4;
50 
51  const STATUS_ACCEPTED = 5;
52 
53  private $sendOwnerUnreadCommentNotification = false;
54 
55  private $sendTakenByUserUnreadCommentNotification = false;
56 
57  public static function getMashableActivityRulesType()
58  {
59  return 'Mission';
60  }
61 
62  public static function getMashableInboxRulesType()
63  {
64  return 'Mission';
65  }
66 
67  public function __toString()
68  {
69  try
70  {
71  if (trim($this->description) == '')
72  {
73  return Zurmo::t('Core', '(Unnamed)');
74  }
75  return $this->description;
76  }
78  {
79  return '';
80  }
81  }
82 
87  protected static function getModifiedSignalAttribute()
88  {
89  return 'description';
90  }
91 
92  public function onCreated()
93  {
94  parent::onCreated();
95  $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
96  }
97 
98  public static function getModuleClassName()
99  {
100  return 'MissionsModule';
101  }
102 
103  public static function canSaveMetadata()
104  {
105  return true;
106  }
107 
108  public static function getDefaultMetadata()
109  {
110  $metadata = parent::getDefaultMetadata();
111  $metadata[__CLASS__] = array(
112  'members' => array(
113  'description',
114  'dueDateTime',
115  'latestDateTime',
116  'reward',
117  'status',
118  ),
119  'relations' => array(
120  'comments' => array(static::HAS_MANY, 'Comment', static::OWNED,
121  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
122  'files' => array(static::HAS_MANY, 'FileModel', static::OWNED,
123  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
124  'takenByUser' => array(static::HAS_ONE, 'User', static::NOT_OWNED,
125  static::LINK_TYPE_SPECIFIC, 'takenByUser'),
126  'personsWhoHaveNotReadLatest' => array(static::HAS_MANY, 'PersonWhoHaveNotReadLatest',
127  static::OWNED),
128  ),
129  'rules' => array(
130  array('description', 'required'),
131  array('description', 'type', 'type' => 'string'),
132  array('dueDateTime', 'type', 'type' => 'datetime'),
133  array('latestDateTime', 'required'),
134  array('latestDateTime', 'readOnly'),
135  array('latestDateTime', 'type', 'type' => 'datetime'),
136  array('status', 'required'),
137  array('status', 'type', 'type' => 'integer'),
138  array('reward', 'type', 'type' => 'string'),
139 
140  ),
141  'elements' => array(
142  'description' => 'TextArea',
143  'dueDateTime' => 'DateTime',
144  'files' => 'Files',
145  'latestDateTime' => 'DateTime',
146  'reward' => 'TextArea',
147  ),
148  'defaultSortAttribute' => 'description',
149  'noAudit' => array(
150  'description',
151  'dueDateTime',
152  'latestDateTime',
153  'reward',
154  ),
155  );
156  return $metadata;
157  }
158 
159  protected static function translatedAttributeLabels($language)
160  {
161  return array_merge(parent::translatedAttributeLabels($language),
162  array(
163  'comments' => Zurmo::t('CommentsModule', 'Comments', array(), null, $language),
164  'description' => Zurmo::t('ZurmoModule', 'Description', array(), null, $language),
165  'dueDateTime' => Zurmo::t('TasksModule', 'Due On', array(), null, $language),
166  'files' => Zurmo::t('ZurmoModule', 'Files', array(), null, $language),
167  'latestDateTime' => Zurmo::t('ZurmoModule', 'Latest Date Time', array(), null, $language),
168  'personsWhoHaveNotReadLatest' => Zurmo::t('MissionsModule', 'Persons Who Have Not Read Latest', array(), null, $language),
169  'reward' => Zurmo::t('MissionsModule', 'Reward', array(), null, $language),
170  'status' => Zurmo::t('ZurmoModule', 'Status', array(), null, $language),
171  'takenByUser' => Zurmo::t('MissionsModule', 'Taken By User', array(), null, $language),
172  )
173  );
174  }
175 
176  public static function isTypeDeletable()
177  {
178  return true;
179  }
180 
181  public static function hasReadPermissionsOptimization()
182  {
183  return true;
184  }
185 
186  public static function getGamificationRulesType()
187  {
188  return 'MissionGamification';
189  }
190 
196  protected function beforeSave()
197  {
198  $missionRules = new MissionMashableInboxRules();
199  $personsToAddAsHaveNotReadLatest = array();
200  if (parent::beforeSave())
201  {
202  if ($this->getIsNewModel())
203  {
204  $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
205  $personsToAddAsHaveNotReadLatest = MissionsUtil::resolvePeopleToSendNotificationToOnNewMission($this);
206  }
207  if (isset($this->originalAttributeValues['status']) &&
208  $this->originalAttributeValues['status'] != $this->status &&
209  $this->status == self::STATUS_TAKEN)
210  {
212  }
213  if ($this->comments->isModified())
214  {
215  $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
216  foreach ($this->comments as $comment)
217  {
218  if ($comment->id < 0)
219  {
220  if (Yii::app()->user->userModel != $this->owner)
221  {
222  $this->sendOwnerUnreadCommentNotification = true;
223  }
224  if (Yii::app()->user->userModel != $this->takenByUser && $this->takenByUser->id > 0)
225  {
226  $this->sendTakenByUserUnreadCommentNotification = true;
227  }
228  }
229  }
230  $people = MissionsUtil::resolvePeopleToSendNotificationToOnNewComment($this, Yii::app()->user->userModel);
231  foreach ($people as $person)
232  {
233  if ($missionRules->hasUserReadLatest($this, $person))
234  {
235  if (!in_array($person, $personsToAddAsHaveNotReadLatest))
236  {
237  $personsToAddAsHaveNotReadLatest[] = $person;
238  }
239  }
240  }
241  }
242  foreach ($personsToAddAsHaveNotReadLatest as $person)
243  {
244  $personWhoHaveNotReadLatest = $missionRules->makePersonWhoHasNotReadLatest($person);
245  $personsToAddAsHaveNotReadLatest[] = $personWhoHaveNotReadLatest;
246  $this->personsWhoHaveNotReadLatest->add($personWhoHaveNotReadLatest);
247  }
248  return true;
249  }
250  else
251  {
252  return false;
253  }
254  }
255 
261  protected function afterSave()
262  {
263  if ($this->isNewModel && $this->getScenario() != 'importModel')
264  {
266  }
267  if (((isset($this->originalAttributeValues['status'])) && !$this->isNewModel) &&
268  $this->originalAttributeValues['status'] != $this->status)
269  {
270  if ($this->status == self::STATUS_TAKEN)
271  {
272  $messageContent = Zurmo::t('MissionsModule', 'A mission you created has been taken on by {takenByUserName}',
273  array('{takenByUserName}' => strval($this->takenByUser)));
274  MissionsUtil::makeAndSubmitStatusChangeNotificationMessage($this->owner, $this->id, $messageContent);
275  }
276  elseif ($this->status == self::STATUS_COMPLETED)
277  {
278  $messageContent = Zurmo::t('MissionsModule', 'A mission you created has been completed');
279  MissionsUtil::makeAndSubmitStatusChangeNotificationMessage($this->owner, $this->id, $messageContent);
280  }
281  elseif ($this->status == self::STATUS_REJECTED && $this->takenByUser->id > 0)
282  {
283  $messageContent = Zurmo::t('MissionsModule', 'A mission you completed has been rejected');
284  MissionsUtil::makeAndSubmitStatusChangeNotificationMessage($this->takenByUser, $this->id, $messageContent);
285  }
286  elseif ($this->status == self::STATUS_ACCEPTED && $this->takenByUser->id > 0)
287  {
288  $messageContent = Zurmo::t('MissionsModule', 'A mission you completed has been accepted');
289  MissionsUtil::makeAndSubmitStatusChangeNotificationMessage($this->takenByUser, $this->id, $messageContent);
290  }
291  }
292  parent::afterSave();
293  }
294 
295  public static function hasRelatedItems()
296  {
297  return false;
298  }
299  }
300 ?>
static makeAndSubmitStatusChangeNotificationMessage(User $userToReceiveMessage, $missionId, $messageContent)
beforeSave()
Definition: Mission.php:196
static markAllUserHasReadLatestExceptOwnerAndTakenBy(Mission $mission)
unrestrictedSet($attributeName, $value)
static resolvePeopleToSendNotificationToOnNewComment(Mission $mission, User $user)
static getModifiedSignalAttribute()
Definition: Mission.php:87
static makeAndSubmitNewMissionNotificationMessage(Mission $mission)
static resolvePeopleToSendNotificationToOnNewMission(Mission $mission)
afterSave()
Definition: Mission.php:261
Generated on Wed Jul 8 2020 07:10:35
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.