public static function isLiked($post_id, $user_id) { if (Like::find()->where(['post_id' => $post_id, 'user_id' => $user_id])->count() > 0) { return true; } else { return false; } }
public function actionDeletePost() { $selection = (array) Yii::$app->request->post('selection'); foreach ($selection as $id) { Post::deleteAll(['id' => $id]); Like::deleteAll(['post_id' => $id]); Comment::deleteAll(['post_id' => $id]); PostTag::deleteAll(['post_id' => $id]); PostNotification::deleteAll(['post_id' => $id]); PostProtected::deleteAll(['post_id' => $id]); } return $this->render('post-manage'); }
public function actionUnlike() { if (Yii::$app->user->isGuest) { $this->redirect(Url::to(['/site/login'])); } if (isset($_POST['id'])) { Like::deleteAll(['user_id' => Yii::$app->user->getId(), 'post_id' => $_POST['id']]); PostNotification::deleteAll(['post_id' => $_POST['id'], 'type' => 0, 'action_id' => Yii::$app->user->getId()]); } }
<?php /** * Created by PhpStorm. * User: Nguyen * Date: 10/27/2015 * Time: 10:46 PM */ $this->title = 'Chi tiết bài'; $this->params['breadcrumbs'][] = $this->title; $listCmt = \common\models\Comment::find()->where(['post_id' => $model['id']])->asArray()->all(); $likeCount = \common\models\Like::find()->where(['post_id' => $model['id']])->count(); $isLiked = \common\models\Like::findOne(['post_id' => $model['id'], 'user_id' => Yii::$app->user->getId()]) != null; ?> <div class="row"> <div class="col-lg-10 col-lg-offset-1"> <!-- Box Comment --> <div class="box box-widget"> <div class="box-header with-border"> <div class="user-block"> <img class="img-circle" src="<?php if ($model['image'] != "") { echo Yii::$app->request->baseUrl . "/images/" . $model['image']; } else { echo Yii::$app->request->baseUrl . "/images/post-icon.png"; } ?> " alt="user image"> <span class="title"><a href="#"> <?php echo $model['title'];