- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/classes/general/countersprocessorinstaller.php
- Класс: CTaskCountersProcessorInstaller
- Вызов: CTaskCountersProcessorInstaller::recountCounters_MY_NEW
static function recountCounters_MY_NEW($userId)
{
global $DB;
$DB->startTransaction();
// Count not viewed tasks by responsible
$strSql = "SELECT COUNT(T.ID) AS MY_NEW_CNT, T.RESPONSIBLE_ID AS RESPONSIBLE_ID
FROM b_tasks T
LEFT JOIN b_tasks_viewed TV ON TV.TASK_ID = T.ID AND TV.USER_ID = T.RESPONSIBLE_ID
WHERE
T.ID IS NOT NULL
AND T.ZOMBIE = 'N'
AND TV.USER_ID IS NULL
AND (T.STATUS = " . CTasks::STATE_NEW . " OR T.STATUS = " . CTasks::STATE_PENDING . ")
";
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_NEW,
(int) $ar['MY_NEW_CNT'],
'**', // $site_id
$tag = '',
false // $sendPull
);
CUserCounter::Set(
(int) $ar['RESPONSIBLE_ID'],
CTaskCountersProcessor::COUNTER_TASKS_MY,
$subtotal + (int) $ar['MY_NEW_CNT'],
'**', // $site_id
$tag = '',
false // $sendPull
);
CUserCounter::Set(
(int) $ar['RESPONSIBLE_ID'],
CTaskCountersProcessor::COUNTER_TASKS_TOTAL,
$total + (int) $ar['MY_NEW_CNT'],
'**', // $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();
}