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'); }
<small><i class="fa fa-clock-o"></i> 5 mins</small> </h4> <p> đã gửi cho bạn một tin nhắn</p> </a> </li>'; } } ?> </ul> </li> <li class="footer"><a href="#">Xem tất cả</a></li> </ul> </li> <?php $listPostNotify = \common\models\PostNotification::find()->where(['receiver_id' => Yii::$app->user->getId()])->limit(20)->orderBy('status')->asArray()->all(); $newPostNotifyCount = \common\models\PostNotification::find()->where(['receiver_id' => Yii::$app->user->getId(), 'status' => 0])->count(); ?> <li class="notify_post dropdown notifications-menu"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-bell-o"></i> <span class="notify_post_count label label-warning"><?php if ($newPostNotifyCount > 0) { echo $newPostNotifyCount; } ?> </span> </a> <ul class="dropdown-menu"> <li class="header">Bạn có <?php echo $newPostNotifyCount; ?>
public function actionComment() { if (isset($_POST['user_id']) && isset($_POST['post_id']) && isset($_POST['content'])) { $comment = new Comment(); $comment['user_id'] = $_POST['user_id']; $comment['post_id'] = $_POST['post_id']; $comment['content'] = $_POST['content']; $comment['create_at'] = $_POST['create_at']; //$comment['create_at'] = Yii::$app->formatter->asDatetime("Y-m-d"); $comment->save(); $user = User::findOne(['id' => $_POST['user_id']]); if ($user['image'] != "") { $image = Yii::$app->request->baseUrl . "/images/" . $user['image']; } else { $image = Yii::$app->request->baseUrl . "/images/avatar-default.jpg"; } $id = $_POST['post_id']; $receiver = Post::findOne(['id' => $id])['user_id']; if ($receiver != Yii::$app->user->getId()) { $newNotify = new PostNotification(); $newNotify['post_id'] = $id; $newNotify['type'] = 1; $newNotify['status'] = 0; $newNotify['action_id'] = Yii::$app->user->getId(); $newNotify['receiver_id'] = $receiver; $newNotify['create_at'] = date("Y/m/d H:i"); $newNotify->save(); } $listComment = Comment::find()->where(['post_id' => $id])->asArray()->all(); foreach ($listComment as $oneComment) { $isAdded[$oneComment['user_id']] = 0; } $isAdded[$receiver] = 1; foreach ($listComment as $oneComment) { $receiver = $oneComment['user_id']; if ($receiver != Yii::$app->user->getId() && $isAdded[$receiver] != 1) { $newNotify = new PostNotification(); $newNotify['post_id'] = $id; $newNotify['type'] = 1; $newNotify['status'] = 0; $newNotify['action_id'] = Yii::$app->user->getId(); $newNotify['receiver_id'] = $receiver; $newNotify['create_at'] = date("Y/m/d H:i"); $newNotify->save(); } $isAdded[$receiver] = 1; } echo '<div class="box-comment">' . '<img class="img-circle img-sm" src="' . $image . '" alt="user image">' . '<div class="comment-text">' . '<span class="username">' . $user['username'] . '<span class="text-muted pull-right">' . $comment['create_at'] . '</span>' . '</span>' . $comment['content'] . '</div>' . '</div>'; } else { echo 'NO'; } }
public function actionMakeOldPostNotification() { PostNotification::updateAll(['status' => 1], 'status=0 AND receiver_id=' . \Yii::$app->user->getId()); }