public function store()
 {
     $entry_id = Input::get('entry_id');
     $user_id = Session::get('user')['id'];
     $like_id = FELikesHelper::getId($entry_id, $user_id, false);
     if ($like_id) {
         $like = Like::find($like_id);
         $like->is_deleted = 0;
         $like->save();
         $result = $like->toArray();
         $result['status'] = 'success';
         echo json_encode($result);
     } else {
         $like = new Like();
         $like->entry_id = $entry_id;
         $like['user_id'] = $user_id;
         $like->is_deleted = 0;
         $like->save();
         $result = $like->toArray();
         $result['status'] = 'success';
         echo json_encode($result);
     }
 }
Exemple #2
0
 /**
  * Comments list
  *
  * @param $request
  * @param $matches
  * @return mixed
  */
 public function likes_list($request, $matches)
 {
     $post = trim($matches->get('post'), '-+ ');
     $filter = ['conditions' => ['post = ?', $post], 'order' => 'created_at DESC'];
     /** @var Listing $paginator */
     $paginator = NCService::load('Paginator.Listing', [$request->page, \Like::count($filter)]);
     $filter = array_merge($filter, $paginator->limit());
     // Likes
     $likes = \Like::find('all', $filter);
     $likes = \Like::as_array($likes);
     // Context
     $context = ['rating' => \Like::rating($post), 'likes' => $likes, 'page' => $paginator->cur_page, 'listing' => $paginator->pages()];
     // Build response
     if ($request->get('type', 'html') == 'json') {
         unset($context['listing']);
         $context['pages'] = $paginator->pages;
         $context['rows'] = $paginator->num_rows;
         return static::json_response($context);
     }
     return $this->view->render('likes/list.twig', $context);
 }