Гость
31 Дек 2012 04:57

Hello,

Does anyone know how to display only the average rating stars anywhere in a template? I need it in the records list, but I think it's the same syntax for any other template file.

Right now, if I choose to display ratings, it gives me the average with the other multiple criteria ratings within the same table, and it spoils my design.

Thank you in advance!

Marius C.

Последние изменения: 02 Март 2014


Sergey
Total posts: 13,748
31 Дек 2012 05:17

I can suggest you what cod you can use but it will be single average. Not multi criteria.

But I need to know average rating of what? Whole section? I mean average of all ratings in whole section?


Гость
31 Дек 2012 05:27

If I'm not wrong, this can be a good option for ratings in the backend where admins can choose what ratings they want to display in a certain place (all the criteria or just the average), in case of multi criteria, of course.

Yes, you understood correctly. I just need to display the average of all criteria from a record, regardless of calculation method.

Thanks!


Sergey
Total posts: 13,748
31 Дек 2012 06:16

$db = JFactory::getDbo();

$query = $db->getQuery(true);

$query->select("AVG(votes_result)");

$query->from("#__js_res_record");

$query->where("section_id = 1");

$query->where("published = 1");

$query->where("parent = 'com_cobalt'");

$db->setQuery($query);

$result = $db->loadResult();

echo '

Total rating: '.RatingHelper::loadRating('default', $result, 0, 0, 'Cobalt.ItemRatingCallBack', 0, 0).'

';


Sergey
Total posts: 13,748
31 Дек 2012 06:17

But as I said it is single rating only. To calculate multi-criteria will take more code and could reduce performance.

Работает на Cobalt