示例#1
0
 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'];