Пример #1
0
 public function getLikes()
 {
     if (!$this->getId()) {
         return array();
     }
     if (is_null($this->_likes)) {
         $like = new Comment_Model_Like();
         $this->_likes = $like->findByComment($this->getId());
         foreach ($this->_likes as $like) {
             $like->setComment($this);
         }
     }
     return $this->_likes;
 }
Пример #2
0
 public function addlikeAction()
 {
     if ($datas = $this->getRequest()->getParams()) {
         try {
             $customer_id = $this->getSession()->getCustomerId();
             $like = new Comment_Model_Like();
             $like->setCommentId($datas['id'])->setCustomerId($customer_id)->setCustomerIp($datas['ip'])->setAdminAgent($datas['ua']);
             $is_saved = $like->save($datas['id'], $customer_id, $datas['ip'], $datas['ua']);
             if ($is_saved) {
                 $message = $this->_('Your like has been successfully added');
                 $html = array('success' => 1, 'message' => $message);
             } else {
                 throw new Exception($this->_('You can\'t like more than once the same news'));
             }
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
 }
Пример #3
0
 public function addlikeAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             $customer_id = $this->getSession()->getCustomerId();
             $ip = md5($_SERVER['REMOTE_ADDR']);
             $ua = md5($_SERVER['HTTP_USER_AGENT']);
             $like = new Comment_Model_Like();
             if (!$like->findByIp($data['comment_id'], $customer_id, $ip, $ua)) {
                 $like->setCommentId($data['comment_id'])->setCustomerId($customer_id)->setCustomerIp($ip)->setAdminAgent($ua);
                 $like->save();
                 $message = $this->_('Your like has been successfully added');
                 $html = array('success' => 1, 'message' => $message);
             } else {
                 throw new Exception($this->_("You can't like more than once the same news"));
             }
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
 }