public static function deleteChallenge($id) { global $db; $params = array(':id' => $id); $sql = "DELETE FROM challenges WHERE id=:id"; $query = $db->query($sql, $params); ClassChallenges::deleteAllMemberships($id); if ($db->affectedRows($query)) { return true; } else { return false; } }
public function go() { $this->setViewTemplate('showclass.tpl'); if (!isset($_GET['id'])) { header('Location: ' . SOURCE_ROOT_PATH . "admin/pages/manageclass.php"); } $class_id = $_GET['id']; if (isset($_POST['submit'])) { if (isset($_POST['updateclassname'])) { if ($_POST['updateclassname'] == '') { header('Location: ' . SOURCE_ROOT_PATH . "admin/pages/showclass.php?id={$class_id}&action=editerror"); } else { $this->name = $_POST['updateclassname']; Classes::updateClassName($class_id, $this->name); header('Location: ' . SOURCE_ROOT_PATH . "admin/pages/showclass.php?id={$class_id}&action=editsuccess"); } } } if (isset($_GET['action']) && $_GET['action'] == "editerror") { $this->addErrorMessage("Class name should not be empty"); } if (isset($_GET['action']) && $_GET['action'] == "editsuccess") { $this->addSuccessMessage("Class name updated successfully"); } if (isset($_GET['action']) && $_GET['action'] == "del") { if (isset($_GET['uid'])) { ClassMemberships::deleteMembership($_GET['uid'], $class_id); $this->addSuccessMessage("User has been deleted from the class succesfully"); } else { if (isset($_GET['cid'])) { ClassChallenges::deleteMembership($_GET['cid'], $class_id); $this->addSuccessMessage("Challenge has been deleted from the class succesfully"); } } } $class = Classes::getClass($class_id); $user_members = ClassMemberships::getAllMemberships($class_id); $challenges_assigned = ClassChallenges::getAllMemberships($class_id); $this->addToView('class', $class); $this->addToView('users', $user_members); $this->addToView('challenges', $challenges_assigned); return $this->generateView(); }
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 function go() { $this->setViewTemplate('classchallenges.tpl'); $challenge_id = $_GET['id']; if (isset($_POST['submit'])) { $class_id = $_POST['class_id']; if (ClassChallenges::doesMembershipExist($challenge_id, $class_id)) { $this->addErrorMessage("Challenge is already a member of this class"); } else { ClassChallenges::addMembership($challenge_id, $class_id); $this->addSuccessMessage("Challenge has been added to the class succesfully"); } } elseif (isset($_GET['action']) && $_GET['action'] == "del") { $class_id = $_GET['class_id']; ClassChallenges::deleteMembership($challenge_id, $class_id); $this->addSuccessMessage("Challenge has been deleted from the class succesfully"); } $class_memberships = ClassChallenges::getMembershipsOfChallenge($challenge_id); $classes = Classes::getAllClasses(); $this->addToView('classes', $classes); $this->addToView('class_memberships', $class_memberships); $this->setViewTemplate('classchallenges.tpl'); $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; }
protected static function isAllowed($username, $challenge_id) { $user = User::findByUserName($username); $classes = ClassMemberships::getMembershipsOfUser($user->id); return ClassChallenges::isAllowed($challenge_id, $classes); }