- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/internals/counter/user.php
- Класс: BitrixTasksInternalsCounterUser
- Вызов: User::saveCounters
public function saveCounters()
{
if (!$this->needSaveCounters)
{
return;
}
$groupFields = array(); //accumulate counters by groups
foreach ($this->counters as $counterName => $groupsValue)
{
foreach ($groupsValue as $groupId => $value)
{
$groupFields[$groupId][$counterName] = $value;
}
}
unset($groupFields['allCounters']);
foreach ($groupFields as $groupId => $counters)
{
$fields = array_map(
function($counterName) use ($counters) {
return strtoupper($counterName).' = '.(int)$counters[$counterName];
},
array_keys($this->counters)
);
$currentDate = "'".date('Y-m-d')."'";
$sql = "
SELECT
ID
FROM
b_tasks_counters
WHERE
DATE = {$currentDate} AND
USER_ID = {$this->userId} AND
GROUP_ID = {$groupId}
";
$res = Application::getConnection()->query($sql)->fetch();
$counterId = $res['ID'];
if (!$counterId)
{
$fields[] = "DATE = ".$currentDate;
$fields[] = "USER_ID = ".$this->userId;
$fields[] = "GROUP_ID = ".$groupId;
$sql = 'INSERT INTO b_tasks_counters SET '.join(',', $fields);
}
else
{
$sql = 'UPDATE b_tasks_counters SET '.join(',', $fields)." WHERE ID = {$counterId}";
}
Application::getConnection()->query($sql);
CUserCounter::Set($this->userId, $this->getPrefix().CounterName::MY, $this->getCounter(CounterName::MY), '**', '', false);
CUserCounter::Set($this->userId, $this->getPrefix().CounterName::ACCOMPLICES, $this->getCounter(CounterName::ACCOMPLICES), '**', '', false);
CUserCounter::Set($this->userId, $this->getPrefix().CounterName::AUDITOR, $this->getCounter(CounterName::AUDITOR), '**', '', false);
CUserCounter::Set($this->userId, $this->getPrefix().CounterName::ORIGINATOR, $this->getCounter(CounterName::ORIGINATOR), '**', '', false);
CUserCounter::Set($this->userId, $this->getPrefix().CounterName::TOTAL, $this->getCounter(CounterName::TOTAL), '**', '', false);
}
}