Revert "[TASK] Remove loadTCA calls"
[Packages/TYPO3.CMS.git] / typo3 / sysext / dbal / Classes / RecordList / DatabaseRecordList.php
1 <?php
2 namespace TYPO3\CMS\Dbal\RecordList;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2009 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * (c) 2006-2009 Karsten Dambekalns <karsten@typo3.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Include file extending localRecordList for DBAL compatibility
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 * @author Karsten Dambekalns <k.dambekalns@fishfarm.de>
35 */
36 /**
37 * Child class for rendering of Web > List (not the final class. see class.db_list_extra)
38 *
39 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
40 * @author Karsten Dambekalns <k.dambekalns@fishfarm.de>
41 */
42 class DatabaseRecordList extends \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList {
43
44 /**
45 * Creates part of query for searching after a word ($this->searchString) fields in input table
46 *
47 * DBAL specific: no LIKE for numeric fields, in this case "uid" (breaks on Oracle)
48 * no LIKE for BLOB fields, skip
49 *
50 * @param string Table, in which the fields are being searched.
51 * @return string Returns part of WHERE-clause for searching, if applicable.
52 * @todo Define visibility
53 */
54 public function makeSearchString($table) {
55 // Make query, only if table is valid and a search string is actually defined:
56 if ($GLOBALS['TCA'][$table] && $this->searchString) {
57 // Loading full table description - we need to traverse fields:
58 \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA($table);
59 // Initialize field array:
60 $sfields = array();
61 $or = '';
62 // add the uid only if input is numeric, cast to int
63 if (is_numeric($this->searchString)) {
64 $queryPart = ' AND (uid=' . (int) $this->searchString . ' OR ';
65 } else {
66 $queryPart = ' AND (';
67 }
68 if ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8')) {
69 foreach ($GLOBALS['TCA'][$table]['columns'] as $fieldName => $info) {
70 if ($GLOBALS['TYPO3_DB']->cache_fieldType[$table][$fieldName]['metaType'] === 'B') {
71
72 } elseif ($info['config']['type'] === 'text' || $info['config']['type'] === 'input' && !preg_match('/date|time|int/', $info['config']['eval'])) {
73 $queryPart .= $or . $fieldName . ' LIKE \'%' . $GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table) . '%\'';
74 $or = ' OR ';
75 }
76 }
77 } else {
78 // Traverse the configured columns and add all columns that can be searched
79 foreach ($GLOBALS['TCA'][$table]['columns'] as $fieldName => $info) {
80 if ($info['config']['type'] === 'text' || $info['config']['type'] === 'input' && !preg_match('/date|time|int/', $info['config']['eval'])) {
81 $sfields[] = $fieldName;
82 }
83 }
84 // If search-fields were defined (and there always are) we create the query:
85 if (count($sfields)) {
86 $like = ' LIKE \'%' . $GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table) . '%\'';
87 // Free-text
88 $queryPart .= implode(($like . ' OR '), $sfields) . $like;
89 }
90 }
91 // Return query:
92 return $queryPart . ')';
93 }
94 }
95
96 }
97
98
99 ?>