I’m looking to reconfigure a StarRating snippet to suit a website redesign which I’m currently embarking on.
The snippet displays a list on my home page of the top 10 best rated circuits on RacingCircuits.info. However, I’ve spotted a couple of issues:
- It’s currently configured to count results only from resources using template 17, when it should really show from resources which use templates 13 or 17;
- I’d like to additionally like to set placeholder values for the pagetitle and a further template variable (named circuit_countrycode) of the parent resource.
I’m not well versed in php and didn’t write the original, so would appreciate any help!
Current snippet code below:
<?php
$showhidden = isset($showhidden) ? $showhidden : 0;
$limit = isset($limit) ? $limit : 10;
$snippetPath = $modx->getOption('core_path').'components/star_rating/';
$modx->addPackage('star_rating',$snippetPath.'model/');
$output='';
//$manager = $modx->getManager();
//$manager->createObjectContainer('starRating');
$c = $modx->newQuery('modResource');
$c->leftJoin('starRating','starRating', array("modResource.id = starRating.star_id"));
$c->select('modResource.id, vote_total/vote_count AS rating');
$where = array(
'modResource.published' => '1',
'modResource.template' => '17',
'modResource.hidemenu' => $showhidden
);
if (isset($parent)) {
$where['modResource.parent']=$parent;
}
if (isset($template)) {
$where['modResource.template']=$template;
}
$c->where($where);
$c->sortby('rating','DESC');
$c->sortby('id','DESC');
$c->limit($limit,0);
//$c->prepare();echo $c->toSQL();
$ratings = $modx->getCollection('modResource', $c);
$idx=1;
foreach ($ratings as $rating) {
$modx->setPlaceholder('pagetitle',$rating->get('pagetitle'));
$modx->setPlaceholder('id',$rating->get('id'));
$modx->setPlaceholder('idx',$idx);
$output.=$modx->getChunk('tplHPCircuitRating');
$idx++;
}
return $output;