This repository was archived by the owner on May 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathclass.ProgressReportController.php
More file actions
145 lines (138 loc) · 5.84 KB
/
class.ProgressReportController.php
File metadata and controls
145 lines (138 loc) · 5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* Hackademic-CMS/controller/class.ReadArticleController.php
*
* Hackademic Frontend Read Article Controller
* Class for creating the frontend Main Menu
*
* Copyright (c) 2012 OWASP
*
* LICENSE:
*
* This file is part of Hackademic CMS
* (https://www.owasp.org/index.php/OWASP_Hackademic_Challenges_Project).
*
* Hackademic CMS is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* Hackademic CMS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Hackademic CMS. If not, see <http://www.gnu.org/licenses/>.
*
* PHP Version 5.
*
* @author Pragya Gupta <pragya18nsit@gmail.com>
* @author Konstantinos Papapanagiotou <conpap@gmail.com>
* @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'</p>';var_dump($class_scores);
//echo'</p>';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'</p>';var_dump($arr);
array_push($data, $arr);
}
}
//var_dump($cleared_challenges);
return $data;
}
}