- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/classes/general/countersprocessorinstaller.php
- Класс: CTaskCountersProcessorInstaller
- Вызов: CTaskCountersProcessorInstaller::recountCounters_MY_WITHOUT_DEADLINES
static function recountCounters_MY_WITHOUT_DEADLINES($userId)
{
global $DB;
$DB->startTransaction();
// Count tasks without DEADLINES
// not in states: CTasks::STATE_SUPPOSEDLY_COMPLETED, CTasks::STATE_COMPLETED, CTasks::STATE_DECLINED
// and where CREATED_BY != RESPONSIBLE_ID.
// Count tasks for resposibles.
$strSql =
"SELECT COUNT(T.ID) AS T_WO_DEADLINES,
T.RESPONSIBLE_ID AS RESPONSIBLE_ID
FROM b_tasks T
WHERE
T.ZOMBIE = 'N'
AND T.CREATED_BY != T.RESPONSIBLE_ID
AND T.CREATED_BY != 0
AND T.RESPONSIBLE_ID != 0
AND T.DEADLINE IS NULL
AND T.STATUS != " . CTasks::STATE_DECLINED . "
AND T.STATUS != " . CTasks::STATE_SUPPOSEDLY_COMPLETED . "
AND T.STATUS != " . CTasks::STATE_COMPLETED . "
";
if ($userId !== '*') // All users or not?
$strSql .= " AND T.RESPONSIBLE_ID = " . (int) $userId;
$strSql .= " GROUP BY T.RESPONSIBLE_ID";
$rc = $DB->query($strSql);
$i = 0;
while ($ar = $rc->fetch())
{
$arValues = CUserCounter::GetValues($ar['RESPONSIBLE_ID'], $site_id = '**');
$total = 0;
if (isset($arValues[CTaskCountersProcessor::COUNTER_TASKS_TOTAL]))
$total = (int) $arValues[CTaskCountersProcessor::COUNTER_TASKS_TOTAL];
$subtotal = 0;
if (isset($arValues[CTaskCountersProcessor::COUNTER_TASKS_MY]))
$subtotal = (int) $arValues[CTaskCountersProcessor::COUNTER_TASKS_MY];
CUserCounter::Set(
(int) $ar['RESPONSIBLE_ID'],
CTaskCountersProcessor::COUNTER_TASKS_MY_WO_DEADLINE,
(int) $ar['T_WO_DEADLINES'],
'**', // $site_id
$tag = '',
false // $sendPull
);
CUserCounter::Set(
(int) $ar['RESPONSIBLE_ID'],
CTaskCountersProcessor::COUNTER_TASKS_MY,
$subtotal + (int) $ar['T_WO_DEADLINES'],
'**', // $site_id
$tag = '',
false // $sendPull
);
CUserCounter::Set(
(int) $ar['RESPONSIBLE_ID'],
CTaskCountersProcessor::COUNTER_TASKS_TOTAL,
$total + (int) $ar['T_WO_DEADLINES'],
'**', // $site_id
$tag = '',
false // $sendPull
);
// commit on after every 100 users have been processed
if ( ! (++$i % 100) )
{
soundex('commit every 100 users');
$DB->commit();
$DB->startTransaction();
}
}
$DB->commit();
}