public function commentsAction() { if ($this->_getParam('xaction') == "destroy") { $id = $this->_getParam("comments"); $id = str_replace('"', '', $id); RatingsComments_Plugin::deleteComment($id); $results["success"] = true; $results["comments"] = ""; } else { $id = $this->_getParam("objectid"); $type = $this->_getParam("type"); if ($type == "object") { $target = Object_Abstract::getById($id); } else { if ($type == "page" || $type == "snippet") { $target = Document::getById($id); } else { //try asset $target = Asset::getById($id); } } $comments = RatingsComments_Plugin::getComments($target); $results = array(); if (is_array($comments)) { foreach ($comments as $comment) { $shorttext = $comment->getComment(); if (strlen($shorttext) > 50) { $shorttext = substr($shorttext, 0, 50) . "..."; } $results["comments"][] = array("c_id" => $comment->getId(), "c_shorttext" => $shorttext, "c_text" => $comment->getComment(), "c_rating" => $comment->getRating(), "c_user" => $comment->getName(), "c_created" => $comment->getDate()); } } if (!isset($results["comments"])) { $results["comments"] = ""; } } echo Zend_Json::encode($results); $this->removeViewRenderer(); }
public function getComments($limit = null) { if (class_exists('RatingsComments_Plugin') and RatingsComments_Plugin::isInstalled()) { if (!$this->isVariant()) { $object = $this; } elseif ($this->getType() == Object_Abstract::OBJECT_TYPE_OBJECT) { $object = $this->getParent(); } elseif ($this->getType() == Object_Abstract::OBJECT_TYPE_VARIANT && $this->getParent()->getType() == Object_Abstract::OBJECT_TYPE_OBJECT) { $object = $this->getParent()->getParent(); } $comments = RatingsComments_Plugin::getComments($object, $limit, false); return $comments; } else { return null; } }