- Timestamp:
- 01/25/12 23:54:54 (4 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
inc/classes/BxDolGrid.php (modified) (5 diffs)
-
inc/classes/BxDolGridQuery.php (modified) (1 diff)
-
install/sql/v70.sql (modified) (1 diff)
-
templates/base/scripts/BxBaseGrid.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/inc/classes/BxDolGrid.php
r15903 r15929 61 61 * - paginate_get_start: GET variable name for 'start'. 62 62 * - paginate_get_per_page: GET variable name for 'per_page'. 63 * - filter_fields: comma separated field names, to search in. 63 * - filter_fields: comma separated list of field names to search in; if field contains language key then it is better to specify it in 'filter_fields_translatable'. 64 * - filter_fields_translatable: comma separated list of field names to search in its translations; enter field name here if field contains language key. 64 65 * - filter_mode: search mode: 65 66 * - like: use SQL LIKE expression for search, if 'source_type' is not 'Sql' it doesn't matter. … … 308 309 309 310 // apply filter 310 if ($sFilter && !empty($this->_aOptions['filter_fields'])) {311 if ($sFilter && (!empty($this->_aOptions['filter_fields']) || !empty($this->_aOptions['filter_fields_translatable']))) { 311 312 $aSource = array(); 312 313 foreach ($this->_aOptions['source'] as $aRow) { 313 foreach ($this->_aOptions['filter_fields'] as $sField) { 314 if (empty($aRow[$sField]) || false === strpos($aRow[$sField], $sFilter)) 315 continue; 316 $aSource[] = $aRow; 317 break; 314 $bFound = false; 315 if (!empty($this->_aOptions['filter_fields'])) { 316 foreach ($this->_aOptions['filter_fields'] as $sField) { 317 if (empty($aRow[$sField]) || false === stripos($aRow[$sField], $sFilter)) 318 continue; 319 $aSource[] = $aRow; 320 $bFound = true; 321 break; 322 } 323 } 324 if (!$bFound && !empty($this->_aOptions['filter_fields_translatable'])) { 325 foreach ($this->_aOptions['filter_fields_translatable'] as $sField) { 326 if (empty($aRow[$sField]) || false === stripos(_t($aRow[$sField]), $sFilter)) 327 continue; 328 $aSource[] = $aRow; 329 $bFound = true; 330 break; 331 } 318 332 } 319 333 } … … 353 367 // add filter condition 354 368 $sOrderByFilter = ''; 355 if ($sFilter && !empty($this->_aOptions['filter_fields'])) {369 if ($sFilter && (!empty($this->_aOptions['filter_fields']) || !empty($this->_aOptions['filter_fields_translatable']))) { 356 370 357 371 $sMode = $this->_aOptions['filter_mode']; … … 360 374 361 375 $sCond = ''; 362 if ('like' == $sMode) { 363 foreach ($this->_aOptions['filter_fields'] as $sField) 364 $sCond .= $oDb->prepare("`{$sField}` LIKE ? OR ", '%' . $sFilter . '%'); 376 if ('like' == $sMode) { // LIKE search 377 378 // condition for regular fields 379 if (!empty($this->_aOptions['filter_fields'])) 380 foreach ($this->_aOptions['filter_fields'] as $sField) 381 $sCond .= $oDb->prepare("`{$sField}` LIKE ? OR ", '%' . $sFilter . '%'); 382 383 // condition for translatable fields 384 if (!empty($this->_aOptions['filter_fields_translatable'])) { 385 $sCondFields = ''; 386 foreach ($this->_aOptions['filter_fields_translatable'] as $sField) 387 $sCondFields .= "`k`.`Key` = `{$sField}` OR "; 388 389 $sCondFields = rtrim($sCondFields, ' OR '); 390 391 if ($sCondFields) 392 $sCond .= $oDb->prepare("(SELECT 1 FROM `sys_localization_strings` AS `s` INNER JOIN `sys_localization_keys` AS `k` ON (`k`.`ID` = `s`.`IDKey`) WHERE `s`.`string` LIKE ? AND ($sCondFields) LIMIT 1) OR ", '%' . $sFilter . '%'); 393 } 394 365 395 $sCond = rtrim($sCond, ' OR '); 366 } else { 367 foreach ($this->_aOptions['filter_fields'] as $sField) 368 $sCond .= "`{$sField}`,"; 369 $sCond = rtrim($sCond, ','); 370 if ($sCond) { 371 $sCond = $oDb->prepare(" MATCH ($sCond) AGAINST (?) ", $sFilter); 372 $sOrderByFilter = $sCond; 373 $sCond .= ' > 1 '; 396 397 } else { // FULLTEXT search 398 399 // condition for regular fields 400 if (!empty($this->_aOptions['filter_fields'])) { 401 402 $sCondFields = ''; 403 foreach ($this->_aOptions['filter_fields'] as $sField) 404 $sCondFields .= "`{$sField}`,"; 405 406 $sCondFields = rtrim($sCondFields, ','); 407 408 if ($sCondFields) { 409 $sCond = $oDb->prepare(" MATCH ($sCondFields) AGAINST (?) ", $sFilter); 410 $sOrderByFilter = $sCond; 411 $sCond .= ' > 1 OR '; 412 } 374 413 } 375 } 414 415 // condition for translatable fields 416 if (!empty($this->_aOptions['filter_fields_translatable'])) { 417 418 $sCondFields = ''; 419 foreach ($this->_aOptions['filter_fields_translatable'] as $sField) 420 $sCondFields .= "`k`.`Key` = `{$sField}` OR "; 421 422 $sCondFields = rtrim($sCondFields, ' OR '); 423 424 if ($sCondFields) 425 $sCond .= $oDb->prepare("(SELECT 1 FROM `sys_localization_strings` AS `s` INNER JOIN `sys_localization_keys` AS `k` ON (`k`.`ID` = `s`.`IDKey`) WHERE MATCH (`s`.`string`) AGAINST (?) AND ($sCondFields) LIMIT 1) OR ", $sFilter); 426 } 427 428 $sCond = rtrim($sCond, ' OR '); 429 } 376 430 377 431 if ($sCond) … … 418 472 protected function _isVisibleGrid ($a) { 419 473 bx_import('BxDolAcl'); 474 if (!isset($a['visible_for_levels'])) 475 return true; 420 476 return BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']); 421 477 } -
trunk/inc/classes/BxDolGridQuery.php
r15774 r15929 36 36 if ($aObject['filter_fields']) 37 37 $aObject['filter_fields'] = array_map('trim', explode(',', $aObject['filter_fields'])); 38 39 if ($aObject['filter_fields_translatable']) 40 $aObject['filter_fields_translatable'] = array_map('trim', explode(',', $aObject['filter_fields_translatable'])); 38 41 39 42 // sorting -
trunk/install/sql/v70.sql
r15924 r15929 4603 4603 `paginate_get_per_page` varchar(255) NOT NULL, 4604 4604 `filter_fields` text NOT NULL, 4605 `filter_fields_translatable` text NOT NULL, 4605 4606 `filter_mode` enum('like','fulltext','auto') NOT NULL DEFAULT 'auto', 4606 4607 `sorting_fields` text NOT NULL, -
trunk/templates/base/scripts/BxBaseGrid.php
r15887 r15929 209 209 ), 210 210 'bx_if:filter' => array ( 211 'condition' => !empty($this->_aOptions['filter_fields']) ,211 'condition' => !empty($this->_aOptions['filter_fields']) || !empty($this->_aOptions['filter_fields_translatable']), 212 212 'content' => array( 213 213 'controls' => $this->_getFilterControls(),
Note: See TracChangeset
for help on using the changeset viewer.