/** * Handles AJAX Post Request to submit new ReportContent */ public function actionReport() { $this->forcePostRequest(); Yii::$app->response->format = 'json'; $json = array(); $json['success'] = false; $form = new ReportReasonForm(); if ($form->load(Yii::$app->request->post()) && $form->validate() && ReportContent::canReportPost($form->object_id)) { $report = new ReportContent(); $report->created_by = Yii::$app->user->id; $report->reason = $form->reason; $report->object_model = Post::className(); $report->object_id = $form->object_id; if ($report->save()) { $json['success'] = true; } } return $json; }
/** * Executes the widget. */ public function run() { if (get_class($this->content) == Post::className() && ReportContent::canReportPost($this->content->id)) { return $this->render('reportSpamLink', array('object' => $this->content, 'model' => new ReportReasonForm())); } }