Esempio n. 1
0
 public function updateReview(DB $db, APIRequest $request, APIResponse $response)
 {
     $this->vars->review = new PerformanceReview();
     $this->vars->review->loadById($db, $request->get('reviewId'));
     //validate?
     foreach ($request->post('questions') as $questionId => $answerPost) {
         $answer = new ReviewAnswer();
         if (!$answer->loadOneWhere($db, 'question_id = ? and review_id = ?', [$questionId, $this->vars->review->id])) {
             $answer->questionId = $questionId;
             $answer->reviewId = $this->vars->review->id;
         }
         $answer->text = $answerPost['text'];
         $answer->scale = $answerPost['scale'];
         $answer->store($db);
     }
     if ($_POST['action'] == 'submit') {
         $this->vars->review->submitted = 'yes';
         $this->vars->review->submittedYmdt = gmdate('Y-m-d H:i:s');
         $this->vars->review->submit($db);
         $updater = new WorkflowUpdater();
         $workflow = new Workflow();
         $workflow->loadOneWhere($db, 'table_row_id = ? and type = ?', [$this->vars->review->id, 'review']);
         $updater->complete($db, $workflow);
     }
     $response->success();
 }
 public function post()
 {
     //validate?
     foreach ($_POST['questions'] as $questionId => $answerPost) {
         $answer = new ReviewAnswer();
         if (!$answer->loadOneWhere($db, 'question_id = ? and review_id = ?', [$questionId, $this->vars->review->id])) {
             $answer->questionId = $questionId;
             $answer->reviewId = $this->vars->review->id;
         }
         $answer->text = $answerPost['text'];
         $answer->scale = $answerPost['scale'];
         $answer->store($db);
     }
     if ($_POST['action'] == 'submit') {
         $this->vars->review->submitted = 'yes';
         $this->vars->review->submittedYmdt = gmdate('Y-m-d H:i:s');
         $this->vars->review->submit($db);
         $updater = new WorkflowUpdater();
         $workflow = new Workflow();
         $workflow->loadOneWhere($db, 'table_row_id = ? and type = ?', [$this->vars->review->id, 'review']);
         $updater->complete($db, $workflow);
     }
     redirect("review.php");
 }
Esempio n. 3
0
File: Review.php Progetto: apuc/NDFL
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getReviewAnswers()
 {
     return $this->hasMany(ReviewAnswer::className(), ['review_id' => 'id']);
 }
Esempio n. 4
0
 /**
  * Set the content of a review from an array
  * @input An array with all the values, including dependent rows
  */
 function setFromArray($input)
 {
     // Be careful: filter input data
     $this->setFilterData(true);
     // OK, call the parent function.
     parent::setFromArray($input);
     // Get the review marks
     $this->_marks = array();
     $criteriaTbl = new Criteria();
     $this->totalWeight = 0;
     $this->weightedMarks = 0;
     $markTbl = new ReviewMArk();
     if (isset($input['marks'])) {
         foreach ($input['marks'] as $idCriteria => $value) {
             $criteria = $criteriaTbl->find($idCriteria)->current();
             $this->_marks[$idCriteria] = $markTbl->createRow();
             $this->totalWeight += $criteria->weight;
             $this->weightedMarks += $criteria->weight * $value;
             // Initialize the mark object.
             $this->_marks[$idCriteria]->setFromArray(array("idPaper" => $this->idPaper, "id_user" => $this->id_user, "idCriteria" => $idCriteria, "mark" => $value));
         }
     }
     // Get the answers to additional questions
     $this->_answers = array();
     $reviewAnswer = new ReviewAnswer();
     if (isset($input['answers'])) {
         foreach ($input['answers'] as $idQuestion => $idAnswer) {
             $this->_answers[$idQuestion] = $reviewAnswer->createRow();
             // Initialize the answer object.
             $this->_answers[$idQuestion]->setFromArray(array("id_paper" => $this->idPaper, "id_user" => $this->id_user, "id_question" => $idQuestion, "id_answer" => $idAnswer));
         }
     }
 }