public function go() { $this->setViewTemplate("rankings.tpl"); if ($this->isLoggedIn()) { $username = $this->getLoggedInUser(); if (Session::isAdmin() || Session::isTeacher()) { $classes = Classes::getAllClasses(); } else { $user = User::findByUserName($username); $classes = ClassMemberships::getMembershipsOfUserObjects($user->id); } $this->addToView('classes', $classes); } if (!isset($_GET["class"]) || $_GET["class"] == "") { $rankings = ChallengeAttempts::getUniversalRankings(); } else { $class_id = $_GET["class"]; $class = Classes::getClass($class_id); if (!$class) { $this->addErrorMessage("Not a valid class"); return $this->generateView(); } else { $rankings = ChallengeAttempts::getClasswiseRankings($class_id); } } $final = array(); $counter = 1; $rank = 1; $rankcount = 1; $prevcount = null; foreach ($rankings as $ranking) { if ($counter != 1 && $prevcount == $ranking['count']) { $rank = $rankcount; $rankcount++; } if ($counter != 1 && $prevcount != $ranking['count']) { $rankcount++; $rank = $rankcount; } $prevcount = $ranking['count']; $counter++; $temp = array('user_id' => $ranking['user_id'], 'time' => $ranking['time'], 'count' => $ranking['count'], 'username' => $ranking['username'], 'rank' => $rank); array_push($final, $temp); } $this->addToView('rankings', $final); return $this->generateView(); }
public function update($status) { if (!Session::isAdmin() && !Session::isTeacher()) { $username = Session::getLoggedInUser(); $url = $_SERVER['REQUEST_URI']; $url_components = explode("/", $url); $count_url_components = count($url_components); for ($i = 0; $url_components[$i] != "challenges"; $i++) { } $pkg_name = $url_components[$i + 1]; $user = User::findByUserName($username); $challenge = Challenge::getChallengeByPkgName($pkg_name); $user_id = $user->id; $challenge_id = $challenge[0]->id; if (!ChallengeAttempts::isChallengeCleared($user_id, $challenge_id)) { ChallengeAttempts::addChallengeAttempt($user_id, $challenge_id, $status); } } }
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(); }