コード例 #1
0
ファイル: leadconverter.php プロジェクト: DarneoStudio/bitrix
 public function initialize()
 {
     if ($this->currentPhase === LeadConversionPhase::INTERMEDIATE) {
         $this->currentPhase = LeadConversionPhase::COMPANY_CREATION;
     }
     if (!\CCrmLead::Exists($this->entityID)) {
         throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Undefined, EntityConversionException::TARG_SRC, EntityConversionException::NOT_FOUND);
     }
     /** @var \CCrmPerms $permissions */
     $permissions = $this->getUserPermissions();
     if (!\CCrmAuthorizationHelper::CheckReadPermission(\CCrmOwnerType::LeadName, $this->entityID, $permissions)) {
         throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Undefined, EntityConversionException::TARG_SRC, EntityConversionException::READ_DENIED);
     }
     if (!\CCrmAuthorizationHelper::CheckUpdatePermission(\CCrmOwnerType::LeadName, $this->entityID, $permissions)) {
         throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Undefined, EntityConversionException::TARG_SRC, EntityConversionException::UPDATE_DENIED);
     }
 }
コード例 #2
0
ファイル: crm_document.php プロジェクト: DarneoStudio/bitrix
 public static function GetDocumentType($documentId)
 {
     $arDocumentID = self::GetDocumentInfo($documentId);
     if (empty($arDocumentID)) {
         throw new CBPArgumentNullException('documentId');
     }
     $exists = false;
     switch ($arDocumentID['TYPE']) {
         case 'CONTACT':
             $exists = CCrmContact::Exists($arDocumentID['ID']);
             break;
         case 'COMPANY':
             $exists = CCrmCompany::Exists($arDocumentID['ID']);
             break;
         case 'DEAL':
             $exists = CCrmDeal::Exists($arDocumentID['ID']);
             break;
         case 'LEAD':
             $exists = CCrmLead::Exists($arDocumentID['ID']);
             break;
     }
     if (!$exists) {
         throw new Exception(GetMessage('CRM_DOCUMENT_ELEMENT_IS_NOT_FOUND'));
     }
     return $arDocumentID['TYPE'];
 }
コード例 #3
0
 public static function UpdateDocument($documentId, $arFields)
 {
     global $DB;
     $arDocumentID = self::GetDocumentInfo($documentId);
     if (empty($arDocumentID)) {
         throw new CBPArgumentNullException('documentId');
     }
     if (!CCrmLead::Exists($arDocumentID['ID'])) {
         throw new Exception(GetMessage('CRM_DOCUMENT_ELEMENT_IS_NOT_FOUND'));
     }
     $arDocumentFields = self::GetDocumentFields($arDocumentID['TYPE']);
     $arKeys = array_keys($arFields);
     foreach ($arKeys as $key) {
         if (!array_key_exists($key, $arDocumentFields)) {
             //Fix for issue #40374
             unset($arFields[$key]);
             continue;
         }
         $fieldType = $arDocumentFields[$key]["Type"];
         if (in_array($fieldType, array("phone", "email", "im", "web"), true)) {
             CCrmDocument::PrepareEntityMultiFields($arFields, strtoupper($fieldType));
             continue;
         }
         $arFields[$key] = is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key]) ? $arFields[$key] : array($arFields[$key]);
         if ($fieldType == "user") {
             $ar = array();
             foreach ($arFields[$key] as $v1) {
                 if (substr($v1, 0, strlen("user_")) == "user_") {
                     $ar[] = substr($v1, strlen("user_"));
                 } else {
                     $a1 = self::GetUsersFromUserGroup($v1, $documentId);
                     foreach ($a1 as $a11) {
                         $ar[] = $a11;
                     }
                 }
             }
             $arFields[$key] = $ar;
         } elseif ($fieldType == "select" && substr($key, 0, 3) == "UF_") {
             self::InternalizeEnumerationField('CRM_LEAD', $arFields, $key);
         } elseif ($fieldType == "file") {
             $arFileOptions = array('ENABLE_ID' => true);
             foreach ($arFields[$key] as &$value) {
                 //Issue #40380. Secure URLs and file IDs are allowed.
                 $file = false;
                 CCrmFileProxy::TryResolveFile($value, $file, $arFileOptions);
                 $value = $file;
             }
             unset($value);
         } elseif ($fieldType == "S:HTML") {
             foreach ($arFields[$key] as &$value) {
                 $value = array("VALUE" => $value);
             }
             unset($value);
         }
         if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key])) {
             if (count($arFields[$key]) > 0) {
                 $a = array_values($arFields[$key]);
                 $arFields[$key] = $a[0];
             } else {
                 $arFields[$key] = null;
             }
         }
     }
     if (isset($arFields['COMMENTS']) && $arFields['COMMENTS'] !== '') {
         $arFields['COMMENTS'] = preg_replace("/[\r\n]+/" . BX_UTF_PCRE_MODIFIER, "<br/>", $arFields['COMMENTS']);
     }
     $DB->StartTransaction();
     $CCrmEntity = new CCrmLead(false);
     $res = $CCrmEntity->Update($arDocumentID['ID'], $arFields);
     if (!$res) {
         $DB->Rollback();
         throw new Exception($CCrmEntity->LAST_ERROR);
     }
     if (COption::GetOptionString("crm", "start_bp_within_bp", "N") == "Y") {
         $CCrmBizProc = new CCrmBizProc('LEAD');
         if (false === $CCrmBizProc->CheckFields($arDocumentID['ID'], true)) {
             throw new Exception($CCrmBizProc->LAST_ERROR);
         }
         if ($res && !$CCrmBizProc->StartWorkflow($arDocumentID['ID'])) {
             $DB->Rollback();
             throw new Exception($CCrmBizProc->LAST_ERROR);
         }
     }
     if ($res) {
         $DB->Commit();
     }
 }
コード例 #4
0
ファイル: restservice.php プロジェクト: mrdeadmouse/u136006
 public function setProductRows($ID, $rows)
 {
     $ID = intval($ID);
     if ($ID <= 0) {
         throw new RestException('The parameter id is invalid or not defined.');
     }
     if (!is_array($rows)) {
         throw new RestException('The parameter rows must be array.');
     }
     if (!CCrmLead::CheckUpdatePermission($ID)) {
         throw new RestException('Access denied.');
     }
     if (!CCrmLead::Exists($ID)) {
         throw new RestException('Not found.');
     }
     $proxy = new CCrmProductRowRestProxy();
     $actualRows = array();
     $qty = count($rows);
     for ($i = 0; $i < $qty; $i++) {
         $row = $rows[$i];
         if (!is_array($row)) {
             continue;
         }
         $proxy->prepareForSave($row);
         if (isset($row['OWNER_TYPE'])) {
             unset($row['OWNER_TYPE']);
         }
         if (isset($row['OWNER_ID'])) {
             unset($row['OWNER_ID']);
         }
         $actualRows[] = $row;
     }
     return CCrmLead::SaveProductRows($ID, $actualRows, true, true, true);
 }