| @@ 900-992 (lines=93) @@ | ||
| 897 | * @return string Returns part of WHERE-clause for searching, if applicable. |
|
| 898 | * @deprecated since TYPO3 v9, will be removed in TYPO3 v10 |
|
| 899 | */ |
|
| 900 | public function makeSearchString($table, $currentPid = -1) |
|
| 901 | { |
|
| 902 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); |
|
| 903 | $expressionBuilder = $queryBuilder->expr(); |
|
| 904 | $constraints = []; |
|
| 905 | $currentPid = (int)$currentPid; |
|
| 906 | $tablePidField = $table === 'pages' ? 'uid' : 'pid'; |
|
| 907 | // Make query, only if table is valid and a search string is actually defined: |
|
| 908 | if (empty($this->searchString)) { |
|
| 909 | return ''; |
|
| 910 | } |
|
| 911 | ||
| 912 | $searchableFields = $this->getSearchFields($table); |
|
| 913 | if (empty($searchableFields)) { |
|
| 914 | return ''; |
|
| 915 | } |
|
| 916 | if (MathUtility::canBeInterpretedAsInteger($this->searchString)) { |
|
| 917 | $constraints[] = $expressionBuilder->eq('uid', (int)$this->searchString); |
|
| 918 | foreach ($searchableFields as $fieldName) { |
|
| 919 | if (!isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) { |
|
| 920 | continue; |
|
| 921 | } |
|
| 922 | $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']; |
|
| 923 | $fieldType = $fieldConfig['type']; |
|
| 924 | $evalRules = $fieldConfig['eval'] ?: ''; |
|
| 925 | if ($fieldType === 'input' && $evalRules && GeneralUtility::inList($evalRules, 'int')) { |
|
| 926 | if (is_array($fieldConfig['search']) |
|
| 927 | && in_array('pidonly', $fieldConfig['search'], true) |
|
| 928 | && $currentPid > 0 |
|
| 929 | ) { |
|
| 930 | $constraints[] = $expressionBuilder->andX( |
|
| 931 | $expressionBuilder->eq($fieldName, (int)$this->searchString), |
|
| 932 | $expressionBuilder->eq($tablePidField, (int)$currentPid) |
|
| 933 | ); |
|
| 934 | } |
|
| 935 | } elseif ($fieldType === 'text' |
|
| 936 | || $fieldType === 'flex' |
|
| 937 | || ($fieldType === 'input' && (!$evalRules || !preg_match('/date|time|int/', $evalRules))) |
|
| 938 | ) { |
|
| 939 | $constraints[] = $expressionBuilder->like( |
|
| 940 | $fieldName, |
|
| 941 | $queryBuilder->quote('%' . (int)$this->searchString . '%') |
|
| 942 | ); |
|
| 943 | } |
|
| 944 | } |
|
| 945 | } else { |
|
| 946 | $like = $queryBuilder->quote('%' . $queryBuilder->escapeLikeWildcards($this->searchString) . '%'); |
|
| 947 | foreach ($searchableFields as $fieldName) { |
|
| 948 | if (!isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) { |
|
| 949 | continue; |
|
| 950 | } |
|
| 951 | $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']; |
|
| 952 | $fieldType = $fieldConfig['type']; |
|
| 953 | $evalRules = $fieldConfig['eval'] ?: ''; |
|
| 954 | $searchConstraint = $expressionBuilder->andX( |
|
| 955 | $expressionBuilder->comparison( |
|
| 956 | 'LOWER(' . $queryBuilder->quoteIdentifier($fieldName) . ')', |
|
| 957 | 'LIKE', |
|
| 958 | 'LOWER(' . $like . ')' |
|
| 959 | ) |
|
| 960 | ); |
|
| 961 | if (is_array($fieldConfig['search'])) { |
|
| 962 | $searchConfig = $fieldConfig['search']; |
|
| 963 | if (in_array('case', $searchConfig)) { |
|
| 964 | // Replace case insensitive default constraint |
|
| 965 | $searchConstraint = $expressionBuilder->andX($expressionBuilder->like($fieldName, $like)); |
|
| 966 | } |
|
| 967 | if (in_array('pidonly', $searchConfig) && $currentPid > 0) { |
|
| 968 | $searchConstraint->add($expressionBuilder->eq($tablePidField, (int)$currentPid)); |
|
| 969 | } |
|
| 970 | if ($searchConfig['andWhere']) { |
|
| 971 | $searchConstraint->add( |
|
| 972 | QueryHelper::stripLogicalOperatorPrefix($fieldConfig['search']['andWhere']) |
|
| 973 | ); |
|
| 974 | } |
|
| 975 | } |
|
| 976 | if ($fieldType === 'text' |
|
| 977 | || $fieldType === 'flex' |
|
| 978 | || $fieldType === 'input' && (!$evalRules || !preg_match('/date|time|int/', $evalRules)) |
|
| 979 | ) { |
|
| 980 | if ($searchConstraint->count() !== 0) { |
|
| 981 | $constraints[] = $searchConstraint; |
|
| 982 | } |
|
| 983 | } |
|
| 984 | } |
|
| 985 | } |
|
| 986 | // If no search field conditions have been build ensure no results are returned |
|
| 987 | if (empty($constraints)) { |
|
| 988 | return '0=1'; |
|
| 989 | } |
|
| 990 | ||
| 991 | return $expressionBuilder->orX(...$constraints); |
|
| 992 | } |
|
| 993 | ||
| 994 | /** |
|
| 995 | * Fetches a list of fields to use in the Backend search for the given table. |
|
| @@ 3471-3563 (lines=93) @@ | ||
| 3468 | * @param int $currentPid Page id for the possible search limit. -1 only if called from an old XCLASS. |
|
| 3469 | * @return string Returns part of WHERE-clause for searching, if applicable. |
|
| 3470 | */ |
|
| 3471 | public function makeSearchString($table, $currentPid = -1) |
|
| 3472 | { |
|
| 3473 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); |
|
| 3474 | $expressionBuilder = $queryBuilder->expr(); |
|
| 3475 | $constraints = []; |
|
| 3476 | $currentPid = (int)$currentPid; |
|
| 3477 | $tablePidField = $table === 'pages' ? 'uid' : 'pid'; |
|
| 3478 | // Make query, only if table is valid and a search string is actually defined: |
|
| 3479 | if (empty($this->searchString)) { |
|
| 3480 | return ''; |
|
| 3481 | } |
|
| 3482 | ||
| 3483 | $searchableFields = $this->getSearchFields($table); |
|
| 3484 | if (empty($searchableFields)) { |
|
| 3485 | return ''; |
|
| 3486 | } |
|
| 3487 | if (MathUtility::canBeInterpretedAsInteger($this->searchString)) { |
|
| 3488 | $constraints[] = $expressionBuilder->eq('uid', (int)$this->searchString); |
|
| 3489 | foreach ($searchableFields as $fieldName) { |
|
| 3490 | if (!isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) { |
|
| 3491 | continue; |
|
| 3492 | } |
|
| 3493 | $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']; |
|
| 3494 | $fieldType = $fieldConfig['type']; |
|
| 3495 | $evalRules = $fieldConfig['eval'] ?: ''; |
|
| 3496 | if ($fieldType === 'input' && $evalRules && GeneralUtility::inList($evalRules, 'int')) { |
|
| 3497 | if (is_array($fieldConfig['search']) |
|
| 3498 | && in_array('pidonly', $fieldConfig['search'], true) |
|
| 3499 | && $currentPid > 0 |
|
| 3500 | ) { |
|
| 3501 | $constraints[] = $expressionBuilder->andX( |
|
| 3502 | $expressionBuilder->eq($fieldName, (int)$this->searchString), |
|
| 3503 | $expressionBuilder->eq($tablePidField, (int)$currentPid) |
|
| 3504 | ); |
|
| 3505 | } |
|
| 3506 | } elseif ($fieldType === 'text' |
|
| 3507 | || $fieldType === 'flex' |
|
| 3508 | || ($fieldType === 'input' && (!$evalRules || !preg_match('/date|time|int/', $evalRules))) |
|
| 3509 | ) { |
|
| 3510 | $constraints[] = $expressionBuilder->like( |
|
| 3511 | $fieldName, |
|
| 3512 | $queryBuilder->quote('%' . (int)$this->searchString . '%') |
|
| 3513 | ); |
|
| 3514 | } |
|
| 3515 | } |
|
| 3516 | } else { |
|
| 3517 | $like = $queryBuilder->quote('%' . $queryBuilder->escapeLikeWildcards($this->searchString) . '%'); |
|
| 3518 | foreach ($searchableFields as $fieldName) { |
|
| 3519 | if (!isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) { |
|
| 3520 | continue; |
|
| 3521 | } |
|
| 3522 | $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']; |
|
| 3523 | $fieldType = $fieldConfig['type']; |
|
| 3524 | $evalRules = $fieldConfig['eval'] ?: ''; |
|
| 3525 | $searchConstraint = $expressionBuilder->andX( |
|
| 3526 | $expressionBuilder->comparison( |
|
| 3527 | 'LOWER(' . $queryBuilder->quoteIdentifier($fieldName) . ')', |
|
| 3528 | 'LIKE', |
|
| 3529 | 'LOWER(' . $like . ')' |
|
| 3530 | ) |
|
| 3531 | ); |
|
| 3532 | if (is_array($fieldConfig['search'])) { |
|
| 3533 | $searchConfig = $fieldConfig['search']; |
|
| 3534 | if (in_array('case', $searchConfig)) { |
|
| 3535 | // Replace case insensitive default constraint |
|
| 3536 | $searchConstraint = $expressionBuilder->andX($expressionBuilder->like($fieldName, $like)); |
|
| 3537 | } |
|
| 3538 | if (in_array('pidonly', $searchConfig) && $currentPid > 0) { |
|
| 3539 | $searchConstraint->add($expressionBuilder->eq($tablePidField, (int)$currentPid)); |
|
| 3540 | } |
|
| 3541 | if ($searchConfig['andWhere']) { |
|
| 3542 | $searchConstraint->add( |
|
| 3543 | QueryHelper::stripLogicalOperatorPrefix($fieldConfig['search']['andWhere']) |
|
| 3544 | ); |
|
| 3545 | } |
|
| 3546 | } |
|
| 3547 | if ($fieldType === 'text' |
|
| 3548 | || $fieldType === 'flex' |
|
| 3549 | || $fieldType === 'input' && (!$evalRules || !preg_match('/date|time|int/', $evalRules)) |
|
| 3550 | ) { |
|
| 3551 | if ($searchConstraint->count() !== 0) { |
|
| 3552 | $constraints[] = $searchConstraint; |
|
| 3553 | } |
|
| 3554 | } |
|
| 3555 | } |
|
| 3556 | } |
|
| 3557 | // If no search field conditions have been build ensure no results are returned |
|
| 3558 | if (empty($constraints)) { |
|
| 3559 | return '0=1'; |
|
| 3560 | } |
|
| 3561 | ||
| 3562 | return $expressionBuilder->orX(...$constraints); |
|
| 3563 | } |
|
| 3564 | ||
| 3565 | /** |
|
| 3566 | * Fetches a list of fields to use in the Backend search for the given table. |
|
| @@ 3342-3434 (lines=93) @@ | ||
| 3339 | * @param int $currentPid Page id for the possible search limit. -1 only if called from an old XCLASS. |
|
| 3340 | * @return string Returns part of WHERE-clause for searching, if applicable. |
|
| 3341 | */ |
|
| 3342 | public function makeSearchString($table, $currentPid = -1) |
|
| 3343 | { |
|
| 3344 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); |
|
| 3345 | $expressionBuilder = $queryBuilder->expr(); |
|
| 3346 | $constraints = []; |
|
| 3347 | $currentPid = (int)$currentPid; |
|
| 3348 | $tablePidField = $table === 'pages' ? 'uid' : 'pid'; |
|
| 3349 | // Make query, only if table is valid and a search string is actually defined: |
|
| 3350 | if (empty($this->searchString)) { |
|
| 3351 | return ''; |
|
| 3352 | } |
|
| 3353 | ||
| 3354 | $searchableFields = $this->getSearchFields($table); |
|
| 3355 | if (empty($searchableFields)) { |
|
| 3356 | return ''; |
|
| 3357 | } |
|
| 3358 | if (MathUtility::canBeInterpretedAsInteger($this->searchString)) { |
|
| 3359 | $constraints[] = $expressionBuilder->eq('uid', (int)$this->searchString); |
|
| 3360 | foreach ($searchableFields as $fieldName) { |
|
| 3361 | if (!isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) { |
|
| 3362 | continue; |
|
| 3363 | } |
|
| 3364 | $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']; |
|
| 3365 | $fieldType = $fieldConfig['type']; |
|
| 3366 | $evalRules = $fieldConfig['eval'] ?: ''; |
|
| 3367 | if ($fieldType === 'input' && $evalRules && GeneralUtility::inList($evalRules, 'int')) { |
|
| 3368 | if (is_array($fieldConfig['search']) |
|
| 3369 | && in_array('pidonly', $fieldConfig['search'], true) |
|
| 3370 | && $currentPid > 0 |
|
| 3371 | ) { |
|
| 3372 | $constraints[] = $expressionBuilder->andX( |
|
| 3373 | $expressionBuilder->eq($fieldName, (int)$this->searchString), |
|
| 3374 | $expressionBuilder->eq($tablePidField, (int)$currentPid) |
|
| 3375 | ); |
|
| 3376 | } |
|
| 3377 | } elseif ($fieldType === 'text' |
|
| 3378 | || $fieldType === 'flex' |
|
| 3379 | || ($fieldType === 'input' && (!$evalRules || !preg_match('/date|time|int/', $evalRules))) |
|
| 3380 | ) { |
|
| 3381 | $constraints[] = $expressionBuilder->like( |
|
| 3382 | $fieldName, |
|
| 3383 | $queryBuilder->quote('%' . (int)$this->searchString . '%') |
|
| 3384 | ); |
|
| 3385 | } |
|
| 3386 | } |
|
| 3387 | } else { |
|
| 3388 | $like = $queryBuilder->quote('%' . $queryBuilder->escapeLikeWildcards($this->searchString) . '%'); |
|
| 3389 | foreach ($searchableFields as $fieldName) { |
|
| 3390 | if (!isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) { |
|
| 3391 | continue; |
|
| 3392 | } |
|
| 3393 | $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']; |
|
| 3394 | $fieldType = $fieldConfig['type']; |
|
| 3395 | $evalRules = $fieldConfig['eval'] ?: ''; |
|
| 3396 | $searchConstraint = $expressionBuilder->andX( |
|
| 3397 | $expressionBuilder->comparison( |
|
| 3398 | 'LOWER(' . $queryBuilder->quoteIdentifier($fieldName) . ')', |
|
| 3399 | 'LIKE', |
|
| 3400 | 'LOWER(' . $like . ')' |
|
| 3401 | ) |
|
| 3402 | ); |
|
| 3403 | if (is_array($fieldConfig['search'])) { |
|
| 3404 | $searchConfig = $fieldConfig['search']; |
|
| 3405 | if (in_array('case', $searchConfig)) { |
|
| 3406 | // Replace case insensitive default constraint |
|
| 3407 | $searchConstraint = $expressionBuilder->andX($expressionBuilder->like($fieldName, $like)); |
|
| 3408 | } |
|
| 3409 | if (in_array('pidonly', $searchConfig) && $currentPid > 0) { |
|
| 3410 | $searchConstraint->add($expressionBuilder->eq($tablePidField, (int)$currentPid)); |
|
| 3411 | } |
|
| 3412 | if ($searchConfig['andWhere']) { |
|
| 3413 | $searchConstraint->add( |
|
| 3414 | QueryHelper::stripLogicalOperatorPrefix($fieldConfig['search']['andWhere']) |
|
| 3415 | ); |
|
| 3416 | } |
|
| 3417 | } |
|
| 3418 | if ($fieldType === 'text' |
|
| 3419 | || $fieldType === 'flex' |
|
| 3420 | || $fieldType === 'input' && (!$evalRules || !preg_match('/date|time|int/', $evalRules)) |
|
| 3421 | ) { |
|
| 3422 | if ($searchConstraint->count() !== 0) { |
|
| 3423 | $constraints[] = $searchConstraint; |
|
| 3424 | } |
|
| 3425 | } |
|
| 3426 | } |
|
| 3427 | } |
|
| 3428 | // If no search field conditions have been build ensure no results are returned |
|
| 3429 | if (empty($constraints)) { |
|
| 3430 | return '0=1'; |
|
| 3431 | } |
|
| 3432 | ||
| 3433 | return $expressionBuilder->orX(...$constraints); |
|
| 3434 | } |
|
| 3435 | ||
| 3436 | /** |
|
| 3437 | * Fetches a list of fields to use in the Backend search for the given table. |
|