news_source (migxdb) id name image url article_count
news_article (migx) id title source_id pub_date url
switch ($modx->event->name) {
case 'OnDocFormSave':
$count = $resource->getTVValue('article_count');
if (!$resource->setTVValue('article_count', $count+1)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'There was a problem setting TV article_count.');
}
break;
}&where=`{"[[+pub_date:date=`%Y`]]:=":"2014"}This question has been answered by Bruno17. See the first response.
<?php
switch ($modx->event->name) {
case 'OnDocFormSave':
$items = $modx->fromJson($resource->getTVValue('news_article'));
$articles = array();
if (is_array($items)){
$count = count($items);
foreach($items as $item){
$date = $modx->getOption('pub_date',$item,'');
$item['year'] = strftime('%Y',strtotime($date));
$articles[] = $item;
}
$articles = $modx->toJson($articles);
}
else{
$count = 0;
$articles = '';
}
if (!$resource->setTVValue('article_count', $count)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'There was a problem setting TV article_count.');
}
if (!$resource->setTVValue('news_article', $articles)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'There was a problem setting TV news_article.');
}
break;
}
&where=`{"year:=":"2014"}