* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBAjax'); /** * Simple AJAX stub: Rating * * Allow to call method via AJAX request * * @version 0.1.1 * @package WB * @subpackage base */ class WBAjax_Rate extends WBAjax { /** * Rating * @var WBDatasource_Rate */ protected $rate; /** * second construcotr * * Called by constructer of super class. * * @see include/WB/WBAjax#init() */ protected function init() { $this->rate = WBClass::create('WBDatasource_Rate'); } /** * Add rating * * Save rating and optionally render current rating * * @see display() * @return string HTML */ protected function add() { $namespace = $this->req->get('namespace', ''); $xid = $this->req->get('xid', 0); $value = $this->req->get('value', 0); $blurb = $this->req->get('blurb', ''); $display = intval($this->req->get('display', 0)); try{ $this->rate->setNamespace($namespace); $this->rate->setXId($xid); $this->rate->add($value, $blurb); } catch (WBException $e) { if (1 <= $display) { return $this->display(); } return 'failed'; } if (1 <= $display) { return $this->display(); } return 'OK'; } /** * Render current rating * * Load templates, set rates as variables and get parsed template */ private function display() { $ns = $this->rate->getNamespace(); $xid = $this->rate->getXid(); $this->loadTemplates('display'); $this->tmpl->addGlobalVar('namespace', $ns); $this->tmpl->addGlobalVar('xid', $xid); return $this->tmpl->getParsedTemplate('snippet'); } }