1 <?php
2 /**
3 * @package FrameworkOnFramework
4 * @subpackage model
5 * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE.txt
7 */
8 // Protect from unauthorized access
9 defined('FOF_INCLUDED') or die;
10
11 /**
12 * FrameworkOnFramework model behavior class
13 *
14 * @package FrameworkOnFramework
15 * @since 2.1
16 */
17 class FOFModelFieldText extends FOFModelField
18 {
19 /**
20 * Constructor
21 *
22 * @param FOFDatabaseDriver $db The database object
23 * @param object $field The field informations as taken from the db
24 */
25 public function __construct($db, $field, $table_alias = false)
26 {
27 parent::__construct($db, $field, $table_alias);
28
29 $this->null_value = '';
30 }
31
32 /**
33 * Returns the default search method for this field.
34 *
35 * @return string
36 */
37 public function getDefaultSearchMethod()
38 {
39 return 'partial';
40 }
41
42 /**
43 * Perform a partial match (search in string)
44 *
45 * @param mixed $value The value to compare to
46 *
47 * @return string The SQL where clause for this search
48 */
49 public function partial($value)
50 {
51 if ($this->isEmpty($value))
52 {
53 return '';
54 }
55
56 return '(' . $this->getFieldName() . ' LIKE ' . $this->_db->quote('%' . $value . '%') . ')';
57 }
58
59 /**
60 * Perform an exact match (match string)
61 *
62 * @param mixed $value The value to compare to
63 *
64 * @return string The SQL where clause for this search
65 */
66 public function exact($value)
67 {
68 if ($this->isEmpty($value))
69 {
70 return '';
71 }
72
73 return '(' . $this->getFieldName() . ' LIKE ' . $this->_db->quote($value) . ')';
74 }
75
76 /**
77 * Dummy method; this search makes no sense for text fields
78 *
79 * @param mixed $from Ignored
80 * @param mixed $to Ignored
81 * @param boolean $include Ignored
82 *
83 * @return string Empty string
84 */
85 public function between($from, $to, $include = true)
86 {
87 return '';
88 }
89
90 /**
91 * Dummy method; this search makes no sense for text fields
92 *
93 * @param mixed $from Ignored
94 * @param mixed $to Ignored
95 * @param boolean $include Ignored
96 *
97 * @return string Empty string
98 */
99 public function outside($from, $to, $include = false)
100 {
101 return '';
102 }
103
104 /**
105 * Dummy method; this search makes no sense for text fields
106 *
107 * @param mixed $value Ignored
108 * @param mixed $interval Ignored
109 * @param boolean $include Ignored
110 *
111 * @return string Empty string
112 */
113 public function interval($value, $interval, $include = true)
114 {
115 return '';
116 }
117
118 /**
119 * Dummy method; this search makes no sense for text fields
120 *
121 * @param mixed $from Ignored
122 * @param mixed $to Ignored
123 * @param boolean $include Ignored
124 *
125 * @return string Empty string
126 */
127 public function range($from, $to, $include = false)
128 {
129 return '';
130 }
131
132 /**
133 * Dummy method; this search makes no sense for text fields
134 *
135 * @param mixed $from Ignored
136 * @param mixed $to Ignored
137 * @param boolean $include Ignored
138 *
139 * @return string Empty string
140 */
141 public function modulo($from, $to, $include = false)
142 {
143 return '';
144 }
145 }
146