Skip to content
This repository was archived by the owner on Nov 21, 2017. It is now read-only.

Commit 7190b9b

Browse files
committed
Update to 2.0.3
- Snippet: `where` parameter
1 parent 0a4449e commit 7190b9b

5 files changed

Lines changed: 78 additions & 3 deletions

File tree

HISTORY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
History
22
================================================================================
3+
- 2.0.3 November 18, 2014
4+
- Snippet: `where` parameter
5+
36
- 2.0.2 October 10, 2014
47
- Module: richtext is now possible
58

assets/tvs/multitv/includes/multitv.class.php

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,74 @@ function getMultiValue($params)
915915
return $tvOutput;
916916
}
917917

918+
function filterMultiValue($tvOutput, $params)
919+
{
920+
foreach ($params['where'] as $fieldclause => $value) {
921+
$fieldclause = explode(':', $fieldclause, 2);
922+
$fieldname = $fieldclause[0];
923+
$fieldclause = (count($fieldclause) == 1) ? '' : $fieldclause[1];
924+
switch (htmlspecialchars_decode($fieldclause)) {
925+
case '':
926+
foreach ($tvOutput as $tvKey => $tvOut) {
927+
if ($tvOut[$fieldname] != $value) {
928+
unset($tvOutput[$tvKey]);
929+
}
930+
}
931+
break;
932+
case '!=':
933+
foreach ($tvOutput as $tvKey => $tvOut) {
934+
if ($tvOut[$fieldname] == $value) {
935+
unset($tvOutput[$tvKey]);
936+
}
937+
}
938+
break;
939+
case '>':
940+
foreach ($tvOutput as $tvKey => $tvOut) {
941+
if ($tvOut[$fieldname] <= $value) {
942+
unset($tvOutput[$tvKey]);
943+
}
944+
}
945+
break;
946+
case '<':
947+
foreach ($tvOutput as $tvKey => $tvOut) {
948+
if ($tvOut[$fieldname] >= $value) {
949+
unset($tvOutput[$tvKey]);
950+
}
951+
}
952+
break;
953+
case '>=':
954+
foreach ($tvOutput as $tvKey => $tvOut) {
955+
if ($tvOut[$fieldname] < $value) {
956+
unset($tvOutput[$tvKey]);
957+
}
958+
}
959+
break;
960+
case '<=':
961+
foreach ($tvOutput as $tvKey => $tvOut) {
962+
if ($tvOut[$fieldname] > $value) {
963+
unset($tvOutput[$tvKey]);
964+
}
965+
}
966+
break;
967+
case 'LIKE':
968+
foreach ($tvOutput as $tvKey => $tvOut) {
969+
if (strpos($tvOut[$fieldname], $value) === false) {
970+
unset($tvOutput[$tvKey]);
971+
}
972+
}
973+
break;
974+
case 'NOT LIKE':
975+
foreach ($tvOutput as $tvKey => $tvOut) {
976+
if (strpos($tvOut[$fieldname], $value) !== false) {
977+
unset($tvOutput[$tvKey]);
978+
}
979+
}
980+
break;
981+
}
982+
}
983+
return $tvOutput;
984+
}
985+
918986
function displayMultiValue($tvOutput, $params)
919987
{
920988
// replace masked placeholder tags (for templates that are set directly set in snippet call by @CODE)
@@ -926,7 +994,7 @@ function displayMultiValue($tvOutput, $params)
926994
$firstEmpty = true;
927995
if ($countOutput) {
928996
// check for first item empty
929-
foreach ($tvOutput[0] as $value) {
997+
foreach (current($tvOutput) as $value) {
930998
if ($value != '') {
931999
$firstEmpty = false;
9321000
}

assets/tvs/multitv/multitv.snippet.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@
7979
$params['paginate'] = (isset($paginate) && $paginate) ? true : false;
8080
$params['offsetKey'] = (isset($offsetKey)) ? $offsetKey : 'page';
8181
$params['offset'] = ($params['paginate'] && ($params['display'] != 'all') && isset($_GET[$params['offsetKey']])) ? (intval($_GET[$params['offsetKey']]) - 1) * $params['display'] : $params['offset'];
82+
$params['where'] = isset($where) ? json_decode($where, true) : false;
8283

8384
if (!empty($fromJson)) {
8485
$tvOutput = json_decode($fromJson, true);
8586
} else {
8687
$tvOutput = $multiTV->getMultiValue($params);
8788
}
89+
if ($params['where']) {
90+
$tvOutput = $multiTV->filterMultiValue($tvOutput, $params);
91+
}
8892
return $multiTV->displayMultiValue($tvOutput, $params);

install/assets/modules/multiTV.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* CRUD module
66
*
77
* @category snippet, module, tv
8-
* @version 2.0.1
8+
* @version 2.0.3
99
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
1010
* @author Jako
1111
* @internal @properties &configs=Configurations;text;event_log

install/assets/snippets/multiTV.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Custom Template Variabe containing a sortable multi item list or a datatable
66
*
77
* @category snippet, tv
8-
* @version 2.0.1
8+
* @version 2.0.3
99
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
1010
* @author Jako
1111
* @internal @modx_category Content

0 commit comments

Comments
 (0)