public function getStudentAnswers($asgId)
 {
     $withinGpAsgsController = new WithinGpAsgsController();
     $result = array();
     $studentAnswers = WithinGpAsgAns::where("asg_id", $asgId)->get();
     foreach ($studentAnswers as $answer) {
         if (!array_key_exists($answer->target_user_id, $result)) {
             $result[$answer->target_user_id] = array();
         }
         if (!array_key_exists($answer->user_id, $result[$answer->target_user_id])) {
             $result[$answer->target_user_id][$answer->user_id] = array();
         }
         array_push($result[$answer->target_user_id][$answer->user_id], $answer);
     }
     return $result;
 }
示例#2
0
 public function insertMultipleAns($asgId, $ans)
 {
     //format of ans - [user_id][criteria_id]
     $courseId = $this->getAsg($asgId)->course_id;
     $currentGpId = (new GroupsController())->getCurrentUserGp($courseId)->id;
     $currentUserId = $this->currentUser->id;
     $targetUserIds = array_keys($ans);
     for ($i = 0; $i < count($targetUserIds); $i++) {
         $targetUserId = $targetUserIds[$i];
         $ansForStudent = $ans[$targetUserId];
         $criteriaIds = array_keys($ansForStudent);
         for ($j = 0; $j < count($criteriaIds); $j++) {
             $criteriaId = $criteriaIds[$j];
             $answer = $ansForStudent[$criteriaId];
             WithinGpAsgAns::firstOrCreate(['asg_id' => $asgId, 'gp_id' => $currentGpId, 'user_id' => $currentUserId, 'target_user_id' => $targetUserId, 'criteria_id' => $criteriaId, 'answer' => $answer]);
         }
     }
     return true;
 }