id: 84 name: listCalcs description: 'Snippet to list Calcs and Dims for each Calcform' category: knit snippet: "/**\n * listCalcs snippet for knit extra\n *\n * Copyright 2021 by Iris Hammer iris.hammer@justknit.de\n * Created on 10-18-2021\n *\n * knit is free software; you can redistribute it and/or modify it under the\n * terms of the GNU General Public License as published by the Free Software\n * Foundation; either version 2 of the License, or (at your option) any later\n * version.\n *\n * knit is distributed in the hope that it will be useful, but WITHOUT ANY\n * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n * A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License along with\n * knit; if not, write to the Free Software Foundation, Inc., 59 Temple\n * Place, Suite 330, Boston, MA 02111-1307 USA\n *\n * @package knit\n */\n\n/**\n * Description\n * -----------\n * Snippet to list Calcs and Dims for each Calcform\n *\n * Variables\n * ---------\n * @var $modx modX\n * @var $scriptProperties array\n *\n * @package knit\n **/\n\n$knit = $modx->getService('knit','Knit',$modx->getOption('knit.core_path',null,$modx->getOption('core_path').'components/knit/').'model/knit/',$scriptProperties);\nif (!($knit instanceof Knit)) return '';\n\n/* setup default properties */\n$tpl = $modx->getOption('tpl',$scriptProperties,'rowTpl');\n$user = $modx->getOption('user',$scriptProperties,$modx->user->get('id'));\n$res = $modx->getOption('res',$scriptProperties,$modx->resource->get('id'));\n$sort = $modx->getOption('sort',$scriptProperties,'editedon');\n$dir = $modx->getOption('dir',$scriptProperties,'ASC');\n//$url = $_GET['url'];\n$url = $modx->resource->get('id');\n\n//$calcs = $modx->getCollection('JustKnitCalcs');\n\n\n$c = $modx->newQuery('JustKnitCalcs');\n$c->sortby($sort,$dir);\n$c->where([\n 'ressource_id' => $res,\n 'ccreatedby' => $user,\n]);\n$calcs = $modx->getCollection('JustKnitCalcs',$c);\n//$makeurl = $modx->makeUrl(25, '', 'cid=world');\n$output = '';\n\n//$output = count($subscribers);\nforeach ($calcs as $calc) {\n $calcArr = $calc->toArray();\n// $calcArr['testurl'] = $modx->makeUrl($url, '', array('cid' => $calc->get('id')), 'full');\n $output .= $knit->getChunk($tpl,$calcArr);\n}\n\n\n//$output = count($subscribers);\nreturn $output;" properties: 'a:0:{}' static: 1 static_file: core/components/knit/elements/snippets/listcalcs.snippet.php ----- /** * listCalcs snippet for knit extra * * Copyright 2021 by Iris Hammer iris.hammer@justknit.de * Created on 10-18-2021 * * knit 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. * * knit 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 * knit; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA * * @package knit */ /** * Description * ----------- * Snippet to list Calcs and Dims for each Calcform * * Variables * --------- * @var $modx modX * @var $scriptProperties array * * @package knit **/ $knit = $modx->getService('knit','Knit',$modx->getOption('knit.core_path',null,$modx->getOption('core_path').'components/knit/').'model/knit/',$scriptProperties); if (!($knit instanceof Knit)) return ''; /* setup default properties */ $tpl = $modx->getOption('tpl',$scriptProperties,'rowTpl'); $user = $modx->getOption('user',$scriptProperties,$modx->user->get('id')); $res = $modx->getOption('res',$scriptProperties,$modx->resource->get('id')); $sort = $modx->getOption('sort',$scriptProperties,'editedon'); $dir = $modx->getOption('dir',$scriptProperties,'ASC'); //$url = $_GET['url']; $url = $modx->resource->get('id'); //$calcs = $modx->getCollection('JustKnitCalcs'); $c = $modx->newQuery('JustKnitCalcs'); $c->sortby($sort,$dir); $c->where([ 'ressource_id' => $res, 'ccreatedby' => $user, ]); $calcs = $modx->getCollection('JustKnitCalcs',$c); //$makeurl = $modx->makeUrl(25, '', 'cid=world'); $output = ''; //$output = count($subscribers); foreach ($calcs as $calc) { $calcArr = $calc->toArray(); // $calcArr['testurl'] = $modx->makeUrl($url, '', array('cid' => $calc->get('id')), 'full'); $output .= $knit->getChunk($tpl,$calcArr); } //$output = count($subscribers); return $output;