コード例 #1
0
 public function RegisterBundle($logEntityID, $logEventID, $entityTypeID, $entityID, &$parents, $options = array())
 {
     if (!CCrmOwnerType::IsDefined($entityTypeID)) {
         return;
     }
     $logEntityID = intval($logEntityID);
     $entityID = intval($entityID);
     if ($logEntityID <= 0 || $entityID <= 0) {
         return;
     }
     if (!is_array($parents)) {
         return;
     }
     if (!is_array($options)) {
         $options = array();
     }
     $entityTypeIDKey = isset($options['ENTITY_TYPE_ID_KEY']) ? $options['ENTITY_TYPE_ID_KEY'] : '';
     if ($entityTypeIDKey === '') {
         $entityTypeIDKey = 'ENTITY_TYPE_ID';
     }
     $entityIDKey = isset($options['ENTITY_ID_KEY']) ? $options['ENTITY_ID_KEY'] : '';
     if ($entityIDKey === '') {
         $entityIDKey = 'ENTITY_ID';
     }
     $defaultTypeID = isset($options['TYPE_ID']) ? intval($options['TYPE_ID']) : CCrmOwnerType::Undefined;
     if (!CCrmSonetRelationType::IsDefined($defaultTypeID)) {
         $defaultTypeID = CCrmSonetRelationType::Ownership;
     }
     $items = array();
     $slEntityType = CCrmLiveFeedEntity::GetByEntityTypeID($entityTypeID);
     $logLastUpdateTime = CCrmLiveFeed::GetLogEventLastUpdateTime($logEntityID, false);
     foreach ($parents as &$parent) {
         $parentEntityTypeID = isset($parent[$entityTypeIDKey]) ? intval($parent[$entityTypeIDKey]) : CCrmOwnerType::Undefined;
         $parentEntityID = isset($parent[$entityIDKey]) ? intval($parent[$entityIDKey]) : 0;
         if (!CCrmOwnerType::IsDefined($parentEntityTypeID) || $parentEntityID <= 0) {
             continue;
         }
         $key = "{$parentEntityTypeID}_{$parentEntityID}";
         if (isset($items[$key])) {
             continue;
         }
         $typeID = isset($parent['TYPE_ID']) ? intval($parent['TYPE_ID']) : CCrmSonetRelationType::Undefined;
         if (!CCrmSonetRelationType::IsDefined($typeID)) {
             $typeID = $defaultTypeID;
         }
         $level = isset($parent['LEVEL']) ? max(intval($parent['LEVEL']), 1) : 1;
         $items[$key] = array('SL_ID' => $logEntityID, 'SL_EVENT_ID' => $logEventID, 'SL_ENTITY_TYPE' => $slEntityType, 'ENTITY_ID' => $entityID, 'SL_PARENT_ENTITY_TYPE' => CCrmLiveFeedEntity::GetByEntityTypeID($parentEntityTypeID), 'PARENT_ENTITY_ID' => $parentEntityID, 'SL_LAST_UPDATED' => $logLastUpdateTime, 'TYPE_ID' => $typeID, 'LVL' => $level);
     }
     unset($parent);
     global $DB;
     CTimeZone::Disable();
     $bulkColumns = '';
     $bulkValues = array();
     foreach ($items as &$item) {
         $data = $DB->PrepareInsert(self::TABLE_NAME, $item);
         if (strlen($bulkColumns) == 0) {
             $bulkColumns = $data[0];
         }
         $bulkValues[] = $data[1];
     }
     unset($item);
     CTimeZone::Enable();
     if (count($bulkValues) == 0) {
         return;
     }
     $query = '';
     foreach ($bulkValues as &$value) {
         if ($query !== '') {
             $query .= ',';
         }
         $query .= "({$value})";
     }
     if (strlen($query) == 0) {
         return;
     }
     $DB->Query('INSERT INTO ' . self::TABLE_NAME . '(' . $bulkColumns . ') VALUES' . $query, false, 'File: ' . __FILE__ . '<br/>Line: ' . __LINE__);
 }