<?php

/**
 * Snippet to display the rating for the content item.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS\module\comments
 * @copyright Copyright (c) 2013 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/* @var $tplEngine cfTemplateEngine */
$controller = $tplEngine->controller;

$module = isset($module) ? $module : $controller->pageData['module'];
$id = isset($id) ? $id : $controller->pageData['contentid'];

$rating = round(clearFusionCMS::getDb()->fetchOne('SELECT AVG(rating) FROM cf_comments_' . clearFusionCMS::getSite() . ' WHERE published && modulename=? && contentid=?', $module, $id));
$s = $rating ? sprintf( __('Rated %d out of 5', 'commentsBackend'), $rating) : __('Not Rated', 'commentsBackend');
echo '<img src="system/modules/comments/images/stars' . $rating . '.png" alt="' . $s . '" />';
