Пример #1
0
 public static function Set($user_id, $page_last_date, $page_size, $page_num = 1, $site_id = SITE_ID, $group_code = '**', $traffic_avg = false, $traffic_cnt = false)
 {
     global $DB;
     $user_id = intval($user_id);
     $page_size = intval($page_size);
     $page_num = intval($page_num);
     $traffic_avg = intval($traffic_avg);
     $traffic_cnt = intval($traffic_cnt);
     if ($user_id <= 0 || $page_size <= 0 || strlen($page_last_date) <= 0) {
         return false;
     }
     $page_last_date = new \Bitrix\Main\Type\DateTime($page_last_date);
     $connection = \Bitrix\Main\Application::getConnection();
     $helper = $connection->getSqlHelper();
     $arInsertFields = array("USER_ID" => $user_id, "SITE_ID" => $DB->ForSQL($site_id), "GROUP_CODE" => $DB->ForSQL($group_code), "PAGE_SIZE" => $page_size, "PAGE_NUM" => $page_num, "PAGE_LAST_DATE" => $page_last_date);
     $arUpdateFields = array("PAGE_LAST_DATE" => $page_last_date);
     if ($traffic_cnt) {
         $arInsertFields["TRAFFIC_AVG"] = $arUpdateFields["TRAFFIC_AVG"] = $traffic_avg;
         $arInsertFields["TRAFFIC_CNT"] = $arUpdateFields["TRAFFIC_CNT"] = $traffic_cnt;
         $arInsertFields["TRAFFIC_LAST_DATE"] = $arUpdateFields["TRAFFIC_LAST_DATE"] = new \Bitrix\Main\DB\SqlExpression($helper->getCurrentDateTimeFunction());
     }
     $merge = $helper->prepareMerge("b_sonet_log_page", array("USER_ID", "SITE_ID", "GROUP_CODE", "PAGE_SIZE", "PAGE_NUM"), $arInsertFields, $arUpdateFields);
     if ($merge[0] != "") {
         $connection->query($merge[0]);
         if ($traffic_cnt) {
             CSocNetLogFollow::checkAutoUnfollow($traffic_cnt, $traffic_avg, $user_id);
         }
     }
 }