Пример #1
0
 public function __construct($entityTypeID, $seedID, $targID, $typeID)
 {
     if (!is_int($entityTypeID)) {
         $entityTypeID = (int) $entityTypeID;
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\ArgumentException('Is not defined', 'entityTypeID');
     }
     $this->entityTypeID = $entityTypeID;
     if (!is_int($seedID)) {
         $seedID = (int) $seedID;
     }
     if ($seedID <= 0) {
         throw new Main\ArgumentException('Must be greater than zero', 'seedID');
     }
     $this->seedID = $seedID;
     if (!is_int($targID)) {
         $targID = (int) $targID;
     }
     if ($targID <= 0) {
         throw new Main\ArgumentException('Must be greater than zero', 'targID');
     }
     $this->targID = $targID;
     if (!is_int($typeID)) {
         $typeID = (int) $typeID;
     }
     if (!self::isTypeDefined($typeID)) {
         throw new Main\ArgumentException('Is not defined', 'typeID');
     }
     $this->typeID = $typeID;
 }
Пример #2
0
 public function __construct($entityTypeID, $userID, $enablePermissionCheck = false)
 {
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\ArgumentException('Is not defined', 'entityTypeID');
     }
     $this->entityTypeID = $entityTypeID;
     $this->setUserID($userID);
     $this->enabledPermissionCheck($enablePermissionCheck);
 }
Пример #3
0
 protected function __construct($entityTypeID)
 {
     if (!is_int($entityTypeID)) {
         throw new Main\ArgumentTypeException('entityTypeID', 'integer');
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\NotSupportedException("Entity ID: '{$entityTypeID}' is not supported in current context");
     }
     $this->entityTypeID = $entityTypeID;
 }
Пример #4
0
 /**
  * Create conversion map for destination entity type
  * @static
  * @param int $entityTypeID Destination Entity Type ID
  * @return EntityConversionMap
  */
 public static function createMap($entityTypeID)
 {
     if (!is_int($entityTypeID)) {
         $entityTypeID = (int) $entityTypeID;
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\ArgumentOutOfRangeException('dstEntityTypeID', \CCrmOwnerType::FirstOwnerType, \CCrmOwnerType::LastOwnerType);
     }
     if ($entityTypeID !== \CCrmOwnerType::Deal && $entityTypeID !== \CCrmOwnerType::Invoice) {
         $dstEntityTypeName = \CCrmOwnerType::ResolveName($entityTypeID);
         throw new Main\NotSupportedException("Entity type: '{$dstEntityTypeName}' is not supported in current context");
     }
     $map = new EntityConversionMap(\CCrmOwnerType::Quote, $entityTypeID);
     if ($entityTypeID === \CCrmOwnerType::Deal) {
         //region Deal Map Static Field Bindings
         $map->createItem('TITLE');
         $map->createItem('COMMENTS');
         $map->createItem('ASSIGNED_BY_ID');
         $map->createItem('OPENED');
         $map->createItem('OPPORTUNITY');
         $map->createItem('CURRENCY_ID');
         $map->createItem('TAX_VALUE');
         $map->createItem('EXCH_RATE');
         $map->createItem('LOCATION_ID');
         $map->createItem('LEAD_ID');
         $map->createItem('COMPANY_ID');
         $map->createItem('CONTACT_ID');
         $map->createItem('PRODUCT_ROWS');
         //endregion
         //region Invoice Map User Field Bindings
         $intersections = UserFieldSynchronizer::getIntersection(\CCrmOwnerType::Quote, \CCrmOwnerType::Deal);
         foreach ($intersections as $intersection) {
             $map->createItem($intersection['SRC_FIELD_NAME'], $intersection['DST_FIELD_NAME']);
         }
         //endregion
     }
     if ($entityTypeID === \CCrmOwnerType::Invoice) {
         //region Invoice Map Static Field Bindings
         $map->createItem('TITLE', 'ORDER_TOPIC');
         $map->createItem('COMPANY_ID', 'UF_COMPANY_ID');
         $map->createItem('CONTACT_ID', 'UF_CONTACT_ID');
         $map->createItem('DEAL_ID', 'UF_DEAL_ID');
         $map->createItem('ASSIGNED_BY_ID', 'RESPONSIBLE_ID');
         $map->createItem('COMMENTS');
         $map->createItem('PRODUCT_ROWS');
         //endregion
         //region Invoice Map User Field Bindings
         $intersections = UserFieldSynchronizer::getIntersection(\CCrmOwnerType::Quote, \CCrmOwnerType::Invoice);
         foreach ($intersections as $intersection) {
             $map->createItem($intersection['SRC_FIELD_NAME'], $intersection['DST_FIELD_NAME']);
         }
         //endregion
     }
     return $map;
 }
Пример #5
0
 public function setEntityTypeID($entityTypeID)
 {
     if (!is_integer($entityTypeID)) {
         $entityTypeID = intval($entityTypeID);
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         $entityTypeID = \CCrmOwnerType::Undefined;
     }
     if ($this->entityTypeID === $entityTypeID) {
         return;
     }
     $this->entityTypeID = $entityTypeID;
 }
 public function __construct($srcEntityTypeID, $srcEntityID)
 {
     if (!is_int($srcEntityTypeID)) {
         $srcEntityTypeID = (int) $srcEntityTypeID;
     }
     if (!\CCrmOwnerType::IsDefined($srcEntityTypeID)) {
         throw new Main\ArgumentOutOfRangeException('srcEntityTypeID', \CCrmOwnerType::FirstOwnerType, \CCrmOwnerType::LastOwnerType);
     }
     $this->srcEntityTypeID = $srcEntityTypeID;
     if (!is_int($srcEntityID)) {
         $srcEntityID = (int) $srcEntityID;
     }
     if ($srcEntityID <= 0) {
         throw new Main\ArgumentException('Owner ID must be greater than zero.', 'srcEntityID');
     }
     $this->srcEntityID = $srcEntityID;
 }
Пример #7
0
 public static function GetDefaultGrigID($entityTypeID)
 {
     $entityTypeID = (int) $entityTypeID;
     if (!CCrmOwnerType::IsDefined($entityTypeID)) {
         return '';
     }
     if ($entityTypeID === CCrmOwnerType::Lead) {
         return 'CRM_LEAD_LIST_V12';
     } elseif ($entityTypeID === CCrmOwnerType::Deal) {
         return 'CRM_DEAL_LIST_V12';
     } elseif ($entityTypeID === CCrmOwnerType::Contact) {
         return 'CRM_CONTACT_LIST_V12';
     } elseif ($entityTypeID === CCrmOwnerType::Company) {
         return 'CRM_COMPANY_LIST_V12';
     }
     return '';
 }
 public static function deleteByEntity($entityTypeID, $entityID)
 {
     if (!is_int($entityTypeID)) {
         $entityTypeID = (int) $entityTypeID;
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\ArgumentException("Is not defined or invalid", 'entityTypeID');
     }
     if (!is_int($entityID)) {
         $entityID = (int) $entityID;
     }
     if ($entityID <= 0) {
         throw new Main\ArgumentException("Must be greater than zero", 'entityID');
     }
     $connection = Main\Application::getConnection();
     $connection->queryExecute("DELETE FROM b_crm_dp_index_mismatch WHERE ENTITY_TYPE_ID = {$entityTypeID} AND L_ENTITY_ID = {$entityID}");
     $connection->queryExecute("DELETE FROM b_crm_dp_index_mismatch WHERE ENTITY_TYPE_ID = {$entityTypeID} AND R_ENTITY_ID = {$entityID}");
 }
Пример #9
0
 /** Create new entity merger by specified entity type ID
  * @static
  * @param int $entityTypeID
  * @param int $currentUserID
  * @param bool $enablePermissionCheck
  * @return EntityMerger
  */
 public static function create($entityTypeID, $currentUserID, $enablePermissionCheck = false)
 {
     if (!is_int($entityTypeID)) {
         $entityTypeID = (int) $entityTypeID;
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\ArgumentException('Is not defined', 'entityTypeID');
     }
     if ($entityTypeID === \CCrmOwnerType::Lead) {
         return new LeadMerger($currentUserID, $enablePermissionCheck);
     } elseif ($entityTypeID === \CCrmOwnerType::Contact) {
         return new ContactMerger($currentUserID, $enablePermissionCheck);
     } elseif ($entityTypeID === \CCrmOwnerType::Company) {
         return new CompanyMerger($currentUserID, $enablePermissionCheck);
     } else {
         throw new Main\NotSupportedException("Entity type: '" . \CCrmOwnerType::ResolveName($entityTypeID) . "' is not supported in current context");
     }
 }
Пример #10
0
 private static function ResolveEntityInfo($typeID, $ID)
 {
     $typeID = intval($typeID);
     $ID = intval($ID);
     if (!(CCrmOwnerType::IsDefined($typeID) && $ID > 0)) {
         return array('TYPE_ID' => $typeID, 'TYPE_NAME' => CCrmOwnerType::ResolveName($typeID), 'ID' => $ID);
     }
     $fields = null;
     if ($typeID === CCrmOwnerType::Lead) {
         $fields = CCrmLead::GetByID($ID, false);
     } elseif ($typeID === CCrmOwnerType::Contact) {
         $fields = CCrmContact::GetByID($ID, false);
     } elseif ($typeID === CCrmOwnerType::Company) {
         $fields = CCrmCompany::GetByID($ID, false);
     } elseif ($typeID === CCrmOwnerType::Deal) {
         $fields = CCrmDeal::GetByID($ID, false);
     }
     return array('TYPE_ID' => $typeID, 'TYPE_NAME' => CCrmOwnerType::ResolveName($typeID), 'ID' => $ID, 'FIELDS' => $fields);
 }
Пример #11
0
 public function enabledFor($entityTypeID, $enable)
 {
     if (!is_int($entityTypeID)) {
         throw new Main\ArgumentTypeException('entityTypeID', 'integer');
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\NotSupportedException("Entity ID: '{$entityTypeID}' is not supported in current context");
     }
     if (!is_bool($enable)) {
         if (is_numeric($enable)) {
             $enable = $enable > 0;
         } elseif (is_string($enable)) {
             $enable = strtoupper($enable) === 'Y';
         } else {
             $enable = false;
         }
     }
     $this->settings['enableFor'][\CCrmOwnerType::ResolveName($entityTypeID)] = $enable ? 'Y' : 'N';
 }
Пример #12
0
 public static function create(array $fields = null, $sourceEntityTypeID = \CCrmOwnerType::Undefined, $destinationEntityTypeID = \CCrmOwnerType::Undefined)
 {
     if (!is_int($sourceEntityTypeID)) {
         throw new Main\ArgumentTypeException('sourceEntityTypeID', 'integer');
     }
     if (!is_int($destinationEntityTypeID)) {
         throw new Main\ArgumentTypeException('destinationEntityTypeID', 'integer');
     }
     if ($sourceEntityTypeID !== \CCrmOwnerType::Undefined && !\CCrmOwnerType::IsDefined($sourceEntityTypeID)) {
         $sourceEntityTypeID = \CCrmOwnerType::Undefined;
     }
     if ($destinationEntityTypeID !== \CCrmOwnerType::Undefined && !\CCrmOwnerType::IsDefined($destinationEntityTypeID)) {
         $destinationEntityTypeID = \CCrmOwnerType::Undefined;
     }
     if (\CCrmOwnerType::IsDefined($sourceEntityTypeID) && !\CCrmOwnerType::IsDefined($destinationEntityTypeID)) {
         $destinationEntityTypeID = $sourceEntityTypeID;
     }
     $adapter = null;
     if ($sourceEntityTypeID !== \CCrmOwnerType::Undefined && $destinationEntityTypeID !== \CCrmOwnerType::Undefined) {
         if ($sourceEntityTypeID === \CCrmOwnerType::Lead) {
             if ($destinationEntityTypeID === \CCrmOwnerType::Company) {
                 $adapter = new EntityAdapter(\CCrmOwnerType::Lead, \CCrmOwnerType::Company, new Mapper(array('COMPANY_TITLE' => 'TITLE')));
             }
         } elseif ($sourceEntityTypeID === \CCrmOwnerType::Company) {
             if ($destinationEntityTypeID === \CCrmOwnerType::Lead) {
                 $adapter = new EntityAdapter(\CCrmOwnerType::Company, \CCrmOwnerType::Lead, new Mapper(array('TITLE' => 'COMPANY_TITLE')));
             }
         }
     }
     if ($adapter === null) {
         $adapter = new EntityAdapter($sourceEntityTypeID, $destinationEntityTypeID);
     }
     if ($fields !== null) {
         $adapter->setFields($fields);
     }
     return $adapter;
 }
Пример #13
0
 public function GetTypeMap($typeID)
 {
     $typeID = intval($typeID);
     if (!CCrmOwnerType::IsDefined($typeID)) {
         return null;
     }
     if (!isset(self::$MAP_BY_LANG[LANGUAGE_ID])) {
         self::$MAP_BY_LANG[LANGUAGE_ID] = array();
     }
     if (isset(self::$MAP_BY_LANG[LANGUAGE_ID][$typeID])) {
         return self::$MAP_BY_LANG[LANGUAGE_ID][$typeID];
     }
     IncludeModuleLangFile(__FILE__);
     if ($typeID === CCrmOwnerType::Lead) {
         return self::$MAP_BY_LANG[LANGUAGE_ID][CCrmOwnerType::Lead] = array('typeId' => CCrmOwnerType::Lead, 'typeName' => CCrmOwnerType::ResolveName(CCrmOwnerType::Lead), 'fields' => array(array('id' => 'ID', 'name' => 'ID'), array('id' => 'TITLE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_TITLE')), array('id' => 'LAST_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_LAST_NAME')), array('id' => 'NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_NAME')), array('id' => 'SECOND_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_SECOND_NAME')), array('id' => 'FORMATTED_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_FORMATTED_NAME')), array('id' => 'COMPANY_TITLE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_COMPANY_TITLE')), array('id' => 'SOURCE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_SOURCE')), array('id' => 'SOURCE_DESCRIPTION', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_SOURCE_DESCRIPTION')), array('id' => 'STATUS', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_STATUS')), array('id' => 'STATUS_DESCRIPTION', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_STATUS_DESCRIPTION')), array('id' => 'POST', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_POST')), array('id' => 'ADDRESS', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ADDRESS')), array('id' => 'CURRENCY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_CURRENCY')), array('id' => 'OPPORTUNITY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_OPPORTUNITY')), array('id' => 'OPPORTUNITY_FORMATTED', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_OPPORTUNITY_FORMATTED')), array('id' => 'ASSIGNED_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ASSIGNED_BY_FULL_NAME')), array('id' => 'ASSIGNED_BY_WORK_POSITION', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ASSIGNED_BY_POST')), array('id' => 'CREATED_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_CREATED_BY_FULL_NAME')), array('id' => 'MODIFY_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_MODIFY_BY_FULL_NAME')), array('id' => 'DATE_CREATE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_DATE_CREATE')), array('id' => 'DATE_MODIFY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_DATE_MODIFY')), array('id' => 'COMMENTS', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_COMMENTS'))));
     } elseif ($typeID === CCrmOwnerType::Deal) {
         return self::$MAP_BY_LANG[LANGUAGE_ID][CCrmOwnerType::Deal] = array('typeId' => CCrmOwnerType::Deal, 'typeName' => CCrmOwnerType::ResolveName(CCrmOwnerType::Deal), 'fields' => array(array('id' => 'ID', 'name' => 'ID'), array('id' => 'TITLE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_TITLE')), array('id' => 'TYPE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_TYPE')), array('id' => 'STAGE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_STAGE')), array('id' => 'PROBABILITY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_PROBABILITY')), array('id' => 'CURRENCY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_CURRENCY')), array('id' => 'OPPORTUNITY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_OPPORTUNITY')), array('id' => 'OPPORTUNITY_FORMATTED', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_OPPORTUNITY_FORMATTED')), array('id' => 'COMPANY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_COMPANY'), 'typeId' => CCrmOwnerType::Company), array('id' => 'CONTACT', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_CONTACT'), 'typeId' => CCrmOwnerType::Contact), array('id' => 'BEGINDATE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_BEGINDATE')), array('id' => 'CLOSEDATE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_CLOSEDATE')), array('id' => 'ASSIGNED_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ASSIGNED_BY_FULL_NAME')), array('id' => 'ASSIGNED_BY_WORK_POSITION', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ASSIGNED_BY_POST')), array('id' => 'CREATED_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_CREATED_BY_FULL_NAME')), array('id' => 'MODIFY_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_MODIFY_BY_FULL_NAME')), array('id' => 'DATE_CREATE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_DATE_CREATE')), array('id' => 'DATE_MODIFY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_DATE_MODIFY')), array('id' => 'COMMENTS', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_COMMENTS'))));
     } elseif ($typeID === CCrmOwnerType::Contact) {
         return self::$MAP_BY_LANG[LANGUAGE_ID][CCrmOwnerType::Contact] = array('typeId' => CCrmOwnerType::Contact, 'typeName' => CCrmOwnerType::ResolveName(CCrmOwnerType::Contact), 'fields' => array(array('id' => 'ID', 'name' => 'ID'), array('id' => 'LAST_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_LAST_NAME')), array('id' => 'NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_NAME')), array('id' => 'SECOND_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_SECOND_NAME')), array('id' => 'FORMATTED_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_FORMATTED_NAME')), array('id' => 'POST', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_POST')), array('id' => 'ADDRESS', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ADDRESS')), array('id' => 'TYPE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_TYPE')), array('id' => 'SOURCE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_SOURCE')), array('id' => 'SOURCE_DESCRIPTION', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_STATUS_DESCRIPTION')), array('id' => 'COMPANY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_COMPANY'), 'typeId' => CCrmOwnerType::Company), array('id' => 'ASSIGNED_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ASSIGNED_BY_FULL_NAME')), array('id' => 'ASSIGNED_BY_WORK_POSITION', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ASSIGNED_BY_POST')), array('id' => 'CREATED_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_CREATED_BY_FULL_NAME')), array('id' => 'MODIFY_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_MODIFY_BY_FULL_NAME')), array('id' => 'DATE_CREATE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_DATE_CREATE')), array('id' => 'DATE_MODIFY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_DATE_MODIFY')), array('id' => 'COMMENTS', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_COMMENTS'))));
     } elseif ($typeID === CCrmOwnerType::Company) {
         return self::$MAP_BY_LANG[LANGUAGE_ID][CCrmOwnerType::Company] = array('typeId' => CCrmOwnerType::Company, 'typeName' => CCrmOwnerType::ResolveName(CCrmOwnerType::Company), 'fields' => array(array('id' => 'ID', 'name' => 'ID'), array('id' => 'TITLE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_TITLE')), array('id' => 'TYPE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_COMPANY_TYPE')), array('id' => 'ADDRESS', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ACTUAL_ADDRESS')), array('id' => 'ADDRESS_LEGAL', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ADDRESS_LEGAL')), array('id' => 'BANKING_DETAILS', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_BANKING_DETAILS')), array('id' => 'INDUSTRY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_INDUSTRY')), array('id' => 'EMPLOYEES', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_EMPLOYEES')), array('id' => 'CURRENCY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_CURRENCY')), array('id' => 'REVENUE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_REVENUE')), array('id' => 'REVENUE_FORMATTED', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_REVENUE_FORMATTED')), array('id' => 'ASSIGNED_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ASSIGNED_BY_FULL_NAME')), array('id' => 'ASSIGNED_BY_WORK_POSITION', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_ASSIGNED_BY_POST')), array('id' => 'CREATED_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_CREATED_BY_FULL_NAME')), array('id' => 'MODIFY_BY_FULL_NAME', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_MODIFY_BY_FULL_NAME')), array('id' => 'DATE_CREATE', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_DATE_CREATE')), array('id' => 'DATE_MODIFY', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_DATE_MODIFY')), array('id' => 'COMMENTS', 'name' => GetMessage('CRM_TEMPLATE_ADAPTER_COMMENTS'))));
     }
     return null;
 }
Пример #14
0
 public static function TryUploadFile(&$result, $options = array())
 {
     //Options initialization -->
     $ownerTypeID = isset($options['OWNER_TYPE_ID']) ? intval($options['OWNER_TYPE_ID']) : CCrmOwnerType::Undefined;
     if ($ownerTypeID !== CCrmOwnerType::Undefined && !CCrmOwnerType::IsDefined($ownerTypeID)) {
         $ownerTypeID = CCrmOwnerType::Undefined;
     }
     $ownerID = isset($options['OWNER_ID']) ? max(intval($options['OWNER_ID']), 0) : 0;
     $scope = isset($options['SCOPE']) ? strtoupper($options['SCOPE']) : '';
     if (!in_array($scope, array('I', 'A', 'F'), true)) {
         $scope = '';
     }
     $extensions = isset($options['EXTENSIONS']) && is_array($options['EXTENSIONS']) ? $options['EXTENSIONS'] : array();
     $maxFileSize = isset($options['MAX_FILE_SIZE']) ? max(intval($options['MAX_FILE_SIZE']), 0) : 0;
     //<-- Options initialization
     if (!is_array($result)) {
         $result = array();
     }
     $file = is_array($_FILES) && isset($_FILES['file']) ? $_FILES['file'] : null;
     if (!is_array($file)) {
         $result['ERROR_MESSAGE'] = 'No files';
         return false;
     }
     $file['MODULE_ID'] = 'crm';
     if ($scope === 'I') {
         $error = CFile::CheckImageFile($file, $maxFileSize, 0, 0);
     } elseif ($scope === 'F') {
         $error = CFile::CheckFile($file, $maxFileSize, false, implode(',', $extensions));
     } else {
         $error = CFile::CheckFile($file, $maxFileSize, false, false);
     }
     $isValid = !(is_string($error) && $error !== '');
     if (!$isValid) {
         $result['ERROR_MESSAGE'] = $error;
         return false;
     }
     $fileID = CFile::SaveFile($file, 'crm');
     if (!is_int($fileID) || $fileID <= 0) {
         $result['ERROR_MESSAGE'] = 'General error.';
         return false;
     }
     if ($ownerTypeID != CCrmOwnerType::Undefined) {
         $key = 'CRM_MBL_' . CCrmOwnerType::ResolveName($ownerTypeID) . '_' . $ownerID . '_FILES';
         if (!isset($_SESSION[$key])) {
             $_SESSION[$key] = array();
         }
         $_SESSION[$key][] = $fileID;
     }
     $result['FILE_ID'] = $fileID;
     return true;
 }
Пример #15
0
 /**
  * Create conversion map for destination entity type
  * @static
  * @param int $entityTypeID Destination Entity Type ID
  * @return EntityConversionMap
  */
 public static function createMap($entityTypeID)
 {
     if (!is_int($entityTypeID)) {
         $entityTypeID = (int) $entityTypeID;
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\ArgumentOutOfRangeException('dstEntityTypeID', \CCrmOwnerType::FirstOwnerType, \CCrmOwnerType::LastOwnerType);
     }
     if ($entityTypeID !== \CCrmOwnerType::Contact && $entityTypeID !== \CCrmOwnerType::Company && $entityTypeID !== \CCrmOwnerType::Deal) {
         $dstEntityTypeName = \CCrmOwnerType::ResolveName($entityTypeID);
         throw new Main\NotSupportedException("Entity type: '{$dstEntityTypeName}' is not supported in current context");
     }
     $map = new EntityConversionMap(\CCrmOwnerType::Lead, $entityTypeID);
     if ($entityTypeID === \CCrmOwnerType::Contact) {
         //region Contact Map Static Field Bindings
         $map->createItem('HONORIFIC');
         $map->createItem('NAME');
         $map->createItem('SECOND_NAME');
         $map->createItem('LAST_NAME');
         $map->createItem('BIRTHDATE');
         $map->createItem('POST');
         $map->createItem('COMMENTS');
         $map->createItem('OPENED');
         $map->createItem('SOURCE_ID');
         $map->createItem('SOURCE_DESCRIPTION');
         $map->createItem('ADDRESS');
         $map->createItem('ADDRESS_2');
         $map->createItem('ADDRESS_CITY');
         $map->createItem('ADDRESS_POSTAL_CODE');
         $map->createItem('ADDRESS_REGION');
         $map->createItem('ADDRESS_PROVINCE');
         $map->createItem('ADDRESS_COUNTRY');
         $map->createItem('ADDRESS_COUNTRY_CODE');
         $map->createItem('PHONE');
         $map->createItem('EMAIL');
         $map->createItem('WEB');
         $map->createItem('IM');
         $map->createItem('ASSIGNED_BY_ID');
         $map->createItem('ORIGINATOR_ID');
         $map->createItem('ORIGIN_ID');
         //endregion
         //region Contact Map User Field Bindings
         $intersections = UserFieldSynchronizer::getIntersection(\CCrmOwnerType::Lead, \CCrmOwnerType::Contact);
         foreach ($intersections as $intersection) {
             $map->createItem($intersection['SRC_FIELD_NAME'], $intersection['DST_FIELD_NAME']);
         }
         //endregion
     } elseif ($entityTypeID === \CCrmOwnerType::Company) {
         //region Company Map Static Field Bindings
         //$map->createItem('COMPANY_TITLE', 'TITLE', array('ALT_SRC_FIELD_IDS' => array('TITLE')));
         $map->createItem('TITLE');
         $map->createItem('COMMENTS');
         $map->createItem('OPENED');
         $map->createItem('ADDRESS');
         $map->createItem('ADDRESS_2');
         $map->createItem('ADDRESS_CITY');
         $map->createItem('ADDRESS_POSTAL_CODE');
         $map->createItem('ADDRESS_REGION');
         $map->createItem('ADDRESS_PROVINCE');
         $map->createItem('ADDRESS_COUNTRY');
         $map->createItem('ADDRESS_COUNTRY_CODE');
         $map->createItem('PHONE');
         $map->createItem('EMAIL');
         $map->createItem('WEB');
         $map->createItem('IM');
         $map->createItem('ASSIGNED_BY_ID');
         $map->createItem('ORIGINATOR_ID');
         $map->createItem('ORIGIN_ID');
         //endregion
         //region Company Map User Field Bindings
         $intersections = UserFieldSynchronizer::getIntersection(\CCrmOwnerType::Lead, \CCrmOwnerType::Company);
         foreach ($intersections as $intersection) {
             $map->createItem($intersection['SRC_FIELD_NAME'], $intersection['DST_FIELD_NAME']);
         }
         //endregion
     } elseif ($entityTypeID === \CCrmOwnerType::Deal) {
         //region Deal Map Static Field Bindings
         $map->createItem('TITLE');
         $map->createItem('OPPORTUNITY');
         $map->createItem('CURRENCY_ID');
         $map->createItem('COMMENTS');
         $map->createItem('OPENED');
         $map->createItem('ADDRESS');
         $map->createItem('ADDRESS_2');
         $map->createItem('ADDRESS_CITY');
         $map->createItem('ADDRESS_POSTAL_CODE');
         $map->createItem('ADDRESS_REGION');
         $map->createItem('ADDRESS_PROVINCE');
         $map->createItem('ADDRESS_COUNTRY');
         $map->createItem('ADDRESS_COUNTRY_CODE');
         $map->createItem('PRODUCT_ROWS');
         $map->createItem('ASSIGNED_BY_ID');
         $map->createItem('ORIGINATOR_ID');
         $map->createItem('ORIGIN_ID');
         //endregion
         //region Deal Map User Field Bindings
         $intersections = UserFieldSynchronizer::getIntersection(\CCrmOwnerType::Lead, \CCrmOwnerType::Deal);
         foreach ($intersections as $intersection) {
             $map->createItem($intersection['SRC_FIELD_NAME'], $intersection['DST_FIELD_NAME']);
         }
         //endregion
     }
     return $map;
 }
Пример #16
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;
 }
Пример #17
0
 public static function markAsJunk($entityTypeID, $entityID)
 {
     if (!is_int($entityTypeID)) {
         $entityTypeID = (int) $entityTypeID;
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\ArgumentException("Is not defined or invalid", 'entityTypeID');
     }
     if (!is_int($entityID)) {
         $entityID = (int) $entityID;
     }
     if ($entityID <= 0) {
         throw new Main\ArgumentException("Must be greater than zero", 'entityID');
     }
     Entity\DuplicateIndexTable::markAsJunk($entityTypeID, $entityID);
 }
Пример #18
0
 public function __toString()
 {
     $entityTypeName = \CCrmOwnerType::ResolveName($this->entityTypeID);
     $entityCaption = \CCrmOwnerType::IsDefined($this->entityTypeID) && $this->entityID > 0 ? \CCrmOwnerType::GetCaption($this->entityTypeID, $this->entityID, false) : '';
     return "{ type: \"{$entityTypeName}\", id: {$this->entityID}, caption: \"{$entityCaption}\" }";
 }
 public function find($entityTypeID = \CCrmOwnerType::Undefined, $limit = 50)
 {
     if ($this->communicationType === '') {
         //Invalid Operation?
         return null;
     }
     if ($this->value === '') {
         //Invalid Operation?
         return null;
     }
     if (!is_int($entityTypeID)) {
         throw new Main\ArgumentTypeException('entityTypeID', 'integer');
     }
     if (!is_int($limit)) {
         throw new Main\ArgumentTypeException('limit', 'integer');
     }
     if ($limit <= 0) {
         $limit = 50;
     }
     $filter = array('=TYPE' => $this->communicationType, '=VALUE' => self::prepareCode($this->communicationType, $this->value));
     if (\CCrmOwnerType::IsDefined($entityTypeID)) {
         $filter['ENTITY_TYPE_ID'] = $entityTypeID;
     }
     $dbResult = DuplicateCommunicationMatchCodeTable::getList(array('select' => array('ENTITY_TYPE_ID', 'ENTITY_ID'), 'order' => array('ENTITY_TYPE_ID' => 'ASC', 'ENTITY_ID' => 'ASC'), 'filter' => $filter, 'limit' => $limit));
     $entities = array();
     while ($fields = $dbResult->fetch()) {
         $entityTypeID = isset($fields['ENTITY_TYPE_ID']) ? intval($fields['ENTITY_TYPE_ID']) : 0;
         $entityID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0;
         if (\CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0) {
             $entities[] = new DuplicateEntity($entityTypeID, $entityID);
         }
     }
     return !empty($entities) ? new Duplicate($this, $entities) : null;
 }
Пример #20
0
 public static function unregister($entityTypeID, $entityID, $typeID)
 {
     if (!is_int($entityTypeID)) {
         $entityTypeID = (int) $entityTypeID;
     }
     if (!\CCrmOwnerType::IsDefined($entityTypeID)) {
         throw new Main\ArgumentOutOfRangeException('entityTypeID', \CCrmOwnerType::FirstOwnerType, \CCrmOwnerType::LastOwnerType);
     }
     if (!is_int($entityID)) {
         $entityID = (int) $entityID;
     }
     if ($entityID <= 0) {
         throw new Main\ArgumentException('Must be greater than zero', 'entityID');
     }
     if (!is_int($typeID)) {
         $typeID = (int) $typeID;
     }
     AddressTable::delete(array('ENTITY_TYPE_ID' => $entityTypeID, 'ENTITY_ID' => $entityID, 'TYPE_ID' => $typeID));
 }
Пример #21
0
<?php

if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CModule::IncludeModule('crm')) {
    ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED'));
    return;
}
if (!CModule::IncludeModule('socialnetwork')) {
    ShowError(GetMessage('SONET_MODULE_NOT_INSTALLED'));
    return;
}
$arResult['POST_FORM_URI'] = isset($arParams['POST_FORM_URI']) ? $arParams['POST_FORM_URI'] : '';
$entityTypeID = isset($arParams['ENTITY_TYPE_ID']) ? intval($arParams['ENTITY_TYPE_ID']) : CCrmOwnerType::Undefined;
if (CCrmOwnerType::IsDefined($entityTypeID)) {
    $entityTypeName = CCrmOwnerType::ResolveName($entityTypeID);
} else {
    $entityTypeName = isset($arParams['ENTITY_TYPE_NAME']) ? $arParams['ENTITY_TYPE_NAME'] : '';
    $entityTypeID = CCrmOwnerType::ResolveID($entityTypeName);
}
$entityID = isset($arParams['ENTITY_ID']) ? intval($arParams['ENTITY_ID']) : 0;
$arResult['ENABLE_LIVE_FEED_EXTENDED_MODE'] = true;
$arResult['LIVE_FEED_ENTITY_TYPE'] = CCrmLiveFeedEntity::GetByEntityTypeID($entityTypeID);
$arResult['ENTITY_TYPE_NAME'] = $entityTypeName;
$arResult['ENTITY_TYPE_ID'] = $entityTypeID;
$arResult['ENTITY_ID'] = $entityID;
$userID = CCrmSecurityHelper::GetCurrentUserID();
$arResult['USER_ID'] = $userID;
$userPerms = CCrmPerms::GetCurrentUserPermissions();
if ($entityTypeName !== '' && !CCrmAuthorizationHelper::CheckUpdatePermission($entityTypeName, $entityID, $userPerms)) {
Пример #22
0
     if ($commValue !== '') {
         $arFields['COMMUNICATIONS'] = array(array('TYPE' => $commType, 'VALUE' => $commValue, 'ENTITY_TYPE_ID' => $ownerTypeID, 'ENTITY_ID' => $ownerID));
     }
 } else {
     $comms = array();
     $commKeys = isset($_REQUEST['comm']) && is_array($_REQUEST['comm']) ? $_REQUEST['comm'] : array();
     if (!empty($commKeys)) {
         foreach ($commKeys as $commKey) {
             $commInfo = explode('_', $commKey);
             if (count($commInfo) < 2) {
                 continue;
             }
             $entityTypeName = strtoupper($commInfo[0]);
             $entityTypeID = CCrmOwnerType::ResolveID($entityTypeName);
             $entityID = intval($commInfo[1]);
             if (!CCrmOwnerType::IsDefined($entityTypeID) || $entityID <= 0 || !CCrmActivity::CheckUpdatePermission($entityTypeID, $entityID, $userPerms)) {
                 continue;
             }
             $commValue = CCrmActivity::GetDefaultCommunicationValue($entityTypeID, $entityID, $commType);
             if ($commValue !== '') {
                 $comms[] = array('TYPE' => $commType, 'VALUE' => $commValue, 'ENTITY_TYPE_ID' => $entityTypeID, 'ENTITY_ID' => $entityID);
             }
         }
     }
     if (empty($comms)) {
         $dbDeal = CCrmDeal::GetListEx(array(), array('=ID' => $ownerID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('CONTACT_ID', 'CONTACT_NAME', 'CONTACT_SECOND_NAME', 'CONTACT_LAST_NAME', 'COMPANY_ID', 'COMPANY_TITLE'));
         $deal = $dbDeal->Fetch();
         if (is_array($deal)) {
             $contactID = isset($deal['CONTACT_ID']) ? intval($deal['CONTACT_ID']) : 0;
             $companyID = isset($deal['COMPANY_ID']) ? intval($deal['COMPANY_ID']) : 0;
             $comms = array();
 public function find($entityTypeID = \CCrmOwnerType::Undefined, $limit = 50)
 {
     if ($this->title === '') {
         //Invalid Operation?
         return null;
     }
     if (!is_int($entityTypeID)) {
         throw new Main\ArgumentTypeException('entityTypeID', 'integer');
     }
     if (!is_int($limit)) {
         throw new Main\ArgumentTypeException('limit', 'integer');
     }
     if ($limit <= 0) {
         $limit = 50;
     }
     $filter = array();
     if ($this->useStrictComparison) {
         $filter['TITLE'] = $this->title;
     } else {
         $filter['%TITLE'] = new \CSQLWhereExpression('?s', strtoupper($this->title) . '%');
     }
     if (\CCrmOwnerType::IsDefined($entityTypeID)) {
         $filter['ENTITY_TYPE_ID'] = $entityTypeID;
     }
     $dbResult = DuplicateOrganizationMatchCodeTable::getList(array('select' => array('ENTITY_TYPE_ID', 'ENTITY_ID'), 'order' => array('ENTITY_TYPE_ID' => 'ASC', 'ENTITY_ID' => 'ASC'), 'filter' => $filter, 'limit' => $limit));
     $entities = array();
     while ($fields = $dbResult->fetch()) {
         $entityTypeID = isset($fields['ENTITY_TYPE_ID']) ? intval($fields['ENTITY_TYPE_ID']) : 0;
         $entityID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0;
         if (\CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0) {
             $entities[] = new DuplicateEntity($entityTypeID, $entityID);
         }
     }
     return !empty($entities) ? new Duplicate($this, $entities) : null;
 }
Пример #24
0
if ($ownerTypeID === CCrmOwnerType::Undefined) {
    $ownerTypeName = '';
}
$arResult['OWNER_TYPE_NAME'] = $ownerTypeName;
$arResult['OWNER_TYPE_ID'] = $ownerTypeID;
$arResult['SHOW_SEARCH_PANEL'] = 'Y';
$needle = '';
$enableSearch = $arResult['ENABLE_SEARCH'] = isset($_REQUEST['SEARCH']) && strtoupper($_REQUEST['SEARCH']) === 'Y';
if ($enableSearch) {
    // decode encodeURIComponent params
    CUtil::JSPostUnescape();
    $needle = isset($_REQUEST['NEEDLE']) ? $_REQUEST['NEEDLE'] : '';
}
$items = array();
$imageless = array();
if (!CCrmOwnerType::IsDefined($ownerTypeID) || $ownerID <= 0) {
    if ($enableSearch && $needle !== '') {
        $results = CCrmActivity::FindContactCommunications($needle, $commType !== 'PERSON' ? $commType : '', 10);
        if ($commType !== '') {
            //If communication type defined add companies communications
            $results = array_merge($results, CCrmActivity::FindCompanyCommunications($needle, $commType !== 'PERSON' ? $commType : '', 10));
        }
        $results = array_merge($results, CCrmActivity::FindLeadCommunications($needle, $commType !== 'PERSON' ? $commType : '', 10));
    } else {
        $results = CCrmActivity::GetRecentlyUsedCommunications($commType !== 'PERSON' ? $commType : '');
        foreach ($results as &$result) {
            CCrmActivity::PrepareCommunicationInfo($result);
        }
        unset($result);
    }
    foreach ($results as &$result) {
Пример #25
0
 }
 $siteID = !empty($_REQUEST['siteID']) ? $_REQUEST['siteID'] : SITE_ID;
 $data = isset($_POST['DATA']) && is_array($_POST['DATA']) ? $_POST['DATA'] : array();
 if (count($data) == 0) {
     echo CUtil::PhpToJSObject(array('ERROR' => 'SOURCE DATA ARE NOT FOUND!'));
     die;
 }
 $ID = isset($data['ID']) ? intval($data['ID']) : 0;
 $isNew = $ID <= 0;
 $ownerTypeName = isset($data['ownerType']) ? strtoupper(strval($data['ownerType'])) : '';
 if ($ownerTypeName === '') {
     echo CUtil::PhpToJSObject(array('ERROR' => 'OWNER TYPE IS NOT DEFINED!'));
     die;
 }
 $ownerTypeID = CCrmOwnerType::ResolveID($ownerTypeName);
 if (!CCrmOwnerType::IsDefined($ownerTypeID)) {
     echo CUtil::PhpToJSObject(array('ERROR' => 'OWNER TYPE IS NOT SUPPORTED!'));
     die;
 }
 $ownerID = isset($data['ownerID']) ? intval($data['ownerID']) : 0;
 if ($ownerID <= 0) {
     echo CUtil::PhpToJSObject(array('ERROR' => 'OWNER ID IS NOT DEFINED!'));
     die;
 }
 if (!CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID)) {
     $entityTitle = CCrmOwnerType::GetCaption($ownerTypeID, $ownerID, false);
     if ($ownerTypeID === CCrmOwnerType::Contact) {
         $errorMsg = GetMessage('CRM_CONTACT_UPDATE_PERMISSION_DENIED', array('#TITLE#' => $entityTitle));
     } elseif ($ownerTypeID === CCrmOwnerType::Company) {
         $errorMsg = GetMessage('CRM_COMPANY_UPDATE_PERMISSION_DENIED', array('#TITLE#' => $entityTitle));
     } elseif ($ownerTypeID === CCrmOwnerType::Lead) {
Пример #26
0
 public static function ProcessLogEventEditPOST($arPOST, $entityTypeID, $entityID, &$arResult)
 {
     $arEntityData = array();
     $errors = array();
     $enableTitle = isset($arPOST['ENABLE_POST_TITLE']) && strtoupper($arPOST['ENABLE_POST_TITLE']) === 'Y';
     $title = $enableTitle && isset($arPOST['POST_TITLE']) ? $arPOST['POST_TITLE'] : '';
     $message = isset($arPOST['MESSAGE']) ? htmlspecialcharsback($arPOST['MESSAGE']) : '';
     $arResult['EVENT']['MESSAGE'] = $message;
     $arResult['EVENT']['TITLE'] = $title;
     $arResult['ENABLE_TITLE'] = $enableTitle;
     $attachedFiles = array();
     $webDavFileFieldName = $arResult['WEB_DAV_FILE_FIELD_NAME'];
     if ($webDavFileFieldName !== '' && isset($GLOBALS[$webDavFileFieldName]) && is_array($GLOBALS[$webDavFileFieldName])) {
         foreach ($GLOBALS[$webDavFileFieldName] as $fileID) {
             if ($fileID === '') {
                 continue;
             }
             //fileID:  "888|165|16"
             $attachedFiles[] = $fileID;
         }
         if (!empty($attachedFiles) && is_array($arResult['WEB_DAV_FILE_FIELD'])) {
             $arResult['WEB_DAV_FILE_FIELD']['VALUE'] = $attachedFiles;
         }
     }
     $allowToAll = COption::GetOptionString('socialnetwork', 'allow_livefeed_toall', 'Y') === 'Y';
     if ($allowToAll) {
         $arToAllRights = unserialize(COption::GetOptionString("socialnetwork", "livefeed_toall_rights", 'a:1:{i:0;s:2:"AU";}'));
         if (!$arToAllRights) {
             $arToAllRights = array('AU');
         }
         $arUserGroupCode = array_merge(array('AU'), CAccess::GetUserCodesArray($arResult['USER_ID']));
         if (count(array_intersect($arToAllRights, $arUserGroupCode)) <= 0) {
             $allowToAll = false;
         }
     }
     $arSocnetRights = array();
     if (!empty($arPOST['SPERM'])) {
         foreach ($arPOST['SPERM'] as $v => $k) {
             if (strlen($v) > 0 && is_array($k) && !empty($k)) {
                 foreach ($k as $vv) {
                     if (strlen($vv) > 0) {
                         $arSocnetRights[] = $vv;
                     }
                 }
             }
         }
     }
     if (in_array('UA', $arSocnetRights) && !$allowToAll) {
         foreach ($arSocnetRights as $key => $value) {
             if ($value == 'UA') {
                 unset($arSocnetRights[$key]);
                 break;
             }
         }
     }
     foreach ($arSocnetRights as $key => $value) {
         if ($value == 'UA') {
             $arSocnetRights[] = 'AU';
             unset($arSocnetRights[$key]);
             break;
         }
     }
     $arSocnetRights = array_unique($arSocnetRights);
     $allFeedEtityTypes = CCrmLiveFeedEntity::GetAll();
     $userPerms = CCrmPerms::GetCurrentUserPermissions();
     foreach ($arSocnetRights as $key => $value) {
         $groupCodeData = array();
         if (CCrmLiveFeed::TryParseGroupCode($value, $groupCodeData) && in_array($groupCodeData['ENTITY_TYPE'], $allFeedEtityTypes, true)) {
             $groupCodeEntityType = $groupCodeData['ENTITY_TYPE'];
             $groupCodeEntityID = $groupCodeData['ENTITY_ID'];
             if (!CCrmLiveFeed::CheckCreatePermission($groupCodeEntityType, $groupCodeEntityID, $userPerms)) {
                 $canonicalEntityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($groupCodeEntityType);
                 $errors[] = GetMessage('CRM_SL_EVENT_EDIT_PERMISSION_DENIED', array('#TITLE#' => CCrmOwnerType::GetCaption($canonicalEntityTypeID, $groupCodeEntityID, false)));
             } else {
                 $arEntityData[] = array('ENTITY_TYPE' => $groupCodeEntityType, 'ENTITY_ID' => $groupCodeEntityID);
             }
         }
     }
     if (!(CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0) && !empty($arEntityData)) {
         $entityData = $arEntityData[0];
         $entityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($entityData['ENTITY_TYPE']);
         $entityID = $entityData['ENTITY_ID'];
     }
     if (!empty($arEntityData)) {
         $arResult['ENTITY_DATA'] = $arEntityData;
     }
     if (!(CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0)) {
         $errors[] = GetMessage('CRM_SL_EVENT_EDIT_ENTITY_NOT_DEFINED');
     }
     if ($message === '') {
         $errors[] = GetMessage('CRM_SL_EVENT_EDIT_EMPTY_MESSAGE');
     }
     if (empty($errors)) {
         $fields = array('ENTITY_TYPE_ID' => $entityTypeID, 'ENTITY_ID' => $entityID, 'USER_ID' => $arResult['USER_ID'], 'TITLE' => $title, 'MESSAGE' => $message, 'RIGHTS' => $arSocnetRights);
         $parents = array();
         CCrmOwnerType::TryGetOwnerInfos($entityTypeID, $entityID, $parents, array('ENABLE_MAPPING' => true));
         foreach ($arEntityData as $entityData) {
             $curEntityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($entityData['ENTITY_TYPE']);
             $curEntityID = $entityData['ENTITY_ID'];
             $entityKey = "{$curEntityTypeID}_{$curEntityID}";
             if (!isset($parents[$entityKey]) && !($curEntityTypeID === $entityTypeID && $curEntityID === $entityID)) {
                 $parents[$entityKey] = array('ENTITY_TYPE_ID' => $curEntityTypeID, 'ENTITY_ID' => $curEntityID);
             }
         }
         if (!empty($parents)) {
             $fields['PARENTS'] = array_values($parents);
         }
         if (!empty($attachedFiles)) {
             $fields['WEB_DAV_FILES'] = array($webDavFileFieldName => $attachedFiles);
         }
         $messageID = CCrmLiveFeed::CreateLogMessage($fields);
         if (!(is_int($messageID) && $messageID > 0)) {
             $errors[] = isset($fields['ERROR']) ? $fields['ERROR'] : 'UNKNOWN ERROR';
         } else {
             preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/is" . BX_UTF_PCRE_MODIFIER, $message, $arMention);
             if (!empty($arMention) && !empty($arMention[1]) && CModule::IncludeModule("im")) {
                 $arMention = $arMention[1];
                 $arMention = array_unique($arMention);
                 $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => "", "FROM_USER_ID" => $arResult['USER_ID'], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "NOTIFY_EVENT" => "mention");
                 $genderSuffix = "";
                 $dbUser = CUser::GetByID($arResult['USER_ID']);
                 if ($arUser = $dbUser->Fetch()) {
                     switch ($arUser["PERSONAL_GENDER"]) {
                         case "M":
                             $genderSuffix = "_M";
                             break;
                         case "F":
                             $genderSuffix = "_F";
                             break;
                         default:
                             $genderSuffix = "";
                     }
                 }
                 $strIMMessageTitle = str_replace(array("\r\n", "\n"), " ", strlen($title) > 0 ? $title : $message);
                 if (CModule::IncludeModule("blog")) {
                     $strIMMessageTitle = trim(blogTextParser::killAllTags($strIMMessageTitle));
                 }
                 $strIMMessageTitle = TruncateText($strIMMessageTitle, 100);
                 $strIMMessageTitleOut = TruncateText($strIMMessageTitle, 255);
                 $strLogEntryURL = COption::GetOptionString("socialnetwork", "log_entry_page", SITE_DIR . "company/personal/log/#log_id#/", SITE_ID);
                 $strLogEntryURL = CComponentEngine::MakePathFromTemplate($strLogEntryURL, array("log_id" => $messageID));
                 $strLogEntryCrmURL = CComponentEngine::MakePathFromTemplate(SITE_DIR . "crm/stream/?log_id=#log_id#", array("log_id" => $messageID));
                 $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
                 foreach ($arMention as $val) {
                     $val = IntVal($val);
                     if ($val > 0 && $val != $arResult['USER_ID']) {
                         $bHasAccess = false;
                         if (in_array('U' . $val, $arSocnetRights)) {
                             $url = $strLogEntryURL;
                             $bHasAccess = true;
                         }
                         if (!$bHasAccess) {
                             $arAccessCodes = array();
                             $dbAccess = CAccess::GetUserCodes($val);
                             while ($arAccess = $dbAccess->Fetch()) {
                                 $arAccessCodes[] = $arAccess["ACCESS_CODE"];
                             }
                             $arTmp = array_intersect($arAccess, $arSocnetRights);
                             if (!empty($arTmp)) {
                                 $url = $strLogEntryURL;
                                 $bHasAccess = true;
                             }
                         }
                         if (!$bHasAccess) {
                             $userPermissions = CCrmPerms::GetUserPermissions($val);
                             foreach ($arEntityData as $arEntity) {
                                 if (CCrmAuthorizationHelper::CheckReadPermission(CCrmOwnerType::ResolveName(CCrmLiveFeedEntity::ResolveEntityTypeID($arEntity['ENTITY_TYPE'])), $arEntity['ENTITY_ID'], $userPermissions)) {
                                     $url = $strLogEntryCrmURL;
                                     $bHasAccess = true;
                                     break;
                                 }
                             }
                         }
                         if ($bHasAccess) {
                             $arMessageFields["TO_USER_ID"] = $val;
                             $arMessageFields["NOTIFY_TAG"] = "CRM|MESSAGE_MENTION|" . $messageID;
                             $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("CRM_SL_EVENT_IM_MENTION_POST" . $genderSuffix, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($strIMMessageTitle) . "</a>"));
                             $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_SL_EVENT_IM_MENTION_POST" . $genderSuffix, array("#title#" => htmlspecialcharsbx($strIMMessageTitleOut))) . " (" . $serverName . $url . ")";
                             CIMNotify::Add($arMessageFields);
                         }
                     }
                 }
             }
             return $messageID;
         }
     }
     return $errors;
 }
 public function find($entityTypeID = \CCrmOwnerType::Undefined, $limit = 50)
 {
     if ($this->lastName === '') {
         //Invalid Operation?
         return null;
     }
     if (!is_int($entityTypeID)) {
         throw new Main\ArgumentTypeException('entityTypeID', 'integer');
     }
     if (!is_int($limit)) {
         throw new Main\ArgumentTypeException('limit', 'integer');
     }
     $listParams = array('select' => array('ENTITY_TYPE_ID', 'ENTITY_ID'), 'order' => array('ENTITY_TYPE_ID' => 'ASC', 'ENTITY_ID' => 'ASC'), 'filter' => array('LAST_NAME' => $this->lastName));
     if (\CCrmOwnerType::IsDefined($entityTypeID)) {
         $listParams['filter']['ENTITY_TYPE_ID'] = $entityTypeID;
     }
     if ($this->name !== '') {
         $listParams['filter']['NAME'] = $this->name;
     }
     if ($this->secondName !== '') {
         $listParams['filter']['SECOND_NAME'] = $this->secondName;
     }
     if ($limit > 0) {
         $listParams['limit'] = $limit;
     }
     $dbResult = DuplicatePersonMatchCodeTable::getList($listParams);
     $entities = array();
     while ($fields = $dbResult->fetch()) {
         $entityTypeID = isset($fields['ENTITY_TYPE_ID']) ? intval($fields['ENTITY_TYPE_ID']) : 0;
         $entityID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0;
         if (\CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0) {
             $entities[] = new DuplicateEntity($entityTypeID, $entityID);
         }
     }
     return !empty($entities) ? new Duplicate($this, $entities) : null;
 }
Пример #28
0
 public function createActivities(array $params)
 {
     $count = isset($params['COUNT']) ? (int) $params['COUNT'] : 0;
     if ($count <= 0) {
         return;
     }
     $typeID = isset($params['TYPE_ID']) ? (int) $params['TYPE_ID'] : \CCrmActivityType::Undefined;
     if (!\CCrmActivityType::IsDefined($typeID)) {
         return;
     }
     $ownerTypeID = isset($params['OWNER_TYPE_ID']) ? (int) $params['OWNER_TYPE_ID'] : \CCrmOwnerType::Undefined;
     if (!\CCrmOwnerType::IsDefined($ownerTypeID)) {
         return;
     }
     $ownerID = isset($params['OWNER_ID']) ? (int) $params['OWNER_ID'] : 0;
     if ($ownerID <= 0) {
         return;
     }
     $clientTypeID = isset($params['CLIENT_TYPE_ID']) ? (int) $params['CLIENT_TYPE_ID'] : \CCrmOwnerType::Undefined;
     $clientID = isset($params['CLIENT_ID']) ? (int) $params['CLIENT_ID'] : 0;
     if (!\CCrmOwnerType::IsDefined($clientTypeID) || $clientID <= 0) {
         $clientTypeID = $ownerTypeID;
         $clientID = $ownerID;
     }
     $commType = $typeID === \CCrmActivityType::Call ? 'PHONE' : '';
     $values = array();
     if ($commType === 'PHONE' || $commType === 'EMAIL') {
         $values = self::getEntityMultifieldValues($clientTypeID, $clientID, $commType);
         if (empty($values)) {
             return;
         }
     }
     $userIDs = isset($params['USER_IDS']) && is_array($params['USER_IDS']) ? $params['USER_IDS'] : array();
     if (empty($userIDs)) {
         $userIDs[] = \CCrmSecurityHelper::GetCurrentUserID();
     }
     $date = isset($params['DATE']) ? $params['DATE'] : null;
     if (!$date) {
         $date = $date = new Date();
     }
     $maxDateOffset = isset($params['MAX_DATE_OFFSET']) ? (int) $params['MAX_DATE_OFFSET'] : 0;
     $dateTimeFormat = Date::convertFormatToPhp(FORMAT_DATETIME);
     $subjectPrefix = isset($params['SUBJECT_PREFIX']) ? $params['SUBJECT_PREFIX'] : '';
     for ($i = 0; $i < $count; $i++) {
         $time = DateTime::createFromTimestamp($date->getTimestamp());
         if ($maxDateOffset > 0) {
             $time->add(mt_rand(0, $maxDateOffset) . ' days');
         }
         $time->setTime(mt_rand(8, 20), mt_rand(0, 59), 0);
         $siteTime = $time->format($dateTimeFormat);
         $fields = array('TYPE_ID' => $typeID, 'START_TIME' => $siteTime, 'END_TIME' => $siteTime, 'SUBJECT' => "{$subjectPrefix} ({$siteTime})", 'COMPLETED' => mt_rand(1, 10) % 2 !== 0 ? 'Y' : 'N', 'PRIORITY' => \CCrmActivityPriority::Medium, 'DESCRIPTION' => '', 'DESCRIPTION_TYPE' => \CCrmContentType::PlainText, 'LOCATION' => '', 'DIRECTION' => \CCrmActivityDirection::Outgoing, 'NOTIFY_TYPE' => \CCrmActivityNotifyType::None, 'RESPONSIBLE_ID' => self::getRandomItem($userIDs), 'OWNER_ID' => $ownerID, 'OWNER_TYPE_ID' => $ownerTypeID, 'BINDINGS' => array(array('OWNER_TYPE_ID' => $ownerTypeID, 'OWNER_ID' => $ownerID)));
         $ID = \CCrmActivity::Add($fields, false, true, array('REGISTER_SONET_EVENT' => true));
         $comms = array(array('TYPE' => $commType, 'VALUE' => self::getRandomItem($values, ''), 'ENTITY_ID' => $clientID, 'ENTITY_TYPE_ID' => $clientTypeID));
         \CCrmActivity::SaveCommunications($ID, $comms, $fields, false, false);
     }
 }
Пример #29
0
 public static function OnBeforeIntantMessangerChatAdd(\Bitrix\Main\Entity\Event $event)
 {
     $result = new \Bitrix\Main\Entity\EventResult();
     $fields = $event->getParameter('fields');
     $entityType = isset($fields['ENTITY_TYPE']) ? $fields['ENTITY_TYPE'] : '';
     $m = null;
     if (preg_match('/^CRM_([A-Z]+)$/i', $entityType, $m) === 1) {
         $entityTypeName = isset($m[1]) ? $m[1] : '';
         $ownerTypeID = CCrmOwnerType::ResolveID($entityTypeName);
         $ownerID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0;
         $ownerInfo = null;
         if (CCrmOwnerType::IsDefined($ownerTypeID) && $ownerID > 0 && CCrmOwnerType::TryGetInfo($ownerTypeID, $ownerID, $ownerInfo, false)) {
             $changedFields['TITLE'] = $ownerInfo['CAPTION'];
             $changedFields['AVATAR'] = $ownerInfo['IMAGE_ID'];
             $result->modifyFields($changedFields);
         }
     }
     return $result;
 }
Пример #30
0
 public function UnRegisterByEntity($entityTypeID, $entityID, $options = array())
 {
     if (!CCrmOwnerType::IsDefined($entityTypeID)) {
         return;
     }
     $entityID = intval($entityID);
     if ($entityID <= 0) {
         return;
     }
     global $DB;
     $tableName = self::TABLE_NAME;
     $modifiers = '';
     if (is_array($options) && isset($options['QUICK']) && $options['QUICK'] === true) {
         $modifiers = ' QUICK';
     }
     $slEntityType = $DB->ForSql(CCrmLiveFeedEntity::GetByEntityTypeID($entityTypeID));
     $deleteSql = "DELETE{$modifiers} FROM {$tableName} WHERE (SL_ENTITY_TYPE = '{$slEntityType}' AND ENTITY_ID = {$entityID}) OR (SL_PARENT_ENTITY_TYPE = '{$slEntityType}' AND PARENT_ENTITY_ID = {$entityID})";
     $DB->Query($deleteSql, false, 'File: ' . __FILE__ . '<br/>Line: ' . __LINE__);
 }