Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
Task.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 
37  class Task extends MashableActivity
38  {
39  /*
40  * Constants for task status
41  */
42  const STATUS_NEW = 1;
43 
44  const STATUS_IN_PROGRESS = 2;
45 
46  const STATUS_AWAITING_ACCEPTANCE = 3;
47 
48  const STATUS_REJECTED = 4;
49 
50  const STATUS_COMPLETED = 5;
51 
55  public function __toString()
56  {
57  try
58  {
59  if (trim($this->name) == '')
60  {
61  return Zurmo::t('Core', '(Unnamed)');
62  }
63  return $this->name;
64  }
66  {
67  return '';
68  }
69  }
70 
75  public static function getModuleClassName()
76  {
77  return 'TasksModule';
78  }
79 
83  public static function canSaveMetadata()
84  {
85  return true;
86  }
87 
91  public static function getDefaultMetadata()
92  {
93  $metadata = parent::getDefaultMetadata();
94  $metadata[__CLASS__] = array(
95  'members' => array(
96  'completedDateTime',
97  'completed',
98  'description',
99  'dueDateTime',
100  'name',
101  'status'
102  ),
103  'relations' => array(
104  'requestedByUser' => array(static::HAS_ONE, 'User', static::NOT_OWNED,
105  static::LINK_TYPE_SPECIFIC, 'requestedByUser'),
106  'comments' => array(static::HAS_MANY, 'Comment', static::OWNED,
107  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
108  'checkListItems' => array(static::HAS_MANY, 'TaskCheckListItem', static::OWNED),
109  'notificationSubscribers' => array(static::HAS_MANY, 'NotificationSubscriber', static::OWNED,
110  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
111  'files' => array(static::HAS_MANY, 'FileModel', static::OWNED,
112  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
113  'project' => array(static::HAS_ONE, 'Project'),
114  ),
115  'rules' => array(
116  array('completedDateTime', 'type', 'type' => 'datetime'),
117  array('completed', 'boolean'),
118  array('dueDateTime', 'type', 'type' => 'datetime'),
119  array('description', 'type', 'type' => 'string'),
120  array('name', 'required'),
121  array('name', 'type', 'type' => 'string'),
122  array('name', 'length', 'min' => 1, 'max' => 128),
123  array('status', 'type', 'type' => 'integer'),
124  array('status', 'default', 'value' => Task::STATUS_NEW),
125  array('status', 'required'),
126  ),
127  'elements' => array(
128  'completedDateTime' => 'DateTime',
129  'description' => 'TextArea',
130  'dueDateTime' => 'DateTime',
131  'requestedByUser' => 'User',
132  'comment' => 'Comment',
133  'checkListItem' => 'TaskCheckListItem',
134  'files' => 'Files',
135  'project' => 'Project',
136  'status' => 'TaskStatusDropDown'
137  ),
138  'defaultSortAttribute' => 'name',
139  'noAudit' => array(
140  'description'
141  ),
142  );
143  return $metadata;
144  }
145 
151  protected function constructDerived($bean, $setDefaults)
152  {
153  assert('$bean === null || $bean instanceof RedBean_OODBBean');
154  assert('is_bool($setDefaults)');
155  parent::constructDerived($bean, $setDefaults);
156  // Even though setting the requestedByUser is not technically
157  // a default in the sense of a Yii default rule,
158  // if true the requestedByUser is not set because blank models
159  // are used for searching mass updating.
160  if ($bean === null && $setDefaults)
161  {
162  $currentUser = Yii::app()->user->userModel;
163  if (!$currentUser instanceof User)
164  {
165  throw new NoCurrentUserSecurityException();
166  }
167  AuditUtil::saveOriginalAttributeValue($this, 'requestedByUser', $currentUser);
168  $this->unrestrictedSet('requestedByUser', $currentUser);
169  }
170  }
171 
176  protected static function translatedAttributeLabels($language)
177  {
178  return array_merge(parent::translatedAttributeLabels($language),
179  array(
180  'completedDateTime' => Zurmo::t('TasksModule', 'Completed On', array(), null, $language),
181  'completed' => Zurmo::t('Core', 'Completed', array(), null, $language),
182  'description' => Zurmo::t('ZurmoModule', 'Description', array(), null, $language),
183  'dueDateTime' => Zurmo::t('TasksModule', 'Due On', array(), null, $language),
184  'name' => Zurmo::t('Core', 'Name', array(), null, $language),
185  'status' => Zurmo::t('ZurmoModule', 'Status', array(), null, $language),
186  'requestedByUser' => Zurmo::t('TasksModule', 'Requested By User', array(), null, $language),
187  'files' => Zurmo::t('ZurmoModule', 'Files', array(), null, $language),
188  )
189  );
190  }
191 
195  public static function isTypeDeletable()
196  {
197  return true;
198  }
199 
203  public static function getMashableActivityRulesType()
204  {
205  return 'Task';
206  }
207 
211  protected function beforeSave()
212  {
213  if (parent::beforeSave())
214  {
216  return true;
217  }
218  else
219  {
220  return false;
221  }
222  }
223 
224  public function __set($attributeName, $value)
225  {
226  parent::__set($attributeName, $value);
227  if ($attributeName == 'status')
228  {
230  }
231  }
232 
236  public static function hasReadPermissionsOptimization()
237  {
238  return true;
239  }
240 
244  public static function getGamificationRulesType()
245  {
246  return 'TaskGamification';
247  }
248 
252  public static function getStatusDropDownArray()
253  {
254  return array(
255  self::STATUS_NEW => Zurmo::t('Core', 'New'),
256  self::STATUS_IN_PROGRESS => Zurmo::t('Core', 'In Progress'),
257  self::STATUS_AWAITING_ACCEPTANCE => Zurmo::t('Core', 'Awaiting Acceptance'),
258  self::STATUS_REJECTED => Zurmo::t('Core', 'Rejected'),
259  self::STATUS_COMPLETED => Zurmo::t('Core', 'Completed'),
260  );
261  }
262 
267  public static function getStatusDisplayName($status)
268  {
269  $statusArray = self::getStatusDropDownArray();
270  if (array_key_exists($status, $statusArray))
271  {
272  return $statusArray[$status];
273  }
274  return Zurmo::t('Core', '(None)');
275  }
276 
281  {
282  return true;
283  }
284 
285  protected function afterSave()
286  {
287  if ($this->getScenario() != 'importModel')
288  {
289  $this->processNotificationsToBeSent();
290  }
291  if ($this->getScenario() != 'kanbanViewButtonClick' && $this->getScenario() != 'kanbanViewDrag')
292  {
294  }
295  parent::afterSave();
296  }
297 
301  private function processNotificationsToBeSent()
302  {
303  if (array_key_exists('status', $this->originalAttributeValues))
304  {
305  if ($this->status == Task::STATUS_AWAITING_ACCEPTANCE &&
306  $this->requestedByUser->id != Yii::app()->user->userModel->id)
307  {
309  TasksNotificationUtil::TASK_STATUS_BECOMES_AWAITING_ACCEPTANCE,
310  Yii::app()->user->userModel);
311  }
312  elseif ($this->status == Task::STATUS_REJECTED &&
313  $this->owner->id != Yii::app()->user->userModel->id)
314  {
316  TasksNotificationUtil::TASK_STATUS_BECOMES_REJECTED,
317  Yii::app()->user->userModel);
318  }
319  elseif ($this->status == Task::STATUS_COMPLETED)
320  {
322  TasksNotificationUtil::TASK_STATUS_BECOMES_COMPLETED,
323  Yii::app()->user->userModel);
324  }
325  }
326  if ($this->isNewModel)
327  {
328  if ($this->owner->id != $this->requestedByUser->id && $this->owner->id != Yii::app()->user->userModel->id)
329  {
331  TasksNotificationUtil::TASK_NEW);
332  }
333  }
334  elseif (array_key_exists('owner', $this->originalAttributeValues))
335  {
336  if ($this->requestedByUser->id != Yii::app()->user->userModel->id)
337  {
339  TasksNotificationUtil::TASK_OWNER_CHANGE);
340  }
341  if ($this->owner->id != Yii::app()->user->userModel->id)
342  {
344  TasksNotificationUtil::TASK_NEW);
345  }
346  }
347  }
348 
352  protected function resolveAndSetDefaultSubscribers()
353  {
354  //Add requested by user as default subscriber
355  if ($this->requestedByUser->id > 0)
356  {
357  NotificationSubscriberUtil::addSubscriber($this->requestedByUser, $this, false);
358  }
359  NotificationSubscriberUtil::addSubscriber($this->owner, $this, false);
360  }
361 
366  {
367  if ($this->status != Task::STATUS_COMPLETED)
368  {
369  $this->completed = false;
370  }
371  else
372  {
373  $this->completed = true;
374  }
375 
376  if ($this->completed == true)
377  {
378  if ($this->completedDateTime == null)
379  {
380  $this->completedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
381  }
382  $this->unrestrictedSet('latestDateTime', $this->completedDateTime);
383  }
384  }
385  }
386 ?>
static addSubscriber(User $user, OwnedSecurableItem $model, $hasReadLatest=false)
Definition: User.php:37
static getDefaultMetadata()
Definition: Task.php:91
__toString()
Definition: Task.php:55
static getModuleClassName()
Definition: Task.php:75
static saveOriginalAttributeValue($auditableModel, $attributeName, $value)
Definition: AuditUtil.php:66
resolveStatusAndSetCompletedFields()
Definition: Task.php:365
Definition: Task.php:37
static canSaveMetadata()
Definition: Task.php:83
static getGamificationRulesType()
Definition: Task.php:244
static getMashableActivityRulesType()
Definition: Task.php:203
static getStatusDisplayName($status)
Definition: Task.php:267
beforeSave()
Definition: Task.php:211
static hasReadPermissionsOptimization()
Definition: Task.php:236
static checkKanbanTypeByStatusAndUpdateIfRequired(Task $task)
Definition: TasksUtil.php:760
unrestrictedSet($attributeName, $value)
constructDerived($bean, $setDefaults)
Definition: Task.php:151
static getStatusDropDownArray()
Definition: Task.php:252
static isTypeDeletable()
Definition: Task.php:195
static submitTaskNotificationMessage(Task $task, $action, User $relatedUser=null, Comment $comment=null)
static hasReadPermissionsSubscriptionOptimization()
Definition: Task.php:280
static translatedAttributeLabels($language)
Definition: Task.php:176
resolveAndSetDefaultSubscribers()
Definition: Task.php:352
Generated on Tue Jul 14 2020 07:10:35
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.