<?php

/**
 * Snippet to create rating microdata.
 *
 * 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) 2014 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 = clearFusionCMS::getDb()->fetchRow('SELECT AVG(rating) AS rating, COUNT(*) AS reviews FROM cf_comments_' . clearFusionCMS::getSite() . ' WHERE published && modulename=? && contentid=?', $module, $id);
echo '<div itemprop="aggregateRating" itemtype="http://schema.org/AggregateRating" itemscope>
	<meta itemprop="ratingValue" content="' . round($rating['rating']) . '" />
	<meta itemprop="reviewCount" content="' . $rating['reviews'] . '" />
</div>';
