Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
TaskKanbanBoardExtendedGridView.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  {
42  public $relatedModelId;
43 
44  public $relatedModelClassName;
45 
46  public $columnsData;
47 
55  protected function resolveDataIntoKanbanColumns()
56  {
58  $kanbanItemsArray = array();
59  $kanbanItems = array();
60  $maximumKanbanItemSortOrder = 0;
61  foreach ($this->dataProvider->getData() as $notUsed => $task)
62  {
63  $kanbanItem = KanbanItem::getByTask($task->id);
64  if ($kanbanItem == null)
65  {
66  //Create KanbanItem here
67  $kanbanItem = TasksUtil::createKanbanItemFromTask($task);
68  }
69  $kanbanItems[] = $kanbanItem;
70  if($kanbanItem->sortOrder > $maximumKanbanItemSortOrder)
71  {
72  $maximumKanbanItemSortOrder = $kanbanItem->sortOrder;
73  }
74  }
75  foreach ($kanbanItems as $kanbanItem)
76  {
77  if(isset($kanbanItemsArray[$kanbanItem->type]) &&
78  isset($kanbanItemsArray[$kanbanItem->type][intval($kanbanItem->sortOrder)]))
79  {
80  $sortOrder = $maximumKanbanItemSortOrder + 1;
81  $maximumKanbanItemSortOrder = $sortOrder;
82  }
83  else
84  {
85  $sortOrder = intval($kanbanItem->sortOrder);
86  }
87  $kanbanItemsArray[$kanbanItem->type][$sortOrder] = $kanbanItem->task;
88  }
89  foreach ($kanbanItemsArray as $type => $kanbanData)
90  {
91  ksort($kanbanData, SORT_NUMERIC);
92  foreach ($kanbanData as $sort => $item)
93  {
94  if (isset($this->columnsData[$type]))
95  {
96  $this->columnsData[$type][] = $item;
97  }
98  }
99  }
101  return $this->columnsData;
102  }
103 
110  protected function resolveOrderByType($columnsData, $type)
111  {
112  if (isset($columnsData[$type]))
113  {
114  return count($columnsData[$type]) + 1;
115  }
116  return 1;
117  }
118 
122  protected function makeColumnsDataAndStructure()
123  {
124  $columnsData = array();
125  foreach ($this->groupByAttributeVisibleValues as $value)
126  {
127  $columnsData[$value] = array();
128  }
129  $this->columnsData = $columnsData;
130  }
131 
138  protected function renderUlTagForKanbanColumn($listItems, $attributeValue = null)
139  {
140  return ZurmoHtml::tag('ul id="task-sortable-rows-' . $attributeValue . '" class="connectedSortable"' ,
141  array(), $listItems);
142  }
143 
147  protected function registerScripts()
148  {
149 
150  }
151 
155  protected function registerKanbanColumnScripts()
156  {
157  Yii::app()->clientScript->registerScript('task-sortable-data', static::registerKanbanColumnSortableScript());
158  $url = Yii::app()->createUrl('tasks/default/updateStatusInKanbanView', array());
159  $this->registerKanbanColumnStartActionScript('action-type-start', Zurmo::t('Core', 'Finish'), Task::STATUS_IN_PROGRESS, $url);
160  $this->registerKanbanColumnStartActionScript('action-type-restart', Zurmo::t('Core', 'Finish'), Task::STATUS_IN_PROGRESS, $url);
161  $this->registerKanbanColumnFinishActionScript(Zurmo::t('Core', 'Accept'),
162  Zurmo::t('Core', 'Reject'), Task::STATUS_AWAITING_ACCEPTANCE, $url);
163  $this->registerKanbanColumnAcceptActionScript('', Task::STATUS_COMPLETED, $url);
164  $this->registerKanbanColumnRejectActionScript(Zurmo::t('Core', 'Restart'), Task::STATUS_REJECTED, $url);
167  }
168 
173  public static function registerKanbanColumnSortableScript()
174  {
175  $url = Yii::app()->createUrl('tasks/default/updateStatusOnDragInKanbanView');
176  return "setUpTaskKanbanSortable('{$url}');";
177  }
178 
185  protected function registerKanbanColumnStartActionScript($sourceButtonClass, $label, $targetStatus, $url)
186  {
187  $script = $this->registerButtonActionScript($sourceButtonClass, KanbanItem::TYPE_IN_PROGRESS,
188  $label, 'action-type-finish', $url, $targetStatus);
189  Yii::app()->clientScript->registerScript($sourceButtonClass . '-action-script', $script);
190  }
191 
198  protected function registerKanbanColumnFinishActionScript($labelAccept, $labelReject, $targetStatus, $url)
199  {
200  $acceptanceStatusLabel = ZurmoHtml::encode(Task::getStatusDisplayName(Task::STATUS_AWAITING_ACCEPTANCE));
201  $acceptanceStatus = Task::STATUS_AWAITING_ACCEPTANCE;
202  $inProgressKanbanType = KanbanItem::TYPE_IN_PROGRESS;
203  // Begin Not Coding Standard
204  $script = "$(document).on('click','.action-type-finish',function()
205  {
206  var element = $(this).parent().parent().parent().parent();
207  var ulelement = $(element).parent();
208  var id = $(element).attr('id');
209  var idParts = id.split('_');
210  var taskId = parseInt(idParts[1]);
211  var rejectLinkElement = $(this).clone();
212  var parent = $(this).parent();
213  $(this).find('.button-label').html('" . $labelAccept . "');
214  $(this).removeClass('action-type-finish').addClass('action-type-accept');
215  $(rejectLinkElement).appendTo($(parent));
216  $(rejectLinkElement).find('.button-label').html('" . $labelReject . "');
217  $(rejectLinkElement).removeClass('action-type-finish').addClass('action-type-reject');
218  $(element).find('.task-status').html('{$acceptanceStatusLabel}');
219  $.ajax(
220  {
221  type : 'GET',
222  data : {'targetStatus':'{$acceptanceStatus}', 'taskId':taskId, 'sourceKanbanType':'{$inProgressKanbanType}'},
223  url : '" . $url . "',
224  beforeSend : function(){
225  $('.ui-overlay-block').fadeIn(50);
226  $(this).makeLargeLoadingSpinner(true, '.ui-overlay-block'); //- add spinner to block anything else
227  },
228  success: function(data){
229  $(this).makeLargeLoadingSpinner(false, '.ui-overlay-block');
230  $('.ui-overlay-block').fadeOut(50);
231  }
232  }
233  );
234  }
235  );";
236  // End Not Coding Standard
237  Yii::app()->clientScript->registerScript('finish-action-script', $script);
238  }
239 
243  protected function getRowClassForTaskKanbanColumn($data)
244  {
245  if ($data->status == Task::STATUS_COMPLETED)
246  {
247  return 'kanban-card item-to-place ui-state-disabled';
248  }
249  else
250  {
251  return 'kanban-card item-to-place';
252  }
253  }
254 
261  protected function createTaskItemForKanbanColumn($data, $row)
262  {
263  return ZurmoHtml::tag('li', array('class' => $this->getRowClassForTaskKanbanColumn($data),
264  'id' => 'items_' . $data->id),
265  ZurmoHtml::tag('div', array('class' => 'clearfix'),
266  $this->renderTaskCardDetailsContent($data, $row)));
267  }
268 
274  protected function getListItemsByAttributeValueAndData($attributeValueAndData)
275  {
276  $listItems = '';
277  foreach ($attributeValueAndData as $key => $data)
278  {
279  $listItems .= $this->createTaskItemForKanbanColumn($data, $key + 1);
280  }
281 
282  return $listItems;
283  }
284 
295  protected function registerButtonActionScript($sourceActionButtonClass, $targetKanbanItemType, $label,
296  $targetButtonClass, $url, $targetStatus)
297  {
298  $rejectStatusLabel = Task::getStatusDisplayName(Task::STATUS_REJECTED);
299  $inProgressStatusLabel = Task::getStatusDisplayName(Task::STATUS_IN_PROGRESS);
300  $completedStatusLabel = Task::getStatusDisplayName(Task::STATUS_COMPLETED);
301  $completedStatus = Task::STATUS_COMPLETED;
302  $rejectedStatusClass = 'status-' . Task::STATUS_REJECTED;
303  $currentUserLoggedInName = '(' . Yii::app()->user->userModel->getFullName() . ')';
304  // Begin Not Coding Standard
305  return "$(document).on('click','." . $sourceActionButtonClass . "',
306  function()
307  {
308  var element = $(this).parent().parent().parent().parent();
309  var ulelement = $(element).parent();
310  var id = $(element).attr('id');
311  var ulid = $(ulelement).attr('id');
312  var ulidParts = ulid.split('-');
313  var idParts = id.split('_');
314  var taskId = parseInt(idParts[1]);
315  var columnType = parseInt(ulidParts[3]);
316  if(parseInt('{$targetKanbanItemType}') != columnType)
317  {
318  $('#task-sortable-rows-{$targetKanbanItemType}').append(element);
319  $('#task-sortable-rows-' + columnType).remove('#' + id);
320  }
321  if('{$targetStatus}' != '{$completedStatus}')
322  {
323  var linkTag = $(element).find('.{$sourceActionButtonClass}');
324  $(linkTag).find('.button-label').html('" . $label . "');
325  $(linkTag).removeClass('" . $sourceActionButtonClass . "').addClass('" . $targetButtonClass . "');
326  if('{$sourceActionButtonClass}' == 'action-type-reject')
327  {
328  $(element).find('.action-type-accept').remove();
329  $(element).find('.task-status').html('{$rejectStatusLabel}');
330  $(element).find('.task-status').parent().addClass('{$rejectedStatusClass}');
331  }
332  else
333  {
334  $(element).find('.task-status').parent().removeClass('{$rejectedStatusClass}');
335  }
336  if('{$sourceActionButtonClass}' == 'action-type-restart')
337  {
338  $(element).find('.task-status').html('{$inProgressStatusLabel}');
339  }
340  if('{$sourceActionButtonClass}' == 'action-type-start')
341  {
342  $(element).find('h4 .task-owner').html('" . addslashes($currentUserLoggedInName) . "');
343  }
344  }
345  else
346  {
347  $(element).find('.button-label').remove();
348  $(element).find('.task-action-toolbar').remove();
349  $(element).addClass('ui-state-disabled');
350  $(element).find('.task-status').html('{$completedStatusLabel}');
351  }
352  $.ajax(
353  {
354  type : 'GET',
355  data : {'targetStatus':'{$targetStatus}', 'taskId':taskId, 'sourceKanbanType':columnType},
356  url : '{$url}',
357  dataType : 'json',
358  beforeSend : function(){
359  $('.ui-overlay-block').fadeIn(50);
360  $(this).makeLargeLoadingSpinner(true, '.ui-overlay-block'); //- add spinner to block anything else
361  },
362  success: function(data){
363  $(element).find('.task-subscribers').html(data.subscriptionContent);
364  $(this).makeLargeLoadingSpinner(false, '.ui-overlay-block');
365  $('.ui-overlay-block').fadeOut(50);
366  }
367  }
368  );
369  }
370  );";
371  // End Not Coding Standard
372  }
373 
380  protected function registerKanbanColumnAcceptActionScript($label, $targetStatus, $url)
381  {
382  $script = $this->registerButtonActionScript('action-type-accept', KanbanItem::TYPE_COMPLETED,
383  $label, 'task-complete-action ui-state-disabled', $url, $targetStatus);
384  Yii::app()->clientScript->registerScript('accept-action-script', $script);
385  }
386 
393  protected function registerKanbanColumnRejectActionScript($label, $targetStatus, $url)
394  {
395  $script = $this->registerButtonActionScript('action-type-reject', KanbanItem::TYPE_IN_PROGRESS,
396  $label, 'action-type-restart', $url, $targetStatus);
397  Yii::app()->clientScript->registerScript('reject-action-script', $script);
398  }
399 
405  protected function renderTaskCardDetailsContent(Task $task, $row)
406  {
407  $statusClass = 'status-' . $task->status;
408 
409  $content = $this->renderCardDataContent($this->cardColumns['completionBar'], $task, $row);
410  $content .= ZurmoHtml::openTag('div', array('class' => 'task-details clearfix ' . $statusClass));
411  $content .= ZurmoHtml::tag('span', array('class' => 'task-status'), Task::getStatusDisplayName($task->status));
412  $content .= $this->resolveAndRenderTaskCardDetailsDueDateContent($task);
413  $content .= ZurmoHtml::closeTag('div');
414 
415  $content .= ZurmoHtml::openTag('div', array('class' => 'task-content clearfix'));
416  $content .= $this->resolveAndRenderTaskCardDetailsStatusContent($task, $row);
417  $content .= Yii::app()->custom->renderExtraAttributesWithNameInKanbanCard($this->cardColumns, $task, $row);
418  $content .= ZurmoHtml::openTag('h4');
419  $content .= $this->renderCardDataContent($this->cardColumns['name'], $task, $row);
420  $content .= ZurmoHtml::closeTag('h4');
421  if ($task->description != null)
422  {
423  $description = $task->description;
424  if (strlen($description) > TaskKanbanBoard::TASK_DESCRIPTION_LENGTH)
425  {
426  $description = substr($description, 0, TaskKanbanBoard::TASK_DESCRIPTION_LENGTH) . '...';
427  }
428  $content .= ZurmoHtml::tag('p', array(), $description);
429  }
430  $content .= ZurmoHtml::closeTag('div');
431 
432  $content .= ZurmoHtml::openTag('div', array('class' => 'task-subscribers'));
434  $content .= $this->renderCardDataContent($this->cardColumns['subscribe'], $task, $row);
435  $content .= ZurmoHtml::closeTag('div');
436 
437  return $content;
438  }
439 
440  protected function resolveAndRenderTaskCardDetailsDueDateContent(Task $task)
441  {
442  if ($task->dueDateTime != null)
443  {
444  $content = DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay(
445  $task->dueDateTime, DateTimeUtil::DATETIME_FORMAT_DATE_WIDTH, null);
446  return ZurmoHtml::tag('span', array('class' => 'task-due-date'), $content);
447  }
448  }
449 
450  protected function resolveAndRenderTaskCardDetailsStatusContent(Task $task, $row)
451  {
452  $statusContent = $this->renderCardDataContent($this->cardColumns['status'], $task, $row);
453  if ($statusContent != null)
454  {
455  $content = ZurmoHtml::openTag('div', array('class' => 'task-action-toolbar pillbox'));
456  $content .= $this->renderCardDataContent($this->cardColumns['status'], $task, $row);
457  $content .= ZurmoHtml::closeTag('div');
458  return $content;
459  }
460  }
461 
466  protected function isMaxCountCheckRequired()
467  {
468  return true;
469  }
470 
474  public static function getMaxCount()
475  {
476  $maxCount = Yii::app()->pagination->getGlobalValueByType('taskKanbanBoardPageSize');
477  return (int) $maxCount;
478  }
479  }
480 ?>
registerKanbanColumnAcceptActionScript($label, $targetStatus, $url)
static encode($text)
Definition: ZurmoHtml.php:47
registerKanbanColumnRejectActionScript($label, $targetStatus, $url)
registerButtonActionScript($sourceActionButtonClass, $targetKanbanItemType, $label, $targetButtonClass, $url, $targetStatus)
Definition: Task.php:37
static createKanbanItemFromTask(Task $task)
Definition: TasksUtil.php:354
static resolveAndRenderTaskCardDetailsSubscribersContent(OwnedSecurableItem $model)
static getStatusDisplayName($status)
Definition: Task.php:267
static registerUnsubscriptionScript($modelClassName, $model=null)
getListItemsByAttributeValueAndData($attributeValueAndData)
registerKanbanColumnFinishActionScript($labelAccept, $labelReject, $targetStatus, $url)
static registerSubscriptionScript($modelClassName, $model=null)
registerKanbanColumnStartActionScript($sourceButtonClass, $label, $targetStatus, $url)
renderUlTagForKanbanColumn($listItems, $attributeValue=null)
static getByTask($taskId)
Definition: KanbanItem.php:160
Generated on Thu Aug 6 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.