. * * PHP Version 5. * * @author Pragya Gupta * @author Konstantinos Papapanagiotou * @copyright 2012 OWASP * @license GNU General Public License http://www.gnu.org/licenses/gpl.html */ require_once HACKADEMIC_PATH."/admin/model/class.ClassMemberships.php"; require_once HACKADEMIC_PATH."/admin/model/class.ClassChallenges.php"; require_once HACKADEMIC_PATH."/model/common/class.Session.php"; require_once HACKADEMIC_PATH."/model/common/class.User.php"; require_once HACKADEMIC_PATH."/model/common/class.ChallengeAttempts.php"; require_once HACKADEMIC_PATH."/controller/class.HackademicController.php"; require_once HACKADEMIC_PATH."admin/model/class.UserChallenges.php"; require_once HACKADEMIC_PATH."/model/common/class.UserScore.php"; require_once HACKADEMIC_PATH."/model/common/class.Debug.php"; class ProgressReportController extends HackademicController { private static $_action_type = 'progress_report'; public function go() { $this->setViewTemplate('progressreport.tpl'); if (self::isAdmin() || self::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(self::$_action_type); } elseif ($user->type) { $this->addErrorMessage("Please select a student!"); return $this->generateView(self::$_action_type); } $data = array(); $class_ids = array(); $class_scores = array(); $classes_of_user = ClassMemberships::getMembershipsOfUserObjects($user->id); //var_dump(UserChallenges::getChallengesOfUser($user->id)); foreach ($classes_of_user as $class) { $progress = ChallengeAttempts::getUserProgress($user->id, $class->id); $user_scores = UserScore::getScoresForUserClass($user->id, $class->id); $class_challenges = ClassChallenges::getAllMemberships($class->id); $data = $this->_buildingScoringInfo($class_challenges, $progress, $user_scores); $class_scores[$class->name] = $data; $class_ids[$class->name] = $class->id; } //echo'

';var_dump($class_scores); //echo'

';var_dump($class_scores); $this->addToView('data', $class_scores); $this->addToView('ids', $class_ids); } else { $this->addErrorMessage("Please select a student to see his progress"); } return $this->generateView(self::$_action_type); } private function _buildingScoringInfo($class_challenges, $progress_arr, $user_scores) { $data = array(); $pts = null; $cleared = null; $cleared_on = null; $attempts = null; if ($class_challenges != false) { foreach ($class_challenges as $challenge) { /* For each class_challenge*/ $pts = null; $cleared = null; $cleared_on = null; $attempts = null; if ($user_scores != false) { foreach ($user_scores as $p) {/* find its associated points */ if ($p->challenge_id == $challenge['challenge_id']) { $pts = $p->points; } } } if ($progress_arr != false) { foreach ($progress_arr as $chal_prog) { /* Find its progress*/ if ($challenge['challenge_id'] == $chal_prog->challenge_id) { /*so we know the attempt count and if and when its cleared*/ $attempts = $chal_prog->tries; if (1 === $chal_prog->status) { $cleared = true; $cleared_on = $chal_prog->time; //unset($progress[$chal_prog]); break; } } } } $arr = array( 'id' => $challenge['challenge_id'], 'title' => $challenge['title'], 'attempts' => $attempts, 'cleared' => $cleared, 'cleared_on' => $cleared_on, 'points' => $pts ); //echo'

';var_dump($arr); array_push($data, $arr); } } //var_dump($cleared_challenges); return $data; } }