public function go() { $this->setViewTemplate('progressreport.tpl'); if ($this->isAdmin() || $this->isTeacher()) { $this->addToView('search_box', true); if (isset($_GET['username'])) { $username = $_GET['username']; } } else { $username = Session::getLoggedInUser(); } if (isset($username)) { $user = User::findByUserName($username); if (!$user) { $this->addErrorMessage("You provided an invalid username"); return $this->generateView(); } elseif ($user->type) { $this->addErrorMessage("Please select a student!"); return $this->generateView(); } $challenges_of_user = ClassChallenges::getChallengesOfUser($user->id); $attempts = ChallengeAttempts::getTotalAttempts($user->id); $cleared_challenges = ChallengeAttempts::getClearedChallenges($user->id); $data = array(); foreach ($challenges_of_user as $id => $title) { $attempt = isset($attempts[$id]) ? $attempts[$id] : 0; $cleared = isset($cleared_challenges[$id]['cleared']) ? $cleared_challenges[$id]['cleared'] : false; if ($cleared) { $cleared_on = $cleared_challenges[$id]['cleared_on']; } else { $cleared_on = false; } $arr = array('id' => $id, 'title' => $title, 'attempts' => $attempt, 'cleared' => $cleared, 'cleared_on' => $cleared_on); array_push($data, $arr); } $this->addToView('data', $data); } else { $this->addErrorMessage("Please select a student to see his progress"); } return $this->generateView(); }
public static function getChallengesAssigned($user) { global $db; $challenge_ids = ClassChallenges::getChallengesOfUser($user); $challenges = array(); foreach ($challenge_ids as $id => $title) { $challenge = self::getChallenge($id); array_push($challenges, $challenge[0]); } return $challenges; }