/** * Finds the Notification model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Notification the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Notification::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionHideNotifiAjax($id) { $model = Notification::findOne($id); if ($model && $model->uid == Yii::$app->user->id) { $model->hide = 1; $model->save(); } }
/** * 伪删除 * @param $id * @return \yii\web\Response * @throws NotFoundHttpException */ public function actionDelete($id) { $model = PostComment::findComment($id); if (!$model->isCurrent()) { throw new NotFoundHttpException(); } // 事物 暂时数据库类型不支持 无效 $transaction = \Yii::$app->db->beginTransaction(); $updateComment = $model->updateCounters(['status' => -1]); $updateNotify = Notification::updateAll(['status' => 0], ['comment_id' => $model->id]); $updateTopic = Topic::updateAllCounters(['comment_count' => -1], ['id' => $model->post_id]); if ($updateNotify && $updateComment && $updateTopic) { $transaction->commit(); } else { $transaction->rollback(); } return $this->redirect(['/topic/default/view', 'id' => $model->post_id]); }
/** * 伪删除 * @param $id * @return \yii\web\Response * @throws NotFoundHttpException */ public function actionDelete($id) { $model = Topic::findTopic($id); if (!$model->isCurrent()) { throw new NotFoundHttpException(); } if ($model->comment_count) { $this->flash("「{$model->title}」此文章已有评论,属于共有财产,不能删除", 'warning'); } else { $model->updateAttributes(['status' => 0]); Notification::updateAll(['status' => 0], ['post_id' => $model->id]); $revoke = Html::a('撤消', ['/topic/default/revoke', 'id' => $model->id]); $this->flash("「{$model->title}」文章删除成功。 反悔了?{$revoke}", 'success'); } return $this->redirect(['index']); }
/** * 查找用户的动作通知 * @param UserMeta $meta * @return null|static */ public function findUserActionNotify(UserMeta $meta) { if ($meta->target_type == 'comment') { $condition['comment_id'] = $meta->target_id; } else { $condition['post_id'] = $meta->target_id; } return Notification::findOne(['from_user_id' => $meta->user_id, 'type' => $meta->target_type . '_' . $meta->type] + $condition); }
/** * 删除帖子 * @param Post $post */ public static function delete(Post $post) { $post->setAttributes(['status' => Post::STATUS_DELETED]); $post->save(); Notification::updateAll(['status' => Post::STATUS_DELETED], ['post_id' => $post->id]); }
/** * Send message to razzded user */ private function sendNotifiRazzd() { $userModel = new \frontend\models\User(); $userName = $userModel->getFullname(Yii::$app->user->id); $notifi = \Yii::createObject(['class' => Notification::className(), 'uid' => $this->responder_uid, 'message' => 'YOU HAVE BEEN RAZZD BY ' . $userName, 'link' => '<a href="/razz/respond/' . $this->id . '" class="btn">RESPOND</a>', 'created_at' => time()]); $notifi->save(); $userModel = new \frontend\models\User(); $razdator = $userModel->getFullname(Yii::$app->user->id); $vis_a_vis = \frontend\models\User::findOne(['email' => $this->email]); $mailer = new \common\helpers\Mandrill($sendTo = $this->email, $subject = 'YOU HAVE BEEN RAZZD BY ' . ucfirst($razdator), $local_tpl_name = null, $sender = null, ['from_name' => '[Notification generator]', 'mandrill_template_name' => 'you-have-been-razzd', 'vars' => ['razee' => ucfirst($vis_a_vis->username), 'header' => $this->title, 'message' => $this->message, 'description' => $this->description, 'razdator' => ucfirst($razdator), 'link' => '<a href="' . Yii::$app->getUrlManager()->createAbsoluteUrl(["razz/respond/" . $this->id]) . '" class="btn">RESPOND</a>']]); $result = $mailer->sendWithMandrillTemplate(); $mess = (string) $result; unset($userModel); }