/** * Get post relation * @return FeedbackPost|null */ public function getFeedbackPost() { return FeedbackPost::find($this->feedback_id); }
/** * Delete feedback post or answer * @param string $type * @param int $id * @return string * @throws \Ffcms\Core\Exception\NativeException * @throws NotFoundException * @throws \Exception * @throws \Ffcms\Core\Exception\SyntaxException */ public function actionDelete($type, $id) { // try to get active record by type $record = null; switch ($type) { case 'post': $record = FeedbackPost::find($id); break; case 'answer': $record = FeedbackAnswer::find($id); break; } // check if we get the row if ($record === null || $record === false) { throw new NotFoundException(__('Feedback item is not founded')); } // if delete is submited if ($this->request->request->get('deleteFeedback')) { // remove all answers if ($type === 'post') { FeedbackAnswer::where('feedback_id', '=', $record->id)->delete(); // remove item $record->delete(); App::$Session->getFlashBag()->add('success', __('Feedback record is successful removed')); $this->response->redirect('feedback/index'); } else { // its a answer, lets remove it and redirect back in post $postId = $record->feedback_id; $record->delete(); $this->response->redirect('feedback/read/' . $postId); } } // render view return $this->view->render('delete', ['type' => $type, 'record' => $record]); }