. * * PHP version 5 * @copyright cgo IT, 2013 * @author Carsten Götzinger (info@cgo-it.de) * @package rateit * @license GNU/LGPL * @filesource */ namespace cgoIT\rateit; /** * Class RateItTopRatingsModule */ class RateItTopRatingsModule extends RateItFrontend { //protected $intStars = 5; /** * Initialize the controller */ public function __construct($objElement) { parent::__construct($objElement); $this->strKey = "rateit_top_ratings"; } /** * Display a wildcard in the back end * @return string */ public function generate() { if (TL_MODE == 'BE') { $objTemplate = new \BackendTemplate('be_wildcard'); $objTemplate->wildcard = '### Rate IT Best/Most Ratings ###'; $objTemplate->title = $this->name; $objTemplate->id = $this->id; $objTemplate->link = $this->name; $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; return $objTemplate->parse(); } $this->strTemplate = $this->rateit_template; $this->arrTypes = deserialize($this->rateit_types); $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/rateit/public/js/onReadyRateIt.js|static'; $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/rateit/public/js/rateit.js|static'; $GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/rateit.min.css||static'; switch ($GLOBALS['TL_CONFIG']['rating_type']) { case 'hearts' : $GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.min.css||static'; break; default: $GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.min.css||static'; } return parent::generate(); } /** * Generate the module/content element */ protected function compile() { $this->Template = new \FrontendTemplate($this->strTemplate); $this->Template->setData($this->arrData); $this->import("\\Database", "Database"); $arrResult = $this->Database->prepare("SELECT i.id AS item_id, i.rkey AS rkey, i.title AS title, i.typ AS typ, i.createdat AS createdat, i.active AS active, IFNULL(AVG(r.rating),0) AS best, COUNT( r.rating ) AS most FROM tl_rateit_items i LEFT OUTER JOIN tl_rateit_ratings r ON (i.id = r.pid) WHERE typ IN ('".implode("', '", $this->arrTypes)."') GROUP BY rkey, title, item_id, typ, createdat, active ORDER BY ".$this->rateit_toptype." DESC") ->limit($this->rateit_count) ->execute() ->fetchAllAssoc(); $objReturn = array(); foreach ($arrResult as $result) { $return = new \stdClass(); $return->title = $result['title']; $return->typ = $result['typ']; // ID ermitteln $stars = $this->percentToStars($result['best']); $return->rateItID = 'rateItRating-'.$result['rkey'].'-'.$result['typ'].'-'. $stars.'_'.intval($GLOBALS['TL_CONFIG']['rating_count']); $return->descriptionId = 'rateItRating-'.$result['rkey'].'-description'; $return->rateit_class = 'rateItRating'; // Beschriftung ermitteln $rating = array(); $rating['totalRatings'] = $result['most']; $rating['rating'] = $result['best']; $return->description = $this->getStarMessage($rating); $return->rating = $result['best']; $return->count = $result['most']; $return->rel = 'not-rateable'; $objReturn[] = $return; } $this->Template->arrRatings = $objReturn; } } ?>