diff --git a/CHANGELOG.md b/CHANGELOG.md index c415592..8b57a6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 5b186aa..b6e569b 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/core/components/dynamicdropdowntv/docs/changelog.txt b/core/components/dynamicdropdowntv/docs/changelog.txt index c415592..8b57a6f 100644 --- a/core/components/dynamicdropdowntv/docs/changelog.txt +++ b/core/components/dynamicdropdowntv/docs/changelog.txt @@ -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 diff --git a/core/components/dynamicdropdowntv/docs/readme.txt b/core/components/dynamicdropdowntv/docs/readme.txt index 0a61266..ec539db 100644 --- a/core/components/dynamicdropdowntv/docs/readme.txt +++ b/core/components/dynamicdropdowntv/docs/readme.txt @@ -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 ················································································ diff --git a/core/components/dynamicdropdowntv/processors/mgr/default/getelements.default.php b/core/components/dynamicdropdowntv/processors/mgr/default/getelements.default.php index 84a9946..66843ee 100644 --- a/core/components/dynamicdropdowntv/processors/mgr/default/getelements.default.php +++ b/core/components/dynamicdropdowntv/processors/mgr/default/getelements.default.php @@ -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]);