public function createPost()
 {
     $newPost = new Post();
     $newPost['title'] = $this->title;
     $newPost['content'] = $this->content;
     $newPost['permit'] = $this->permit[0];
     if ($this->upload()) {
         $newPost['image'] = $this->thumbnail;
     }
     if ($this->date == "") {
         $newPost['create_at'] = date("Y-m-d");
     } else {
         $newPost['create_at'] = $this->date;
     }
     $newPost['user_id'] = $this->user_id;
     $newPost->save();
     if ($newPost['permit'] == 2) {
         foreach ($this->reader as $userId) {
             $newPostProtected = new PostProtected();
             $newPostProtected['create_at'] = $newPost['create_at'];
             $newPostProtected['post_id'] = $newPost['id'];
             $newPostProtected['user_id'] = $userId;
             $newPostProtected->save();
         }
     }
 }
 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 actionDelete()
 {
     if (Yii::$app->user->isGuest) {
         $this->redirect(Url::to(['/site/login']));
     }
     if (isset($_POST['id'])) {
         $id = $_POST['id'];
         Post::findOne(['id' => $id])->delete();
         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]);
     }
 }
/**
 * Created by PhpStorm.
 * User: Nguyen
 * Date: 11/4/2015
 * Time: 7:53 PM
 */
$this->title = 'Tham quan';
$this->params['breadcrumbs'][] = $this->title;
$listPost = \common\models\Post::find()->where(['user_id' => $model['id']])->asArray()->all();
$listTemp = $listPost;
foreach ($listTemp as $post) {
    $isCanRead = true;
    if ($post['permit'] == 1) {
        $isCanRead = false;
    } elseif ($post['permit'] == 2) {
        $isCanRead = \common\models\PostProtected::find()->where(['post_id' => $post['id'], 'user_id' => Yii::$app->user->getId()])->count() > 0;
    } elseif ($post['permit'] == 3) {
        $isCanRead = \common\models\Relationship::isInRelationship($model['id'], Yii::$app->user->getId());
    }
    if (!$isCanRead) {
        if (($key = array_search($post, $listPost)) !== false) {
            unset($listPost[$key]);
        }
    }
}
$friendCount = \common\models\Relationship::find()->where(['user_id_1' => $model['id'], 'status' => 1])->count() + \common\models\Relationship::find()->where(['user_id_2' => $model['id'], 'status' => 1])->count();
?>

<div class="row">
    <div class="col-md-3">