Ejemplo n.º 1
0
 public static function PrepareFilter(&$arFilter, $arFilter2Logic = null)
 {
     if (!is_array($arFilter2Logic)) {
         $arFilter2Logic = array('TITLE', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'POST', 'ADDRESS', 'COMMENTS');
     }
     // converts data from filter
     if (isset($arFilter['FIND_list']) && !empty($arFilter['FIND'])) {
         $arFilter[strtoupper($arFilter['FIND_list'])] = $arFilter['FIND'];
         unset($arFilter['FIND_list'], $arFilter['FIND']);
     }
     static $arImmutableFilters = array('FM', 'ID', 'COMPANY_ID', 'ASSIGNED_BY_ID', 'CREATED_BY_ID', 'MODIFY_BY_ID', 'TYPE_ID', 'SOURCE_ID', 'GRID_FILTER_APPLIED', 'GRID_FILTER_ID');
     foreach ($arFilter as $k => $v) {
         if (in_array($k, $arImmutableFilters, true)) {
             continue;
         }
         $arMatch = array();
         if ($k === 'ORIGINATOR_ID') {
             // HACK: build filter by internal entities
             $arFilter['=ORIGINATOR_ID'] = $v !== '__INTERNAL' ? $v : null;
             unset($arFilter[$k]);
         } elseif ($k === 'ADDRESS' || $k === 'ADDRESS_2' || $k === 'ADDRESS_CITY' || $k === 'ADDRESS_REGION' || $k === 'ADDRESS_PROVINCE' || $k === 'ADDRESS_POSTAL_CODE' || $k === 'ADDRESS_COUNTRY') {
             $arFilter["=%{$k}"] = "{$v}%";
             unset($arFilter[$k]);
         } elseif (preg_match('/(.*)_from$/i' . BX_UTF_PCRE_MODIFIER, $k, $arMatch)) {
             if (strlen($v) > 0) {
                 $arFilter['>=' . $arMatch[1]] = $v;
             }
             unset($arFilter[$k]);
         } elseif (preg_match('/(.*)_to$/i' . BX_UTF_PCRE_MODIFIER, $k, $arMatch)) {
             if (strlen($v) > 0) {
                 if (($arMatch[1] == 'DATE_CREATE' || $arMatch[1] == 'DATE_MODIFY') && !preg_match('/\\d{1,2}:\\d{1,2}(:\\d{1,2})?$/' . BX_UTF_PCRE_MODIFIER, $v)) {
                     $v = CCrmDateTimeHelper::SetMaxDayTime($v);
                 }
                 $arFilter['<=' . $arMatch[1]] = $v;
             }
             unset($arFilter[$k]);
         } elseif (in_array($k, $arFilter2Logic)) {
             // Bugfix #26956 - skip empty values in logical filter
             $v = trim($v);
             if ($v !== '') {
                 $arFilter['?' . $k] = $v;
             }
             unset($arFilter[$k]);
         } elseif ($k != 'ID' && $k != 'LOGIC' && $k != '__INNER_FILTER' && strpos($k, 'UF_') !== 0 && preg_match('/^[^\\=\\%\\?\\>\\<]{1}/', $k) === 1) {
             $arFilter['%' . $k] = $v;
             unset($arFilter[$k]);
         }
     }
 }
Ejemplo n.º 2
0
 public static function PrepareFilter(&$arFilter, $arFilter2Logic = null)
 {
     if (!is_array($arFilter2Logic)) {
         $arFilter2Logic = array('TITLE', 'COMMENTS');
     }
     static $arImmutableFilters = array('FM', 'ID', 'ASSIGNED_BY_ID', 'CURRENCY_ID', 'CONTACT_ID', 'COMPANY_ID', 'CREATED_BY_ID', 'MODIFY_BY_ID', 'PRODUCT_ROW_PRODUCT_ID', 'GRID_FILTER_APPLIED', 'GRID_FILTER_ID');
     foreach ($arFilter as $k => $v) {
         if (in_array($k, $arImmutableFilters, true)) {
             continue;
         }
         $arMatch = array();
         if (in_array($k, array('PRODUCT_ID', 'TYPE_ID', 'STAGE_ID', 'COMPANY_ID', 'CONTACT_ID'))) {
             // Bugfix #23121 - to suppress comparison by LIKE
             $arFilter['=' . $k] = $v;
             unset($arFilter[$k]);
         } elseif ($k === 'ORIGINATOR_ID') {
             // HACK: build filter by internal entities
             $arFilter['=ORIGINATOR_ID'] = $v !== '__INTERNAL' ? $v : null;
             unset($arFilter[$k]);
         } elseif (preg_match('/(.*)_from$/i' . BX_UTF_PCRE_MODIFIER, $k, $arMatch)) {
             if (strlen($v) > 0) {
                 $arFilter['>=' . $arMatch[1]] = $v;
             }
             unset($arFilter[$k]);
         } elseif (preg_match('/(.*)_to$/i' . BX_UTF_PCRE_MODIFIER, $k, $arMatch)) {
             if (strlen($v) > 0) {
                 if (($arMatch[1] == 'DATE_CREATE' || $arMatch[1] == 'DATE_MODIFY') && !preg_match('/\\d{1,2}:\\d{1,2}(:\\d{1,2})?$/' . BX_UTF_PCRE_MODIFIER, $v)) {
                     $v = CCrmDateTimeHelper::SetMaxDayTime($v);
                 }
                 $arFilter['<=' . $arMatch[1]] = $v;
             }
             unset($arFilter[$k]);
         } elseif (in_array($k, $arFilter2Logic)) {
             // Bugfix #26956 - skip empty values in logical filter
             $v = trim($v);
             if ($v !== '') {
                 $arFilter['?' . $k] = $v;
             }
             unset($arFilter[$k]);
         } elseif ($k != 'ID' && $k != 'LOGIC' && $k != '__INNER_FILTER' && strpos($k, 'UF_') !== 0 && preg_match('/^[^\\=\\%\\?\\>\\<]{1}/', $k) === 1) {
             $arFilter['%' . $k] = $v;
             unset($arFilter[$k]);
         }
     }
 }