CCrmEvent::Add

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmEvent
  4. Add
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_event.php
  • Класс: \CCrmEvent
  • Вызов: CCrmEvent::Add
public function Add($arFields, $bPermCheck = true)
{
	$err_mess = (self::err_mess()).'
Function: Add
Line: '; $db_events = GetModuleEvents('crm', 'OnBeforeCrmAddEvent'); while($arEvent = $db_events->Fetch()) $arFields = ExecuteModuleEventEx($arEvent, array($arFields)); if (isset($arFields['ENTITY']) && is_array($arFields['ENTITY'])) { foreach($arFields['ENTITY'] as $key => $arEntity) if (!(isset($arEntity['ENTITY_TYPE']) && isset($arEntity['ENTITY_ID']))) unset($arEntity['ENTITY'][$key]); } else if (isset($arFields['ENTITY_TYPE']) && isset($arFields['ENTITY_ID'])) { $arFields['ENTITY'] = array( array( 'ENTITY_TYPE' => $arFields['ENTITY_TYPE'], 'ENTITY_ID' => $arFields['ENTITY_ID'], 'ENTITY_FIELD' => isset($arFields['ENTITY_FIELD']) ? $arFields['ENTITY_FIELD'] : '', 'USER_ID' => (int)(isset($arFields['USER_ID']) ? intval($arFields['USER_ID']) : $this->currentUserID) ) ); } else return false; if (isset($arFields['EVENT_ID'])) { $CCrmStatus = new CCrmStatus('EVENT_TYPE'); $ar = $CCrmStatus->GetStatusByStatusId($arFields['EVENT_ID']); $arFields['EVENT_NAME'] = isset($ar['NAME'])? $ar['NAME']: ''; } if (!$this->CheckFields($arFields)) return false; if (!isset($arFields['EVENT_TYPE'])) $arFields['EVENT_TYPE'] = 0; $arFiles = Array(); if (isset($arFields['FILES']) && !empty($arFields['FILES'])) { $arFields['~FILES'] = Array(); if (isset($arFields['FILES'][0])) $arFields['~FILES'] = $arFields['FILES']; else { foreach($arFields['FILES'] as $type => $ar) foreach($ar as $key => $value) $arFields['~FILES'][$key][$type] = $value; } foreach($arFields['~FILES'] as &$arFile) { $arFile['del'] = 'N'; $arFile['MODULE_ID'] = 'crm'; $fid = intval(CFile::SaveFile($arFile, 'crm')); if ($fid > 0) { $arFiles[] = $fid; } } unset($arFile); } $arFields_i = Array( 'ASSIGNED_BY_ID'=> (int)(isset($arFields['USER_ID']) ? intval($arFields['USER_ID']) : $this->currentUserID), 'CREATED_BY_ID' => (int)(isset($arFields['USER_ID']) ? intval($arFields['USER_ID']) : $this->currentUserID), 'EVENT_ID' => isset($arFields['EVENT_ID'])? $arFields['EVENT_ID']: '', 'EVENT_NAME' => $arFields['EVENT_NAME'], 'EVENT_TYPE' => intval($arFields['EVENT_TYPE']), 'EVENT_TEXT_1' => isset($arFields['EVENT_TEXT_1'])? $arFields['EVENT_TEXT_1']: '', 'EVENT_TEXT_2' => isset($arFields['EVENT_TEXT_2'])? $arFields['EVENT_TEXT_2']: '', 'FILES' => null, ); if (count($arFiles) > 0) { $arFields_i['FILES'] = serialize($arFiles); } //Validate DATE_CREATE if (isset($arFields['DATE_CREATE'])) { $sqlTime = CDatabase::FormatDate($arFields['DATE_CREATE'], CLang::GetDateFormat('FULL', false), 'YYYY-MM-DD HH:MI:SS'); if (!(is_string($sqlTime) && $sqlTime !== '')) { unset($arFields['DATE_CREATE']); } } if (isset($arFields['DATE_CREATE'])) { $arFields_i['DATE_CREATE'] = $arFields['DATE_CREATE']; } else { $arFields_i['~DATE_CREATE'] = $this->cdb->GetNowFunction(); } $EVENT_ID = $this->cdb->Add('b_crm_event', $arFields_i, array("FILES"), 'FILE: '.__FILE__.'
LINE: '.__LINE__); $this->AddRelation($EVENT_ID, $arFields['ENTITY'], $bPermCheck); $db_events = GetModuleEvents('crm', 'OnAfterCrmAddEvent'); while($arEvent = $db_events->Fetch()) ExecuteModuleEventEx($arEvent, array($EVENT_ID, $arFields)); return $EVENT_ID; }

Добавить комментарий