public static function PrepareFromQueryData(array $arSql, $tableName, $tableAlias, $dbType, $arNavStartParams = false)
 {
     global $DB;
     $sql = 'SELECT ' . $arSql['SELECT'] . ' FROM ' . $tableName . ' ' . $tableAlias . ' ' . $arSql['FROM'] . ' GROUP BY ' . $arSql['GROUPBY'] . ' ORDER BY ' . $arSql['ORDERBY'];
     $enableNavigation = is_array($arNavStartParams);
     $top = $enableNavigation && isset($arNavStartParams['nTopCount']) ? (int) $arNavStartParams['nTopCount'] : 0;
     if ($enableNavigation && $top <= 0) {
         if (COption::GetOptionString('crm', 'enable_rough_row_count', 'Y') === 'Y') {
             $cnt = self::GetRoughRowCount($arSql, $tableName, $tableAlias, $dbType);
         } else {
             $cnt = CSqlUtil::GetRowCount($arSql, $tableName, $tableAlias, $dbType);
         }
         $dbResult = new CDBResult();
         $dbResult->NavQuery($sql, $cnt, $arNavStartParams);
         return $dbResult;
     }
     if ($enableNavigation && $top > 0) {
         CSqlUtil::PrepareSelectTop($sql, $top, $dbType);
     }
     $dbResult = $DB->Query($sql, false, 'File: ' . __FILE__ . '<br/>Line: ' . __LINE__);
     return $dbResult;
 }
예제 #2
0
 private static function BuilUserAddresseeSelectSql(&$params, $options = array())
 {
     global $DB, $DBType;
     $userID = isset($params['USER_ID']) ? intval($params['USER_ID']) : 0;
     if ($userID <= 0) {
         $userID = CCrmSecurityHelper::GetCurrentUserID();
     }
     if (!is_array($options)) {
         $options = array();
     }
     $startTime = isset($options['START_TIME']) ? $options['START_TIME'] : '';
     if ($startTime !== '') {
         $startTime = $DB->CharToDateFunction($DB->ForSql($startTime), 'FULL');
     }
     $top = isset($options['TOP']) ? intval($options['TOP']) : 0;
     $allEntitySql = CCrmLiveFeedEntity::GetForSqlString(isset($params['ENTITY_TYPES']) ? $params['ENTITY_TYPES'] : null);
     $sql = "SELECT L1.ID FROM b_sonet_log L1\n\t\t\t\tINNER JOIN b_sonet_log_right LR1\n\t\t\t\t\tON L1.ID = LR1.LOG_ID AND LR1.GROUP_CODE = 'U{$userID}'\n\t\t\t\t\tAND L1.ENTITY_TYPE IN ({$allEntitySql})";
     if ($startTime !== '') {
         $sql .= " AND L1.LOG_UPDATE >= {$startTime}";
     }
     if ($top > 0) {
         $sql .= ' ORDER BY L1.LOG_UPDATE DESC';
         CSqlUtil::PrepareSelectTop($sql, $top, $DBType);
     }
     return $sql;
 }
예제 #3
0
 public static function GetCommunications($activityID, $top = 0)
 {
     $activityID = intval($activityID);
     if ($activityID <= 0) {
         self::RegisterError(array('text' => 'Invalid arguments are supplied.'));
         return false;
     }
     global $DB;
     $commTableName = CCrmActivity::COMMUNICATION_TABLE_NAME;
     $sql = "SELECT ID, TYPE, VALUE, ENTITY_ID, ENTITY_TYPE_ID, ENTITY_SETTINGS FROM {$commTableName} WHERE ACTIVITY_ID = {$activityID} ORDER BY ID ASC";
     $top = intval($top);
     if ($top > 0) {
         CSqlUtil::PrepareSelectTop($sql, $top, CCrmActivity::DB_TYPE);
     }
     $dbRes = $DB->Query($sql, false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
     $result = array();
     while ($arRes = $dbRes->Fetch()) {
         $arRes['ENTITY_SETTINGS'] = isset($arRes['ENTITY_SETTINGS']) && $arRes['ENTITY_SETTINGS'] !== '' ? unserialize($arRes['ENTITY_SETTINGS']) : array();
         $result[] = $arRes;
     }
     return $result;
 }
예제 #4
0
 public function ImportResponsibility($entityTypeID, $userID, $top)
 {
     if (!CCrmOwnerType::IsDefined($entityTypeID)) {
         return false;
     }
     $userID = max(intval($userID), 0);
     $top = max(intval($top), 0);
     $typeID = CCrmSonetSubscriptionType::Observation;
     global $DB;
     $tableName = self::TABLE_NAME;
     $slEntityType = $DB->ForSql(CCrmLiveFeedEntity::GetByEntityTypeID($entityTypeID));
     $selectSql = '';
     if ($entityTypeID === CCrmOwnerType::Lead || $entityTypeID === CCrmOwnerType::Contact || $entityTypeID === CCrmOwnerType::Company || $entityTypeID === CCrmOwnerType::Deal || $entityTypeID === CCrmOwnerType::Activity) {
         if ($entityTypeID === CCrmOwnerType::Lead) {
             $selectTableName = CCrmLead::TABLE_NAME;
             $userFieldName = 'ASSIGNED_BY_ID';
         } elseif ($entityTypeID === CCrmOwnerType::Contact) {
             $selectTableName = CCrmContact::TABLE_NAME;
             $userFieldName = 'ASSIGNED_BY_ID';
         } elseif ($entityTypeID === CCrmOwnerType::Company) {
             $selectTableName = CCrmCompany::TABLE_NAME;
             $userFieldName = 'ASSIGNED_BY_ID';
         } elseif ($entityTypeID === CCrmOwnerType::Deal) {
             $selectTableName = CCrmDeal::TABLE_NAME;
             $userFieldName = 'ASSIGNED_BY_ID';
         } else {
             $selectTableName = CCrmActivity::TABLE_NAME;
             $userFieldName = 'RESPONSIBLE_ID';
         }
         $userFieldCondition = $userID > 0 ? " = {$userID}" : ' > 0';
         $selectSql = "SELECT {$userFieldName}, '{$slEntityType}', ID, {$typeID} FROM {$selectTableName} WHERE {$userFieldName}{$userFieldCondition} ORDER BY ID DESC";
     }
     if ($selectSql === '') {
         return false;
     }
     if ($top > 0) {
         CSqlUtil::PrepareSelectTop($selectSql, $top, self::DB_TYPE);
     }
     $deleteSql = "DELETE QUICK FROM {$tableName} WHERE SL_ENTITY_TYPE = '{$slEntityType}' AND TYPE_ID = {$typeID}";
     if ($userID > 0) {
         $deleteSql .= " AND USER_ID = {$userID}";
     }
     $DB->Query($deleteSql, false, 'File: ' . __FILE__ . '<br/>Line: ' . __LINE__);
     $insertSql = "INSERT INTO {$tableName}(USER_ID, SL_ENTITY_TYPE, ENTITY_ID, TYPE_ID) " . $selectSql;
     $dbResult = $DB->Query($insertSql, false, 'File: ' . __FILE__ . '<br/>Line: ' . __LINE__);
     return is_object($dbResult);
 }