public static function getList($userId, $taskId, array $parameters = array()) { $data = array(); $can = array(); $task = static::getTask($userId, $taskId); if ($task !== null && $task->checkCanRead()) { list($items, $arMetaData) = \CTaskCheckListItem::fetchList($task, array('SORT_INDEX' => 'ASC')); unset($arMetaData); foreach ($items as $item) { $checklistItemId = $item->getId(); $data[$checklistItemId] = $item->getData($parameters['ESCAPE_DATA']); $can[$checklistItemId]['ACTION'] = array('MODIFY' => $item->isActionAllowed(\CTaskCheckListItem::ACTION_MODIFY), 'REMOVE' => $item->isActionAllowed(\CTaskCheckListItem::ACTION_REMOVE), 'TOGGLE' => $item->isActionAllowed(\CTaskCheckListItem::ACTION_TOGGLE)); } } return array('DATA' => $data, 'CAN' => $can); }
/** * Get all check list items for a specified task */ public function getListByTask($taskId, array $order = array()) { global $USER; $result = array(); if ($taskId = $this->checkTaskId($taskId)) { $task = \CTaskItem::getInstanceFromPool($taskId, $USER->GetId()); // or directly, new \CTaskItem($taskId, $USER->GetId()); // todo: make this and TasksTaskComponent::getTaskDataChecklist() use common code $items = \CTaskCheckListItem::fetchList($task, $order); foreach ($items as $item) { $data = $item->getData(false); $id = $data->getId(); $result['DATA']['CHECKLIST'][$id] = $data; $result['CAN']['CHECKLIST'][$id]['ACTION'] = array('MODIFY' => $item->isActionAllowed(\CTaskCheckListItem::ACTION_MODIFY), 'REMOVE' => $item->isActionAllowed(\CTaskCheckListItem::ACTION_REMOVE), 'TOGGLE' => $item->isActionAllowed(\CTaskCheckListItem::ACTION_TOGGLE)); } } return $result; }
/** * Duplicate task and return an instance of the clone. * * @param mixed[] $overrideTaskData Task data needs to be overrided externally. * @param mixed[] $parameters Various set of parameters. * * <li> CLONE_CHILD_TASKS boolean clone subtasks or not * <li> CLONE_CHECKLIST_ITEMS boolean clone check list items or not * <li> CLONE_TAGS boolean clone tags or not * <li> CLONE_REMINDERS boolean clone reminders or not * <li> CLONE_TASK_DEPENDENCY boolean clone previous tasks or not * <li> CLONE_FILES boolean clone files or not * * @throws TasksException - on access denied, task not found. * @throws CTaskAssertException. * @throws Exception - on unexpected error. * * @return CTaskItem[] */ public function duplicate($overrideTaskData = array(), $parameters = array('CLONE_CHILD_TASKS' => true, 'CLONE_CHECKLIST_ITEMS' => true, 'CLONE_TAGS' => true, 'CLONE_REMINDERS' => true, 'CLONE_TASK_DEPENDENCY' => true, 'CLONE_FILES' => true)) { if (!is_array($overrideTaskData)) { $overrideTaskData = array(); } if (!is_array($parameters)) { $parameters = array(); } if (!isset($parameters['CLONE_CHILD_TASKS'])) { $parameters['CLONE_CHILD_TASKS'] = true; } if (!isset($parameters['CLONE_CHECKLIST_ITEMS'])) { $parameters['CLONE_CHECKLIST_ITEMS'] = true; } if (!isset($parameters['CLONE_TAGS'])) { $parameters['CLONE_TAGS'] = true; } if (!isset($parameters['CLONE_REMINDERS'])) { $parameters['CLONE_REMINDERS'] = true; } if (!isset($parameters['CLONE_TASK_DEPENDENCY'])) { $parameters['CLONE_TASK_DEPENDENCY'] = true; } if (!isset($parameters['CLONE_FILES'])) { $parameters['CLONE_FILES'] = true; } $result = array(); $data = $this->getData(false); // ensure we have access to the task if (is_array($data)) { $data = array_merge($data, $overrideTaskData); // drop unwanted unset($data['ID']); unset($data['GUID']); unset($data['STATUS']); // detach forum, if any unset($data['FORUM_TOPIC_ID']); unset($data['COMMENTS_COUNT']); // clean dates unset($data['CREATED_DATE']); unset($data['CHANGED_DATE']); unset($data['VIEWED_DATE']); unset($data['STATUS_CHANGED_DATE']); unset($data['CHANGED_BY']); $files = array(); if (is_array($data['UF_TASK_WEBDAV_FILES']) && !empty($data['UF_TASK_WEBDAV_FILES'])) { $files = $data['UF_TASK_WEBDAV_FILES']; } unset($data['UF_TASK_WEBDAV_FILES']); $clone = static::add($data, $this->getExecutiveUserId()); $taskDupId = $clone->getId(); if (intval($taskDupId)) { $result[$clone->getId()] = $clone; if ($parameters['CLONE_CHECKLIST_ITEMS']) { list($arChecklistItems, $arMetaData) = CTaskCheckListItem::fetchList($this, array('SORT_INDEX' => 'ASC')); unset($arMetaData); foreach ($arChecklistItems as $oChecklistItem) { $cliData = $oChecklistItem->getData(); $cliCloneData = array('TITLE' => $cliData['TITLE'], 'IS_COMPLETE' => $cliData['IS_COMPLETE'], 'SORT_INDEX' => $cliData['SORT_INDEX']); CTaskCheckListItem::add($clone, $cliCloneData); } } if ($parameters['CLONE_TAGS']) { $tags = $this->getTags(); if (is_array($tags)) { foreach ($tags as $tag) { if ((string) $tag != '') { $oTag = new CTaskTags(); $oTag->Add(array('TASK_ID' => $taskDupId, 'NAME' => $tag), $this->getExecutiveUserId()); } } } } if ($parameters['CLONE_REMINDERS']) { $res = CTaskReminders::GetList(false, array('TASK_ID' => $this->getId())); while ($item = $res->fetch()) { $item['TASK_ID'] = $taskDupId; $item['USER_ID'] = $this->getExecutiveUserId(); $oReminder = new CTaskReminders(); $oReminder->Add($item); } } if ($parameters['CLONE_TASK_DEPENDENCY']) { $res = CTaskDependence::GetList(array(), array('TASK_ID' => $this->getId())); while ($item = $res->fetch()) { $depInstance = new CTaskDependence(); if (is_array($item)) { $depInstance->Add(array('TASK_ID' => $taskDupId, 'DEPENDS_ON_ID' => $item['DEPENDS_ON_ID'])); } } } if ($parameters['CLONE_FILES'] && !empty($files) && \Bitrix\Main\Loader::includeModule('disk')) { // find which files are new and which are old $old = array(); $new = array(); foreach ($files as $fileId) { if ((string) $fileId) { if (strpos($fileId, 'n') === 0) { $new[] = $fileId; } else { $old[] = $fileId; } } } if (!empty($old)) { $userFieldManager = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager(); $old = $userFieldManager->cloneUfValuesFromAttachedObject($old, $this->getExecutiveUserId()); if (is_array($old) && !empty($old)) { $new = array_merge($new, $old); } } if (!empty($new)) { $clone->update(array('UF_TASK_WEBDAV_FILES' => $new)); } } if ($parameters['CLONE_CHILD_TASKS']) { $notifADWasDisabled = CTaskNotifications::disableAutoDeliver(); $clones = $this->duplicateChildTasks($clone); if (is_array($clones)) { foreach ($clones as $cId => $cInst) { $result[$cId] = $cInst; } } if ($notifADWasDisabled) { CTaskNotifications::enableAutoDeliver(); } } } } return $result; }
$arKnownModes = array('VIEW TASK', 'CREATE TASK FORM'); if ($arParams['MODE'] === 'VIEW TASK') { $arWhiteList = array('checklist', 'buttons', 'right_sidebar'); } elseif ($arParams['MODE'] === 'CREATE TASK FORM') { $arWhiteList = array('checklist'); } elseif ($arParams['MODE'] === 'JUST AFTER TASK CREATED' || $arParams['MODE'] === 'JUST AFTER TASK EDITED') { $arChecklistItems = array(); if (isset($_POST['CHECKLIST_ITEM_ID'])) { if (!is_array($_POST['CHECKLIST_ITEM_ID'])) { CTaskAssert::logError('[0x17949379] array expected in $_POST[\'CHECKLIST_ITEM_ID\']'); } elseif (!empty($_POST['CHECKLIST_ITEM_ID'])) { if ($arParams['TASK_ID'] > 0) { $oTask = CTaskItem::getInstance($arParams['TASK_ID'], $USER->getId()); } if ($arParams['TASK_ID'] > 0 && $arParams['MODE'] === 'JUST AFTER TASK EDITED') { list($arChecklistItemsInDb, $arMetaData) = CTaskCheckListItem::fetchList($oTask, array('SORT_INDEX' => 'ASC')); unset($arMetaData); $arChecklistItemsInDbIds = array(); foreach ($arChecklistItemsInDb as $oChecklistItem) { $arChecklistItemsInDbIds[] = $oChecklistItem->getId(); } } $sortIndex = 0; $arChecklistItemsInPostIds = array(); foreach ($_POST['CHECKLIST_ITEM_ID'] as $postId) { if (!(isset($_POST['CHECKLIST_ITEM_TITLE'][$postId]) && isset($_POST['CHECKLIST_ITEM_IS_CHECKED'][$postId]))) { CTaskAssert::logError('[0x513f2d9a] CHECKLIST_ITEM_TITLE[$postId] and CHECKLIST_ITEM_IS_CHECKED[$postId] are expected in $_POST'); continue; } $arChecklistItemsInPostIds[] = $postId; try {