Пример #1
0
 /**
  * Prepare the response.
  *
  * @return  mixed
  *
  * @since   1.0
  * @throws  \Exception
  */
 protected function prepareResponse()
 {
     // Verify the user has permissions to perform this action
     if (!$this->getContainer()->get('app')->getUser()->authorize('view')) {
         throw new \Exception('Anonymous votes are not allowed.');
     }
     /* @type Input $input */
     $input = $this->getContainer()->get('app')->input;
     $issue = $input->getUint('issueId');
     $experienced = $input->getInt('experienced');
     $importance = $input->getInt('importance');
     $userID = $this->getContainer()->get('app')->getUser()->id;
     if (!$issue) {
         throw new \Exception('No issue ID received.');
     }
     if (!$importance) {
         throw new \Exception('Issue importance not received');
     }
     $model = new IssueModel($this->getContainer()->get('db'));
     $data = $model->vote($issue, $experienced, $importance, $userID);
     // Add the new score
     $data->importanceScore = $data->score / $data->votes;
     $this->response->data = $data;
     $this->response->message = g11n3t('Vote successfully added');
 }