- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/internals/task/template/checklist.php
- Класс: BitrixTasksInternalsTaskTemplateCheckListTable
- Вызов: CheckListTable::moveAfterItem
static function moveAfterItem($templateId, $selectedItemId, $insertAfterItemId)
{
$templateId = Assert::expectIntegerPositive($templateId, '$templateId');
$selectedItemId = Assert::expectIntegerPositive($selectedItemId, '$selectedItemId');
$insertAfterItemId = Assert::expectIntegerPositive($insertAfterItemId, '$insertAfterItemId');
$res = static::getList(array('filter' => array(
'=TEMPLATE_ID' => $templateId
), 'order' => array(
'SORT' => 'asc',
'ID' => 'asc'
), 'select' => array(
'ID',
'SORT'
)));
$items = array($selectedItemId => 0); // by default to first position
$prevItemId = 0;
$sortIndex = 1;
while($item = $res->fetch())
{
if ($insertAfterItemId == $prevItemId)
$items[$selectedItemId] = $sortIndex++;
if ($item['ID'] != $selectedItemId)
$items[$item['ID']] = $sortIndex++;
$prevItemId = $item['ID'];
}
if ($insertAfterItemId == $prevItemId)
$items[$selectedItemId] = $sortIndex;
if (!empty($items))
{
$sql = "
UPDATE ".static::getTableName()."
SET
SORT = CASE ";
foreach ($items as $id => $sortIndex)
$sql .= " WHEN ID = '".intval($id)."' THEN '".intval($sortIndex)."'";
$sql .= " END
WHERE TEMPLATE_ID = '".intval($templateId)."'";
BitrixMainHttpApplication::getConnection()->query($sql);
}
}