Created
December 20, 2021 16:57
-
-
Save Electrica/c30d79ef1214ee3b45c312983ccf45a6 to your computer and use it in GitHub Desktop.
views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @var MODX $modx | |
*/ | |
$obResource = $modx->resource; | |
//Вытаскиваем просмотры | |
$q = $modx->newQuery('modTemplateVarResource'); | |
$q->where(['tmplvarid' => 11, 'contentid' => $obResource->id]); | |
$obView = $modx->getObject('modTemplateVarResource', $q); | |
if(is_object($obView)){ | |
$arView = $obView->toArray(); | |
$arView['value'] = $arView['value']+1; | |
$obView->fromArray($arView); | |
$obView->save(); | |
}else{ | |
//Нету просмотров, создаем | |
$obView = $modx->newObject('modTemplateVarResource'); | |
$arr = [ | |
'tmplvarid' => 11, | |
'contentid' => $obResource->id, | |
'value' => 1 | |
]; | |
$obView->fromArray($arr); | |
$obView->save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment