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