Exemplo n.º 1
0
 public static function SynchronizeUserActivity($ownerTypeID, $ownerID, $userID)
 {
     $ownerTypeID = intval($ownerTypeID);
     $ownerID = intval($ownerID);
     $userID = intval($userID);
     if ($userID < 0) {
         $userID = 0;
     }
     if ($ownerTypeID <= CCrmOwnerType::Undefined || $ownerID <= 0) {
         return;
     }
     $arResult = CCrmActivity::GetNearest($ownerTypeID, $ownerID, $userID);
     if (is_array($arResult)) {
         $activityID = isset($arResult['ID']) ? intval($arResult['ID']) : 0;
         $deadline = isset($arResult['DEADLINE']) ? $arResult['DEADLINE'] : '';
     } else {
         $activityID = 0;
         $deadline = '';
     }
     if ($activityID > 0 && $deadline !== '') {
         CCrmActivity::DoSaveNearestUserActivity(array('USER_ID' => $userID, 'OWNER_ID' => $ownerID, 'OWNER_TYPE_ID' => $ownerTypeID, 'ACTIVITY_ID' => $activityID, 'ACTIVITY_TIME' => $deadline, 'SORT' => ($userID > 0 ? '1' : '0') . date('YmdHis', MakeTimeStamp($deadline))));
     } else {
         global $DB;
         $tableName = CCrmActivity::USER_ACTIVITY_TABLE_NAME;
         $DB->Query("DELETE FROM {$tableName} WHERE USER_ID = {$userID} AND OWNER_TYPE_ID = {$ownerTypeID} AND OWNER_ID = {$ownerID}", false, 'File: ' . __FILE__ . '<br/>Line: ' . __LINE__);
     }
     $counter = new CCrmUserCounter($userID, CCrmUserCounter::CurrentActivies);
     $counter->Synchronize();
 }