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

Commit

Permalink
Update to 2.0.3
Browse files Browse the repository at this point in the history
- Snippet: `where` parameter
  • Loading branch information
Jako committed Nov 18, 2014
1 parent 0a4449e commit 7190b9b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
3 changes: 3 additions & 0 deletions HISTORY.md
@@ -1,5 +1,8 @@
History
================================================================================
- 2.0.3 November 18, 2014
- Snippet: `where` parameter

- 2.0.2 October 10, 2014
- Module: richtext is now possible

Expand Down
70 changes: 69 additions & 1 deletion assets/tvs/multitv/includes/multitv.class.php
Expand Up @@ -915,6 +915,74 @@ function getMultiValue($params)
return $tvOutput;
}

function filterMultiValue($tvOutput, $params)
{
foreach ($params['where'] as $fieldclause => $value) {
$fieldclause = explode(':', $fieldclause, 2);
$fieldname = $fieldclause[0];
$fieldclause = (count($fieldclause) == 1) ? '' : $fieldclause[1];
switch (htmlspecialchars_decode($fieldclause)) {
case '':
foreach ($tvOutput as $tvKey => $tvOut) {
if ($tvOut[$fieldname] != $value) {
unset($tvOutput[$tvKey]);
}
}
break;
case '!=':
foreach ($tvOutput as $tvKey => $tvOut) {
if ($tvOut[$fieldname] == $value) {
unset($tvOutput[$tvKey]);
}
}
break;
case '>':
foreach ($tvOutput as $tvKey => $tvOut) {
if ($tvOut[$fieldname] <= $value) {
unset($tvOutput[$tvKey]);
}
}
break;
case '<':
foreach ($tvOutput as $tvKey => $tvOut) {
if ($tvOut[$fieldname] >= $value) {
unset($tvOutput[$tvKey]);
}
}
break;
case '>=':
foreach ($tvOutput as $tvKey => $tvOut) {
if ($tvOut[$fieldname] < $value) {
unset($tvOutput[$tvKey]);
}
}
break;
case '<=':
foreach ($tvOutput as $tvKey => $tvOut) {
if ($tvOut[$fieldname] > $value) {
unset($tvOutput[$tvKey]);
}
}
break;
case 'LIKE':
foreach ($tvOutput as $tvKey => $tvOut) {
if (strpos($tvOut[$fieldname], $value) === false) {
unset($tvOutput[$tvKey]);
}
}
break;
case 'NOT LIKE':
foreach ($tvOutput as $tvKey => $tvOut) {
if (strpos($tvOut[$fieldname], $value) !== false) {
unset($tvOutput[$tvKey]);
}
}
break;
}
}
return $tvOutput;
}

function displayMultiValue($tvOutput, $params)
{
// replace masked placeholder tags (for templates that are set directly set in snippet call by @CODE)
Expand All @@ -926,7 +994,7 @@ function displayMultiValue($tvOutput, $params)
$firstEmpty = true;
if ($countOutput) {
// check for first item empty
foreach ($tvOutput[0] as $value) {
foreach (current($tvOutput) as $value) {
if ($value != '') {
$firstEmpty = false;
}
Expand Down
4 changes: 4 additions & 0 deletions assets/tvs/multitv/multitv.snippet.php
Expand Up @@ -79,10 +79,14 @@
$params['paginate'] = (isset($paginate) && $paginate) ? true : false;
$params['offsetKey'] = (isset($offsetKey)) ? $offsetKey : 'page';
$params['offset'] = ($params['paginate'] && ($params['display'] != 'all') && isset($_GET[$params['offsetKey']])) ? (intval($_GET[$params['offsetKey']]) - 1) * $params['display'] : $params['offset'];
$params['where'] = isset($where) ? json_decode($where, true) : false;

if (!empty($fromJson)) {
$tvOutput = json_decode($fromJson, true);
} else {
$tvOutput = $multiTV->getMultiValue($params);
}
if ($params['where']) {
$tvOutput = $multiTV->filterMultiValue($tvOutput, $params);
}
return $multiTV->displayMultiValue($tvOutput, $params);
2 changes: 1 addition & 1 deletion install/assets/modules/multiTV.tpl
Expand Up @@ -5,7 +5,7 @@
* CRUD module
*
* @category snippet, module, tv
* @version 2.0.1
* @version 2.0.3
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
* @author Jako
* @internal @properties &configs=Configurations;text;event_log
Expand Down
2 changes: 1 addition & 1 deletion install/assets/snippets/multiTV.tpl
Expand Up @@ -5,7 +5,7 @@
* Custom Template Variabe containing a sortable multi item list or a datatable
*
* @category snippet, tv
* @version 2.0.1
* @version 2.0.3
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
* @author Jako
* @internal @modx_category Content
Expand Down

0 comments on commit 7190b9b

Please sign in to comment.