Ejemplo n.º 1
1
 public static function GetDocument($documentId)
 {
     $arDocumentID = self::GetDocumentInfo($documentId);
     if (empty($arDocumentID)) {
         throw new CBPArgumentNullException('documentId');
     }
     $arResult = null;
     switch ($arDocumentID['TYPE']) {
         case 'CONTACT':
             $dbDocumentList = CCrmContact::GetListEx(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), false, false, array('*', 'UF_*'));
             break;
         case 'COMPANY':
             $dbDocumentList = CCrmCompany::GetListEx(array(), array('ID' => $arDocumentID['ID'], 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*'));
             break;
         case 'DEAL':
             $dbDocumentList = CCrmDeal::GetListEx(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), false, false, array('*', 'UF_*'));
             break;
         case 'LEAD':
             $dbDocumentList = CCrmLead::GetListEx(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), false, false, array('*', 'UF_*'));
             break;
     }
     if (($objDocument = $dbDocumentList->Fetch()) !== false) {
         $assignedByID = isset($objDocument['ASSIGNED_BY_ID']) ? intval($objDocument['ASSIGNED_BY_ID']) : 0;
         if ($assignedByID > 0) {
             $dbUsers = CUser::GetList($sortBy = 'id', $sortOrder = 'asc', array('ID' => $assignedByID), array('SELECT' => array('EMAIL')));
             $arUser = is_object($dbUsers) ? $dbUsers->Fetch() : null;
             $objDocument['ASSIGNED_BY_EMAIL'] = is_array($arUser) ? $arUser['EMAIL'] : '';
         }
         $arUserField = array('CREATED_BY', 'CREATED_BY_ID', 'MODIFY_BY', 'MODIFY_BY_ID', 'ASSIGNED_BY', 'ASSIGNED_BY_ID');
         foreach ($arUserField as $sField) {
             if (isset($objDocument[$sField])) {
                 $objDocument[$sField] = 'user_' . $objDocument[$sField];
             }
         }
         if (COption::GetOptionString('crm', 'bp_version', 2) == 2) {
             $userFieldsList = null;
             switch ($arDocumentID['TYPE']) {
                 case 'CONTACT':
                     $userFieldsList = CCrmContact::GetUserFields();
                     break;
                 case 'COMPANY':
                     $userFieldsList = CCrmCompany::GetUserFields();
                     break;
                 case 'DEAL':
                     $userFieldsList = CCrmDeal::GetUserFields();
                     break;
                 case 'LEAD':
                     $userFieldsList = CCrmLead::GetUserFields();
                     break;
             }
             if (is_array($userFieldsList)) {
                 foreach ($userFieldsList as $userFieldName => $userFieldParams) {
                     $fieldTypeID = isset($userFieldParams['USER_TYPE']) ? $userFieldParams['USER_TYPE']['USER_TYPE_ID'] : '';
                     $isFieldMultiple = isset($userFieldParams['MULTIPLE']) && $userFieldParams['MULTIPLE'] === 'Y';
                     $fieldSettings = isset($userFieldParams['SETTINGS']) ? $userFieldParams['SETTINGS'] : array();
                     if (isset($objDocument[$userFieldName])) {
                         $fieldValue = $objDocument[$userFieldName];
                     } elseif (isset($fieldSettings['DEFAULT_VALUE'])) {
                         $fieldValue = $fieldSettings['DEFAULT_VALUE'];
                     } else {
                         $objDocument[$userFieldName] = $objDocument[$userFieldName . '_PRINTABLE'] = '';
                         continue;
                     }
                     if ($fieldTypeID == 'employee') {
                         if (!$isFieldMultiple) {
                             $objDocument[$userFieldName] = 'user_' . $fieldValue;
                         } else {
                             $objDocument[$userFieldName] = array();
                             foreach ($fieldValue as $value) {
                                 $objDocument[$userFieldName][] = 'user_' . $value;
                             }
                         }
                     } elseif ($fieldTypeID == 'crm') {
                         $defaultTypeName = '';
                         foreach ($fieldSettings as $typeName => $flag) {
                             if ($flag === 'Y') {
                                 $defaultTypeName = $typeName;
                                 break;
                             }
                         }
                         if (!$isFieldMultiple) {
                             $objDocument[$userFieldName . '_PRINTABLE'] = self::PrepareCrmUserTypeValueView($fieldValue, $defaultTypeName);
                         } else {
                             $views = array();
                             foreach ($fieldValue as $value) {
                                 $views[] = self::PrepareCrmUserTypeValueView($value, $defaultTypeName);
                             }
                             $objDocument[$userFieldName . '_PRINTABLE'] = $views;
                         }
                     } elseif ($fieldTypeID == 'enumeration') {
                         self::ExternalizeEnumerationField($objDocument, $userFieldName);
                     } elseif ($fieldTypeID === 'boolean') {
                         //Convert UF boolean values (1/0) in to bizproc boolean values (Y/N) is display type checkbox
                         if (isset($fieldSettings['DISPLAY']) && $fieldSettings['DISPLAY'] === 'CHECKBOX') {
                             $objDocument[$userFieldName] = $fieldValue > 0 ? 'Y' : 'N';
                         }
                         $objDocument[$userFieldName . '_PRINTABLE'] = GetMessage($fieldValue > 0 ? 'MAIN_YES' : 'MAIN_NO');
                     }
                 }
             }
         }
         $res = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $arDocumentID['TYPE'], 'ELEMENT_ID' => $arDocumentID['ID']));
         while ($ar = $res->Fetch()) {
             if (!isset($objDocument[$ar['TYPE_ID']])) {
                 $objDocument[$ar['TYPE_ID']] = array();
             }
             $objDocument[$ar['TYPE_ID']]['n0' . $ar['ID']] = array('VALUE' => $ar['VALUE'], 'VALUE_TYPE' => $ar['VALUE_TYPE']);
             if (!isset($objDocument[$ar['TYPE_ID'] . "_" . $ar['VALUE_TYPE']])) {
                 $objDocument[$ar['TYPE_ID'] . "_" . $ar['VALUE_TYPE']] = array();
             }
             $objDocument[$ar['TYPE_ID'] . "_" . $ar['VALUE_TYPE']][] = $ar['VALUE'];
             if (!isset($objDocument[$ar['TYPE_ID'] . "_" . $ar['VALUE_TYPE'] . "_PRINTABLE"])) {
                 $objDocument[$ar['TYPE_ID'] . "_" . $ar['VALUE_TYPE'] . "_PRINTABLE"] = "";
             }
             $objDocument[$ar['TYPE_ID'] . "_" . $ar['VALUE_TYPE'] . "_PRINTABLE"] .= (strlen($objDocument[$ar['TYPE_ID'] . "_" . $ar['VALUE_TYPE'] . "_PRINTABLE"]) > 0 ? ", " : "") . $ar['VALUE'];
             if (!isset($objDocument[$ar['TYPE_ID'] . "_PRINTABLE"])) {
                 $objDocument[$ar['TYPE_ID'] . "_PRINTABLE"] = "";
             }
             $objDocument[$ar['TYPE_ID'] . "_PRINTABLE"] .= (strlen($objDocument[$ar['TYPE_ID'] . "_PRINTABLE"]) > 0 ? ", " : "") . $ar['VALUE'];
         }
         $multiFieldTypes = CCrmFieldMulti::GetEntityTypeList();
         foreach ($multiFieldTypes as $typeId => $arFields) {
             if (!isset($objDocument[$typeId])) {
                 $objDocument[$typeId] = array();
             }
             $printableFieldName = $typeId . '_PRINTABLE';
             if (!isset($objDocument[$printableFieldName])) {
                 $objDocument[$printableFieldName] = '';
             }
             foreach ($arFields as $valueType => $valueName) {
                 $fieldName = $typeId . '_' . $valueType;
                 if (!isset($objDocument[$fieldName])) {
                     $objDocument[$fieldName] = array('');
                 }
                 $printableFieldName = $fieldName . '_PRINTABLE';
                 if (!isset($objDocument[$printableFieldName])) {
                     $objDocument[$printableFieldName] = '';
                 }
             }
         }
         // Preparation of user names -->
         $nameFormat = CSite::GetNameFormat(false);
         if (isset($objDocument['ASSIGNED_BY_ID'])) {
             $objDocument['ASSIGNED_BY_PRINTABLE'] = CUser::FormatName($nameFormat, array('LOGIN' => isset($objDocument['ASSIGNED_BY_LOGIN']) ? $objDocument['ASSIGNED_BY_LOGIN'] : '', 'NAME' => isset($objDocument['ASSIGNED_BY_NAME']) ? $objDocument['ASSIGNED_BY_NAME'] : '', 'LAST_NAME' => isset($objDocument['ASSIGNED_BY_LAST_NAME']) ? $objDocument['ASSIGNED_BY_LAST_NAME'] : '', 'SECOND_NAME' => isset($objDocument['ASSIGNED_BY_SECOND_NAME']) ? $objDocument['ASSIGNED_BY_SECOND_NAME'] : ''), true, false);
         }
         if (isset($objDocument['CREATED_BY_ID'])) {
             $objDocument['CREATED_BY_PRINTABLE'] = CUser::FormatName($nameFormat, array('LOGIN' => isset($objDocument['CREATED_BY_LOGIN']) ? $objDocument['CREATED_BY_LOGIN'] : '', 'NAME' => isset($objDocument['CREATED_BY_NAME']) ? $objDocument['CREATED_BY_NAME'] : '', 'LAST_NAME' => isset($objDocument['CREATED_BY_LAST_NAME']) ? $objDocument['CREATED_BY_LAST_NAME'] : '', 'SECOND_NAME' => isset($objDocument['CREATED_BY_SECOND_NAME']) ? $objDocument['CREATED_BY_SECOND_NAME'] : ''), true, false);
         }
         // <-- Preparation of user names
         switch ($arDocumentID['TYPE']) {
             case 'DEAL':
                 CCrmDocumentDeal::PrepareDocument($objDocument);
                 break;
             case 'LEAD':
                 CCrmDocumentLead::PrepareDocument($objDocument);
                 break;
             case 'CONTACT':
                 CCrmDocumentContact::PrepareDocument($objDocument);
                 break;
         }
         return $objDocument;
     }
     return null;
 }
Ejemplo n.º 2
0
 protected function getEntityUserFieldsInfo()
 {
     return \CCrmContact::GetUserFields();
 }