7d2594d3eba991d2d52e8021b243290356fd844f
[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 // Initialize field array:
58 $sfields = array();
59 $or = '';
60 // add the uid only if input is numeric, cast to int
61 if (is_numeric($this->searchString)) {
62 $queryPart = ' AND (uid=' . (int) $this->searchString . ' OR ';
63 } else {
64 $queryPart = ' AND (';
65 }
66 if ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8')) {
67 foreach ($GLOBALS['TCA'][$table]['columns'] as $fieldName => $info) {
68 if ($GLOBALS['TYPO3_DB']->cache_fieldType[$table][$fieldName]['metaType'] === 'B') {
69
70 } elseif ($info['config']['type'] === 'text' || $info['config']['type'] === 'input' && !preg_match('/date|time|int/', $info['config']['eval'])) {
71 $queryPart .= $or . $fieldName . ' LIKE \'%' . $GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table) . '%\'';
72 $or = ' OR ';
73 }
74 }
75 } else {
76 // Traverse the configured columns and add all columns that can be searched
77 foreach ($GLOBALS['TCA'][$table]['columns'] as $fieldName => $info) {
78 if ($info['config']['type'] === 'text' || $info['config']['type'] === 'input' && !preg_match('/date|time|int/', $info['config']['eval'])) {
79 $sfields[] = $fieldName;
80 }
81 }
82 // If search-fields were defined (and there always are) we create the query:
83 if (count($sfields)) {
84 $like = ' LIKE \'%' . $GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table) . '%\'';
85 // Free-text
86 $queryPart .= implode(($like . ' OR '), $sfields) . $like;
87 }
88 }
89 // Return query:
90 return $queryPart . ')';
91 }
92 }
93
94 }
95
96
97 ?>