예제 #1
0
파일: Like.php 프로젝트: ockor/yii2adv-blog
 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;
     }
 }
예제 #2
0
 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');
 }
예제 #3
0
 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()]);
     }
 }
예제 #4
0
<?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="#">&nbsp;&nbsp;&nbsp;<?php 
echo $model['title'];