Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
TasksUtil.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 
40  class TasksUtil
41  {
47  public static function getUrlToEmail($model)
48  {
49  assert('$model instanceof Task');
50  return Yii::app()->createAbsoluteUrl('tasks/default/details/', array('id' => $model->id));
51  }
52 
60  public static function resolveExplicitPermissionsForRequestedByUser(Task $task, Permitable $origRequestedByUser, Permitable $requestedByUser, ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions)
61  {
62  $explicitReadWriteModelPermissions->addReadWritePermitableToRemove($origRequestedByUser);
63  $explicitReadWriteModelPermissions->addReadWritePermitable($requestedByUser);
65  resolveExplicitReadWriteModelPermissions($task, $explicitReadWriteModelPermissions);
66  }
67 
71  public static function getModalDetailsTitle()
72  {
74  $title = Zurmo::t('TasksModule', 'Collaborate On This TasksModuleSingularLabel', $params);
75  return $title;
76  }
77 
81  public static function getModalEditTitle()
82  {
84  $title = Zurmo::t('TasksModule', 'Edit TasksModuleSingularLabel', $params);
85  return $title;
86  }
87 
93  public static function getModalTitleForCreateTask($renderType = "Create")
94  {
96  if ($renderType == "Create")
97  {
98  $title = Zurmo::t('TasksModule', 'Create TasksModuleSingularLabel', $params);
99  }
100  elseif ($renderType == "Copy")
101  {
102  $title = Zurmo::t('TasksModule', 'Copy TasksModuleSingularLabel', $params);
103  }
104  elseif ($renderType == "Details")
105  {
106  $title = static::getModalDetailsTitle();
107  }
108  else
109  {
110  $title = Zurmo::t('TasksModule', 'Edit TasksModuleSingularLabel', $params);
111  }
112  return $title;
113  }
114 
119  public static function resolveAjaxOptionsForCreateMenuItem()
120  {
121  return static::resolveAjaxOptionsForModalView('Create');
122  }
123 
127  public static function getModalContainerId()
128  {
129  return ModalContainerView::ID;
130  }
131 
137  public static function resolveAjaxOptionsForModalView($renderType, $sourceKanbanBoardId = null)
138  {
139  assert('is_string($renderType)');
140  $title = self::getModalTitleForCreateTask($renderType);
141  return ModalView::getAjaxOptionsForModalLink($title, self::getModalContainerId(), 'auto', 600,
142  array('my'=>'center top+25','at'=>'center top+25'), $class = "'task-dialog'", // Not Coding Standard
143  static::resolveExtraCloseScriptForModalAjaxOptions($sourceKanbanBoardId));
144  }
145 
146  public static function resolveExtraCloseScriptForModalAjaxOptions($sourceId = null)
147  {
148  assert('is_string($sourceId) || $sourceId == null');
149  if ($sourceId != null)
150  {
151  return "$('#{$sourceId}').yiiGridView('update');";
152  }
153  }
154 
163  public static function getModalDetailsLink(Task $task,
164  $controllerId,
165  $moduleId,
166  $moduleClassName,
167  $isOwnerRequiredInDisplay = true)
168  {
169  assert('is_string($controllerId) || $controllerId === null');
170  assert('is_string($moduleId) || $moduleId === null');
171  assert('is_string($moduleClassName)');
172  if ($isOwnerRequiredInDisplay)
173  {
174  $label = $task->name . ZurmoHtml::tag('span', array('class' => 'task-owner'), '(' . strval($task->owner) . ')');
175  }
176  else
177  {
178  $label = $task->name;
179  }
180  $params = array('label' => $label, 'routeModuleId' => 'tasks',
181  'wrapLabel' => false,
182  'htmlOptions' => array('id' => 'task-' . $task->id)
183  );
184  $goToDetailsFromRelatedModalLinkActionElement = new GoToDetailsFromRelatedModalLinkActionElement(
185  $controllerId, $moduleId, $task->id, $params);
186  $linkContent = $goToDetailsFromRelatedModalLinkActionElement->render();
187  $string = TaskActionSecurityUtil::resolveViewLinkToModelForCurrentUser($task, $moduleClassName, $linkContent);
188  return $string;
189  }
190 
199  public static function resolveActionButtonForTaskByStatus($statusId, $controllerId, $moduleId, $taskId)
200  {
201  assert('is_string($statusId) || is_int($statusId)');
202  assert('is_string($controllerId)');
203  assert('is_string($moduleId)');
204  assert('is_int($taskId)');
205  $type = self::resolveKanbanItemTypeForTaskStatus(intval($statusId));
206  $route = Yii::app()->createUrl('tasks/default/updateStatusInKanbanView');
207  switch(intval($statusId))
208  {
209  case Task::STATUS_NEW:
210  $element = new TaskStartLinkActionElement($controllerId, $moduleId, $taskId,
211  array('route' => $route));
212  break;
213  case Task::STATUS_IN_PROGRESS:
214 
215  $element = new TaskFinishLinkActionElement($controllerId, $moduleId, $taskId,
216  array('route' => $route));
217  break;
218  case Task::STATUS_REJECTED:
219 
220  $element = new TaskRestartLinkActionElement($controllerId, $moduleId, $taskId,
221  array('route' => $route));
222  break;
223  case Task::STATUS_AWAITING_ACCEPTANCE:
224 
225  $acceptLinkElement = new TaskAcceptLinkActionElement($controllerId, $moduleId, $taskId,
226  array('route' => $route));
227  $rejectLinkElement = new TaskRejectLinkActionElement($controllerId, $moduleId, $taskId,
228  array('route' => $route));
229  return $acceptLinkElement->render() . $rejectLinkElement->render();
230  case Task::STATUS_COMPLETED:
231  return null;
232  default:
233  $element = new TaskStartLinkActionElement($controllerId, $moduleId, $taskId,
234  array('route' => $route));
235  break;
236  }
237  return $element->render();
238  }
239 
245  {
246  return array(
247  Task::STATUS_NEW => KanbanItem::TYPE_SOMEDAY,
248  Task::STATUS_IN_PROGRESS => KanbanItem::TYPE_IN_PROGRESS,
249  Task::STATUS_AWAITING_ACCEPTANCE => KanbanItem::TYPE_IN_PROGRESS,
250  Task::STATUS_REJECTED => KanbanItem::TYPE_IN_PROGRESS,
251  Task::STATUS_COMPLETED => KanbanItem::TYPE_COMPLETED
252  );
253  }
254 
260  public static function resolveKanbanItemTypeForTaskStatus($status)
261  {
262  if ($status == null)
263  {
264  return KanbanItem::TYPE_SOMEDAY;
265  }
266  $data = self::getTaskStatusMappingToKanbanItemTypeArray();
267  return $data[intval($status)];
268  }
269 
276  public static function isKanbanItemTypeValidBasedOnTaskStatus($kanbanItemType, $taskStatus)
277  {
278  if ($taskStatus == null && $kanbanItemType == KanbanItem::TYPE_SOMEDAY)
279  {
280  return true;
281  }
282  elseif ($taskStatus == null)
283  {
284  return false;
285  }
286  if ($taskStatus == Task::STATUS_NEW)
287  {
288  if ($kanbanItemType == KanbanItem::TYPE_SOMEDAY || $kanbanItemType == KanbanItem::TYPE_TODO)
289  {
290  return true;
291  }
292  else
293  {
294  return false;
295  }
296  }
297  $data = self::getTaskStatusMappingToKanbanItemTypeArray();
298  if ($data[intval($taskStatus)] == $kanbanItemType)
299  {
300  return true;
301  }
302  return false;
303  }
304 
310  public static function getTaskCompletionPercentage(Task $task)
311  {
312  $checkListItemsCount = count($task->checkListItems);
313  if ($checkListItemsCount == 0)
314  {
315  return 0;
316  }
317  else
318  {
319  $completedItemsCount = self::getTaskCompletedCheckListItems($task);
320  }
321  $completionPercent = ($completedItemsCount/$checkListItemsCount) * 100;
322  return $completionPercent;
323  }
324 
330  {
331  return array(
332  KanbanItem::TYPE_TODO => Task::STATUS_NEW,
333  KanbanItem::TYPE_SOMEDAY => Task::STATUS_NEW,
334  KanbanItem::TYPE_IN_PROGRESS => Task::STATUS_IN_PROGRESS,
335  KanbanItem::TYPE_COMPLETED => Task::STATUS_COMPLETED
336  );
337  }
338 
343  public static function getDefaultTaskStatusForKanbanItemType($kanbanItemType)
344  {
345  assert('is_int(intval($kanbanItemType))');
346  $mappingArray = self::getKanbanItemTypeToDefaultTaskStatusMappingArray();
347  return $mappingArray[intval($kanbanItemType)];
348  }
349 
354  public static function createKanbanItemFromTask(Task $task)
355  {
356  $kanbanItem = new KanbanItem();
357  $kanbanItem->type = TasksUtil::resolveKanbanItemTypeForTaskStatus($task->status);
358  $kanbanItem->task = $task;
359  if ($task->project->id > 0)
360  {
361  $kanbanItem->kanbanRelatedItem = $task->project;
362  }
363  else
364  {
365  $kanbanItem->kanbanRelatedItem = $task->activityItems->offsetGet(0);
366  }
367  $sortOrder = self::resolveAndGetSortOrderForTaskOnKanbanBoard($kanbanItem->type, $task);
368  $kanbanItem->sortOrder = $sortOrder;
369  $kanbanItem->save();
370  return $kanbanItem;
371  }
372 
378  public static function renderCompletionProgressBarContent(Task $task)
379  {
380  $checkListItemsCount = count($task->checkListItems);
381  if ( $checkListItemsCount == 0)
382  {
383  return null;
384  }
385  $percentageComplete = ceil(static::getTaskCompletionPercentage($task));
386  return ZurmoHtml::tag('div', array('class' => 'completion-percentage-bar', 'style' => 'width:' . $percentageComplete . '%'),
387  $percentageComplete . '%');
388  }
389 
395  public static function getTaskCompletedCheckListItems(Task $task)
396  {
397  $completedItemsCount = 0;
398  foreach ($task->checkListItems as $checkListItem)
399  {
400  if ((bool)$checkListItem->completed)
401  {
402  $completedItemsCount++;
403  }
404  }
405  return $completedItemsCount;
406  }
407 
419  public static function resolveTaskKanbanViewForRelation($model,
420  $moduleId, $controller,
421  $kanbanView, $pageView,
422  $searchForm, $dataProvider)
423  {
424  assert('$model instanceof RedBeanModel');
425  assert('is_string($moduleId)');
426  assert('$controller instanceof ZurmoModuleController');
427  assert('is_string($kanbanView)');
428  assert('is_string($pageView)');
429  $breadCrumbLinks = array(StringUtil::getChoppedStringContent(strval($model), 25));
430  $kanbanItem = new KanbanItem();
431  $kanbanBoard = new TaskKanbanBoard($kanbanItem, 'type', $model, get_class($model));
432  $kanbanBoard->setIsActive();
433  $params['relationModel'] = $model;
434  $params['relationModuleId'] = $moduleId;
435  $params['redirectUrl'] = null;
436  $listView = new $kanbanView($controller->getId(), 'tasks', 'Task', $dataProvider,
437  $params, null, array(), $kanbanBoard, $searchForm);
438  $view = new $pageView(ZurmoDefaultViewUtil::
439  makeViewWithBreadcrumbsForCurrentUser(
440  $controller, $listView, $breadCrumbLinks, 'KanbanBoardBreadCrumbView'));
441  return $view;
442  }
443 
453  public static function resolveOverallTaskKanbanView($controller,
454  $kanbanView, $pageView,
455  $searchForm, $dataProvider)
456  {
457  assert('$controller instanceof ZurmoModuleController');
458  assert('is_string($kanbanView)');
459  assert('is_string($pageView)');
460  $breadCrumbLinks = array();
461  $kanbanItem = new KanbanItem();
462  $kanbanBoard = new TaskOverallKanbanBoard($kanbanItem, 'type');
463  $kanbanBoard->setIsActive();
464  $params['redirectUrl'] = null;
465  $listView = new $kanbanView($controller->getId(), 'tasks', 'Task', $dataProvider,
466  $params, null, array(), $kanbanBoard, $searchForm);
467  $view = new $pageView(ZurmoDefaultViewUtil::
468  makeViewWithBreadcrumbsForCurrentUser(
469  $controller, $listView, $breadCrumbLinks, 'KanbanBoardBreadCrumbView'));
470  return $view;
471  }
472 
473  public static function resolveRelatedAdditionalSearchMetadata($searchForm, & $metadata, $relationAttributeName)
474  {
475  if ($relationAttributeName == 'project')
476  {
477  $value = (int)$searchForm->relationModel->id;
478  }
479  else
480  {
481  $value = (int)$searchForm->relationModel->getClassId('Item');
482  }
483  $additionalMetaData = array(
484  'attributeName' => $relationAttributeName,
485  'relatedAttributeName' => 'id',
486  'operatorType' => 'equals',
487  'value' => $value,
488  );
489 
490  $clausesCount = 0;
491  if (isset($metadata['clauses']))
492  {
493  $clausesCount = count($metadata['clauses']);
494  $metadata['clauses'][count($metadata['clauses']) + 1] = $additionalMetaData;
495  }
496  else
497  {
498  $metadata['clauses'][1] = $additionalMetaData;
499  }
500  if ($clausesCount == 0)
501  {
502  $metadata['structure'] = '(1)';
503  }
504  else
505  {
506  $count = $clausesCount + 1;
507  $metadata['structure'] = $metadata['structure'] . ' and (' . $count . ')';
508  }
509  }
510 
515  public static function registerTaskModalDetailsScript($sourceId)
516  {
517  assert('is_string($sourceId)');
518  $modalId = TasksUtil::getModalContainerId();
519  $url = Yii::app()->createUrl('tasks/default/modalDetails');
520  $ajaxOptions = TasksUtil::resolveAjaxOptionsForModalView('Details', $sourceId);
521  $ajaxOptions['beforeSend'] = new CJavaScriptExpression($ajaxOptions['beforeSend']);
522  $script = " $(document).off('click.taskDetailLink', '#{$sourceId} .task-kanban-detail-link');
523  $(document).on('click.taskDetailLink', '#{$sourceId} .task-kanban-detail-link', function()
524  {
525  var id = $(this).attr('id');
526  var idParts = id.split('-');
527  var taskId = parseInt(idParts[1]);
528  $.ajax(
529  {
530  'type' : 'GET',
531  'url' : '{$url}' + '?id=' + taskId,
532  'beforeSend' : {$ajaxOptions['beforeSend']},
533  'update' : '{$ajaxOptions['update']}',
534  'success': function(html){jQuery('#{$modalId}').html(html)}
535  });
536  return false;
537  }
538  );";
539  Yii::app()->clientScript->registerScript('taskModalDetailsScript' . $sourceId, $script);
540  }
541 
548  public static function registerOpenToTaskModalDetailsScript($taskId, $sourceId)
549  {
550  assert('is_int($taskId)');
551  assert('is_string($sourceId)');
552  $modalId = TasksUtil::getModalContainerId();
553  $url = Yii::app()->createUrl('tasks/default/modalDetails', array('id' => $taskId));
554  $ajaxOptions = TasksUtil::resolveAjaxOptionsForModalView('Details', $sourceId);
555  $options = array('type' => 'GET',
556  'url' => $url,
557  'beforeSend' => $ajaxOptions['beforeSend'],
558  'update' => $ajaxOptions['update'],
559  'success' => "function(html){jQuery('#{$modalId}').html(html)}");
560  $script = ZurmoHtml::ajax($options);
561  Yii::app()->clientScript->registerScript('openToTaskModalDetailsScript' . $sourceId, $script);
562  }
563 
569  public static function resolveFirstRelatedModelStringValue(Task $task)
570  {
571  $modelOrNull = static::resolveFirstRelatedModel($task);
572  if ($modelOrNull === null)
573  {
574  return null;
575  }
576  return strval($modelOrNull);
577  }
578 
584  public static function resolveFirstRelatedModel(Task $task)
585  {
586  if ($task->project->id > 0)
587  {
588  return $task->project;
589  }
590  elseif ($task->activityItems->count() > 0)
591  {
592  try
593  {
594  $castedDownModel = TasksUtil::castDownActivityItem($task->activityItems[0]);
595  return $castedDownModel;
596  }
597  catch (NotFoundException $e)
598  {
599  }
600  }
601  return null;
602  }
603 
604  public static function castDownActivityItem(Item $activityItem)
605  {
606  $relationModelClassNames = ActivitiesUtil::getActivityItemsModelClassNames();
607  foreach ($relationModelClassNames as $relationModelClassName)
608  {
609  try
610  {
611  $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($relationModelClassName);
612  return $activityItem->castDown(array($modelDerivationPathToItem));
613  }
614  catch (NotFoundException $e)
615  {
616  }
617  }
618  }
619 
625  public static function renderCompletionDateTime(Task $task)
626  {
627  if ($task->completedDateTime == null)
628  {
629  $task->completedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
630  }
631  return '<p>' . Zurmo::t('TasksModule', 'Completed On') . ': ' .
632  DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($task->completedDateTime) . '</p>';
633  }
634 
639  public static function resolveModalSaveActionNameForByRelationModelId($relationModelId, $copyAction = null)
640  {
641  assert('is_string($relationModelId) || is_int($relationModelId) ||$relationModelId == null');
642  assert('is_string($copyAction) || $copyAction == null');
643  if ($copyAction == 'copy')
644  {
645  return 'modalCopyFromRelation';
646  }
647  else
648  {
649  if ($relationModelId != null)
650  {
651  return 'modalSaveFromRelation';
652  }
653  else
654  {
655  return 'modalSave';
656  }
657  }
658  }
659 
666  public static function processKanbanItemUpdateOnButtonAction($targetStatus, $taskId, $sourceKanbanType)
667  {
668  assert('is_int($targetStatus)');
669  assert('is_int($taskId)');
670  assert('is_int($sourceKanbanType)');
671  $task = Task::getById($taskId);
672  $kanbanItem = KanbanItem::getByTask($taskId);
673  $targetKanbanType = null;
674  if ($sourceKanbanType == KanbanItem::TYPE_SOMEDAY || $sourceKanbanType == KanbanItem::TYPE_TODO)
675  {
676  $targetKanbanType = KanbanItem::TYPE_IN_PROGRESS;
677  }
678  elseif ($sourceKanbanType == KanbanItem::TYPE_IN_PROGRESS)
679  {
680  if ($targetStatus == Task::STATUS_AWAITING_ACCEPTANCE ||
681  $targetStatus == Task::STATUS_REJECTED ||
682  $targetStatus == Task::STATUS_IN_PROGRESS)
683  {
684  $targetKanbanType = KanbanItem::TYPE_IN_PROGRESS;
685  }
686  elseif (intval($targetStatus) == Task::STATUS_COMPLETED)
687  {
688  $targetKanbanType = KanbanItem::TYPE_COMPLETED;
689  }
690  }
691 
692  //If kanbantype is changed, do the sort
693  if ($sourceKanbanType != $targetKanbanType)
694  {
695  //Set the sort and type for target
696  $sortOrder = self::resolveAndGetSortOrderForTaskOnKanbanBoard($targetKanbanType, $task);
697  $kanbanItem->sortOrder = $sortOrder;
698  $kanbanItem->type = $targetKanbanType;
699  if (!$kanbanItem->save())
700  {
701  throw new FailedToSaveModelException();
702  }
703  //Resort the source one
704  if ($task->project->id > 0)
705  {
706  TasksUtil::sortKanbanColumnItems($sourceKanbanType, $task->project);
707  }
708  else
709  {
710  TasksUtil::sortKanbanColumnItems($sourceKanbanType, $task->activityItems->offsetGet(0));
711  }
712  }
713  }
714 
721  public static function resolveAndGetSortOrderForTaskOnKanbanBoard($targetKanbanType, Task $task)
722  {
723  if ($task->project->id > 0)
724  {
725  $sortOrder = KanbanItem::getMaximumSortOrderByType(intval($targetKanbanType), $task->project);
726  }
727  elseif ($task->activityItems->count() > 0)
728  {
729  $sortOrder = KanbanItem::getMaximumSortOrderByType(intval($targetKanbanType), $task->activityItems->offsetGet(0));
730  }
731  else
732  {
733  $sortOrder = 1;
734  }
735  return $sortOrder;
736  }
737 
745  public static function sortKanbanColumnItems($kanbanType, Item $childObjectOfItem)
746  {
747  $models = KanbanItem::getAllTasksByType(intval($kanbanType), $childObjectOfItem);
748  foreach ($models as $index => $model)
749  {
750  $model->sortOrder = $index + 1;
751  $model->save();
752  }
753  }
754 
760  public static function checkKanbanTypeByStatusAndUpdateIfRequired(Task $task)
761  {
762  $kanbanItem = KanbanItem::getByTask($task->id);
763  //It should be created here but check for create as well here
764  if ($kanbanItem == null)
765  {
767  }
768  else
769  {
770  if (!TasksUtil::isKanbanItemTypeValidBasedOnTaskStatus($kanbanItem->type, $task->status))
771  {
772  $kanbanTypeByStatus = TasksUtil::resolveKanbanItemTypeForTaskStatus($task->status);
773  if ($kanbanItem->type != $kanbanTypeByStatus)
774  {
775  $sourceKanbanItemType = $kanbanItem->type;
776  //put the item at the end
777  $kanbanItem->sortOrder = TasksUtil::resolveAndGetSortOrderForTaskOnKanbanBoard($kanbanTypeByStatus, $task);
778  $kanbanItem->type = $kanbanTypeByStatus;
779  $kanbanItem->save();
780  //Resort the source column
781  if ($task->project->id > 0)
782  {
783  TasksUtil::sortKanbanColumnItems($sourceKanbanItemType, $task->project);
784  }
785  elseif ($task->activityItems->count() > 0)
786  {
787  TasksUtil::sortKanbanColumnItems($sourceKanbanItemType, $task->activityItems->offsetGet(0));
788  }
789  }
790  }
791  }
792  }
793 
799  public static function registerTaskModalEditScript($sourceId, $routeParams)
800  {
801  assert('is_string($sourceId)');
802  assert('is_array($routeParams)');
803  $modalId = TasksUtil::getModalContainerId();
804  $url = Yii::app()->createUrl('tasks/default/modalEdit', $routeParams);
805  $script = self::registerTaskModalScript("Edit", $url, '.edit-related-open-task', $sourceId);
806  Yii::app()->clientScript->registerScript('taskModalEditScript', $script, ClientScript::POS_END);
807  }
808 
814  public static function registerTaskModalCopyScript($sourceId, $routeParams)
815  {
816  assert('is_string($sourceId)');
817  assert('is_array($routeParams)');
818  $modalId = TasksUtil::getModalContainerId();
819  $url = Yii::app()->createUrl('tasks/default/modalCopy',
820  array_merge($routeParams, array('action' => 'copy')));
821  $script = self::registerTaskModalScript("Copy", $url, '.copy-related-open-task', $sourceId);
822  Yii::app()->clientScript->registerScript('taskModalCopyScript', $script, ClientScript::POS_END);
823  }
824 
833  public static function registerTaskModalScript($type, $url, $selector, $sourceId = null)
834  {
835  assert('is_string($type)');
836  assert('is_string($url)');
837  assert('is_string($selector)');
838  assert('is_string($sourceId) || $sourceId == null');
839  $modalId = TasksUtil::getModalContainerId();
840  $ajaxOptions = TasksUtil::resolveAjaxOptionsForModalView($type, $sourceId);
841  $ajaxOptions['beforeSend'] = new CJavaScriptExpression($ajaxOptions['beforeSend']);
842  return "$(document).on('click', '{$selector}', function()
843  {
844  var id = $(this).attr('id');
845  var idParts = id.split('-');
846  var taskId = parseInt(idParts[1]);
847  $.ajax(
848  {
849  'type' : 'GET',
850  'url' : '{$url}' + '&id=' + taskId,
851  'beforeSend' : {$ajaxOptions['beforeSend']},
852  'update' : '{$ajaxOptions['update']}',
853  'success': function(html){jQuery('#{$modalId}').html(html)}
854  });
855  }
856  );";
857  }
858 
863  public static function registerTaskModalDeleteScript($sourceId)
864  {
865  assert('is_string($sourceId)');
866  $url = Yii::app()->createUrl('tasks/default/delete');
868  $confirmTitle = Zurmo::t('Core', 'Are you sure you want to delete this {modelLabel}?',
869  array('{modelLabel}' => Zurmo::t('TasksModule', 'TasksModuleSingularLabel', $params)));
870  $script = "$(document).on('click', '.delete-related-open-task', function()
871  {
872  if (!confirm('{$confirmTitle}'))
873  {
874  return false;
875  }
876  var id = $(this).attr('id');
877  var idParts = id.split('-');
878  var taskId = parseInt(idParts[3]);
879  $.ajax(
880  {
881  'type' : 'GET',
882  'url' : '{$url}' + '?id=' + taskId,
883 
884  'success': function(data)
885  {
886  $.fn.yiiGridView.update('{$sourceId}');
887  }
888  });
889  }
890  );";
891  Yii::app()->clientScript->registerScript('taskModalDeleteScript', $script, ClientScript::POS_END);
892  }
893 
897  public static function resolveShouldOpenToTask($gridId)
898  {
899  $getData = GetUtil::getData();
900  if (null != $taskId = ArrayUtil::getArrayValue($getData, 'openToTaskId'))
901  {
902  Yii::app()->custom->registerOpenToTaskModalDetailsScript((int)$taskId, $gridId);
903  }
904  }
905 
910  public function getCalendarItemData()
911  {
912  $name = $this->name;
913  $status = self::getStatusDisplayName($this->status);
914  $requestedByUser = $this->requestedByUser->getFullName();
915  $owner = $this->owner->getFullName();
916  $language = Yii::app()->languageHelper->getForCurrentUser();
917  $translatedAttributeLabels = self::translatedAttributeLabels($language);
918  return array(Zurmo::t('Core', 'Name', array(), null, $language) => $name,
919  Zurmo::t('ZurmoModule', 'Status', array(), null, $language) => $status,
920  $translatedAttributeLabels['requestedByUser'] => $requestedByUser,
921  $translatedAttributeLabels['owner'] => $owner);
922  }
923 
928  {
929  $getData = GetUtil::getData();
930  //This would be required in case edit of task navigates to a new page and not modal
931  if (null != $gridId = ArrayUtil::getArrayValue($getData, 'sourceId'))
932  {
934  }
935  }
936 
943  {
944  if ($redirectUrl != null)
945  {
946  $routeData = explode('?', $redirectUrl);
947  if (count($routeData) > 1)
948  {
949  $queryData = explode('&', $routeData[1]);
950  foreach ($queryData as $val)
951  {
952  if (strpos($val, 'id=') !== false)
953  {
954  $routeData[1] = $val;
955  break;
956  }
957  }
958  }
959  $redirectUrl = implode('?', $routeData);
960  }
961  return $redirectUrl;
962  }
963  }
964 ?>
static getDefaultTaskStatusForKanbanItemType($kanbanItemType)
Definition: TasksUtil.php:343
static resolveShouldOpenToTask($gridId)
Definition: TasksUtil.php:897
static getTaskCompletionPercentage(Task $task)
Definition: TasksUtil.php:310
static getUrlToEmail($model)
Definition: TasksUtil.php:47
static resolveAjaxOptionsForModalView($renderType, $sourceKanbanBoardId=null)
Definition: TasksUtil.php:137
static getModalTitleForCreateTask($renderType="Create")
Definition: TasksUtil.php:93
static registerTaskModalDetailsScript($sourceId)
Definition: TasksUtil.php:515
static resolveOverallTaskKanbanView($controller, $kanbanView, $pageView, $searchForm, $dataProvider)
Definition: TasksUtil.php:453
static resolveKanbanItemTypeForTaskStatus($status)
Definition: TasksUtil.php:260
static resolveFirstRelatedModelStringValue(Task $task)
Definition: TasksUtil.php:569
static resolveExplicitReadWriteModelPermissions(SecurableItem $securableItem, ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions, $validate=false)
static getChoppedStringContent($string, $length, $ellipsis= '...')
Definition: StringUtil.php:51
static getTranslationParamsForAllModules()
Definition: LabelUtil.php:75
static sortKanbanColumnItems($kanbanType, Item $childObjectOfItem)
Definition: TasksUtil.php:745
static getModalContainerId()
Definition: TasksUtil.php:127
static resolveActionButtonForTaskByStatus($statusId, $controllerId, $moduleId, $taskId)
Definition: TasksUtil.php:199
static getModalDetailsLink(Task $task, $controllerId, $moduleId, $moduleClassName, $isOwnerRequiredInDisplay=true)
Definition: TasksUtil.php:163
static renderCompletionProgressBarContent(Task $task)
Definition: TasksUtil.php:378
static resolveTaskKanbanViewForRelation($model, $moduleId, $controller, $kanbanView, $pageView, $searchForm, $dataProvider)
Definition: TasksUtil.php:419
static registerOpenToTaskModalDetailsScript($taskId, $sourceId)
Definition: TasksUtil.php:548
static getTaskCompletedCheckListItems(Task $task)
Definition: TasksUtil.php:395
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
static registerTaskModalScript($type, $url, $selector, $sourceId=null)
Definition: TasksUtil.php:833
Definition: Task.php:37
static resolveShouldOpenToTaskForDetailsAndRelationsView()
Definition: TasksUtil.php:927
offsetGet($offset)
static resolveExplicitPermissionsForRequestedByUser(Task $task, Permitable $origRequestedByUser, Permitable $requestedByUser, ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions)
Definition: TasksUtil.php:60
static createKanbanItemFromTask(Task $task)
Definition: TasksUtil.php:354
static getTaskStatusMappingToKanbanItemTypeArray()
Definition: TasksUtil.php:244
static resolveViewLinkToModelForCurrentUser($model, $moduleClassName, $linkContent)
static resolveFirstRelatedModel(Task $task)
Definition: TasksUtil.php:584
static resolveAndGetSortOrderForTaskOnKanbanBoard($targetKanbanType, Task $task)
Definition: TasksUtil.php:721
static resolveOpenTasksActionsRedirectUrlForDetailsAndRelationsView($redirectUrl)
Definition: TasksUtil.php:942
static isKanbanItemTypeValidBasedOnTaskStatus($kanbanItemType, $taskStatus)
Definition: TasksUtil.php:276
static getMaximumSortOrderByType($taskType, Item $childObjectOfItem)
Definition: KanbanItem.php:195
getCalendarItemData()
Definition: TasksUtil.php:910
Definition: Item.php:37
static registerTaskModalDeleteScript($sourceId)
Definition: TasksUtil.php:863
static processKanbanItemUpdateOnButtonAction($targetStatus, $taskId, $sourceKanbanType)
Definition: TasksUtil.php:666
static getModelDerivationPathToItem($modelClassName)
Definition: RuntimeUtil.php:79
static checkKanbanTypeByStatusAndUpdateIfRequired(Task $task)
Definition: TasksUtil.php:760
static resolveAjaxOptionsForCreateMenuItem()
Definition: TasksUtil.php:119
static getModalEditTitle()
Definition: TasksUtil.php:81
static getById($id, $modelClassName=null)
castDown(array $derivedModelClassNames)
static getAllTasksByType($taskType, Item $childObjectOfItem)
Definition: KanbanItem.php:214
static resolveModalSaveActionNameForByRelationModelId($relationModelId, $copyAction=null)
Definition: TasksUtil.php:639
static getKanbanItemTypeToDefaultTaskStatusMappingArray()
Definition: TasksUtil.php:329
static registerTaskModalCopyScript($sourceId, $routeParams)
Definition: TasksUtil.php:814
static registerTaskModalEditScript($sourceId, $routeParams)
Definition: TasksUtil.php:799
static renderCompletionDateTime(Task $task)
Definition: TasksUtil.php:625
static getByTask($taskId)
Definition: KanbanItem.php:160
static getModalDetailsTitle()
Definition: TasksUtil.php:71
Generated on Tue Jul 7 2020 07:10:36
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.