public function checkLike($post_id, $user_id) { $check = PostLike::model()->findByAttributes(array('post_id' => $post_id, 'user_id' => $user_id)); if ($check) { return TRUE; } return FALSE; }
public function getPostById($id, $user_id, $flag) { $returnArr = array(); $item = Post::model()->findByPk($id); // var_dump($data); die; $returnArr['user'] = User::model()->getUserInfoById($item->user_id); $returnArr['location'] = Location::model()->findByPk($item->location_id); $returnArr['post_id'] = $item->post_id; $returnArr['content'] = $item->content; $returnArr['date'] = $item->date; $returnArr['post_comment_count'] = $item->post_comment_count; $returnArr['post_like_count'] = $item->post_like_count; $returnArr['is_like'] = PostLike::model()->checkLike($id, $user_id); $returnArr['subjects'] = $this->getSubjectByPost($item->post_id); if ($flag != 1) { $returnArr['comments'] = $this->getCommentByPost($id); // $returnArr[] = $itemArr; } return $returnArr; }
public function actionCheckLike() { $request = Yii::app()->request; try { $post_id = StringHelper::filterString($request->getPost('post_id')); $user_id = StringHelper::filterString($request->getPost('user_id')); if (PostLike::model()->checkLike($post_id, $user_id)) { ResponseHelper::JsonReturnSuccess('', 'liked'); } else { ResponseHelper::JsonReturnError('', 'not like'); } } catch (Exception $ex) { var_dump($ex->getMessage()); } }