
This question has been answered by multiple community members. See the first response.
if (!function_exists("my_debug")) {
function my_debug($message, $clear = false)
{
global $modx;
/* @var $chunk modChunk */
$content = '';
$chunk = $modx->getObject('modChunk', array('name' => 'debug'));
if (!$chunk) {
$chunk = $modx->newObject('modChunk', array('name' => 'debug'));
$chunk->setContent('');
$chunk->save();
$chunk = $modx->getObject('modChunk', array('name' => 'debug'));
} else {
if ($clear) {
$content = '';
} else {
$content = $chunk->getContent();
}
}
$chunk->setContent($content . "\n" . $message);
$chunk->save();
}
}
if (isset($scriptProperties['data']['tvs'])) {
unset($scriptProperties['data']['tvs']);
$tvs = array();
foreach($scriptProperties['data'] as $k => $v) {
if(strstr($k,'tvbrowser')) {
continue;
}
if (substr($k,0,2) == 'tv') {
$tvs[$k] = $v;
}
}
$d = print_r($tvs, true);
my_debug($d);
foreach($tvs as $k => $v) {
$tvNumber = (integer) substr($k,2);
$oldVal = $resource->getTVValue($tv);
if ($val != $v) {
$ok = false;
my_debug('TV ' . $tvNumber . ' Changed' );
my_debug('OLD: ' . $oldVal . 'NEW: ' . $v);
break;
}
}
}<?php
if (!function_exists("my_debug")) {
function my_debug($message, $clear = false) {
global $modx;
/* @var $chunk modChunk */
$content = '';
$chunk = $modx->getObject('modChunk', array('name' => 'debug'));
if (!$chunk) {
$chunk = $modx->newObject('modChunk', array('name' => 'debug'));
$chunk->setContent('');
$chunk->save();
$chunk = $modx->getObject('modChunk', array('name' => 'debug'));
} else {
if ($clear) {
$content = '';
} else {
$content = $chunk->getContent();
}
}
$content .= $message . "\n";
$chunk->setContent($content);
$chunk->save();
}
}
my_debug('IN PLUGIN', true);
$tvName = 'tv4208';
$tvId = 4208;
if (isset($scriptProperties['data']['tvs'])) {
my_debug('OLD: ' . $resource->getTVValue($tvId));
my_debug('NEW: ' . $scriptProperties['data'][$tvName]);
if (isset($scriptProperties['data'][$tvName]) &&
($scriptProperties['data'][$tvName] !== $resource->getTVValue($tvId))){
my_debug('CHANGED');
} else {
my_debug('NOT CHANGED');
}
}<?php
if (!function_exists("my_debug")) {
function my_debug($message, $clear = false) {
global $modx;
/* @var $chunk modChunk */
$content = '';
$chunk = $modx->getObject('modChunk', array('name' => 'debug'));
if (!$chunk) {
$chunk = $modx->newObject('modChunk', array('name' => 'debug'));
$chunk->setContent('');
$chunk->save();
$chunk = $modx->getObject('modChunk', array('name' => 'debug'));
} else {
if ($clear) {
$content = '';
} else {
$content = $chunk->getContent();
}
}
$content .= $message . "\n";
$chunk->setContent($content);
$chunk->save();
}
}
my_debug('IN PLUGIN', true);
$tvName = 'tv4208';
$tvId = 4208;
$newVal = null;
$oldVal = null;
$resourceId = $resource->get('id');
/* get new raw value of the TV */
if (isset($scriptProperties['data']['tvs'])) {
if (isset($scriptProperties['data'][$tvName])) {
$newVal = $scriptProperties['data'][$tvName];
}
/* get raw old value of the TV */
$tvr = $modx->getObject('modTemplateVarResource',
array('tmplvarid' => $tvId, 'contentid' => $resourceId));
if ($tvr) {
$oldVal = $tvr->get('value');
} else {
$tv = $modx->getObject('modTemplateVar', $tvId);
if ($tv) {
$oldVal = $tv->get('default_text');
}
}
my_debug('OLD: ' . $oldVal);
my_debug('NEW: ' . $newVal);
if ($newVal !== $oldVal){
my_debug('CHANGED');
} else {
my_debug('NOT CHANGED');
}
}<?php
if (!function_exists("my_debug")) {
function my_debug($message, $clear = false) {
global $modx;
/* @var $chunk modChunk */
$content = '';
$chunk = $modx->getObject('modChunk', array('name' => 'debug'));
if (!$chunk) {
$chunk = $modx->newObject('modChunk', array('name' => 'debug'));
$chunk->setContent('');
$chunk->save();
$chunk = $modx->getObject('modChunk', array('name' => 'debug'));
} else {
if ($clear) {
$content = '';
} else {
$content = $chunk->getContent();
}
}
$content .= $message . "\n";
$chunk->setContent($content);
$chunk->save();
}
}
my_debug('IN PLUGIN', true);
$tvId = 4208;
$tvName = 'tv' . $tvId;
$newVal = null;
$oldVal = null;
/** @var $modx modX */
/* get new raw value of the TV */
if (isset($scriptProperties['data']['tvs'])) {
$resourceId = $resource->get('id');
if (isset($scriptProperties['data'][$tvName])) {
$tv = $modx->getObject('modTemplateVar', $tvId);
if (!$tv) {
$modx->log(modx::LOG_LEVEL_ERROR, 'Could not find TV with ID: ' . $tvId);
return;
}
$default = $tv->get('default_text');
$newVal = $scriptProperties['data'][$tvName];
if (empty($newVal) && (! is_numeric($newVal))) {
$newVal = $default;
}
} else { /* Nothing to check */
return;
}
/* get raw old value of the TV */
$tvr = $modx->getObject('modTemplateVarResource',
array('tmplvarid' => $tvId, 'contentid' => $resourceId));
if ($tvr) {
$oldVal = $tvr->get('value');
}
if (!$tvr || (empty($oldVal) && (!is_numeric($oldVal)))) {
$oldVal = $default;
}
my_debug('OLD: ' . $oldVal);
my_debug('NEW: ' . $newVal);
if ($newVal !== $oldVal){
my_debug('CHANGED');
} else {
my_debug('NOT CHANGED');
}
}$tvId = 4208; $tvName = 'tv' . $tvId;