getInstance
Static method for editing checklist item.
- Editing checklist item
- Deleting checklist item
- Checking access permission for checklist item actions
- Updating sorting index
- Moving item 5 below checklist item 2
- Checklist item was completed/not completed
- Complete checklist item
- Mark checklist item as not completed
Editing checklist item:
$task = \CTaskItem::getInstance($taskId, $userId); $item = new \CTaskCheckListItem($task, $itemId); $item->update(['TITLE'=>'title 2']);
Events
OnBeforeTaskCheckListItemUpdate ($task, $fields) OnAfterTaskCheckListItemUpdate ($task, $oldFields, $newFields)
REST query
// 20190207175155 // http://site.com/rest/1/********/tasks.task.checklist.update?taskId=1&checkListItemId=29&fields[TITLE]=Hello%20world { "result": { "item": [ { "ID": "1", "CREATED_BY": "1", "TASK_ID": "1", "TITLE": "Hello world", "IS_COMPLETE": "N", "SORT_INDEX": "1" } ] }, "time": { "start": 1549554715.4373, "finish": 1549554715.54894, "duration": 0.11163997650146484, "processing": 0.038207054138183594, "date_start": "2019-02-07T17:51:55+02:00", "date_finish": "2019-02-07T17:51:55+02:00" } }
Delete checklist item:
$task = \CTaskItem::getInstance($taskId, $userId); $item = new \CTaskCheckListItem($task, $itemId); $item->delete();
Events
OnBeforeTaskCheckListItemDelete ($task, $fields) OnAfterTaskCheckListItemDelete ($task)
REST query
// 20190207175321 // http://site.com/rest/1/********/tasks.task.checklist.delete?taskId=1&checkListItemId=29 { "result": { "item": true }, "time": { "start": 1549554801.140385, "finish": 1549554801.24166, "duration": 0.10127520561218262, "processing": 0.032243967056274414, "date_start": "2019-02-07T17:53:21+02:00", "date_finish": "2019-02-07T17:53:21+02:00" } }
Checking access permissions to checklist items:
task = \CTaskItem::getInstance($taskId, $userId); $item = new \CTaskCheckListItem($task, $itemId); $task->isActionAllowed(\CTaskItem::ACTION_CHECKLIST_ADD_ITEMS); // to add checklist item, permission should be requested for a task, not checklist! $item = new \CTaskCheckListItem($task, $itemId); // deleting $item->isActionAllowed(\CTaskCheckListItem::ACTION_REMOVE); // sorting $item->isActionAllowed(\CTaskCheckListItem::ACTION_REORDER); // updating $item->isActionAllowed(\CTaskCheckListItem::ACTION_MODIFY); // executing $item->isActionAllowed(\CTaskCheckListItem::ACTION_TOGGLE);
Possible options $actionId:
\CTaskCheckListItem::ACTION_ADD = 0x01; // adding \CTaskCheckListItem::ACTION_MODIFY = 0x02; // updating \CTaskCheckListItem::ACTION_REMOVE = 0x03; // deleting \CTaskCheckListItem::ACTION_TOGGLE = 0x04; // executing \CTaskCheckListItem::ACTION_REORDER = 0x05; // sorting
Updating sort index:
$task = \CTaskItem::getInstance($taskId, $userId); $item = new \CTaskCheckListItem($task, $itemId); $newIndex = 19; $item->setSortIndex($newIndex);
Events
OnBeforeTaskCheckListItemSort ($task, $fields) OnAfterTaskCheckListItemSort ($task, $oldFields, $newFields)
Move item 5 below checklist item 2:
$task = \CTaskItem::getInstance($taskId, $userId); $item5 = new \CTaskCheckListItem($task, $itemId5); $item2 = new \CTaskCheckListItem($task, $itemId2); $item5->moveAfterItem($item2->getId());
Events
OnCheckListItemMoveItem ($selectedItemId, $insertAfterItemId)
REST query
// 20190207175514 // http://site.com/rest/1/********/tasks.task.checklist.moveafter?taskId=1&checkListItemId=2&afterItemId=6 { "result": { "item": [ { "ID": "2", "CREATED_BY": "1", "TASK_ID": "1", "TITLE": "Hello world", "IS_COMPLETE": "N", "SORT_INDEX": "17" } ] }, "time": { "start": 1549555019.965198, "finish": 1549555020.053995, "duration": 0.08879685401916504, "processing": 0.035902976989746094, "date_start": "2019-02-07T17:56:59+02:00", "date_finish": "2019-02-07T17:57:00+02:00" } }
Yes/no for checklist item completed status
$task = \CTaskItem::getInstance($taskId, $userId); $item = new \CTaskCheckListItem($task, $itemId); echo $item->iSComplete() ? 'Completed' : 'Not completed';
Complete checklist item:
$task = \CTaskItem::getInstance($taskId, $userId); $item = new \CTaskCheckListItem($task, $itemId); echo $item->сomplete();
Events
See method update.
REST query
// 20190207175514 // http://site.com/rest/1/********/tasks.task.checklist.complete?taskId=1&checkListItemId=2 { "result": { "item": [ { "ID": "2", "CREATED_BY": "1", "TASK_ID": "1", "TITLE": "Hello world", "IS_COMPLETE": "Y", "SORT_INDEX": "4" } ] }, "time": { "start": 1549554914.300577, "finish": 1549554914.371372, "duration": 0.07079505920410156, "processing": 0.03411412239074707, "date_start": "2019-02-07T17:55:14+02:00", "date_finish": "2019-02-07T17:55:14+02:00" } }
Mark checklist item as incomplete
Contrary to the method toggle this method does not switch task status as completed/not completed, but forcefully sets item status as "not completed".
$task = \CTaskItem::getInstance($taskId, $userId); $item = new \CTaskCheckListItem($task, $itemId); echo $item->renew();
Events
See method update.
REST query
// 20190207175514 // http://site.com/rest/1/********/tasks.task.checklist.renew?taskId=1&checkListItemId=2 { "result": { "item": [ { "ID": "2", "CREATED_BY": "1", "TASK_ID": "1", "TITLE": "Hello world", "IS_COMPLETE": "N", "SORT_INDEX": "4" } ] }, "time": { "start": 1549554914.300577, "finish": 1549554914.371372, "duration": 0.07079505920410156, "processing": 0.03411412239074707, "date_start": "2019-02-07T17:55:14+02:00", "date_finish": "2019-02-07T17:55:14+02:00" } }
© «Bitrix24», 2001-2024