Repository navigation
Expand file tree
/
Copy pathMultiGrid.snippet.php
More file actions
66 lines (58 loc) · 2.36 KB
/
Copy pathMultiGrid.snippet.php
File metadata and controls
66 lines (58 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* MultiGrid
* @category snippet
* @version 1.2
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
* @author Jako (thomas.jakobi@partout.info)
* Modifications by sam (sam@gmx-topmail.de)
*
* @internal @description: <strong>1.2</strong> Transform template variables into a table/grid.
* @internal @snippet code: return include(MODX_BASE_PATH.'assets/plugins/multigrid/MultiGrid.snippet.php');
*/
if (MODX_BASE_PATH == '') {
die('<h1>ERROR:</h1><p>Please use do not access this file directly.</p>');
}
// snippet parameter
$tvName = isset($tvName) ? $tvName : '';
$docid = isset($docid) ? $docid : $modx->documentObject['id'];
$columnNames = isset($columnNames) ? $columnNames : 'key,value';
$outerTpl = isset($outerTpl) ? $outerTpl : '@CODE:<select name="'.$tvName.'">[+wrapper+]</select>';
$rowTpl = isset($rowTpl) ? $rowTpl : '@CODE:<option value="[+value+]">[+key+]</option>';
$pluginPath = isset($pluginPath) ? trim($pluginPath, '/').'/' : 'assets/plugins/multigrid/';
$config = isset($config) ? $config : '';
// snippet code
if ($config != '') {
$settings = array();
include (MODX_BASE_PATH.$pluginPath."configs/".trim($config).'.config.inc.php');
$columnNames = (isset($settings['columnNames']) && $settings['columnNames'] != '') ? $settings['columnNames'] : $columnNames;
}
$maskedTags = array('(('=>'[+', '))'=>'+]', '{+'=>'[+', '+}'=>'+]');
$outerTpl = str_replace(array_keys($maskedTags), array_values($maskedTags), $outerTpl);
$rowTpl = str_replace(array_keys($maskedTags), array_values($maskedTags), $rowTpl);
$columns = explode(',', $columnNames);
$columnCount = count($columns);
$tvOutput = $modx->getTemplateVarOutput(array($tvName), $docid);
$tvOutput = $tvOutput[$tvName];
$tvOutput = json_decode($tvOutput);
// stop if there is no output
if (!count($tvOutput))
return;
// parse the output chunks
if (!class_exists('gridChunkie')) {
include (MODX_BASE_PATH.$pluginPath.'/includes/chunkie.class.inc.php');
}
$wrapper = '';
foreach ($tvOutput as $num => $value) {
$parser = new gridChunkie($rowTpl);
for ($i = 0; $i < $columnCount; $i++) {
$parser->AddVar($columns[$i], $value[$i]);
}
$parser->AddVar('num', $num);
$wrapper .= $parser->Render();
}
$parser = new gridChunkie($outerTpl);
$parser->AddVar('wrapper', $wrapper);
$output = $parser->Render();
return $output;
?>