Пример #1
0
 public static function WriteEventFileToResponse($eventID, $fileID, &$errors, $options = array())
 {
     $eventID = intval($eventID);
     $fileID = intval($fileID);
     if ($eventID <= 0 || $fileID <= 0) {
         $errors[] = 'File not found';
         return false;
     }
     //Get event file IDs and check permissions
     $dbResult = CCrmEvent::GetListEx(array(), array('=ID' => $eventID), false, false, array('ID', 'FILES'), array());
     $event = $dbResult ? $dbResult->Fetch() : null;
     if (!$event) {
         $errors[] = 'File not found';
         return false;
     }
     if (is_array($event['FILES'])) {
         $eventFiles = $event['FILES'];
     } elseif (is_string($event['FILES']) && $event['FILES'] !== '') {
         $eventFiles = unserialize($event['FILES']);
     } else {
         $eventFiles = array();
     }
     if (empty($eventFiles) || !is_array($eventFiles) || !in_array($fileID, $eventFiles, true)) {
         $errors[] = 'File not found';
         return false;
     }
     return self::InnerWriteFileToResponse($fileID, $errors, $options);
 }
Пример #2
0
 public static function prepareRecoveryData($entityTypeID, $entityID, array $options = null)
 {
     if (!is_int($entityTypeID)) {
         $entityTypeID = intval($entityTypeID);
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\ArgumentException('Is not defined', 'entityTypeID');
     }
     if (!is_int($entityID)) {
         $entityID = intval($entityID);
     }
     if ($entityID <= 0) {
         throw new Main\ArgumentException('Must be greater than zero', 'entityID');
     }
     if (!is_array($options)) {
         $options = array();
     }
     $item = new EntityRecoveryData();
     $item->setEntityTypeID($entityTypeID);
     $item->setEntityID($entityID);
     $userID = isset($options['USER_ID']) ? intval($options['USER_ID']) : 0;
     if ($userID > 0) {
         $item->setUserID($userID);
     }
     if ($entityTypeID === \CCrmOwnerType::Lead) {
         $result = \CCrmLead::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*'));
         $fields = is_object($result) ? $result->Fetch() : null;
         if (!is_array($fields)) {
             throw new Main\ObjectNotFoundException("The lead with ID '{$entityTypeID}' is not found");
         }
         $item->setDataItem('FIELDS', $fields);
         if (isset($fields['TITLE'])) {
             $item->setTitle($fields['TITLE']);
         }
         if (isset($fields['ASSIGNED_BY_ID'])) {
             $item->setResponsibleID(intval($fields['ASSIGNED_BY_ID']));
         }
     } elseif ($entityTypeID === \CCrmOwnerType::Contact) {
         $result = \CCrmContact::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*'));
         $fields = is_object($result) ? $result->Fetch() : null;
         if (!is_array($fields)) {
             throw new Main\ObjectNotFoundException("The contact with ID '{$entityTypeID}' is not found");
         }
         $item->setDataItem('FIELDS', $fields);
         $item->setTitle(\CCrmContact::GetFullName($fields, true));
         if (isset($fields['ASSIGNED_BY_ID'])) {
             $item->setResponsibleID(intval($fields['ASSIGNED_BY_ID']));
         }
     } elseif ($entityTypeID === \CCrmOwnerType::Company) {
         $result = \CCrmCompany::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*'));
         $fields = is_object($result) ? $result->Fetch() : null;
         if (!is_array($fields)) {
             throw new Main\ObjectNotFoundException("The company with ID '{$entityTypeID}' is not found");
         }
         $item->setDataItem('FIELDS', $fields);
         if (isset($fields['TITLE'])) {
             $item->setTitle($fields['TITLE']);
         }
         if (isset($fields['ASSIGNED_BY_ID'])) {
             $item->setResponsibleID(intval($fields['ASSIGNED_BY_ID']));
         }
     } else {
         throw new Main\NotSupportedException("The entity type '" . \CCrmOwnerType::ResolveName($entityTypeID) . "' is not supported in current context");
     }
     $entityTypeName = \CCrmOwnerType::ResolveName($entityTypeID);
     //MULTI FIELDS -->
     $multiFieldData = array();
     $multiFieldTypes = array(\CCrmFieldMulti::PHONE, \CCrmFieldMulti::EMAIL, \CCrmFieldMulti::WEB, \CCrmFieldMulti::IM);
     foreach ($multiFieldTypes as $multiFieldType) {
         $result = \CCrmFieldMulti::GetListEx(array('ID' => 'ASC'), array('TYPE_ID' => $multiFieldType, 'ENTITY_ID' => $entityTypeName, 'ELEMENT_ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, array('nTopCount' => 50), array('VALUE_TYPE', 'VALUE'));
         if (!is_object($result)) {
             continue;
         }
         while ($multiFields = $result->Fetch()) {
             $valueType = isset($multiFields['VALUE_TYPE']) ? $multiFields['VALUE_TYPE'] : '';
             $value = isset($multiFields['VALUE']) ? $multiFields['VALUE'] : '';
             if ($value === '') {
                 continue;
             }
             if (!isset($multiFieldData[$multiFieldType])) {
                 $multiFieldData[$multiFieldType] = array();
             }
             $multiFieldData[$multiFieldType][] = array('VALUE_TYPE' => $valueType, 'VALUE' => $value);
         }
     }
     if (!empty($multiFieldData)) {
         $item->setDataItem('MULTI_FIELDS', $multiFieldData);
     }
     //<-- MULTI FIELDS
     //ACTIVITIES -->
     $activityIDs = \CCrmActivity::GetBoundIDs($entityTypeID, $entityID);
     if (!empty($activityIDs)) {
         $item->setDataItem('ACTIVITY_IDS', $activityIDs);
     }
     //<-- ACTIVITIES
     //EVENTS -->
     $eventIDs = array();
     $result = \CCrmEvent::GetListEx(array('EVENT_REL_ID' => 'ASC'), array('ENTITY_TYPE' => $entityTypeName, 'ENTITY_ID' => $entityID, 'EVENT_TYPE' => 0, 'CHECK_PERMISSIONS' => 'N'), false, false, array('EVENT_REL_ID'));
     if (is_object($result)) {
         while ($eventFields = $result->Fetch()) {
             $eventIDs[] = intval($eventFields['EVENT_REL_ID']);
         }
     }
     if (!empty($eventIDs)) {
         $item->setDataItem('EVENT_IDS', $eventIDs);
     }
     //<-- EVENTS
     return $item;
 }
Пример #3
0
if ($arResult['GRID_FILTER_APPLIED']) {
    $filterID = $arResult['GRID_FILTER_ID'] = isset($filter['GRID_FILTER_ID']) ? $filter['GRID_FILTER_ID'] : '';
    $arResult['GRID_FILTER_NAME'] = isset($arResult['FILTER_PRESETS'][$filterID]) ? $arResult['FILTER_PRESETS'][$filterID]['name'] : '';
} else {
    $arResult['GRID_FILTER_ID'] = '';
    $arResult['GRID_FILTER_NAME'] = '';
}
if ($entityTypeID > 0 && $entityID > 0) {
    $arResult['RUBRIC']['ENABLED'] = true;
    $filter['ENTITY_TYPE'] = CCrmOwnerType::ResolveName($entityTypeID);
    $filter['ENTITY_ID'] = $entityID;
    $arResult['RUBRIC']['TITLE'] = CCrmOwnerType::GetCaption($entityTypeID, $entityID);
    $arResult['RUBRIC']['FILTER_PRESETS'] = array('clear_filter', 'filter_custom');
}
$arResult['ITEMS'] = array();
$dbRes = CCrmEvent::GetListEx($sort, $filter, false, $arNavParams, $select, array());
$dbRes->NavStart($navParams['nPageSize'], false);
$arResult['PAGE_NAVNUM'] = intval($dbRes->NavNum);
// pager index
$arResult['PAGE_NUMBER'] = intval($dbRes->NavPageNomer);
// current page index
$arResult['PAGE_NAVCOUNT'] = intval($dbRes->NavPageCount);
// page count
$arResult['PAGER_PARAM'] = "PAGEN_{$arResult['PAGE_NAVNUM']}";
$arResult['PAGE_NEXT_NUMBER'] = $arResult['PAGE_NUMBER'] + 1;
while ($item = $dbRes->Fetch()) {
    CCrmMobileHelper::PrepareEventItem($item, $arParams);
    $arResult['ITEMS'][] =& $item;
    unset($item);
}
//NEXT_PAGE_URL, SEARCH_PAGE_URL, SERVICE_URL -->
Пример #4
0
    $key = array_search('ENTITY_TITLE', $arSelect, true);
    if ($key !== false) {
        unset($arSelect[$key]);
    }
}
$CGridOptions->SetVisibleColumns($arSelect);
$nTopCount = false;
if ($arResult['GADGET'] == 'Y') {
    $nTopCount = $arResult['EVENT_COUNT'];
}
if ($nTopCount > 0) {
    $arNavParams['nTopCount'] = $nTopCount;
}
$arEntityList = array();
$arResult['EVENT'] = array();
$obRes = CCrmEvent::GetListEx($arResult['SORT'], $arFilter, false, $arNavParams, array(), array());
$arResult['DB_LIST'] = $obRes;
$arResult['ROWS_COUNT'] = $obRes->NavRecordCount;
// Prepare raw filter ('=CREATED_BY' => 'CREATED_BY')
$arResult['DB_FILTER'] = array();
foreach ($arFilter as $filterKey => &$filterItem) {
    $info = CSqlUtil::GetFilterOperation($filterKey);
    $arResult['DB_FILTER'][$info['FIELD']] = $filterItem;
}
unset($filterItem);
while ($arEvent = $obRes->Fetch()) {
    $arEvent['~FILES'] = $arEvent['FILES'];
    $arEvent['~EVENT_NAME'] = $arEvent['EVENT_NAME'];
    if (!empty($arEvent['CREATED_BY_ID'])) {
        $arEvent['~CREATED_BY_FULL_NAME'] = CUser::FormatName($arParams["NAME_TEMPLATE"], array('LOGIN' => $arEvent['CREATED_BY_LOGIN'], 'NAME' => $arEvent['CREATED_BY_NAME'], 'LAST_NAME' => $arEvent['CREATED_BY_LAST_NAME'], 'SECOND_NAME' => $arEvent['CREATED_BY_SECOND_NAME']), true, false);
    }