id: 86
name: getSubscriber
description: 'Snippet to get subscriber data for UpdateProfile'
category: knit
snippet: "/**\n * getSubscriber snippet for knit extra\n *\n * Copyright 2021 by Iris Hammer iris.hammer@justknit.de\n * Created on 10-25-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 subscriber data for UpdateProfile\n *\n * Variables\n * ---------\n * @var $modx modX\n * @var $scriptProperties array\n *\n * @package knit\n **/\n\n// UserId to check ownership\n$userId = $modx->getOption('user', $scriptProperties, '', true);\n\n$ks = $modx->getService('knitsubscription','KnitSubscription',$modx->getOption('knit.core_path',null,$modx->getOption('core_path').'components/knit/').'model/knit/',$scriptProperties);\nif (!($ks instanceof KnitSubscription)) {\n $message = '[JustKnit] Could not load KnitSubscription class';\n $modx->log(modX::LOG_LEVEL_ERROR,$message);\n return false;\n}\n//$modx->log(modX::LOG_LEVEL_ERROR,'$userId'.$userId);\n// $ksm = $modx->getObject('JustKnitSubscriberMeta', ['subscriber_id' => $userId]);\n// $smid = is_object($ksm) ? $ksm->get('id') : '';\n// $hook->setValue('smid', $smid);\n $subscriberData = $ks->getSubscriberMeta($scriptProperties);\n\n// $modx->log(modX::LOG_LEVEL_ERROR,'' . print_r($calcfields, 1).'
'.$cid);\n// $hook->setValues($subscriberData);\n$modx->toPlaceholders($subscriberData);\n$profile = $modx->user->getOne('Profile');\n//$modx->log(modX::LOG_LEVEL_ERROR,'' . print_r($subscriberData, 1).'
'.$cid);\n//$modx->log(modX::LOG_LEVEL_ERROR,'' . print_r($subscriberData, 1).'
');\nif (is_object($profile)){\n $modx->toPlaceholders($profile);\n}\n\n\n//$modx->log(modX::LOG_LEVEL_ERROR,'$smid '.$smid );\n//$modx->log(modX::LOG_LEVEL_ERROR,'$subscriberData ' .print_r($subscriberData, 1).'
');\nreturn '';"
properties: 'a:0:{}'
static: 1
static_file: core/components/knit/elements/snippets/getsubscriber.snippet.php
-----
/**
* getSubscriber snippet for knit extra
*
* Copyright 2021 by Iris Hammer iris.hammer@justknit.de
* Created on 10-25-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 subscriber data for UpdateProfile
*
* Variables
* ---------
* @var $modx modX
* @var $scriptProperties array
*
* @package knit
**/
// UserId to check ownership
$userId = $modx->getOption('user', $scriptProperties, '', true);
$ks = $modx->getService('knitsubscription','KnitSubscription',$modx->getOption('knit.core_path',null,$modx->getOption('core_path').'components/knit/').'model/knit/',$scriptProperties);
if (!($ks instanceof KnitSubscription)) {
$message = '[JustKnit] Could not load KnitSubscription class';
$modx->log(modX::LOG_LEVEL_ERROR,$message);
return false;
}
//$modx->log(modX::LOG_LEVEL_ERROR,'$userId'.$userId);
// $ksm = $modx->getObject('JustKnitSubscriberMeta', ['subscriber_id' => $userId]);
// $smid = is_object($ksm) ? $ksm->get('id') : '';
// $hook->setValue('smid', $smid);
$subscriberData = $ks->getSubscriberMeta($scriptProperties);
// $modx->log(modX::LOG_LEVEL_ERROR,'' . print_r($calcfields, 1).'
'.$cid);
// $hook->setValues($subscriberData);
$modx->toPlaceholders($subscriberData);
$profile = $modx->user->getOne('Profile');
//$modx->log(modX::LOG_LEVEL_ERROR,'' . print_r($subscriberData, 1).'
'.$cid);
//$modx->log(modX::LOG_LEVEL_ERROR,'' . print_r($subscriberData, 1).'
');
if (is_object($profile)){
$modx->toPlaceholders($profile);
}
//$modx->log(modX::LOG_LEVEL_ERROR,'$smid '.$smid );
//$modx->log(modX::LOG_LEVEL_ERROR,'$subscriberData ' .print_r($subscriberData, 1).'
');
return '';