Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
================================================================================
- 1.3.1
- Added support for @-bindings (@CHUNK, @FILE, @SELECT) in Input Options Values field

- 1.3.0

- 1.2
- Checked/rewritten documentation
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ The format for the input option values is:

Creating a new line after the `##` is allowed.

##### @bindings

You can also use `@CHUNK`, `@SELECT` or `@FILE` bindings in the Input Option Values.
Example for the first dropdown:
`@CHUNK my_random_chunk_with_key_value_pairs`

For the child dropdown, you can combine multiple variants:
`Parentvalue1::@CHUNK key_values_for_Parentvalue1##Parentvalue2::plain==1||text==2||..##Parentvalue3::@SELECT name,id FROM mytable`

### Example 3: Individual processor usage

Create three Dynamic Dropdown template variables:
Expand Down
4 changes: 4 additions & 0 deletions core/components/dynamicdropdowntv/docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
================================================================================
- 1.3.1
- Added support for @-bindings (@CHUNK, @FILE, @SELECT) in Input Options Values field

- 1.3.0

- 1.2
- Checked/rewritten documentation
Expand Down
12 changes: 11 additions & 1 deletion core/components/dynamicdropdowntv/docs/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,23 @@ Input Options | Input Option Values | 1::TEST1a==1a||TEST1a==1a##2::TES

The names `dynamicX` and `dynamicGroup` are just examples and could be changed.

This example will add two dropdown select TVs, where you can different values. After selecting a value in the first TV dynamic0, the dropdown select of the second TV dynamic1 will show related values. If you select again a value in the first TV dynamic0 all children of this Dynamic Dropdown TV (dynamic1) will be reseted.
This example will add two dropdown select TVs, where you can select different values. After selecting a value in the first TV dynamic0, the dropdown select of the second TV dynamic1 will show related values. If you select again a value in the first TV dynamic0 all children of this Dynamic Dropdown TV (dynamic1) will be reseted.

The format for the input option values is:
`Parentvalue::Key==Value||…||Key==Value##Parentvalue::Key==Value||…||Key==Value`

Creating a new line after the `##` is allowed.

####@bindings

You can also use `@CHUNK`, `@SELECT` or `@FILE` bindings in the Input Option Values.
Example for the first dropdown:
`@CHUNK my_random_chunk_with_key_value_pairs`

For the child dropdown, you can combine multiple variants:
`Parentvalue1::@CHUNK key_values_for_Parentvalue1##Parentvalue2::plain==1||text==2||..##Parentvalue3::@SELECT name,id FROM mytable`


Example 3: Individual processor usage
················································································

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,55 @@
$elementValues = array();
$elements = explode('##', $elements);
foreach ($elements as $element) {
$element = explode('::', trim($element));
// Check for any binding in element string
$regex = '/(.*)@(\w+)\W+(\w.+)/';

if(preg_match($regex,$element,$mtch)) {
$prefix = $mtch[1];
$type = $mtch[2]; //binding type
$val = $mtch[3]; //binding value string
$el;

switch($type) {
case 'CHUNK':
$el = $modx->parseChunk($val,array());
break;
case 'FILE':
$el = file_get_contents($modx->config['base_path'] . $val);
break;
case 'SELECT':
$sql = 'SELECT '. $val;

$c = new xPDOCriteria($modx,$sql); // connect to the MODX DB
$rows = array();
if ($c->stmt && $c->stmt->execute())
{
while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC))
{
if(count($row) > 1) {
$rows[] = $row['name']."==".$row['id'];
} else {
$rows[] = $row['id'];
}
}
$el = implode('||',$rows);
break;
}
break;
/*
case 'INLINE':
$chunk = $modx->newObject('modChunk');
$chunk->setCacheable(false);
$elements = $chunk->process();
break;
*/
default:
break;
}
$element = $prefix . $el;
}

$element = explode('::', trim($element));
if (count($element) > 1) {
$key = trim($element[0]);
$values = explode('||', $element[1]);
Expand All @@ -49,15 +97,33 @@
}

$parent = $modx->getOption('parent', $inputProperties, '');
$parentValue = ($scriptProperties[$parent] != '') ? $scriptProperties[$parent] : '#ROOT#';
$elementValues = isset($elementValues[$parentValue]) ? $elementValues[$parentValue] : array();
$parentValue = (isset($scriptProperties[$parent]) && $scriptProperties[$parent] != '') ? $scriptProperties[$parent] : '#ROOT#';
$parentValue = ($parentValue == '#ROOT#') ? '#ROOT#' : explode('||', $parentValue);

if($parentValue != '#ROOT#' && count($parentValue) >= 1) {
$elementValues = array_intersect_key( $elementValues, array_flip( $parentValue ) ); //filter the array with parent key
} else {
$elementValues = isset($elementValues[$parentValue]) ? $elementValues[$parentValue] : array();
}

$options = array();
$count = 1;
$rows = array();

$options[] = array('id' => '', 'name' => $firstText);

$flat = array();
foreach($elementValues as $val) {
if(is_array($val)) {
foreach($val as $v) {
$flat[] = $v;
}
} else {
$flat[] = $val;
}
}
$elementValues = $flat;

$count += count($elementValues);
foreach ($elementValues as $elementValue) {
$elementValue = explode('==', $elementValue, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
$packageName = $modx->getOption('packagename', $inputProperties, '');
$prefix = $modx->getOption('prefix', $inputProperties, '');
$prefix = empty($prefix) ? null : $prefix;
$delimiter = $modx->getOption('valueDelimiter', $inputProperties, '||');

if (!empty($packageName)) {
$packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
Expand All @@ -70,7 +71,17 @@
$count = 1;

if (!empty($query)) {
$c->where(array($namefield . ':LIKE' => $query . '%'));
$qry = explode($delimiter, $query);
$num = true;
foreach($qry as $t) {
$num = ($num && is_numeric($t));
}

if($num) {
$c->where(array($idfield . ':IN' => $qry) );
} else {
$c->where(array($namefield . ':LIKE' => $query . '%'));
}
} else {
$options[] = array('id' => '', 'name' => $firstText);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* DynamicDropdownTV
*
* Copyright 2012-2013 by Bruno Perner <b.perner@gmx.de>
*
* DynamicDropdownTV is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option) any
* later version.
*
* DynamicDropdownTV is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* DynamicDropdownTV; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package dynamicdropdowntv
* @subpackage input render
*
* Input Render for DynamicDropdownTV Multiple
*/
if (!class_exists('DynamicDropdownMultipleInputRender')) {

class DynamicDropdownMultipleInputRender extends modTemplateVarInputRender {

public function getTemplate() {
$corePath = $this->modx->getOption('dynamicdropdowntv.core_path', null, $this->modx->getOption('core_path') . 'components/dynamicdropdowntv/');
return $corePath . 'tv/input/tpl/dynamicdropdown_mlti.tpl';
}

public function process($value, array $params = array()) {
$corePath = $this->modx->getOption('dynamicdropdowntv.core_path', null, $this->modx->getOption('core_path') . 'components/dynamicdropdowntv/');

// fetch only the tv lexicon
$this->modx->lexicon->load('tv_widget');
$this->modx->lexicon->load('dynamicdropdowntv:inputoptions');
$lang = $this->modx->lexicon->fetch();
foreach ($lang as $k => $v) {
if (strpos($k, 'dynamicdropdowntv.') !== false) {
$k = str_replace('dynamicdropdowntv.', '', $k);
$k = str_replace('.', '_', $k);
}
$this->setPlaceholder('lang_' . $k, $v);
}
$this->setPlaceholder('params', $params);

$resource = is_object($this->modx->resource) ? $this->modx->resource->toArray() : array();

$ddId = $this->tv->get('name');
$groupPath = 'mgr/' . $params['group'];
$defaultPath = 'mgr/default';
$actionPath = file_exists($corePath . 'processors/' . $groupPath) ? $groupPath . '/' : $defaultPath . '/';

if ($this->tv->get('elements') == '') {
$default_processor = 'getoptions.default';
$ddProcessor = 'getoptions.' . $ddId;
} else {
$default_processor = 'getelements.default';
$ddProcessor = 'getelements.' . $ddId;
}

$action = file_exists($corePath . 'processors/' . $actionPath . $ddProcessor . '.php') ? $actionPath . $ddProcessor : $actionPath . $default_processor;

$this->setPlaceholder('connector_path', "'" . $this->modx->getOption('dynamicdropdowntv.assets_path', NULL, "' + MODx.config.assets_url + 'components/dynamicdropdowntv/") . "connector.php'");
$this->setPlaceholder('resource', $resource);
$this->setPlaceholder('object_id', $this->modx->getOption('object_id', $_REQUEST, ''));
$this->setPlaceholder('params', $params);
$this->setPlaceholder('action', $action);
$this->setPlaceholder('children', $this->modx->toJson(explode(',', $params['childs'])));
$this->setPlaceholder('parents', $this->modx->toJson(explode(',', $params['parents'])));
$this->setPlaceholder('ddId', $ddId);
}

}

}
return 'DynamicDropdownMultipleInputRender';
Loading