Skip to content

Commit a47b5a2

Browse files
committed
Dev: Adding basic support for ColumnControl's searchDateTime mask option
Dev: Correct return type for Editor->Field()
1 parent f0e1a08 commit a47b5a2

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

Database/Query.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ public function bind($name, $value, $type = null)
276276
return $this;
277277
}
278278

279+
/**
280+
* Generate a unique name for binding values.
281+
*
282+
* @return string Name
283+
*/
284+
public function bindName()
285+
{
286+
return ':binding_' . count($this->_bindings);
287+
}
288+
279289
/**
280290
* Get the Database host for this query instance.
281291
*

Editor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public function debug($_ = null, $path = null)
322322
* * `array` - An array of {@see Field} instances to add to the list
323323
* of fields.
324324
*
325-
* @return ($_ is null ? ($_ is string ? Field : Field[]) : $this) The selected field, an array of fields, depending on the input parameter.
325+
* @return ($_ is null ? Field[] : ($_ is string ? Field : $this)) The selected field, an array of fields, depending on the input parameter.
326326
*
327327
* @see {@see Field} for field documentation.
328328
*/

Editor/ColumnControl.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function ssp(&$editor, &$query, $http)
3333
if ($type === 'num') {
3434
self::_sspNumber($query, $field, $value, $logic);
3535
} elseif ($type === 'date') {
36-
self::_sspDate($query, $field, $value, $logic);
36+
self::_sspDate($query, $field, $value, $logic, $search['mask']);
3737
} else {
3838
self::_sspText($query, $field, $value, $logic);
3939
}
@@ -57,8 +57,24 @@ public static function ssp(&$editor, &$query, $http)
5757
* @param string $value Search term
5858
* @param string $logic Search logic
5959
*/
60-
private static function _sspDate(&$query, $field, $value, $logic)
60+
private static function _sspDate(&$query, $field, $value, $logic, $mask)
6161
{
62+
$bindingName = $query->bindName();
63+
$dbField = $field->dbField();
64+
$search = $bindingName;
65+
66+
// Only support date and time masks. This departs from the client side which allows
67+
// any component in the date/time to be masked out.
68+
if ($mask === 'YYYY-MM-DD') {
69+
$dbField = 'DATE(' . $dbField . ')';
70+
$search = 'DATE(' . $bindingName . ')';
71+
} elseif ($mask === 'hh:mm:ss') {
72+
$dbField = 'TIME(' . $dbField . ')';
73+
$search = 'TIME(' . $bindingName . ')';
74+
} else {
75+
$search = '(' . $bindingName . ')';
76+
}
77+
6278
if ($logic === 'empty') {
6379
$query->where($field->dbField(), null);
6480
} elseif ($logic === 'notEmpty') {
@@ -67,13 +83,21 @@ private static function _sspDate(&$query, $field, $value, $logic)
6783
// Empty search value means no search for the other logic operators
6884
return;
6985
} elseif ($logic === 'equal') {
70-
$query->where($field->dbField(), $value);
86+
$query
87+
->where($dbField, $search, '=', false)
88+
->bind($bindingName, $value);
7189
} elseif ($logic === 'notEqual') {
72-
$query->where($field->dbField(), $value, '!=');
90+
$query
91+
->where($dbField, $search, '!=', false)
92+
->bind($bindingName, $value);
7393
} elseif ($logic === 'greater') {
74-
$query->where($field->dbField(), $value, '>');
94+
$query
95+
->where($dbField, $search, '>', false)
96+
->bind($bindingName, $value);
7597
} elseif ($logic === 'less') {
76-
$query->where($field->dbField(), $value, '<');
98+
$query
99+
->where($dbField, $search, '<', false)
100+
->bind($bindingName, $value);
77101
}
78102
}
79103

0 commit comments

Comments
 (0)