- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/classes/general/taskreminders.php
- Класс: CTaskReminders
- Вызов: CTaskReminders::SendAgent
static function SendAgent()
{
$arFilter = array(
// although DateTime created with 'new', here we get user time, because toString() always returns time in user offset
"<=REMIND_DATE" => ((string) new BitrixMainTypeDateTime())
);
$rsReminders = CTaskReminders::GetList(array("date" => "asc"), $arFilter);
while ($arReminder = $rsReminders->Fetch())
{
$rsTask = CTasks::GetByID($arReminder["TASK_ID"], false);
if ($arTask = $rsTask->Fetch())
{
// remind about not closed tasks only
if ($arTask['CLOSED_DATE'] === NULL)
{
if($arReminder['RECEPIENT_TYPE'] == self::RECEPIENT_TYPE_RESPONSIBLE)
{
$userTo = $arTask['RESPONSIBLE_ID']; // has access by definition
}
elseif($arReminder['RECEPIENT_TYPE'] == self::RECEPIENT_TYPE_ORIGINATOR)
{
$userTo = $arTask['CREATED_BY']; // has access by definition
}
else
{
$userTo = $arReminder["USER_ID"];
// need to check access
try
{
$task = new CTaskItem($arReminder["TASK_ID"], $userTo);
if(!$task->checkCanRead()) // no access at this moment, drop reminder
{
$userTo = false;
}
}
catch (CTaskAssertException $e)
{
$userTo = false;
}
}
if(intval($userTo))
{
$rsUser = CUser::GetByID($userTo);
if ($arUser = $rsUser->Fetch())
{
if (MailUser::isEmail($arUser))
{
// public link
$arTask['PATH_TO_TASK'] = tasksServerName() . MailTask::getDefaultPublicPath($arTask['ID']);
}
else
{
$arTask["PATH_TO_TASK"] = CTaskNotifications::GetNotificationPath($arUser, $arTask["ID"]);
}
$arFilterForSendedRemind = array_merge(
$arFilter,
array(
'TASK_ID' => $arReminder['TASK_ID'],
'USER_ID' => $arReminder['USER_ID'],
'TRANSPORT' => $arReminder['TRANSPORT'],
'TYPE' => $arReminder['TYPE']
)
);
CTaskReminders::Delete($arFilterForSendedRemind);
if (
$arReminder["TRANSPORT"] == self::REMINDER_TRANSPORT_EMAIL
|| !CModule::IncludeModule("socialnetwork")
|| !CTaskReminders::__SendJabberReminder($arUser["ID"], $arTask)
)
{
CTaskReminders::__SendEmailReminder($arUser["EMAIL"], $arTask);
}
}
}
}
}
}
// Some older items can still exists (for removed users, etc.)
CTaskReminders::Delete($arFilter);
return "CTaskReminders::SendAgent();";
}