id: 82 name: loadCalcs description: 'Snippet to get Data from Calcs and Dims for each Calcform' category: knit snippet: "/**\n * loadCalcs snippet for knit extra\n *\n * Copyright 2021 by Iris Hammer iris.hammer@justknit.de\n * Created on 10-14-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 get Data from Calcs and Dims for each Calcform\n *\n * Variables\n * ---------\n * @var $modx modX\n * @var $scriptProperties array\n *\n * @package knit\n **/\n// UserGroup for Permission of save/add Calcs\n$uG = $modx->getOption('uG', $scriptProperties, '', true);\n// RessourceId to find Calcs and Dims\n$resId = $modx->getOption('res', $scriptProperties, '', true);\n// UserId to check ownership\n$userId = $modx->getOption('user', $scriptProperties, '', true);\n// names of the Calcs\n$calcs = $modx->getOption('calcs', $scriptProperties, '[]', true);\n$calcs = !empty($calcs) ? explode(',', $calcs) : '[]';\n//$modx->log(modX::LOG_LEVEL_ERROR,'
$calcs' . print_r($calcs, 1) . '
');\n// names of the Dims\n$dims = $modx->getOption('dims', $scriptProperties, '[]', true);\n$dims = !empty($dims) ? explode(',', $dims) : '[]';\n//$modx->log(modX::LOG_LEVEL_ERROR,'
$dims' . print_r($dims, 1) . '
');\n$dims = array_map('trim', $dims);\n\n$cid = isset($_GET['cid']) && !empty($_GET['cid']) ? $_GET['cid'] : '';\n//$modx->log(modX::LOG_LEVEL_ERROR,'cid $_GET ' . $cid .'empty? '.empty($cid));\n//$modx->log(modX::LOG_LEVEL_ERROR,'
$dims trimmed' . print_r($dims, 1) . '
');\n//$patArray['pcreatedon'] = strftime('%Y-%m-%d %H:%M:%S',$patArray['pcreatedon'])\n$defaults = array(\n 'ressource_id' => $resId,\n 'ccreatedby' => $userId,\n 'calcedby' => $userId,\n 'ceditedby' => $userId,\n 'createdon' => strftime('%Y-%m-%d %H:%M:%S',time()),\n 'editedon' => strftime('%Y-%m-%d %H:%M:%S',time()),\n 'dtn_d' => '',\n);\n$kc = $modx->getService('knitcalculations','KnitCalculations',$modx->getOption('knit.core_path',null,$modx->getOption('core_path').'components/knit/').'model/knit/',$scriptProperties);\nif (!($kc instanceof KnitCalculations)) {\n $message = '[JustKnit] Could not load KnitCalculations class';\n $modx->log(modX::LOG_LEVEL_ERROR,$message);\n return false;\n}\n$language = $modx->getOption('language', $scriptProperties, '');\n$language = !empty($language)\n ? $language\n : $modx->getOption('cultureKey', NULL,\n $modx->getOption('manager_language', NULL, 'en'));\n$modx->lexicon->load($language . ':knit:calcs');\n$modx->lexicon->load($language . ':knit:default');\n//$modx->log(modX::LOG_LEVEL_ERROR,$modx->getOption('cultureKey'));\n//$modx->log(modX::LOG_LEVEL_ERROR,'Vor setPlchldFields');\n$setKnitChunks = $kc->setPlchldFields($scriptProperties,$cid);\n//$modx->log(modX::LOG_LEVEL_ERROR,'$setKnitChunks' .print_r($setKnitChunks, 1).'');\n$modx->log(modX::LOG_LEVEL_ERROR,'HURRAA! loadcalcs wird geladen');\n//$hook->setValues($setKnitChunks);\n\n\n// UserGroup == 4: Always load the one existing row of Calc\nif ($uG == 4) {\n $modx->log(modX::LOG_LEVEL_ERROR,'YESS! loadcalcs uG=4');\n $ca = $modx->getObject('JustKnitCalcs', ['ressource_id' => $resId,'ccreatedby' => $userId,]);\n $cid = is_object($ca) ? $ca->get('id') : '';\n $hook->setValue('cid', $cid);\n $calcfields = $kc->getCalcFields($scriptProperties,$cid);\n //$modx->log(modX::LOG_LEVEL_ERROR,'
' . print_r($calcfields, 1).'
'.$cid.' $calcs '.print_r($calcs, 1));\n foreach ($calcs as $calc => $cval) {\n if (is_object($ca)) {\n //$modx->log(modX::LOG_LEVEL_ERROR,'$calcfields[$cval_pattern_meta]: '.$calcfields[$cval.'_pattern_meta']);\n if (!is_null($calcfields[$cval.'_pattern_meta'])) {\n// $modx->log(modX::LOG_LEVEL_ERROR,'$calcfields[$cval_pattern_meta]: '.print_r(json_decode($calcfields[$cval.'_pattern_meta'],1), 1));\n $calcfields = array_merge($calcfields,array_diff_key(json_decode($calcfields[$cval.'_pattern_meta'],1),$calcfields));\n// $modx->log(modX::LOG_LEVEL_ERROR,'$calcfields beim Laden: '. print_r($calcfields, 1));\n }\n }\n }\n// Hier muss noch rein, dass die Felder, die nicht aus den Tabellen kommen, für die es aber trotzdem\n// Formularfelder gibt aus dem \"gauge_pattern_meta\" übernommen werden.\n/* Das geht ungefär so:\n * foreach ($calcs as $calc) {\n Vergleiche die Felder in $calc.'_pattern_meta' mit den $calcfields\n gibt es welche, die im Formular vorhanden sind. Dann fülle den Wert auch in $calcfields\n erst gauge_pattern_meta in php array umwandeln. dann\n $differenz = array_diff_key(gauge_pattern_meta, $calcfields);\n}\n*/\n/**\n * Irgend so ne Trulla hat irre Werte eingegeben. (Daniela Baumgartner ID: 146)\n * Dadurch war gauge_pattern_meta NULL\n * Dann gibts einen PHP_Error\n */\n// $Mycalcfields[$cval] = $calcfields[$cval.'_pattern_meta'];\n //$savedfields[$cval] = json_decode($Mycalcfields[$cval],1);\n //$differenz = array_diff_key($savedfields[$cval],$calcfields);\n// $modx->log(modX::LOG_LEVEL_ERROR,'$Mycalcfields[$cval]: '.$Mycalcfields[$cval]);\n //$modx->log(modX::LOG_LEVEL_ERROR,'$savedfields[$cval]: '.print_r($savedfields[$cval],1));\n //$modx->log(modX::LOG_LEVEL_ERROR,'$differenz: '.print_r($differenz,1));\n //$calcfields = array_merge($calcfields,$differenz);\n// Die Werte aus gauge_pattern_meta von json in array umwandeln und dann die differenz an das array $calcfields anhängen\n\n// $calcfields = array_merge($calcfields,array_diff_key(json_decode($calcfields[$cval.'_pattern_meta'],1),$calcfields));\n\n //$modx->log(modX::LOG_LEVEL_ERROR,'$calcfields-new: '.print_r($calcfields,1));\n\n\n $hook->setValues($calcfields);\n}\n// UserGroup == 5: Load the existing row of Calc if the property is set ????\nif ($uG == 5) {\n $c = $modx->newQuery('JustKnitCalcs');\n if (!empty($cid)){\n $ca = $modx->getObject('JustKnitCalcs', ['ressource_id' => $resId,'ccreatedby' => $userId,'id' => $cid,]);\n } else {\n $c->where(['ressource_id' => $resId,'ccreatedby' => $userId,]);\n $c->sortby('editedon','DESC');\n $ca = $modx->getObject('JustKnitCalcs',$c);\n $cid = is_object($ca) ? $ca->get('id') : '';\n }\n// $modx->log(modX::LOG_LEVEL_ERROR,'load UG: '.$uG.' cid:'.$cid);\n $calcfields = $kc->getCalcFields($scriptProperties,$cid);\n// $modx->log(modX::LOG_LEVEL_ERROR,'
$$calcfields' . print_r($calcfields, 1) . '
');\n $hook->setValue('cid', $cid);\n $hook->setValues($calcfields);\n}\n// Only for UserGroup 4 or 5 set default values\nif ($uG == 4 || $uG == 5) {\n // Set default fields\n $defFields = array();\n foreach ($calcs as $ck => $cv) {\n foreach ($defaults as $k => $v) {\n $defFields[$cv.'_'.$k] = $v;\n $hook->setValue($cv.'_calcname',$cv);\n }\n }\n foreach ($dims as $dk => $dv) {\n foreach ($defaults as $k => $v) {\n $defFields[$dv.'_'.$k] = $v;\n $hook->setValue($dv.'_dimname',$dv);\n if ($k == 'dtn_d') {\n if (str_starts_with($dv, 'w') || str_starts_with($dv, 'h')) {\n $dtn = str_split($dv)[0];\n $hook->setValue($dv.'_dtn_d',$dtn);\n }\n }\n }\n }\n foreach ($defFields as $f => $g) {\n $setfld = $hook->getValue($f);\n if ( !isset($setfld) || $setfld == 0 || $setfld == '' || $setfld == NULL) {\n $hook->setValue($f,$g);\n }\n }\n}\n$modx->log(modX::LOG_LEVEL_ERROR,'Loadcalcs ist fertig');\nreturn true;\n/**\n * [[!+modx.user.id:userinfo=`primary_group`:is=`3`:then=`Basis`]]\n * [[!+modx.user.id:userinfo=`primary_group`:is=`4`:then=`Standard`]]\n * [[!+modx.user.id:userinfo=`primary_group`:is=`5`:then=`Premium`]]\n */\n// Hier muss jetzt rein, dass bei Standard immer die eine Calc geladen wird,\n// bei Basis gar nichts passiert und bei Premium immer ein neuer Datensatz erstellt wird.\n\n\n\n// TODO: For Standard Group load the one allowed Calculation\n\n// UserGroup == 4: Always load the one existing row of Calc\n//if ($uG == 4) {\n// Um das Speichern zu testen lasse ich das erst mal weg.\n// Hier muss rein, dass nur die eine Berechnung geladen wird\n//$c = $modx->newQuery('JustKnitCalcs');\n//$c->where(['ressource_id' => $resId,'ccreatedby' => $userId,]);\n//$calc = $modx->get('JustKnitCalcs',$c);\n//$calcs = $modx->getCollection('JustKnitCalcs',$c);\n/* $ca = $modx->getObject('JustKnitCalcs', ['ressource_id' => $resId,'ccreatedby' => $userId,]);\n if (is_object($ca)) {\n $cid = $ca->get('id');\n }\n $hook->setValue('cid', $cid);\n $calcfields = $kc->getCalcFields($scriptProperties,$cid);\n// $modx->log(modX::LOG_LEVEL_ERROR,'
' . print_r($calcfields, 1).'
'.$cid);\n $hook->setValues($calcfields);\n}\n*/\n// UserGroup == 5: Load the existing row of Calc if the property is set ????\n//if ($uG == 5) {\n// ALERT: Achtung hier muss rein, dass nur die aktuelle cid geladen wird. Sonst werden alle cid des Users verarbeitet.\n// Die cids, die zusammen gehören müssen erkannt werden.\n/*\n$c = $modx->newQuery('JustKnitCalcs');\n$c->where(['ressource_id' => $resId,'ccreatedby' => $userId,]);\n$ca = $modx->getObject('JustKnitCalcs',$c);\n//$calcs = $modx->getCollection('JustKnitCalcs',$c);\nif (is_object($ca)) {\n $cid = $ca->get('id');\n}\n\n// if (!empty($cid)) {\n$modx->log(modX::LOG_LEVEL_ERROR,'load UG: '.$uG.' cid:'.$cid);\n $calcfields = $kc->getCalcFields($scriptProperties,$cid);\n// $modx->log(modX::LOG_LEVEL_ERROR,'
$$calcfields' . print_r($calcfields, 1) . '
');\n $hook->setValue('cid', $cid);\n $hook->setValues($calcfields);\n// } else {\n*/\n// }\n//}\n//Only UserGroup 4&5 can save or edit rows\n/*\nif ($uG == 4 || $uG == 5) {\n // Set default fields\n $defFields = array();\n foreach ($calcs as $ck => $cv) {\n foreach ($defaults as $k => $v) {\n $defFields[$cv.'_'.$k] = $v;\n $hook->setValue($cv.'_calcname',$cv);\n }\n }\n foreach ($dims as $dk => $dv) {\n foreach ($defaults as $k => $v) {\n $defFields[$dv.'_'.$k] = $v;\n $hook->setValue($dv.'_dimname',$dv);\n if ($k == 'dtn_d') {\n if (str_starts_with($dv, 'w') || str_starts_with($dv, 'h')) {\n $dtn = str_split($dv)[0];\n }\n $hook->setValue($dv.'_dtn_d',$dtn);\n }\n }\n }\n foreach ($defFields as $f => $g) {\n $setfld = $hook->getValue($f);\n // $modx->log(modX::LOG_LEVEL_ERROR,$setfld,$f,$g);\n if ( !isset($setfld) || $setfld == 0 || $setfld == '' || $setfld == NULL) {\n $hook->setValue($f,$g);\n }\n }\n}\n*/\n//if (isset($_POST['cid'])) {\n// $modx->log(modX::LOG_LEVEL_ERROR,'post '.$_POST['cid']);\n//}\n\n//if (isset($_GET['cid'])) {\n// $modx->log(modX::LOG_LEVEL_ERROR,'get '.$_GET['cid']);\n // remove url\n// $test1 = $_SERVER['REQUEST_URI'];\n// $test2 = $_SERVER['QUERY_STRING'];\n\n// $modx->log(modX::LOG_LEVEL_ERROR,$test1.' ' .$test3);\n// test1 = parse_url();\n//}\n\n//return true;" properties: 'a:0:{}' static: 1 static_file: core/components/knit/elements/snippets/loadcalcs.snippet.php ----- /** * loadCalcs snippet for knit extra * * Copyright 2021 by Iris Hammer iris.hammer@justknit.de * Created on 10-14-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 get Data from Calcs and Dims for each Calcform * * Variables * --------- * @var $modx modX * @var $scriptProperties array * * @package knit **/ // UserGroup for Permission of save/add Calcs $uG = $modx->getOption('uG', $scriptProperties, '', true); // RessourceId to find Calcs and Dims $resId = $modx->getOption('res', $scriptProperties, '', true); // UserId to check ownership $userId = $modx->getOption('user', $scriptProperties, '', true); // names of the Calcs $calcs = $modx->getOption('calcs', $scriptProperties, '[]', true); $calcs = !empty($calcs) ? explode(',', $calcs) : '[]'; //$modx->log(modX::LOG_LEVEL_ERROR,'
$calcs' . print_r($calcs, 1) . '
'); // names of the Dims $dims = $modx->getOption('dims', $scriptProperties, '[]', true); $dims = !empty($dims) ? explode(',', $dims) : '[]'; //$modx->log(modX::LOG_LEVEL_ERROR,'
$dims' . print_r($dims, 1) . '
'); $dims = array_map('trim', $dims); $cid = isset($_GET['cid']) && !empty($_GET['cid']) ? $_GET['cid'] : ''; //$modx->log(modX::LOG_LEVEL_ERROR,'cid $_GET ' . $cid .'empty? '.empty($cid)); //$modx->log(modX::LOG_LEVEL_ERROR,'
$dims trimmed' . print_r($dims, 1) . '
'); //$patArray['pcreatedon'] = strftime('%Y-%m-%d %H:%M:%S',$patArray['pcreatedon']) $defaults = array( 'ressource_id' => $resId, 'ccreatedby' => $userId, 'calcedby' => $userId, 'ceditedby' => $userId, 'createdon' => strftime('%Y-%m-%d %H:%M:%S',time()), 'editedon' => strftime('%Y-%m-%d %H:%M:%S',time()), 'dtn_d' => '', ); $kc = $modx->getService('knitcalculations','KnitCalculations',$modx->getOption('knit.core_path',null,$modx->getOption('core_path').'components/knit/').'model/knit/',$scriptProperties); if (!($kc instanceof KnitCalculations)) { $message = '[JustKnit] Could not load KnitCalculations class'; $modx->log(modX::LOG_LEVEL_ERROR,$message); return false; } $language = $modx->getOption('language', $scriptProperties, ''); $language = !empty($language) ? $language : $modx->getOption('cultureKey', NULL, $modx->getOption('manager_language', NULL, 'en')); $modx->lexicon->load($language . ':knit:calcs'); $modx->lexicon->load($language . ':knit:default'); //$modx->log(modX::LOG_LEVEL_ERROR,$modx->getOption('cultureKey')); //$modx->log(modX::LOG_LEVEL_ERROR,'Vor setPlchldFields'); $setKnitChunks = $kc->setPlchldFields($scriptProperties,$cid); //$modx->log(modX::LOG_LEVEL_ERROR,'$setKnitChunks' .print_r($setKnitChunks, 1).''); $modx->log(modX::LOG_LEVEL_ERROR,'HURRAA! loadcalcs wird geladen'); //$hook->setValues($setKnitChunks); // UserGroup == 4: Always load the one existing row of Calc if ($uG == 4) { $modx->log(modX::LOG_LEVEL_ERROR,'YESS! loadcalcs uG=4'); $ca = $modx->getObject('JustKnitCalcs', ['ressource_id' => $resId,'ccreatedby' => $userId,]); $cid = is_object($ca) ? $ca->get('id') : ''; $hook->setValue('cid', $cid); $calcfields = $kc->getCalcFields($scriptProperties,$cid); //$modx->log(modX::LOG_LEVEL_ERROR,'
' . print_r($calcfields, 1).'
'.$cid.' $calcs '.print_r($calcs, 1)); foreach ($calcs as $calc => $cval) { if (is_object($ca)) { //$modx->log(modX::LOG_LEVEL_ERROR,'$calcfields[$cval_pattern_meta]: '.$calcfields[$cval.'_pattern_meta']); if (!is_null($calcfields[$cval.'_pattern_meta'])) { // $modx->log(modX::LOG_LEVEL_ERROR,'$calcfields[$cval_pattern_meta]: '.print_r(json_decode($calcfields[$cval.'_pattern_meta'],1), 1)); $calcfields = array_merge($calcfields,array_diff_key(json_decode($calcfields[$cval.'_pattern_meta'],1),$calcfields)); // $modx->log(modX::LOG_LEVEL_ERROR,'$calcfields beim Laden: '. print_r($calcfields, 1)); } } } // Hier muss noch rein, dass die Felder, die nicht aus den Tabellen kommen, für die es aber trotzdem // Formularfelder gibt aus dem "gauge_pattern_meta" übernommen werden. /* Das geht ungefär so: * foreach ($calcs as $calc) { Vergleiche die Felder in $calc.'_pattern_meta' mit den $calcfields gibt es welche, die im Formular vorhanden sind. Dann fülle den Wert auch in $calcfields erst gauge_pattern_meta in php array umwandeln. dann $differenz = array_diff_key(gauge_pattern_meta, $calcfields); } */ /** * Irgend so ne Trulla hat irre Werte eingegeben. (Daniela Baumgartner ID: 146) * Dadurch war gauge_pattern_meta NULL * Dann gibts einen PHP_Error */ // $Mycalcfields[$cval] = $calcfields[$cval.'_pattern_meta']; //$savedfields[$cval] = json_decode($Mycalcfields[$cval],1); //$differenz = array_diff_key($savedfields[$cval],$calcfields); // $modx->log(modX::LOG_LEVEL_ERROR,'$Mycalcfields[$cval]: '.$Mycalcfields[$cval]); //$modx->log(modX::LOG_LEVEL_ERROR,'$savedfields[$cval]: '.print_r($savedfields[$cval],1)); //$modx->log(modX::LOG_LEVEL_ERROR,'$differenz: '.print_r($differenz,1)); //$calcfields = array_merge($calcfields,$differenz); // Die Werte aus gauge_pattern_meta von json in array umwandeln und dann die differenz an das array $calcfields anhängen // $calcfields = array_merge($calcfields,array_diff_key(json_decode($calcfields[$cval.'_pattern_meta'],1),$calcfields)); //$modx->log(modX::LOG_LEVEL_ERROR,'$calcfields-new: '.print_r($calcfields,1)); $hook->setValues($calcfields); } // UserGroup == 5: Load the existing row of Calc if the property is set ???? if ($uG == 5) { $c = $modx->newQuery('JustKnitCalcs'); if (!empty($cid)){ $ca = $modx->getObject('JustKnitCalcs', ['ressource_id' => $resId,'ccreatedby' => $userId,'id' => $cid,]); } else { $c->where(['ressource_id' => $resId,'ccreatedby' => $userId,]); $c->sortby('editedon','DESC'); $ca = $modx->getObject('JustKnitCalcs',$c); $cid = is_object($ca) ? $ca->get('id') : ''; } // $modx->log(modX::LOG_LEVEL_ERROR,'load UG: '.$uG.' cid:'.$cid); $calcfields = $kc->getCalcFields($scriptProperties,$cid); // $modx->log(modX::LOG_LEVEL_ERROR,'
$$calcfields' . print_r($calcfields, 1) . '
'); $hook->setValue('cid', $cid); $hook->setValues($calcfields); } // Only for UserGroup 4 or 5 set default values if ($uG == 4 || $uG == 5) { // Set default fields $defFields = array(); foreach ($calcs as $ck => $cv) { foreach ($defaults as $k => $v) { $defFields[$cv.'_'.$k] = $v; $hook->setValue($cv.'_calcname',$cv); } } foreach ($dims as $dk => $dv) { foreach ($defaults as $k => $v) { $defFields[$dv.'_'.$k] = $v; $hook->setValue($dv.'_dimname',$dv); if ($k == 'dtn_d') { if (str_starts_with($dv, 'w') || str_starts_with($dv, 'h')) { $dtn = str_split($dv)[0]; $hook->setValue($dv.'_dtn_d',$dtn); } } } } foreach ($defFields as $f => $g) { $setfld = $hook->getValue($f); if ( !isset($setfld) || $setfld == 0 || $setfld == '' || $setfld == NULL) { $hook->setValue($f,$g); } } } $modx->log(modX::LOG_LEVEL_ERROR,'Loadcalcs ist fertig'); return true; /** * [[!+modx.user.id:userinfo=`primary_group`:is=`3`:then=`Basis`]] * [[!+modx.user.id:userinfo=`primary_group`:is=`4`:then=`Standard`]] * [[!+modx.user.id:userinfo=`primary_group`:is=`5`:then=`Premium`]] */ // Hier muss jetzt rein, dass bei Standard immer die eine Calc geladen wird, // bei Basis gar nichts passiert und bei Premium immer ein neuer Datensatz erstellt wird. // TODO: For Standard Group load the one allowed Calculation // UserGroup == 4: Always load the one existing row of Calc //if ($uG == 4) { // Um das Speichern zu testen lasse ich das erst mal weg. // Hier muss rein, dass nur die eine Berechnung geladen wird //$c = $modx->newQuery('JustKnitCalcs'); //$c->where(['ressource_id' => $resId,'ccreatedby' => $userId,]); //$calc = $modx->get('JustKnitCalcs',$c); //$calcs = $modx->getCollection('JustKnitCalcs',$c); /* $ca = $modx->getObject('JustKnitCalcs', ['ressource_id' => $resId,'ccreatedby' => $userId,]); if (is_object($ca)) { $cid = $ca->get('id'); } $hook->setValue('cid', $cid); $calcfields = $kc->getCalcFields($scriptProperties,$cid); // $modx->log(modX::LOG_LEVEL_ERROR,'
' . print_r($calcfields, 1).'
'.$cid); $hook->setValues($calcfields); } */ // UserGroup == 5: Load the existing row of Calc if the property is set ???? //if ($uG == 5) { // ALERT: Achtung hier muss rein, dass nur die aktuelle cid geladen wird. Sonst werden alle cid des Users verarbeitet. // Die cids, die zusammen gehören müssen erkannt werden. /* $c = $modx->newQuery('JustKnitCalcs'); $c->where(['ressource_id' => $resId,'ccreatedby' => $userId,]); $ca = $modx->getObject('JustKnitCalcs',$c); //$calcs = $modx->getCollection('JustKnitCalcs',$c); if (is_object($ca)) { $cid = $ca->get('id'); } // if (!empty($cid)) { $modx->log(modX::LOG_LEVEL_ERROR,'load UG: '.$uG.' cid:'.$cid); $calcfields = $kc->getCalcFields($scriptProperties,$cid); // $modx->log(modX::LOG_LEVEL_ERROR,'
$$calcfields' . print_r($calcfields, 1) . '
'); $hook->setValue('cid', $cid); $hook->setValues($calcfields); // } else { */ // } //} //Only UserGroup 4&5 can save or edit rows /* if ($uG == 4 || $uG == 5) { // Set default fields $defFields = array(); foreach ($calcs as $ck => $cv) { foreach ($defaults as $k => $v) { $defFields[$cv.'_'.$k] = $v; $hook->setValue($cv.'_calcname',$cv); } } foreach ($dims as $dk => $dv) { foreach ($defaults as $k => $v) { $defFields[$dv.'_'.$k] = $v; $hook->setValue($dv.'_dimname',$dv); if ($k == 'dtn_d') { if (str_starts_with($dv, 'w') || str_starts_with($dv, 'h')) { $dtn = str_split($dv)[0]; } $hook->setValue($dv.'_dtn_d',$dtn); } } } foreach ($defFields as $f => $g) { $setfld = $hook->getValue($f); // $modx->log(modX::LOG_LEVEL_ERROR,$setfld,$f,$g); if ( !isset($setfld) || $setfld == 0 || $setfld == '' || $setfld == NULL) { $hook->setValue($f,$g); } } } */ //if (isset($_POST['cid'])) { // $modx->log(modX::LOG_LEVEL_ERROR,'post '.$_POST['cid']); //} //if (isset($_GET['cid'])) { // $modx->log(modX::LOG_LEVEL_ERROR,'get '.$_GET['cid']); // remove url // $test1 = $_SERVER['REQUEST_URI']; // $test2 = $_SERVER['QUERY_STRING']; // $modx->log(modX::LOG_LEVEL_ERROR,$test1.' ' .$test3); // test1 = parse_url(); //} //return true;