Hallo,
wird im Katalog-Ajaxrating irgendwo die Anzahl der Bewertungen festgehalten?
MfG,
typoburns
wird im Katalog-Ajaxrating irgendwo die Anzahl der Bewertungen festgehalten?
MfG,
typoburns
if (($this->Input->get('q') == 'rating') && ($objCatalog->pid==$this->Input->get('ratecat')) && ($objCatalog->id==$this->Input->get('rateitem')))
{
if (!$hasVoted)
{
$this->Database->prepare("INSERT INTO tl_catalog_rating (cat_id, item_id, value, ip, time) VALUES (?, ?, ?, ?, ?)")
->execute($objCatalog->pid, $objCatalog->id, $this->Input->get('value'), $_SERVER['REMOTE_ADDR'], time());
// Would love to use $this->Environment->ip here but this is the internal IP of an network if behind NAT, therefore useless.
$votecount++;
$votesum+=$this->Input->get('value');
$value=$this->calculate($votesum, $votecount);
// now we are pretty dirty in here, we have to update ourselves "on the fly".
$table=$this->Database->prepare("SELECT tableName FROM tl_catalog_types WHERE id=?")
->execute($objCatalog->pid);
if($table->next()) {
$this->Database->prepare("UPDATE ".$table->tableName." SET ".$k."=? WHERE id=?")
->execute($this->calculate($votesum, $votecount), $objCatalog->id);
}
}
if ($this->Input->get('isAjax') == '1')
{
$objVotes=$this->Database->prepare("SELECT *, COUNT(*) AS totalVotes, SUM(value) AS sumValue FROM tl_catalog_rating WHERE cat_id=? AND item_id=? GROUP BY cat_id, item_id")
->execute($objCatalog->pid, $objCatalog->id);
$objVotes->next();
echo round($objVotes->sumValue/$objVotes->totalVotes, 2);
exit;
}
else
{
$this->redirect(preg_replace('@(\?|&)q=[^&]*&ratecat=[^&]*&rateitem=[^&]*&value=[^&]*@', '', $this->Environment->request));
}
}
$objWidth=$this->Database->prepare("SELECT ajaxratingfield FROM tl_catalog_fields WHERE pid=? AND colName=?")
->execute($objCatalog->pid, $k);
$ajaxWidget = new CatalogAjaxRatingWidget(array
(
'value'=>$value,
'size' => 5,
'strId' => (($objCatalogInstance instanceof ModuleCatalogReader) ? $objCatalog->pid . '_' . $objCatalog->id : ''),
'catId' => $objCatalog->pid,
'itemId' => $objCatalog->id,
'voted' => $hasVoted,
'tableless' => true,
'intRatingUnitWidth' => $objWidth->ajaxratingfield,
));
$html = $ajaxWidget->parse();
return array
(
'items' => array($html),
'values' => false,
'html' => $html,
);
}
}
Kommentar