id: 83
name: saveCalcs
description: 'Snippet to save Data for Calcs and Dims for each Calcform'
category: knit
snippet: "/**\n * saveCalcs 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 save Data for 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// 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$modx->log(modX::LOG_LEVEL_ERROR,'HURRAA! savecalcs wird geladen');\n// NOTE: So gehts net. die cid ist beim Speichern leer. Die muss woanders her kommen\n//$cid = isset($_GET['cid']) && !empty($_GET['cid']) ? $_GET['cid'] : '';\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$formFields = $hook->getValues();\n$modx->log(modX::LOG_LEVEL_ERROR,'HURRAA! savecalcs wird geladen');\n$modx->log(modX::LOG_LEVEL_ERROR,'saveCalcs snippet cid ' . $formFields['cid'] );\nif ($uG == 4) {\n $modx->log(modX::LOG_LEVEL_ERROR,'$formFields' . print_r($formFields, 1) . '
');\n if (!empty($formFields['cid'])) {\n $success = $kc->saveCalcFields($formFields,$scriptProperties);\n// $modx->log(modX::LOG_LEVEL_ERROR,'Und hast du gespeichert?? JAA');\n// $modx->log(modX::LOG_LEVEL_ERROR,'Und welche $formFields'. print_r($formFields, 1));\n } else {\n $success = $kc->newCalcFields($formFields,$scriptProperties);\n }\n// $success = $kc->saveCalcFields($formFields,$scriptProperties);\n}\nif ($uG == 5) {\n if ($formFields['actionFld'] == 'NEW') {\n $success = $kc->newCalcFields($formFields,$scriptProperties);\n\n } else {\n if (!empty($formFields['cid'])) {\n $success = $kc->saveCalcFields($formFields,$scriptProperties);\n\n } else {\n $success = $kc->newCalcFields($formFields,$scriptProperties);\n }\n }\n}\n/**\n * Das mit dem actionFld ist um eine neue leere Berechnung für Premium zu erzeugen.\n */\n//$modx->log(modX::LOG_LEVEL_ERROR,'$formFields[actionFld]):'.$formFields['actionFld']);\nif (!$success) {\n return false;\n}\nreturn true;\n\n\n\n\n\n\n\n\n// ALERT: Hier muss entschieden werden was bei welcher UserGroup passiert und wann gelöscht wird oder\n// geupdated oder neu erstellt.\n\n//$modx->log(modX::LOG_LEVEL_ERROR,'wird mein Hook geladen?');\n//$modx->log(modX::LOG_LEVEL_ERROR,'Warum geht es dann nicht?');\n\n\n\n//$formFields2 = $hook->getValues();\n//$test = $formFields2['gauge.editedon'];\n\n//$modx->log(modX::LOG_LEVEL_ERROR,'$formFields savecalc' . print_r($formFields, 1) . '
');\n//$modx->log(modX::LOG_LEVEL_ERROR,'$formFields2' . print_r($formFields2, 1) . '
');\n//$success = $kc->saveCalcFields($formFields,$scriptProperties);\n//$modx->log(modX::LOG_LEVEL_ERROR,'$formFields2' . print_r($formFields2, 1) . '
', $success);"
properties: 'a:0:{}'
static: 1
static_file: core/components/knit/elements/snippets/savecalcs.snippet.php
-----
/**
* saveCalcs 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 save Data for 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);
$modx->log(modX::LOG_LEVEL_ERROR,'HURRAA! savecalcs wird geladen');
// NOTE: So gehts net. die cid ist beim Speichern leer. Die muss woanders her kommen
//$cid = isset($_GET['cid']) && !empty($_GET['cid']) ? $_GET['cid'] : '';
$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;
}
$formFields = $hook->getValues();
$modx->log(modX::LOG_LEVEL_ERROR,'HURRAA! savecalcs wird geladen');
$modx->log(modX::LOG_LEVEL_ERROR,'saveCalcs snippet cid ' . $formFields['cid'] );
if ($uG == 4) {
$modx->log(modX::LOG_LEVEL_ERROR,'$formFields' . print_r($formFields, 1) . '
');
if (!empty($formFields['cid'])) {
$success = $kc->saveCalcFields($formFields,$scriptProperties);
// $modx->log(modX::LOG_LEVEL_ERROR,'Und hast du gespeichert?? JAA');
// $modx->log(modX::LOG_LEVEL_ERROR,'Und welche $formFields'. print_r($formFields, 1));
} else {
$success = $kc->newCalcFields($formFields,$scriptProperties);
}
// $success = $kc->saveCalcFields($formFields,$scriptProperties);
}
if ($uG == 5) {
if ($formFields['actionFld'] == 'NEW') {
$success = $kc->newCalcFields($formFields,$scriptProperties);
} else {
if (!empty($formFields['cid'])) {
$success = $kc->saveCalcFields($formFields,$scriptProperties);
} else {
$success = $kc->newCalcFields($formFields,$scriptProperties);
}
}
}
/**
* Das mit dem actionFld ist um eine neue leere Berechnung für Premium zu erzeugen.
*/
//$modx->log(modX::LOG_LEVEL_ERROR,'$formFields[actionFld]):'.$formFields['actionFld']);
if (!$success) {
return false;
}
return true;
// ALERT: Hier muss entschieden werden was bei welcher UserGroup passiert und wann gelöscht wird oder
// geupdated oder neu erstellt.
//$modx->log(modX::LOG_LEVEL_ERROR,'wird mein Hook geladen?');
//$modx->log(modX::LOG_LEVEL_ERROR,'Warum geht es dann nicht?');
//$formFields2 = $hook->getValues();
//$test = $formFields2['gauge.editedon'];
//$modx->log(modX::LOG_LEVEL_ERROR,'$formFields savecalc' . print_r($formFields, 1) . '
');
//$modx->log(modX::LOG_LEVEL_ERROR,'$formFields2' . print_r($formFields2, 1) . '
');
//$success = $kc->saveCalcFields($formFields,$scriptProperties);
//$modx->log(modX::LOG_LEVEL_ERROR,'$formFields2' . print_r($formFields2, 1) . '
', $success);