Initialer Commit in GIT
This commit is contained in:
113
classes/DcaHelper.php
Normal file
113
classes/DcaHelper.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 DcaHelper
|
||||
*/
|
||||
class DcaHelper extends \Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all navigation templates as array
|
||||
* @param DataContainer
|
||||
* @return array
|
||||
*/
|
||||
public function getRateItTemplates(\DataContainer $dc)
|
||||
{
|
||||
$intPid = $dc->activeRecord->pid;
|
||||
|
||||
if ($this->Input->get('act') == 'overrideAll')
|
||||
{
|
||||
$intPid = $this->Input->get('id');
|
||||
}
|
||||
|
||||
return $this->getTemplateGroup('rateit_', $intPid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Anlegen eines Datensatzes in der Tabelle tl_rateit_items, falls dieser noch nicht exisitiert.
|
||||
* @param mixed
|
||||
* @param object
|
||||
* @return string
|
||||
*/
|
||||
public function insertOrUpdateRatingKey(\DC_Table $dc, $type, $ratingTitle) {
|
||||
if ($dc->activeRecord->rateit_active || $dc->activeRecord->addRating) {
|
||||
$actRecord = $this->Database->prepare("SELECT * FROM tl_rateit_items WHERE rkey=? and typ=?")
|
||||
->execute($dc->activeRecord->id, $type)
|
||||
->fetchAssoc();
|
||||
if (!is_array($actRecord)) {
|
||||
$arrSet = array('rkey' => $dc->activeRecord->id,
|
||||
'tstamp' => time(),
|
||||
'typ' => $type,
|
||||
'createdat' => time(),
|
||||
'title'=> $ratingTitle,
|
||||
'active' => '1'
|
||||
);
|
||||
$insertRecord = $this->Database->prepare("INSERT INTO tl_rateit_items %s")
|
||||
->set($arrSet)
|
||||
->execute()
|
||||
->insertId;
|
||||
} else {
|
||||
$this->Database->prepare("UPDATE tl_rateit_items SET active='1', title=? WHERE rkey=? and typ=?")
|
||||
->execute($ratingTitle, $dc->activeRecord->id, $type)
|
||||
->updatedId;
|
||||
}
|
||||
} else {
|
||||
$this->Database->prepare("UPDATE tl_rateit_items SET active='' WHERE rkey=? and typ=?")
|
||||
->execute($dc->activeRecord->id, $typ)
|
||||
->updatedId;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Löschen eines Datensatzes aus der Tabelle tl_rateit_items.
|
||||
* @param mixed
|
||||
* @param object
|
||||
* @return string
|
||||
*/
|
||||
public function deleteRatingKey(\DC_Table $dc, $type)
|
||||
{
|
||||
$this->Database->prepare("DELETE FROM tl_rateit_items WHERE rkey=? and typ=?")
|
||||
->execute($dc->activeRecord->id, $type);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
274
classes/RateItArticle.php
Normal file
274
classes/RateItArticle.php
Normal file
@ -0,0 +1,274 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 RateItArticle extends RateItFrontend {
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function parseTemplateRateIt($objTemplate) {
|
||||
if ($objTemplate->type == 'article') {
|
||||
$objTemplate = $this->doArticle($objTemplate);
|
||||
} else if ($objTemplate->type == 'articleList') {
|
||||
$objTemplate = $this->doArticleList($objTemplate);
|
||||
} else if ($objTemplate->type == 'gallery') {
|
||||
$objTemplate = $this->doGallery($objTemplate);
|
||||
}
|
||||
return $objTemplate;
|
||||
}
|
||||
|
||||
private function doArticle($objTemplate) {
|
||||
$arrArticle = $this->Database->prepare('SELECT * FROM tl_article WHERE ID=?')
|
||||
->limit(1)
|
||||
->execute($objTemplate->id)
|
||||
->fetchAssoc();
|
||||
|
||||
if ($arrArticle['addRating']) {
|
||||
if ($objTemplate->multiMode && $objTemplate->showTeaser) {
|
||||
$objTemplate->setName('mod_'.$arrArticle['rateit_template'].'_teaser');
|
||||
} else {
|
||||
$objTemplate->setName($arrArticle['rateit_template']);
|
||||
}
|
||||
|
||||
$ratingId = $arrArticle['id'];
|
||||
$rating = $this->loadRating($ratingId, 'article');
|
||||
$stars = !$rating ? 0 : $this->percentToStars($rating['rating']);
|
||||
$percent = round($rating['rating'], 0)."%";
|
||||
|
||||
$objTemplate->descriptionId = 'rateItRating-'.$ratingId.'-description';
|
||||
$objTemplate->description = $this->getStarMessage($rating);
|
||||
$objTemplate->rateItID = 'rateItRating-'.$ratingId.'-article-'.$stars.'_'.$this->intStars;
|
||||
$objTemplate->rateit_class = 'rateItRating';
|
||||
$objTemplate->itemreviewed = $rating['title'];
|
||||
$objTemplate->actRating = $this->percentToStars($rating['rating']);
|
||||
$objTemplate->maxRating = $this->intStars;
|
||||
$objTemplate->votes = $rating[totalRatings];
|
||||
|
||||
if ($this->strTextPosition == "before") {
|
||||
$objTemplate->showBefore = true;
|
||||
}
|
||||
else if ($this->strTextPosition == "after") {
|
||||
$objTemplate->showAfter = true;
|
||||
}
|
||||
|
||||
if ($arrArticle['rateit_position'] == 'before') {
|
||||
$objTemplate->rateit_rating_before = true;
|
||||
} else if ($arrArticle['rateit_position'] == 'after') {
|
||||
$objTemplate->rateit_rating_after = true;
|
||||
}
|
||||
|
||||
$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.css||static';
|
||||
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
|
||||
case 'hearts' :
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
|
||||
break;
|
||||
default:
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.css||static';
|
||||
}
|
||||
}
|
||||
|
||||
return $objTemplate;
|
||||
}
|
||||
|
||||
private function doArticleList($objTemplate) {
|
||||
if ($objTemplate->rateit_active) {
|
||||
$bolTemplateFixed = false;
|
||||
$arrArticles = array();
|
||||
foreach ($objTemplate->articles as $article) {
|
||||
$arrArticle = $this->Database->prepare('SELECT * FROM tl_article WHERE ID=?')
|
||||
->limit(1)
|
||||
->execute($article['articleId'])
|
||||
->fetchAssoc();
|
||||
|
||||
if ($arrArticle['addRating']) {
|
||||
if (!$bolTemplateFixed) {
|
||||
$objTemplate->setName($objTemplate->getName().'_rateit');
|
||||
$bolTemplateFixed = true;
|
||||
}
|
||||
|
||||
$ratingId = $arrArticle['id'];
|
||||
$rating = $this->loadRating($ratingId, 'article');
|
||||
$stars = !$rating ? 0 : $this->percentToStars($rating['rating']);
|
||||
$percent = round($rating['rating'], 0)."%";
|
||||
|
||||
$article['descriptionId'] = 'rateItRating-'.$ratingId.'-description';
|
||||
$article['description'] = $this->getStarMessage($rating);
|
||||
$article['rateItID'] = 'rateItRating-'.$ratingId.'-article-'.$stars.'_'.$this->intStars;
|
||||
$article['rateit_class'] = 'rateItRating';
|
||||
$article['itemreviewed'] = $rating['title'];
|
||||
$article['actRating'] = $this->percentToStars($rating['rating']);
|
||||
$article['maxRating'] = $this->intStars;
|
||||
$article['votes'] = $rating[totalRatings];
|
||||
|
||||
if ($this->strTextPosition == "before") {
|
||||
$article['showBefore'] = true;
|
||||
}
|
||||
else if ($this->strTextPosition == "after") {
|
||||
$article['showAfter'] = true;
|
||||
}
|
||||
|
||||
if ($arrArticle['rateit_position'] == 'before') {
|
||||
$article['rateit_rating_before'] = true;
|
||||
} else if ($arrArticle['rateit_position'] == 'after') {
|
||||
$article['rateit_rating_after'] = true;
|
||||
}
|
||||
|
||||
$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.css||static';
|
||||
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
|
||||
case 'hearts' :
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
|
||||
break;
|
||||
default:
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.css||static';
|
||||
}
|
||||
}
|
||||
|
||||
$arrArticles[] = $article;
|
||||
}
|
||||
$objTemplate->articles = $arrArticles;
|
||||
}
|
||||
return $objTemplate;
|
||||
}
|
||||
|
||||
private function doGallery($objTemplate) {
|
||||
$arrGallery = $this->Database->prepare('SELECT * FROM tl_content WHERE ID=?')
|
||||
->limit(1)
|
||||
->execute($objTemplate->id)
|
||||
->fetchAssoc();
|
||||
|
||||
if ($arrGallery['rateit_active']) {
|
||||
$arrRating = array();
|
||||
|
||||
if (version_compare(VERSION, '3.2', '>=')) {
|
||||
$objFiles = \FilesModel::findMultipleByUuids(deserialize($arrGallery['multiSRC']));
|
||||
} else {
|
||||
$objFiles = \FilesModel::findMultipleByIds(deserialize($arrGallery['multiSRC']));
|
||||
}
|
||||
|
||||
if ($objFiles !== null) {
|
||||
// Get all images
|
||||
while ($objFiles->next()) {
|
||||
// Continue if the files has been processed or does not exist
|
||||
if (isset($arrRating[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Single files
|
||||
if ($objFiles->type == 'file') {
|
||||
$objFile = new \File($objFiles->path, true);
|
||||
|
||||
if (!$objFile->isGdImage) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->addRatingForImage($arrRating, $arrGallery['id'], $objFile->id, $objFile->path);
|
||||
}
|
||||
// Folders
|
||||
else {
|
||||
if (version_compare(VERSION, '3.2', '>=')) {
|
||||
$objSubfiles = \FilesModel::findByPid($objFiles->uuid);
|
||||
} else {
|
||||
$objSubfiles = \FilesModel::findByPid($objFiles->id);
|
||||
}
|
||||
|
||||
if ($objSubfiles === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
while ($objSubfiles->next()) {
|
||||
// Skip subfolders
|
||||
if ($objSubfiles->type == 'folder') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$objFile = new \File($objSubfiles->path, true);
|
||||
|
||||
if (!$objFile->isGdImage) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->addRatingForImage($arrRating, $arrGallery['id'], $objSubfiles->id, $objSubfiles->path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$objTemplate->arrRating = $arrRating;
|
||||
|
||||
$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.css||static';
|
||||
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
|
||||
case 'hearts' :
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
|
||||
break;
|
||||
default:
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.css||static';
|
||||
}
|
||||
}
|
||||
|
||||
return $objTemplate;
|
||||
}
|
||||
|
||||
private function addRatingForImage(&$arrRating, $galleryId, $picId, $picPath) {
|
||||
$ratingId = $galleryId.'|'.$picId;
|
||||
$rating = $this->loadRating($ratingId, 'galpic');
|
||||
$stars = !$rating ? 0 : $this->percentToStars($rating['rating']);
|
||||
$percent = round($rating['rating'], 0)."%";
|
||||
|
||||
$arrRating[$picPath] = array();
|
||||
$arrRating[$picPath]['descriptionId'] = 'rateItRating-'.$ratingId.'-description';
|
||||
$arrRating[$picPath]['description'] = $this->getStarMessage($rating);
|
||||
$arrRating[$picPath]['rateItID'] = 'rateItRating-'.$ratingId.'-galpic-'.$stars.'_'.$this->intStars;
|
||||
$arrRating[$picPath]['rateit_class'] = 'rateItRating';
|
||||
$arrRating[$picPath]['itemreviewed'] = $rating['title'];
|
||||
$arrRating[$picPath]['actRating'] = $this->percentToStars($rating['rating']);
|
||||
$arrRating[$picPath]['maxRating'] = $this->intStars;
|
||||
$arrRating[$picPath]['votes'] = $rating[totalRatings];
|
||||
|
||||
if ($this->strTextPosition == "before") {
|
||||
$arrRating[$picPath]['showBefore'] = true;
|
||||
}
|
||||
else if ($this->strTextPosition == "after") {
|
||||
$arrRating[$picPath]['showAfter'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
110
classes/RateItBackend.php
Normal file
110
classes/RateItBackend.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 RateItBackend
|
||||
{
|
||||
const path = 'system/modules/rateit/';
|
||||
|
||||
/**
|
||||
* Get a css file.
|
||||
* @param string $file The basename if the file (without extension).
|
||||
* @return string The file path.
|
||||
*/
|
||||
public static function css($file)
|
||||
{
|
||||
return self::path.'public/css/'. $file.'.css';
|
||||
} // file
|
||||
|
||||
/**
|
||||
* Get a js file.
|
||||
* @param string $file The basename if the file (without extension).
|
||||
* @return string The file path.
|
||||
*/
|
||||
public static function js($file)
|
||||
{
|
||||
return self::path.'public/js/'. $file.'.js';
|
||||
} // file
|
||||
|
||||
/**
|
||||
* Get image url from the theme.
|
||||
* @param string $file The basename if the image (without extension).
|
||||
* @return string The image path.
|
||||
*/
|
||||
public static function image($file)
|
||||
{
|
||||
$url = self::path.'public/images/';
|
||||
if (is_file(TL_ROOT.'/'.$url.$file.'.png')) return $url.$file.'.png';
|
||||
if (is_file(TL_ROOT.'/'.$url.$file.'.gif')) return $url.$file.'.gif';
|
||||
return $url.'default.png';
|
||||
} // image
|
||||
|
||||
/**
|
||||
* Create a 'img' tag from theme icons.
|
||||
* @param string $file The basename if the image (without extension).
|
||||
* @param string $alt The 'alt' text.
|
||||
* @param string $attributes Additional tag attributes.
|
||||
* @return string The html code.
|
||||
*/
|
||||
public static function createImage($file, $alt='', $attributes='')
|
||||
{
|
||||
if ($alt=='') $alt = 'icon';
|
||||
$img = self::image($file);
|
||||
$size = getimagesize(TL_ROOT.'/'.$img);
|
||||
return '<img'.((substr($img, -4) == '.png') ? ' class="pngfix"' : '').' src="'.$img.'" '.$size[3].' alt="'.specialchars($alt).'"'.(($attributes != '') ? ' '.$attributes : '').'>';
|
||||
} // createImage
|
||||
|
||||
/**
|
||||
* Create a list button (link button)
|
||||
* @param string $file The basename if the image (without extension).
|
||||
* @param string $link The URL of the link to create.
|
||||
* @param string $text The alt/title text.
|
||||
* @param string $confirm Optional confirmation text before redirecting to the link.
|
||||
* @param boolean $popup Open the target in a new window.
|
||||
* @return string The html code.
|
||||
*/
|
||||
public function createListButton($file, $link, $text, $confirm='', $popup=false)
|
||||
{
|
||||
$target = $popup ? ' target="_blank"' : '';
|
||||
$onclick = ($confirm!='') ? ' onclick="if(!confirm(\''.$confirm.'\'))return false"' : '';
|
||||
return '<a href="'.$link.'" title="'.$text.'"'.$target.$onclick.'>'.$this->createImage($file,$text).'</a>';
|
||||
} // createListButton
|
||||
|
||||
public function createMainButton($file, $link, $text, $confirm='')
|
||||
{
|
||||
$onclick = ($confirm=='')
|
||||
? ''
|
||||
: ' onclick="if(!confirm(\''.$confirm.'\'))return false"';
|
||||
return '<a href="'.$link.'" title="'.$text.'"'.$onclick.'>'.$this->createImage($file,$text).' '.$text.'</a>';
|
||||
} // createMainButton
|
||||
} // class RateItBackend
|
||||
|
||||
?>
|
801
classes/RateItBackendModule.php
Normal file
801
classes/RateItBackendModule.php
Normal file
@ -0,0 +1,801 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 rateitBackendModule extends \BackendModule
|
||||
{
|
||||
protected $strTemplate;
|
||||
protected $actions = array();
|
||||
|
||||
protected $rateit;
|
||||
|
||||
protected $tl_root;
|
||||
protected $tl_files;
|
||||
protected $languages;
|
||||
|
||||
private $compiler;
|
||||
private $action = '';
|
||||
private $parameter = '';
|
||||
|
||||
private $arrExportHeader;
|
||||
private $arrExportHeaderDetails;
|
||||
|
||||
/**
|
||||
* Anzahl der Herzen/Sterne
|
||||
* @var int
|
||||
*/
|
||||
protected $intStars = 5;
|
||||
|
||||
protected $label;
|
||||
protected $labels;
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function __construct($objElement=array()) {
|
||||
parent::__construct($objElement);
|
||||
|
||||
$this->label = $GLOBALS['TL_CONFIG']['rating_type'] == 'hearts' ? $GLOBALS['TL_LANG']['rateit']['heart'] : $GLOBALS['TL_LANG']['rateit']['star'];
|
||||
$this->labels = $GLOBALS['TL_CONFIG']['rating_type'] == 'hearts' ? $GLOBALS['TL_LANG']['rateit']['hearts'] : $GLOBALS['TL_LANG']['rateit']['stars'];
|
||||
|
||||
$this->actions = array(
|
||||
// act[0] strTemplate compiler
|
||||
array('', 'rateitbe_ratinglist', 'listRatings' ),
|
||||
array('reset_ratings', '', 'resetRatings' ),
|
||||
array('view', 'rateitbe_ratingview', 'viewRating' ),
|
||||
array('export', '', 'exportRatings' ),
|
||||
array('exportDetails', '', 'exportRatingDetails' ),
|
||||
);
|
||||
|
||||
$this->loadLanguageFile('rateit_backend');
|
||||
$this->arrExportHeader = &$GLOBALS['TL_LANG']['tl_rateit']['xls_headers'];
|
||||
$this->arrExportHeaderDetails = &$GLOBALS['TL_LANG']['tl_rateit']['xls_headers_detail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate module:
|
||||
* - Display a wildcard in the back end
|
||||
* - Select the template and compiler in the front end
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$this->rateit = new \stdClass();
|
||||
$rateit = &$this->rateit;
|
||||
$rateit->username = $this->BackendUser->username;
|
||||
$rateit->isadmin = $this->BackendUser->isAdmin;
|
||||
|
||||
$this->strTemplate = $this->actions[0][1];
|
||||
$this->compiler = $this->actions[0][2];
|
||||
|
||||
$act = \Input::get('act');
|
||||
if (!$act) $act = \Input::post('act');
|
||||
foreach ($this->actions as $action) {
|
||||
if ($act == $action[0]) {
|
||||
$this->parameter = $act;
|
||||
$this->action = $action[0];
|
||||
$this->strTemplate = $action[1];
|
||||
$this->compiler = $action[2];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$stars = intval($GLOBALS['TL_CONFIG']['rating_count']);
|
||||
if ($stars > 0) {
|
||||
$this->intStars = $stars;
|
||||
}
|
||||
|
||||
return str_replace(array('{{', '}}'), array('[{]', '[}]'), parent::generate());
|
||||
} // generate
|
||||
|
||||
/**
|
||||
* Compile module: common initializations and forwarding to distinct function compiler
|
||||
*/
|
||||
protected function compile()
|
||||
{
|
||||
// hide module?
|
||||
$compiler = $this->compiler;
|
||||
if ($compiler=='hide') return;
|
||||
|
||||
// load other helpers
|
||||
$this->tl_root = str_replace("\\",'/',TL_ROOT).'/';
|
||||
$this->tl_files = str_replace("\\",'/',$GLOBALS['TL_CONFIG']['uploadPath']).'/';
|
||||
$this->Template->rateit = $this->rateit;
|
||||
|
||||
// complete rateit initialization
|
||||
$rateit = &$this->rateit;
|
||||
$rateit->f_link = $this->createUrl(array($this->action => $this->parameter));
|
||||
$rateit->f_action = $this->compiler;
|
||||
$rateit->f_mode = $this->action;
|
||||
$rateit->theme = new RateItBackend();
|
||||
$rateit->backLink = $this->getReferer(true);
|
||||
$rateit->homeLink = $this->createUrl();
|
||||
|
||||
// execute compiler
|
||||
$this->$compiler($this->parameter);
|
||||
} // compile
|
||||
|
||||
/**
|
||||
* List the ratings
|
||||
*/
|
||||
protected function listRatings()
|
||||
{
|
||||
$rateit = &$this->Template->rateit;
|
||||
$rateit->f_page = 0;
|
||||
|
||||
// returning from submit?
|
||||
if ($this->filterPost('rateit_action') == $rateit->f_action) {
|
||||
// get url parameters
|
||||
$rateit->f_typ = trim(\Input::post('rateit_typ'));
|
||||
$rateit->f_active = trim(\Input::post('rateit_active'));
|
||||
$rateit->f_order = trim(\Input::post('rateit_order'));
|
||||
$rateit->f_page = trim(\Input::post('rateit_page'));
|
||||
$rateit->f_find = trim(\Input::post('rateit_find'));
|
||||
$this->Session->set(
|
||||
'rateit_settings',
|
||||
array(
|
||||
'rateit_typ' => $rateit->f_typ,
|
||||
'rateit_order' => $rateit->f_order,
|
||||
'rateit_page' => $rateit->f_page,
|
||||
'rateit_find' => $rateit->f_find
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$stg = $this->Session->get('rateit_settings');
|
||||
if (is_array($stg)) {
|
||||
$rateit->f_typ = trim($stg['rateit_typ']);
|
||||
$rateit->f_active = trim($stg['rateit_active']);
|
||||
$rateit->f_order = trim($stg['rateit_order']);
|
||||
$rateit->f_page = trim($stg['rateit_page']);
|
||||
$rateit->f_find = trim($stg['rateit_find']);
|
||||
} // if
|
||||
} // if
|
||||
|
||||
if ($rateit->f_order=='') $rateit->f_order = 'rating';
|
||||
//if (!isset($rateit->f_active)) $rateit->f_active = '-1';
|
||||
|
||||
if (isset($GLOBALS['TL_CONFIG']['rating_listsize']))
|
||||
$perpage = (int)trim($GLOBALS['TL_CONFIG']['rating_listsize']);
|
||||
if (!isset($perpage) || $perpage < 0) $perpage = 10;
|
||||
|
||||
if ($rateit->f_page>=0 && $perpage>0) {
|
||||
$options['first'] = $rateit->f_page * $perpage;
|
||||
$options['limit'] = $perpage;
|
||||
} // if
|
||||
if ($rateit->f_typ != '') $options['typ'] = $rateit->f_typ;
|
||||
if ($rateit->f_active != '') $options['active'] = $rateit->f_active == '0' ? '' : $rateit->f_active;
|
||||
if ($rateit->f_find != '') $options['find'] = $rateit->f_find;
|
||||
|
||||
switch ($rateit->f_order) {
|
||||
case 'title' : $options['order'] = 'title'; break;
|
||||
case 'typ' : $options['order'] = 'typ'; break;
|
||||
case 'createdat' : $options['order'] = 'createdat'; break;
|
||||
default : $options['order'] = 'rating desc';
|
||||
} // switch
|
||||
|
||||
$rateit->exportLink = $this->createUrl(array('act' => 'export'));
|
||||
|
||||
// query extensions
|
||||
$rateit->ratingitems = $this->getRatingItems($options);
|
||||
if ($rateit->f_page>=0 && $perpage>0 && count($rateit->ratingitems)==0) {
|
||||
$rateit->f_page = 0;
|
||||
$options['first'] = 0;
|
||||
$rateit->ratingitems = $this->getRatingItems($options);
|
||||
} // if
|
||||
|
||||
// add view links
|
||||
foreach ($rateit->ratingitems as &$ext) {
|
||||
$ext->viewLink = $this->createUrl(array('act' => 'view', 'rkey' => $ext->rkey, 'typ' => $ext->typ));
|
||||
$totrecs = $ext->totcount;
|
||||
} // foreach
|
||||
|
||||
// create pages list
|
||||
$rateit->pages = array();
|
||||
if ($perpage > 0) {
|
||||
$first = 1;
|
||||
while ($totrecs > 0) {
|
||||
$cnt = $totrecs > $perpage ? $perpage : $totrecs;
|
||||
$rateit->pages[] = $first . ' - ' . ($first+$cnt-1);
|
||||
$first += $cnt;
|
||||
$totrecs -= $cnt;
|
||||
} // while
|
||||
} // if
|
||||
} // listRatings
|
||||
|
||||
/**
|
||||
* Export all ratings as MS-Excel-File
|
||||
*/
|
||||
protected function exportRatings()
|
||||
{
|
||||
$this->import('String');
|
||||
$rateit = &$this->Template->rateit;
|
||||
|
||||
$options['order'] = 'rating desc';
|
||||
|
||||
// query ratings
|
||||
$rateit->ratingitems = $this->getRatingItems($options, true);
|
||||
|
||||
$xls = new \xlsexport();
|
||||
$strXlsSheet = $GLOBALS['TL_LANG']['tl_rateit']['xls_sheetname_ratings'];
|
||||
$xls->addworksheet($strXlsSheet);
|
||||
|
||||
$intRowCounter = -1;
|
||||
$intColCounter = 0;
|
||||
|
||||
$intRowCounter++;
|
||||
|
||||
// Header setzen
|
||||
foreach(array_values($this->arrExportHeader) as $header) {
|
||||
$xls->setcell(array("sheetname" => $strXlsSheet,"row" => $intRowCounter, "col" => $intColCounter, "data" => $header, "fontweight" => XLSFONT_BOLD, "vallign" => XLSXF_VALLIGN_TOP, "fontfamily" => XLSFONT_FAMILY_NORMAL));
|
||||
$xls->setcolwidth($strXlsSheet, $intColCounter, 0x1aff);
|
||||
$intColCounter++;
|
||||
}
|
||||
|
||||
$intRowCounter++;
|
||||
|
||||
// Werte setzen
|
||||
foreach($rateit->ratingitems as $item) {
|
||||
$arrItem = (array)$item;
|
||||
|
||||
$intColCounter = 0;
|
||||
foreach(array_keys($this->arrExportHeader) as $key) {
|
||||
$strVal = $arrItem[$key];
|
||||
$strVal = $this->String->decodeEntities($strVal);
|
||||
$strVal = preg_replace(array('/<br.*\/*>/si'), array("\n"), $strVal);
|
||||
$strVal = $this->convertEncoding($strVal, $GLOBALS['TL_CONFIG']['characterSet'], 'CP1252');
|
||||
|
||||
$cellType = CELL_STRING;
|
||||
switch ($key) {
|
||||
case 'typ' :
|
||||
$strVal = $GLOBALS['TL_LANG']['tl_rateit_type_options'][$strVal];
|
||||
break;
|
||||
case 'createdat' :
|
||||
$strVal = $strVal ? date($GLOBALS['TL_CONFIG']['datimFormat'], $strVal) : '';
|
||||
break;
|
||||
case 'active' :
|
||||
$strVal = $strVal == '1' ? 'Ja' : 'Nein';
|
||||
break;
|
||||
case 'rating' :
|
||||
if (!isset($strVal) || empty($strVal)) {
|
||||
$strVal = '0';
|
||||
}
|
||||
$cellType = CELL_FLOAT;
|
||||
break;
|
||||
case 'stars' :
|
||||
case 'percent' :
|
||||
case 'totalRatings' :
|
||||
case 'rkey' :
|
||||
$cellType = CELL_FLOAT;
|
||||
break;
|
||||
}
|
||||
$xls->setcell(array("sheetname" => $strXlsSheet,"row" => $intRowCounter, "col" => $intColCounter, "data" => $strVal, "type" => $cellType, "vallign" => XLSXF_VALLIGN_TOP, "fontfamily" => XLSFONT_FAMILY_NORMAL));
|
||||
$intColCounter++;
|
||||
}
|
||||
|
||||
$intRowCounter++;
|
||||
}
|
||||
|
||||
$xls->sendfile("export_rateit_" . date("Ymd_His") . ".xls");
|
||||
exit;
|
||||
} // exportRatings
|
||||
|
||||
/**
|
||||
* Detailed view of one rating.
|
||||
* @param string
|
||||
*/
|
||||
protected function viewRating()
|
||||
{
|
||||
$rateit = &$this->Template->rateit;
|
||||
|
||||
$rateit->f_page = 0;
|
||||
|
||||
// returning from submit?
|
||||
if ($this->filterPost('rateit_action') == $rateit->f_action) {
|
||||
// get url parameters
|
||||
$rateit->f_page = trim(\Input::post('rateit_details_page'));
|
||||
$this->Session->set(
|
||||
'rateit_settings',
|
||||
array(
|
||||
'rateit_details_page' => $rateit->f_page
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$stg = $this->Session->get('rateit_settings');
|
||||
if (is_array($stg)) {
|
||||
$rateit->f_page = trim($stg['rateit_details_page']);
|
||||
} // if
|
||||
} // if
|
||||
|
||||
$rkey = \Input::get('rkey');
|
||||
if (strstr($rkey, '|')) {
|
||||
$arrRkey = explode('|', $rkey);
|
||||
foreach ($arrRkey as $key) {
|
||||
if (!is_numeric($key)) {
|
||||
$this->redirect($rateit->homeLink);
|
||||
exit;
|
||||
}
|
||||
$id = $rkey;
|
||||
}
|
||||
} else {
|
||||
if (is_numeric($rkey)) {
|
||||
$id = $rkey;
|
||||
} else {
|
||||
$this->redirect($rateit->homeLink);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$typ = \Input::get('typ');
|
||||
|
||||
// compose base options
|
||||
$options = array(
|
||||
'rkey' => $rkey,
|
||||
'typ' => $typ
|
||||
);
|
||||
|
||||
$this->rateit->f_link = $this->createUrl(array('act' => 'view', 'rkey' => $rkey, 'typ' => $typ));
|
||||
|
||||
if (isset($GLOBALS['TL_CONFIG']['rating_listsize']))
|
||||
$perpage = (int)trim($GLOBALS['TL_CONFIG']['rating_listsize']);
|
||||
if (!isset($perpage) || $perpage < 0) $perpage = 10;
|
||||
|
||||
if ($rateit->f_page>=0 && $perpage>0) {
|
||||
$options['first'] = $rateit->f_page * $perpage;
|
||||
$options['limit'] = $perpage;
|
||||
} // if
|
||||
|
||||
$rateit->ratingitems = $this->getRatingItems($options, true);
|
||||
if (count($rateit->ratingitems)<1) $this->redirect($rateit->homeLink);
|
||||
$ext = &$rateit->ratingitems[0];
|
||||
|
||||
$ext->ratings = $this->getRatings($ext, $options);
|
||||
if ($rateit->f_page>=0 && $perpage>0 && count($ext->ratings)==0) {
|
||||
$rateit->f_page = 0;
|
||||
$options['first'] = 0;
|
||||
$rateit->ratings = $this->getRatings($ext, $options);
|
||||
} // if
|
||||
|
||||
if (count($ext->ratings) > 0) {
|
||||
$totrecs = $ext->ratings[0]->totcount;
|
||||
} else {
|
||||
$totrecs = 0;
|
||||
}
|
||||
|
||||
// create pages list
|
||||
$rateit->pages = array();
|
||||
if ($perpage > 0) {
|
||||
$first = 1;
|
||||
while ($totrecs > 0) {
|
||||
$cnt = $totrecs > $perpage ? $perpage : $totrecs;
|
||||
$rateit->pages[] = $first . ' - ' . ($first+$cnt-1);
|
||||
$first += $cnt;
|
||||
$totrecs -= $cnt;
|
||||
} // while
|
||||
} // if
|
||||
|
||||
$rateit->exportLink = $this->createUrl(array('act' => 'exportDetails', 'rkey' => $rkey, 'typ' => $typ));
|
||||
|
||||
$ext->statistics = $this->getRatingStatistics($ext->item_id);
|
||||
$ext->ratingsChartData = $this->getRatingsChartData($ext->statistics);
|
||||
$ext->monthsChartData = $this->getMonthsChartData($ext->item_id);
|
||||
} // viewRating
|
||||
|
||||
protected function resetRatings()
|
||||
{
|
||||
$rateit = &$this->Template->rateit;
|
||||
|
||||
// nothing checked?
|
||||
$ids0 = \Input::post('selectedids');
|
||||
if (!is_array($ids0)) {
|
||||
$this->redirect($rep->homeLink); return;
|
||||
}
|
||||
|
||||
foreach ($ids0 as $id) {
|
||||
list($rkey, $typ) = explode('__', $id);
|
||||
$pid = $this->Database->prepare('SELECT id FROM tl_rateit_items WHERE rkey=? and typ=?')
|
||||
->execute($rkey, $typ)
|
||||
->fetchRow();
|
||||
$this->Database->prepare('DELETE FROM tl_rateit_ratings WHERE pid=?')
|
||||
->execute($pid[0]);
|
||||
}
|
||||
|
||||
$this->redirect($rateit->homeLink);
|
||||
|
||||
} // resetRatings
|
||||
|
||||
/**
|
||||
* Export the details of one rating as MS-Excel-File
|
||||
*/
|
||||
protected function exportRatingDetails()
|
||||
{
|
||||
$rkey = \Input::get('rkey');
|
||||
if (!is_numeric($rkey))
|
||||
$this->redirect($rateit->backLink);
|
||||
$typ = \Input::get('typ');
|
||||
|
||||
$this->rateit->backLink = $this->createUrl(array('act' => 'view', 'rkey' => $rkey, 'typ' => $typ));
|
||||
|
||||
// compose base options
|
||||
$options = array(
|
||||
'rkey' => $rkey,
|
||||
'typ' => $typ
|
||||
);
|
||||
|
||||
$this->import('String');
|
||||
$rateit = &$this->Template->rateit;
|
||||
|
||||
// query ratings
|
||||
$rateit->ratingitems = $this->getRatingItems($options);
|
||||
if (count($rateit->ratingitems)<1) $this->redirect($rateit->backLink);
|
||||
$ext = &$rateit->ratingitems[0];
|
||||
$ext->ratings = $this->getRatings($ext);
|
||||
$ext->statistics = $this->getRatingStatistics($ext->item_id);
|
||||
|
||||
$xls = new \xlsexport();
|
||||
$strXlsSheet = $GLOBALS['TL_LANG']['tl_rateit']['xls_sheetname_rating'];
|
||||
$xls->addworksheet($strXlsSheet);
|
||||
|
||||
$intRowCounter = -1;
|
||||
$intColCounter = 0;
|
||||
|
||||
$intRowCounter++;
|
||||
|
||||
// Header setzen
|
||||
foreach(array_values($this->arrExportHeaderDetails) as $header) {
|
||||
$xls->setcell(array("sheetname" => $strXlsSheet,"row" => $intRowCounter, "col" => $intColCounter, "data" => $header, "fontweight" => XLSFONT_BOLD, "vallign" => XLSXF_VALLIGN_TOP, "fontfamily" => XLSFONT_FAMILY_NORMAL));
|
||||
$xls->setcolwidth($strXlsSheet, $intColCounter, 0x1aff);
|
||||
$intColCounter++;
|
||||
}
|
||||
|
||||
$intRowCounter++;
|
||||
|
||||
// Werte setzen
|
||||
foreach($ext->ratings as $item) {
|
||||
$arrItem = (array)$item;
|
||||
|
||||
$intColCounter = 0;
|
||||
foreach(array_keys($this->arrExportHeaderDetails) as $key) {
|
||||
$strVal = $arrItem[$key];
|
||||
$strVal = $this->String->decodeEntities($strVal);
|
||||
$strVal = preg_replace(array('/<br.*\/*>/si'), array("\n"), $strVal);
|
||||
$strVal = $this->convertEncoding($strVal, $GLOBALS['TL_CONFIG']['characterSet'], 'CP1252');
|
||||
|
||||
$cellType = CELL_STRING;
|
||||
switch ($key) {
|
||||
case 'createdat' :
|
||||
$strVal = $strVal ? date($GLOBALS['TL_CONFIG']['datimFormat'], $strVal) : '';
|
||||
break;
|
||||
case 'rating' :
|
||||
if (!isset($strVal) || empty($strVal)) {
|
||||
$strVal = '0';
|
||||
}
|
||||
$cellType = CELL_FLOAT;
|
||||
break;
|
||||
case 'stars' :
|
||||
case 'percent' :
|
||||
case 'totalRatings' :
|
||||
case 'rkey' :
|
||||
$cellType = CELL_FLOAT;
|
||||
break;
|
||||
}
|
||||
$xls->setcell(array("sheetname" => $strXlsSheet,"row" => $intRowCounter, "col" => $intColCounter, "data" => $strVal, "type" => $cellType, "vallign" => XLSXF_VALLIGN_TOP, "fontfamily" => XLSFONT_FAMILY_NORMAL));
|
||||
$intColCounter++;
|
||||
}
|
||||
|
||||
$intRowCounter++;
|
||||
}
|
||||
|
||||
$xls->sendfile("export_rateit_" . date("Ymd_His") . ".xls");
|
||||
exit;
|
||||
} // exportRatingDetails
|
||||
|
||||
/**
|
||||
* Create url for hyperlink to the current page.
|
||||
* @param array $aParams Assiciative array with key/value pairs as parameters.
|
||||
* @return string The create link.
|
||||
*/
|
||||
protected function createUrl($aParams = null)
|
||||
{
|
||||
return $this->createPageUrl(\Input::get('do'), $aParams);
|
||||
} // createUrl
|
||||
|
||||
/**
|
||||
* Create url for hyperlink to an arbitrary page.
|
||||
* @param string $aPage The page ID.
|
||||
* @param array $aParams Assiciative array with key/value pairs as parameters.
|
||||
* @return string The create link.
|
||||
*/
|
||||
protected function createPageUrl($aPage, $aParams = null)
|
||||
{
|
||||
$url = \Environment::get('script') . '?do='.$aPage;
|
||||
if (is_array($aParams)) {
|
||||
foreach ($aParams as $key => $val)
|
||||
if ($val!='')
|
||||
$url .= '&'.$key .'='.$val;
|
||||
}
|
||||
return $url;
|
||||
} // createPageUrl
|
||||
|
||||
/**
|
||||
* Get post parameter and filter value.
|
||||
* @param string $aKey The post key. When filtering html, remove all attribs and
|
||||
* keep the plain tags.
|
||||
* @param string $aMode '': no filtering
|
||||
* 'nohtml': strip all html
|
||||
* 'text': Keep tags p br ul li em
|
||||
* @return string The filtered input.
|
||||
*/
|
||||
protected function filterPost($aKey, $aMode = '')
|
||||
{
|
||||
$v = trim(\Input::postRaw($aKey));
|
||||
if ($v == '' || $aMode=='') return $v;
|
||||
switch ($aMode) {
|
||||
case 'nohtml':
|
||||
$v = strip_tags($v);
|
||||
break;
|
||||
case 'text':
|
||||
$v = strip_tags($v, rateit_TEXTTAGS);
|
||||
break;
|
||||
} // switch
|
||||
$v = preg_replace('/<(\w+) .*>/U', '<$1>', $v);
|
||||
return $v;
|
||||
} // filterPost
|
||||
|
||||
protected function getRatingItems($aOptions, $noLimit=false) {
|
||||
$sql = "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 rating,
|
||||
COUNT( r.rating ) AS totalRatings
|
||||
FROM tl_rateit_items i
|
||||
LEFT OUTER JOIN tl_rateit_ratings r
|
||||
ON (i.id = r.pid)
|
||||
%w
|
||||
GROUP BY rkey, title, item_id, typ, createdat, active
|
||||
%o
|
||||
%l";
|
||||
|
||||
$cntSql = "SELECT COUNT(*) FROM tl_rateit_items i %s";
|
||||
|
||||
$where = '';
|
||||
$firstWhere = true;
|
||||
$limit = '';
|
||||
$order = '';
|
||||
|
||||
foreach ($aOptions as $k=>$v) {
|
||||
if ($k == 'find') {
|
||||
if (!$firstWhere) {
|
||||
$where .= " AND";
|
||||
}
|
||||
$where .= " title like '%$v%'";
|
||||
$firstWhere = false;
|
||||
}
|
||||
else if ($k != 'order' && $k != 'limit' && $k != 'first') {
|
||||
if (!$firstWhere) {
|
||||
$where .= " AND";
|
||||
}
|
||||
$where .= " $k='$v'";
|
||||
$firstWhere = false;
|
||||
} else {
|
||||
if ($k == 'limit' && !$noLimit) {
|
||||
$cntRows = $v;
|
||||
} else if ($k == 'first' && !$noLimit) {
|
||||
$first = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($cntRows) && isset($first)) {
|
||||
$limit = "LIMIT $first, $cntRows";
|
||||
}
|
||||
|
||||
if (strlen($where) > 0) {
|
||||
$where = "WHERE ".$where;
|
||||
}
|
||||
|
||||
if (isset($aOptions['order']) && !empty($aOptions['order']))
|
||||
$order = "ORDER BY ".$aOptions['order'];
|
||||
|
||||
$sql = str_replace('%o', $order, $sql);
|
||||
$sql = str_replace('%w', $where, $sql);
|
||||
$sql = str_replace('%l', $limit, $sql);
|
||||
|
||||
$cntSql = str_replace('%s', $where, $cntSql);
|
||||
|
||||
$count = $this->Database->prepare($cntSql)
|
||||
->execute()
|
||||
->fetchRow();
|
||||
|
||||
$arrRatingItems = $this->Database->prepare($sql)
|
||||
->execute()
|
||||
->fetchAllAssoc();
|
||||
$arrReturn = array();
|
||||
foreach ($arrRatingItems as $rating) {
|
||||
if ($rating['active'] != '1') $rating['active'] = '0';
|
||||
$rating['percent'] = $rating['rating'];
|
||||
$rating['rating'] = $this->percentToStars($rating['percent']);
|
||||
$rating['stars'] = $this->intStars;
|
||||
$rating['totcount'] = $count[0];
|
||||
$arrReturn[] = (object) $rating;
|
||||
}
|
||||
return $arrReturn;
|
||||
} // getRatingItems
|
||||
|
||||
protected function getRatings($ext, $options = array()) {
|
||||
// Gesamtanzahl (für Paging wichtig) ermitteln
|
||||
$cntSql = "SELECT COUNT(*) FROM tl_rateit_ratings r WHERE r.pid=$ext->item_id";
|
||||
$count = $this->Database->prepare($cntSql)
|
||||
->execute()
|
||||
->fetchRow();
|
||||
|
||||
foreach ($options as $k=>$v) {
|
||||
if ($k == 'limit') {
|
||||
$cntRows = $v;
|
||||
} else if ($k == 'first') {
|
||||
$first = $v;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($cntRows) && isset($first)) {
|
||||
$limit = "LIMIT $first, $cntRows";
|
||||
}
|
||||
|
||||
$sql = "SELECT id AS rating_id, ip_address AS ip, memberid, rating, createdat
|
||||
FROM tl_rateit_ratings r
|
||||
WHERE r.pid=$ext->item_id
|
||||
ORDER BY createdat DESC
|
||||
%l";
|
||||
$sql = str_replace('%l', $limit, $sql);
|
||||
|
||||
$arrRatings = $this->Database->prepare($sql)
|
||||
->execute()
|
||||
->fetchAllAssoc();
|
||||
$arrReturn = array();
|
||||
foreach ($arrRatings as $rating) {
|
||||
$rating['percent'] = $rating['rating'];
|
||||
$rating['rating'] = $this->percentToStars($rating['percent']);
|
||||
$rating['stars'] = $this->intStars;
|
||||
$rating['totcount'] = $count[0];
|
||||
if ($rating['memberid'] != null) {
|
||||
$member = $this->Database->prepare("SELECT firstname, lastname FROM tl_member WHERE id=?")
|
||||
->limit(1)
|
||||
->execute($rating['memberid'])
|
||||
->fetchAssoc();
|
||||
$rating['member'] = $member['firstname']." ".$member['lastname'];
|
||||
}
|
||||
$arrReturn[] = (object) $rating;
|
||||
}
|
||||
return $arrReturn;
|
||||
} // getRatings
|
||||
|
||||
protected function getRatingStatistics($item_id) {
|
||||
$sql = "SELECT rating, count(*) as count
|
||||
FROM tl_rateit_ratings r
|
||||
WHERE r.pid=$item_id
|
||||
GROUP BY rating
|
||||
ORDER BY rating";
|
||||
|
||||
$arrRatingStatistics = $this->Database->prepare($sql)
|
||||
->execute()
|
||||
->fetchAllAssoc();
|
||||
$arrReturn = array();
|
||||
foreach ($arrRatingStatistics as $rating) {
|
||||
$rating['percent'] = $rating['rating'];
|
||||
$rating['rating'] = $this->percentToStars($rating['percent']);
|
||||
$arrReturn[$rating['percent']] = (object) $rating;
|
||||
}
|
||||
return $arrReturn;
|
||||
} // getRatings
|
||||
|
||||
protected function getRatingsChartData($statistics) {
|
||||
$arr = array();
|
||||
$arr['cols'] = array();
|
||||
$arr['rows'] = array();
|
||||
|
||||
// Spalten anlegen
|
||||
$arr['cols'][] = array('id'=>'rating', 'label'=>$GLOBALS['TL_LANG']['tl_rateit']['rating_chart_legend'][2], 'type'=>'string');
|
||||
$arr['cols'][] = array('id'=>'count', 'label'=>$GLOBALS['TL_LANG']['tl_rateit']['rating_chart_legend'][3], 'type'=>'number');
|
||||
|
||||
// Zeilen anlegen
|
||||
foreach($statistics as $obj) {
|
||||
$arr['rows'][] = array('c'=>array(array('v'=>$obj->rating.' '.($obj->rating == 1 ? $this->label : $this->labels)), array('v'=>(int)$obj->count, 'f'=>$obj->count.' '.$GLOBALS['TL_LANG']['tl_rateit']['vote'][$obj->count == 1 ? 0 : 1])));
|
||||
}
|
||||
return json_encode($arr);
|
||||
}
|
||||
|
||||
protected function getMonthsChartData($item_id) {
|
||||
|
||||
$sql = "SELECT count(*) AS anzahl, avg(rating) AS bewertung, month(date(FROM_UNIXTIME(createdat))) AS monat, year(date(FROM_UNIXTIME(createdat))) AS jahr
|
||||
FROM tl_rateit_ratings r
|
||||
WHERE r.pid=$item_id
|
||||
GROUP BY monat, jahr
|
||||
ORDER BY jahr DESC , monat DESC
|
||||
LIMIT 0 , 12";
|
||||
|
||||
$arrResult = $this->Database->prepare($sql)
|
||||
->execute()
|
||||
->fetchAllAssoc();
|
||||
|
||||
$arrResult = array_reverse($arrResult);
|
||||
|
||||
$this->loadLanguageFile('default');
|
||||
|
||||
$arr = array();
|
||||
$arr['cols'] = array();
|
||||
$arr['rows'] = array();
|
||||
|
||||
// Spalten anlegen
|
||||
$arr['cols'][] = array('id'=>'month', 'label'=>$GLOBALS['TL_LANG']['tl_rateit']['month_chart_legend'][3], 'type'=>'string');
|
||||
$arr['cols'][] = array('id'=>'count', 'label'=>$GLOBALS['TL_LANG']['tl_rateit']['month_chart_legend'][4], 'type'=>'number');
|
||||
$arr['cols'][] = array('id'=>'avg', 'label'=>$GLOBALS['TL_LANG']['tl_rateit']['month_chart_legend'][2], 'type'=>'number');
|
||||
|
||||
// Zeilen anlegen
|
||||
foreach($arrResult as $result) {
|
||||
$month = $GLOBALS['TL_LANG']['MONTHS'][$result['monat']-1].' '.$result['jahr'];
|
||||
$avgValue = round((float)(($result['bewertung']*$this->intStars)/100), 1);
|
||||
$arr['rows'][] = array('c'=>array(array('v'=>$month),
|
||||
array('v'=>(int)$result['anzahl']),
|
||||
array('v'=>$avgValue)));
|
||||
}
|
||||
return json_encode($arr);
|
||||
}
|
||||
|
||||
protected function percentToStars($percent) {
|
||||
$modifier = 100 / $this->intStars;
|
||||
return round($percent / $modifier, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert encoding
|
||||
* @return String
|
||||
* @param $strString String to convert
|
||||
* @param $from charset to convert from
|
||||
* @param $to charset to convert to
|
||||
*/
|
||||
public function convertEncoding($strString, $from, $to) {
|
||||
if (USE_MBSTRING) {
|
||||
@mb_substitute_character('none');
|
||||
return @mb_convert_encoding($strString, $to, $from);
|
||||
}
|
||||
elseif (function_exists('iconv')) {
|
||||
if (strlen($iconv = @iconv($from, $to . '//IGNORE', $strString))) {
|
||||
return $iconv;
|
||||
}
|
||||
else {
|
||||
return @iconv($from, $to, $strString);
|
||||
}
|
||||
}
|
||||
return $strString;
|
||||
}
|
||||
} // class rateitBackendModule
|
51
classes/RateItCE.php
Normal file
51
classes/RateItCE.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 RateItCE
|
||||
*/
|
||||
class RateItCE extends RateItHybrid
|
||||
{
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function __construct($objElement) {
|
||||
parent::__construct($objElement);
|
||||
}
|
||||
|
||||
protected function getType() {
|
||||
return 'ce';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
159
classes/RateItFaq.php
Normal file
159
classes/RateItFaq.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 RateItFaq extends RateItFrontend {
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getContentElementRateIt($objRow, $strBuffer) {
|
||||
if ($objRow->type == 'module') {
|
||||
$objModule = $this->Database->prepare("SELECT * FROM tl_module WHERE id=? AND type IN ('faqpage', 'faqreader')")
|
||||
->limit(1)
|
||||
->execute($objRow->module);
|
||||
|
||||
if ($objModule->numRows == 1) {
|
||||
$this->faq_categories = deserialize($objModule->faq_categories);
|
||||
|
||||
if ($objModule->type == 'faqreader') {
|
||||
$strBuffer = $this->generateForFaqReader($objModule, $strBuffer);
|
||||
} else {
|
||||
$strBuffer = $this->generateForFaqPage($objModule, $strBuffer);
|
||||
}
|
||||
|
||||
$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.css||static';
|
||||
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
|
||||
case 'hearts' :
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
|
||||
break;
|
||||
default:
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.css||static';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $strBuffer;
|
||||
}
|
||||
|
||||
private function generateForFaqPage($objModule, $strBuffer) {
|
||||
$objFaq = $this->Database
|
||||
->execute("SELECT *, author AS authorId, (SELECT headline FROM tl_faq_category WHERE tl_faq_category.id=tl_faq.pid) AS category, (SELECT name FROM tl_user WHERE tl_user.id=tl_faq.author) AS author FROM tl_faq WHERE pid IN(" . implode(',', array_map('intval', $this->faq_categories)) . ")" . (!BE_USER_LOGGED_IN ? " AND published=1" : ""));
|
||||
|
||||
if ($objFaq->numRows < 1) {
|
||||
return $strBuffer;
|
||||
}
|
||||
|
||||
$htmlBuffer = new \simple_html_dom();
|
||||
$htmlBuffer->load($strBuffer);
|
||||
|
||||
$arrFaqs = $objFaq->fetchAllAssoc();
|
||||
foreach ($arrFaqs as $arrFaq) {
|
||||
$rating = $this->generateSingle($arrFaq, $strBuffer);
|
||||
|
||||
$h3 = $htmlBuffer->find('#'.$arrFaq['alias']);
|
||||
if (is_array($h3) && count($h3) == 1) {
|
||||
$section = $h3[0]->parent();
|
||||
|
||||
if ($arrFaq['rateit_position'] == 'before') {
|
||||
$section->innertext = $rating.$section->innertext;
|
||||
} else if ($arrFaq['rateit_position'] == 'after') {
|
||||
$section->innertext = $section->innertext.$rating;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$strBuffer = $htmlBuffer->save();
|
||||
|
||||
// Aufräumen
|
||||
$htmlBuffer->clear();
|
||||
unset($htmlBuffer);
|
||||
|
||||
return $strBuffer;
|
||||
}
|
||||
|
||||
private function generateForFaqReader($objModule, $strBuffer) {
|
||||
// Set the item from the auto_item parameter
|
||||
if ($GLOBALS['TL_CONFIG']['useAutoItem'] && isset($_GET['auto_item'])) {
|
||||
$this->Input->setGet('items', $this->Input->get('auto_item'));
|
||||
}
|
||||
|
||||
// Do not index or cache the page if no FAQ has been specified
|
||||
if (!$this->Input->get('items')) {
|
||||
return $strBuffer;
|
||||
}
|
||||
|
||||
$objFaq = $this->Database->prepare("SELECT *, author AS authorId, (SELECT title FROM tl_faq_category WHERE tl_faq_category.id=tl_faq.pid) AS category, (SELECT name FROM tl_user WHERE tl_user.id=tl_faq.author) AS author FROM tl_faq WHERE pid IN(" . implode(',', array_map('intval', $this->faq_categories)) . ") AND (id=? OR alias=?)" . (!BE_USER_LOGGED_IN ? " AND published=1" : ""))
|
||||
->limit(1)
|
||||
->execute((is_numeric($this->Input->get('items')) ? $this->Input->get('items') : 0), $this->Input->get('items'));
|
||||
|
||||
if ($objFaq->numRows == 1) {
|
||||
$arrFaq = $objFaq->fetchAssoc();
|
||||
|
||||
$rating = $this->generateSingle($arrFaq, $strBuffer);
|
||||
}
|
||||
|
||||
if ($arrFaq['rateit_position'] == 'before') {
|
||||
$strBuffer = $rating.$strBuffer;
|
||||
} else if ($arrFaq['rateit_position'] == 'after') {
|
||||
$strBuffer = $strBuffer.$rating;
|
||||
}
|
||||
|
||||
return $strBuffer;
|
||||
}
|
||||
|
||||
private function generateSingle($arrFaq, $strBuffer) {
|
||||
$rating = '';
|
||||
|
||||
if ($arrFaq['addRating']) {
|
||||
$actRecord = $this->Database->prepare("SELECT * FROM tl_rateit_items WHERE rkey=? and typ='faq'")
|
||||
->execute($arrFaq['id'])
|
||||
->fetchAssoc();
|
||||
|
||||
if ($actRecord['active']) {
|
||||
$this->import('rateit\\RateItRating', 'RateItRating');
|
||||
$this->RateItRating->rkey = $arrFaq['id'];
|
||||
$this->RateItRating->ratingType = 'faq';
|
||||
$this->RateItRating->generate();
|
||||
|
||||
$rating = $this->RateItRating->output();
|
||||
}
|
||||
}
|
||||
|
||||
return $rating;
|
||||
}
|
||||
}
|
||||
?>
|
157
classes/RateItFrontend.php
Normal file
157
classes/RateItFrontend.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 RateItFrontend
|
||||
*/
|
||||
class RateItFrontend extends \Hybrid
|
||||
{
|
||||
|
||||
/**
|
||||
* Primary key
|
||||
* @var string
|
||||
*/
|
||||
protected $strPk = 'id';
|
||||
|
||||
/**
|
||||
* Typ
|
||||
* @var string
|
||||
*/
|
||||
protected $strType = 'hearts';
|
||||
|
||||
/**
|
||||
* Template
|
||||
* @var string
|
||||
*/
|
||||
protected $strTemplate = 'rateit_default';
|
||||
|
||||
/**
|
||||
* Anzahl der Herzen/Sterne
|
||||
* @var int
|
||||
*/
|
||||
protected $intStars = 5;
|
||||
|
||||
/**
|
||||
* Textposition
|
||||
* @var string
|
||||
*/
|
||||
protected $strTextPosition = 'after';
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function __construct($objElement=array()) {
|
||||
if (!empty($objElement)) {
|
||||
if ($objElement instanceof \Model) {
|
||||
$this->strTable = $objElement->getTable();
|
||||
}
|
||||
elseif ($objElement instanceof \Model\Collection) {
|
||||
$this->strTable = $objElement->current()->getTable();
|
||||
}
|
||||
|
||||
$this->strKey = $this->strPk;
|
||||
}
|
||||
|
||||
$stars = intval($GLOBALS['TL_CONFIG']['rating_count']);
|
||||
if ($stars > 0) {
|
||||
$this->intStars = $stars;
|
||||
}
|
||||
parent::__construct($objElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a wildcard in the back end
|
||||
* @return string
|
||||
*/
|
||||
public function generate() {
|
||||
return parent::generate();
|
||||
$this->loadLanguageFile('default');
|
||||
$this->strType = $GLOBALS['TL_CONFIG']['rating_type'];
|
||||
$stars = intval($GLOBALS['TL_CONFIG']['rating_count']);
|
||||
if ($stars > 0) {
|
||||
$this->intStars = $stars;
|
||||
}
|
||||
$this->strTemplate = $GLOBALS['TL_CONFIG']['rating_template'];
|
||||
$this->strTextPosition = $GLOBALS['TL_CONFIG']['rating_textposition'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the module/content element
|
||||
*/
|
||||
protected function compile() {
|
||||
}
|
||||
|
||||
public function getStarMessage($rating) {
|
||||
$this->loadLanguageFile('default');
|
||||
$stars = $this->percentToStars($rating['rating']);
|
||||
preg_match('/^.*\[(.+)\|(.+)\].*$/i', $GLOBALS['TL_CONFIG']['rating_description'], $labels);
|
||||
if (!is_array($labels) || !count($labels) == 2 || !count($labels) == 3) {
|
||||
$label = ($rating[totalRatings] > 1 || $rating[totalRatings] == 0) || !$rating ? $GLOBALS['TL_LANG']['rateit']['rating_label'][1] : $GLOBALS['TL_LANG']['rateit']['rating_label'][0];
|
||||
$description = '%current%/%max% %type% (%count% ['.$GLOBALS['TL_LANG']['tl_rateit']['vote'][0].'|'.$GLOBALS['TL_LANG']['tl_rateit']['vote'][1].'])';
|
||||
} else {
|
||||
$label = count($labels) == 2 ? $labels[1] : ($rating[totalRatings] > 1 || $rating[totalRatings] == 0) || !$rating ? $labels[2] : $labels[1];
|
||||
$description = $GLOBALS['TL_CONFIG']['rating_description'];
|
||||
}
|
||||
$actValue = $rating === false ? 0 : $rating[totalRatings];
|
||||
$type = $GLOBALS['TL_CONFIG']['rating_type'] == 'hearts' ? $GLOBALS['TL_LANG']['rateit']['hearts'] : $GLOBALS['TL_LANG']['rateit']['stars'];
|
||||
// return str_replace('.', ',', $stars)."/$this->intStars ".$type." ($actValue $label)";
|
||||
$description = str_replace('%current%', str_replace('.', ',', $stars), $description);
|
||||
$description = str_replace('%max%', $this->intStars, $description);
|
||||
$description = str_replace('%type%', $type, $description);
|
||||
$description = str_replace('%count%', $actValue, $description);
|
||||
$description = preg_replace('/^(.*)(\[.*\])(.*)$/i', "\\1$label\\3", $description);
|
||||
return $description;
|
||||
}
|
||||
|
||||
public function loadRating($rkey, $typ) {
|
||||
$SQL_GET_RATINGS = "SELECT i.rkey AS rkey,
|
||||
i.title AS title,
|
||||
IFNULL(AVG(r.rating),0) AS rating,
|
||||
COUNT( r.rating ) AS totalRatings
|
||||
FROM tl_rateit_items i
|
||||
LEFT OUTER JOIN tl_rateit_ratings r
|
||||
ON ( i.id = r.pid ) WHERE i.rkey = ? and typ=? and active='1'
|
||||
GROUP BY i.rkey;";
|
||||
$result = $this->Database->prepare($SQL_GET_RATINGS)
|
||||
->execute($rkey, $typ)
|
||||
->fetchAssoc();
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function percentToStars($percent) {
|
||||
$modifier = 100 / $this->intStars;
|
||||
return round($percent / $modifier, 1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
116
classes/RateItHybrid.php
Normal file
116
classes/RateItHybrid.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 RateItHybrid
|
||||
*/
|
||||
abstract class RateItHybrid extends RateItFrontend
|
||||
{
|
||||
//protected $intStars = 5;
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function __construct($objElement) {
|
||||
parent::__construct($objElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ###';
|
||||
$objTemplate->title = $this->rateit_title;
|
||||
$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 = $GLOBALS['TL_CONFIG']['rating_template'];
|
||||
|
||||
$this->strType = $GLOBALS['TL_CONFIG']['rating_type'];
|
||||
$this->strTextPosition = $GLOBALS['TL_CONFIG']['rating_textposition'];
|
||||
|
||||
$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.css||static';
|
||||
switch ($this->strType) {
|
||||
case 'hearts' :
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
|
||||
break;
|
||||
default:
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.css||static';
|
||||
}
|
||||
|
||||
return parent::generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the module/content element
|
||||
*/
|
||||
protected function compile() {
|
||||
$this->Template = new \FrontendTemplate($this->strTemplate);
|
||||
|
||||
$this->Template->setData($this->arrData);
|
||||
|
||||
$rating = $this->loadRating($this->getParent()->id, $this->getType());
|
||||
$ratingId = $this->getParent()->id;
|
||||
$stars = !$rating ? 0 : $this->percentToStars($rating['rating']);
|
||||
$percent = round($rating['rating'], 0)."%";
|
||||
|
||||
$this->Template->descriptionId = 'rateItRating-'.$ratingId.'-description';
|
||||
$this->Template->description = $this->getStarMessage($rating);
|
||||
$this->Template->id = 'rateItRating-'.$ratingId.'-'.$this->getType().'-'.$stars.'_'.$this->intStars;
|
||||
$this->Template->rateit_class = 'rateItRating';
|
||||
$this->Template->itemreviewed = $rating['title'];
|
||||
$this->Template->actRating = $this->percentToStars($rating['rating']);
|
||||
$this->Template->maxRating = $this->intStars;
|
||||
$this->Template->votes = $rating[totalRatings];
|
||||
|
||||
if ($this->strTextPosition == "before") {
|
||||
$this->Template->showBefore = true;
|
||||
}
|
||||
else if ($this->strTextPosition == "after") {
|
||||
$this->Template->showAfter = true;
|
||||
}
|
||||
|
||||
return parent::compile();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
51
classes/RateItModule.php
Normal file
51
classes/RateItModule.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 RateItModule
|
||||
*/
|
||||
class RateItModule extends RateItHybrid
|
||||
{
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function __construct($objElement) {
|
||||
parent::__construct($objElement);
|
||||
}
|
||||
|
||||
protected function getType() {
|
||||
return 'module';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
85
classes/RateItNews.php
Normal file
85
classes/RateItNews.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 RateItNews extends RateItFrontend {
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function parseArticle($objTemplate, $objArticle, $caller) {
|
||||
if (strpos(get_class($caller), "ModuleNews") !== false &&
|
||||
$objArticle['addRating']) {
|
||||
$ratingId = $objTemplate->id;
|
||||
$rating = $this->loadRating($ratingId, 'news');
|
||||
$stars = !$rating ? 0 : $this->percentToStars($rating['rating']);
|
||||
$percent = round($rating['rating'], 0)."%";
|
||||
|
||||
$objTemplate->descriptionId = 'rateItRating-'.$ratingId.'-description';
|
||||
$objTemplate->description = $this->getStarMessage($rating);
|
||||
$objTemplate->id = 'rateItRating-'.$ratingId.'-news-'.$stars.'_'.$this->intStars;
|
||||
$objTemplate->rateit_class = 'rateItRating';
|
||||
$objTemplate->itemreviewed = $rating['title'];
|
||||
$objTemplate->actRating = $this->percentToStars($rating['rating']);
|
||||
$objTemplate->maxRating = $this->intStars;
|
||||
$objTemplate->votes = $rating[totalRatings];
|
||||
|
||||
if ($this->strTextPosition == "before") {
|
||||
$objTemplate->showBefore = true;
|
||||
}
|
||||
else if ($this->strTextPosition == "after") {
|
||||
$objTemplate->showAfter = true;
|
||||
}
|
||||
|
||||
if ($objArticle['rateit_position'] == 'before') {
|
||||
$objTemplate->rateit_rating_before = true;
|
||||
} else if ($objArticle['rateit_position'] == 'after') {
|
||||
$objTemplate->rateit_rating_after = true;
|
||||
}
|
||||
|
||||
$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.css||static';
|
||||
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
|
||||
case 'hearts' :
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
|
||||
break;
|
||||
default:
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.css||static';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
110
classes/RateItPage.php
Normal file
110
classes/RateItPage.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 RateItPage extends \Frontend {
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->loadDataContainer('settings');
|
||||
}
|
||||
|
||||
public function outputFrontendTemplate($strContent, $strTemplate) {
|
||||
global $objPage;
|
||||
|
||||
if ($objPage->addRating && !($strTemplate == $GLOBALS['TL_CONFIG']['rating_template'])) {
|
||||
$actRecord = $this->Database->prepare("SELECT * FROM tl_rateit_items WHERE rkey=? and typ='page'")
|
||||
->execute($objPage->id)
|
||||
->fetchAssoc();
|
||||
|
||||
if ($actRecord['active']) {
|
||||
$this->import('rateit\\RateItRating', 'RateItRating');
|
||||
$this->RateItRating->rkey = $objPage->id;
|
||||
$this->RateItRating->generate();
|
||||
|
||||
$rating = $this->RateItRating->output();
|
||||
$rating .= $this->includeJs();
|
||||
$rating .= $this->includeCss();
|
||||
|
||||
$posMainDiv = strpos($strContent, '<div id="main">');
|
||||
$posInsideDiv = strpos($strContent, '<div class="inside">', $posMainDiv);
|
||||
|
||||
$return = substr($strContent, 0, $posInsideDiv).'<div class="inside">';
|
||||
$return .= $rating;
|
||||
$return .= substr($strContent, $posInsideDiv + strlen('<div id="inside">') + 3);
|
||||
$strContent = $return;
|
||||
}
|
||||
}
|
||||
return $strContent;
|
||||
}
|
||||
|
||||
private function includeCss() {
|
||||
$included = false;
|
||||
$strHeadTags = '';
|
||||
foreach ($GLOBALS['TL_CSS'] as $script) {
|
||||
if ($script == 'system/modules/rateit/public/css/rateit.css') {
|
||||
$included = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$included) {
|
||||
$strHeadTags = '<link rel="stylesheet" href="'.$this->addStaticUrlTo('system/modules/rateit/public/css/rateit.css').'">';
|
||||
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
|
||||
case 'hearts' :
|
||||
$strHeadTags .= '<link rel="stylesheet" href="'.$this->addStaticUrlTo('system/modules/rateit/public/css/heart.css').'">';
|
||||
break;
|
||||
default:
|
||||
$strHeadTags .= '<link rel="stylesheet" href="'.$this->addStaticUrlTo('system/modules/rateit/public/css/star.css').'">';
|
||||
}
|
||||
}
|
||||
return $strHeadTags;
|
||||
}
|
||||
|
||||
private function includeJs() {
|
||||
$included = false;
|
||||
$strHeadTags = '';
|
||||
foreach ($GLOBALS['TL_JAVASCRIPT'] as $script) {
|
||||
if ($script == 'system/modules/rateit/public/js/rateit.js') {
|
||||
$included = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$included) {
|
||||
$strHeadTags = '<script' . (($objPage->outputFormat == 'xhtml') ? ' type="text/javascript"' : '') . ' src="' . $this->addStaticUrlTo('system/modules/rateit/public/js/onReadyRateIt.js') . '"></script>' . "\n";
|
||||
$strHeadTags .= '<script' . (($objPage->outputFormat == 'xhtml') ? ' type="text/javascript"' : '') . ' src="' . $this->addStaticUrlTo('system/modules/rateit/public/js/rateit.js') . '"></script>' . "\n";
|
||||
}
|
||||
return $strHeadTags;
|
||||
}
|
||||
}
|
||||
?>
|
96
classes/RateItRating.php
Normal file
96
classes/RateItRating.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 RateItRating extends RateItFrontend {
|
||||
|
||||
/**
|
||||
* RatingKey
|
||||
* @var int
|
||||
*/
|
||||
public $rkey = 0;
|
||||
|
||||
public $ratingType = 'page';
|
||||
|
||||
/**
|
||||
* Initialize the controller
|
||||
*/
|
||||
public function __construct($objElement=array()) {
|
||||
parent::__construct($objElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a wildcard in the back end
|
||||
* @return string
|
||||
*/
|
||||
public function generate() {
|
||||
parent::generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile
|
||||
*/
|
||||
protected function compile()
|
||||
{
|
||||
$this->loadLanguageFile('default');
|
||||
|
||||
$this->Template = new \FrontendTemplate($this->strTemplate);
|
||||
$this->Template->setData($this->arrData);
|
||||
|
||||
$rating = $this->loadRating($this->rkey, $this->ratingType);
|
||||
$ratingId = $this->rkey;
|
||||
$stars = !$rating ? 0 : $this->percentToStars($rating['rating']);
|
||||
$percent = round($rating['rating'], 0)."%";
|
||||
|
||||
$this->Template->descriptionId = 'rateItRating-'.$ratingId.'-description';
|
||||
$this->Template->description = $this->getStarMessage($rating);
|
||||
$this->Template->id = 'rateItRating-'.$ratingId.'-'.$this->ratingType.'-'.$stars.'_'.$this->intStars;
|
||||
$this->Template->class = 'rateItRating';
|
||||
$this->Template->itemreviewed = $rating['title'];
|
||||
$this->Template->actRating = $this->percentToStars($rating['rating']);
|
||||
$this->Template->maxRating = $this->intStars;
|
||||
$this->Template->votes = $rating[totalRatings];
|
||||
|
||||
if ($this->strTextPosition == "before") {
|
||||
$this->Template->showBefore = true;
|
||||
}
|
||||
else if ($this->strTextPosition == "after") {
|
||||
$this->Template->showAfter = true;
|
||||
}
|
||||
|
||||
return $this->Template->parse();
|
||||
}
|
||||
|
||||
public function output() {
|
||||
return $this->compile();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
142
classes/RateItTopRatingsModule.php
Normal file
142
classes/RateItTopRatingsModule.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2011 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this program. If not, please visit the Free
|
||||
* Software Foundation website at <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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.css||static';
|
||||
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
|
||||
case 'hearts' :
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
|
||||
break;
|
||||
default:
|
||||
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
1721
classes/extern/simple_html_dom.php
vendored
Normal file
1721
classes/extern/simple_html_dom.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user