/** * Save data to database */ public function make() { $this->_record->name = $this->name; $this->_record->email = $this->email; $this->_record->message = $this->message; $this->_record->save(); }
/** * Process submit new request * @return FeedbackPost */ public function make() { // calculate security hash to direct-on access $hash = Str::randomLatinNumeric(mt_rand(16, 64)); // init new row and set row data $record = new FeedbackPost(); $record->name = $this->name; $record->email = $this->email; $record->message = $this->message; $record->hash = $hash; if (App::$User->isAuth()) { $record->user_id = App::$User->identity()->getId(); } $record->ip = App::$Request->getClientIp(); // save row to db $record->save(); // send notification to email $this->sendEmail($record); return $record; }
/** * Add new row to database and set post is unreaded */ public function make() { // update readed marker $this->_post->readed = 0; $this->_post->save(); // add new answer row in database $record = new FeedbackAnswer(); $record->feedback_id = $this->_post->id; $record->name = $this->name; $record->email = $this->email; $record->message = $this->message; if ($this->_userId > 0) { $record->user_id = $this->_userId; } $record->ip = $this->_ip; $record->save(); // add notification msg $targetId = $this->_post->user_id; if ($targetId !== null && (int) $targetId > 0 && $targetId !== $this->_userId) { $notify = new EntityAddNotification($targetId); $uri = '/feedback/read/' . $this->_post->id . '/' . $this->_post->hash . '#feedback-answer-' . $record->id; $notify->add($uri, EntityAddNotification::MSG_ADD_FEEDBACKANSWER, ['snippet' => Text::snippet($this->message, 50), 'post' => Text::snippet($this->_post->message, 50)]); } }
/** * List feedback requests messages from authorized user * @return string * @throws \Ffcms\Core\Exception\NativeException * @throws ForbiddenException * @throws \Ffcms\Core\Exception\SyntaxException */ public function actionList() { // set current page and offset $page = (int) $this->request->query->get('page'); $offset = $page * self::ITEM_PER_PAGE; // check if user is authorized or throw exception if (!App::$User->isAuth()) { throw new ForbiddenException(__('Feedback listing available only for authorized users')); } // get current user object $user = App::$User->identity(); // initialize query with major condition $query = FeedbackPost::where('user_id', '=', $user->getId()); // build pagination $pagination = new SimplePagination(['url' => ['feedback/list'], 'page' => $page, 'step' => self::ITEM_PER_PAGE, 'total' => $query->count()]); // build records object from prepared query using page offset $records = $query->orderBy('id', 'desc')->skip($offset)->take(self::ITEM_PER_PAGE)->get(); // render viewer with parameters return $this->view->render('list', ['records' => $records, 'pagination' => $pagination]); }
/** * 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]); }
/** * Calculate unreaded feedback */ private function calcNewFeedback() { $this->feedback = FeedbackPost::where('readed', '=', 0)->where('closed', '=', 0)->count(); }