- Модуль: timeman
- Путь к файлу: ~/bitrix/modules/timeman/classes/general/timeman_report_full.php
- Класс: CTimeManReportFull
- Вызов: CTimeManReportFull::Add
static function Add($arFields)
{
global $DB;
$tm_user = new CUserReportFull($arFields["USER_ID"] ?? null);
$arReportDate = $tm_user->GetReportInfo();
if ($arReportDate["IS_REPORT_DAY"]!="Y")
return false;
$shortFormat = CSite::getDateFormat("SHORT", SITE_ID);
$fullFormat = CSite::getDateFormat("FULL", SITE_ID);
$arFields["DATE_TO"] = ConvertTimeStamp(MakeTimeStamp($arReportDate["DATE_TO"], $shortFormat),"SHORT");
$arFields["DATE_FROM"] = ConvertTimeStamp(MakeTimeStamp($arReportDate["DATE_FROM"], $shortFormat),"SHORT");
$arFields["REPORT_DATE"] = ConvertTimeStamp(MakeTimeStamp($arFields["REPORT_DATE"] ?? '', $fullFormat),"FULL");
foreach(GetModuleEvents('timeman', 'OnBeforeFullReportAdd', true) as $event)
{
if (false === ExecuteModuleEventEx($event, array(&$arFields)))
return false;
}
if (!self::CheckFields('ADD', $arFields))
return false;
//we try to find report with DATE_TO>DATE_FROM-of-current-report
$dbreport = CTimeManReportFull::GetList(
Array("DATE_FROM"=>"DESC"),
Array(
">=DATE_TO"=>$arFields["DATE_FROM"],
"USER_ID"=>$arFields["USER_ID"],
"ACTIVE"=>"Y"
),
Array("ID","DATE_TO"),
Array("nTopCount"=>1)
);
if ($last_report = $dbreport->Fetch())//if we found it
//fix date from
$arFields["DATE_FROM"] = ConvertTimeStamp(strtotime("next day", MakeTimeStamp($last_report["DATE_TO"])),"SHORT");
if (MakeTimeStamp($arFields["DATE_FROM"])>MakeTimeStamp($arFields["DATE_TO"]))
//fix date to
$arFields["DATE_TO"] = $arFields["DATE_FROM"];
CTimeZone::Disable();
$ID = $DB->Add('b_timeman_report_full', $arFields, array('REPORT', 'TASKS', 'EVENTS','FILES'));
CTimeZone::Enable();
if ($ID > 0)
{
$last_date = ConvertTimeStampForReport(MakeTimeStamp($arFields["DATE_TO"]),"SHORT");
$arFields['ID'] = $ID;
foreach(GetModuleEvents('timeman', 'OnAfterFullReportAdd', true) as $a)
{
ExecuteModuleEventEx($a, array($arFields));
}
if ($arFields["ACTIVE"] != "N")
{
$tm_user->SetLastDate($arFields["USER_ID"], $last_date);
}
}
return $ID;
}