AddEventHandler('rest', 'OnRestServiceBuildDescription', ['\MyRestApi', 'OnRestServiceBuildDescription']);
class MyRestApi
{
public static function OnRestServiceBuildDescription()
{
return [
'task' => [
'task.item.add' => [
'callback' => [__CLASS__, 'taskAdd'],
'options' => [],
],
],
];
}
public static function taskAdd($query, $nav, \CRestServer $server)
{
if ($query['error'])
{
throw new \Bitrix\Rest\RestException(
'Message',
'ERROR_CODE',
\CRestServer::STATUS_PAYMENT_REQUIRED
);
}
if (!isset($query['id']))
{
return [
'error' => 'ERROR_METHOD_NOT_FOUND',
'error_description' => 'Method not found! ' . __LINE__,
];
}
if (!isset($query['fields']))
{
return [
'error' => 'ERROR_METHOD_NOT_FOUND',
'error_description' => 'Method not found! ' . __LINE__,
];
}
$id = intval($query['id']);
if ($id <= 0)
{
return [
'error' => 'ERROR_METHOD_NOT_FOUND',
'error_description' => 'Method not found! ' . __LINE__,
];
}
$file = $_SERVER['DOCUMENT_ROOT'] . '/logg.log';
$data = serialize($query);
file_put_contents($file, $data);
return array('result' => 'ok');
}
}
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler(
'tasks',
'\Bitrix\Tasks\Task::onAfterAdd',
['TaskEvent', 'addCheckList']
);
$field['CHECKLIST'] = [
[
'NODE_ID' => 'test1',
'PARENT_NODE_ID' => 0,
'COPIED_ID' => '',
'PARENT_ID' => null,
'TITLE' => 'чек-лист 1',
'SORT_INDEX' => 0,
'IS_COMPLETE' => 0,
'IS_IMPORTANT' => false,
'ACTION' => [
'MODIFY' => true,
'REMOVE' => true,
'TOGGLE' => true,
]
],
[
'NODE_ID' => 'sub_test',
'PARENT_NODE_ID' => 'test1',
'COPIED_ID' => '',
'PARENT_ID' => null,
'TITLE' => 'пункт 1',
'SORT_INDEX' => 0,
'IS_COMPLETE' => 0,
'IS_IMPORTANT' => false,
'ACTION' => [
'MODIFY' => true,
'REMOVE' => true,
'TOGGLE' => true,
]
],
];