public function handle($data)
 {
     $this->validate_request(["assignment", "answers"]);
     $assignmentId = Token::decode($data->{'assignment'});
     $user = UserBackend::fetch_user_profile($this->params['id']);
     $assignment = AssignmentBackend::fetch_assignment_profile($assignmentId);
     $answers = AssessmentBackend::fetch_assessment_answers(new AssessmentProfile($assignment['assessment-id']));
     $provided = $data->{'answers'};
     $scores = [];
     foreach ($answers as $answer) {
         /** @var Token $question */
         $question = $answer['question-id'];
         $score = ["question-id" => $question->toString(), "question-number" => $answer['question-number'], "max-score" => 1];
         if ($answer['question-type'] == QuestionType::MULTI_CHOICE) {
             $score['score'] = $this->mark_multichoice_question($answer['answer-value'], $provided->{$question->toString()});
         } elseif ($answer['question-type'] == QuestionType::ANSWER) {
             $score['score'] = $this->mark_answer_question($answer['answer-value'], $provided->{$question->toString()});
         }
         $scores[] = $score;
     }
     if (count($scores) != count($answers)) {
         throw new EndpointExecutionException("An error has occurred whilst executing this endpoint");
     }
     UserBackend::add_assignment_scores($user, $assignmentId, $assignment['assessment-id'], $scores);
     return ["scores" => $scores];
 }
 public function handle($data)
 {
     $this->validate_request(["assessment", "deadline"]);
     $id = Token::generateNewToken(TOKEN_ASSIGNMENT);
     AssignmentBackend::create_assignment($id, Token::decode($data->{"assessment"}), $data->{"deadline"});
     return ["assignment-id" => $id->toString(), "assessment-id" => $data->{"assessment"}, "deadline" => $data->{"deadline"}];
 }
 public function handle($data)
 {
     $group = GroupBackend::fetch_group_profile($this->params['id']);
     $assignment = AssignmentBackend::fetch_assignment_profile(Token::decode($this->params['assignment']));
     $data = [];
     /** @var UserProfile $user */
     foreach (GroupBackend::fetch_group_users($group) as $user) {
         $data[] = ["user" => $user->toExternalForm(), "score" => UserBackend::fetch_user_scores($user, $assignment)];
     }
     return ["users" => $data];
 }
 public function handle($data)
 {
     $this->validate_request(["assignment"]);
     $group = GroupBackend::fetch_group_profile($this->params['id']);
     $users = GroupBackend::fetch_group_users($group);
     $assignmentId = Token::decode($data->{"assignment"});
     foreach ($users as $user) {
         UserBackend::add_user_assignment($user, $assignmentId);
     }
     $assignmentId = AssignmentBackend::fetch_assignment_profile($assignmentId);
     return ["assignment" => $assignmentId];
 }
 public function handle($data)
 {
     $user = UserBackend::fetch_user_profile($this->params['id']);
     $assignment = AssignmentBackend::fetch_assignment_profile(Token::decode($this->params['assignment']));
     return UserBackend::fetch_user_scores($user, $assignment);
 }
 public function handle($data)
 {
     $assignments = AssignmentBackend::fetch_all_assignments();
     return ["count" => count($assignments), "assignments" => $assignments];
 }
 public function handleDelete($data)
 {
     AssignmentBackend::delete_assignment(Token::decode($this->params['id']));
     return [];
 }
 public static function add_user_assignment(UserProfile $profile, Token $id)
 {
     if ($id->getType() != TOKEN_ASSIGNMENT) {
         throw new InvalidAssignmentException("Assignment id provided is not a valid assignment id", $id);
     }
     $assignment = AssignmentBackend::fetch_assignment_profile($id);
     $query = Database::generate_query("user_assignment_add", [$profile->getUserId()->toString(), $assignment["assignment-id"], $assignment["assessment-id"]->toString()]);
     $query->execute();
     return $assignment;
 }