@@ -58,7 +58,7 @@ |
||
58 | 58 | * @param null $feedback_type |
59 | 59 | * @param null $counter |
60 | 60 | * @param null $score |
61 | - * @return null|string |
|
61 | + * @return string |
|
62 | 62 | */ |
63 | 63 | function return_header($feedback_type = null, $counter = null, $score = null) |
64 | 64 | { |
@@ -95,7 +95,7 @@ |
||
95 | 95 | |
96 | 96 | /** |
97 | 97 | * Get the progress of this learnpath. Only the last attempt are taken into account. |
98 | - * @param $stud_id student id (default: all students who have results - then the average is returned) |
|
98 | + * @param integer $stud_id student id (default: all students who have results - then the average is returned) |
|
99 | 99 | * @return array (score, max) if student is given |
100 | 100 | * array (sum of scores, number of scores) otherwise |
101 | 101 | * or null if no scores available |
@@ -9,261 +9,261 @@ |
||
9 | 9 | */ |
10 | 10 | class LearnpathLink extends AbstractLink |
11 | 11 | { |
12 | - private $course_info = null; |
|
13 | - private $learnpath_table = null; |
|
14 | - private $learnpath_data = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct(); |
|
22 | - $this->set_type(LINK_LEARNPATH); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Generate an array of learnpaths that a teacher hasn't created a link for. |
|
27 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
28 | - */ |
|
29 | - public function get_not_created_links() |
|
30 | - { |
|
31 | - return false; |
|
32 | - if (empty($this->course_code)) |
|
33 | - die('Error in get_not_created_links() : course code not set'); |
|
34 | - |
|
35 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
36 | - |
|
37 | - $sql = 'SELECT id, name from '.$this->get_learnpath_table().' lp |
|
12 | + private $course_info = null; |
|
13 | + private $learnpath_table = null; |
|
14 | + private $learnpath_data = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct(); |
|
22 | + $this->set_type(LINK_LEARNPATH); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Generate an array of learnpaths that a teacher hasn't created a link for. |
|
27 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
28 | + */ |
|
29 | + public function get_not_created_links() |
|
30 | + { |
|
31 | + return false; |
|
32 | + if (empty($this->course_code)) |
|
33 | + die('Error in get_not_created_links() : course code not set'); |
|
34 | + |
|
35 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
36 | + |
|
37 | + $sql = 'SELECT id, name from '.$this->get_learnpath_table().' lp |
|
38 | 38 | WHERE c_id = '.$this->course_id.' AND id NOT IN ' |
39 | - .' (SELECT ref_id FROM '.$tbl_grade_links |
|
40 | - .' WHERE type = '.LINK_LEARNPATH |
|
41 | - ." AND course_code = '".$this->get_course_code()."'" |
|
42 | - .') AND lp.session_id='.api_get_session_id().''; |
|
43 | - |
|
44 | - $result = Database::query($sql); |
|
45 | - |
|
46 | - $cats=array(); |
|
47 | - while ($data=Database::fetch_array($result)) { |
|
48 | - $cats[] = array ($data['id'], $data['name']); |
|
49 | - } |
|
50 | - |
|
51 | - return $cats; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Generate an array of all learnpaths available. |
|
56 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
57 | - */ |
|
58 | - public function get_all_links() |
|
59 | - { |
|
60 | - if (empty($this->course_code)) |
|
61 | - die('Error in get_not_created_links() : course code not set'); |
|
62 | - |
|
63 | - $session_id = api_get_session_id(); |
|
64 | - if (empty($session_id)) { |
|
65 | - $session_condition = api_get_session_condition(0, true); |
|
66 | - } else { |
|
67 | - $session_condition = api_get_session_condition($session_id, true, true); |
|
68 | - } |
|
69 | - |
|
70 | - $sql = 'SELECT id, name FROM '.$this->get_learnpath_table().' |
|
39 | + .' (SELECT ref_id FROM '.$tbl_grade_links |
|
40 | + .' WHERE type = '.LINK_LEARNPATH |
|
41 | + ." AND course_code = '".$this->get_course_code()."'" |
|
42 | + .') AND lp.session_id='.api_get_session_id().''; |
|
43 | + |
|
44 | + $result = Database::query($sql); |
|
45 | + |
|
46 | + $cats=array(); |
|
47 | + while ($data=Database::fetch_array($result)) { |
|
48 | + $cats[] = array ($data['id'], $data['name']); |
|
49 | + } |
|
50 | + |
|
51 | + return $cats; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Generate an array of all learnpaths available. |
|
56 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
57 | + */ |
|
58 | + public function get_all_links() |
|
59 | + { |
|
60 | + if (empty($this->course_code)) |
|
61 | + die('Error in get_not_created_links() : course code not set'); |
|
62 | + |
|
63 | + $session_id = api_get_session_id(); |
|
64 | + if (empty($session_id)) { |
|
65 | + $session_condition = api_get_session_condition(0, true); |
|
66 | + } else { |
|
67 | + $session_condition = api_get_session_condition($session_id, true, true); |
|
68 | + } |
|
69 | + |
|
70 | + $sql = 'SELECT id, name FROM '.$this->get_learnpath_table().' |
|
71 | 71 | WHERE c_id = '.$this->course_id.' '.$session_condition.' '; |
72 | - $result = Database::query($sql); |
|
72 | + $result = Database::query($sql); |
|
73 | 73 | |
74 | - $cats = array(); |
|
75 | - while ($data=Database::fetch_array($result)) { |
|
76 | - $cats[] = array ($data['id'], $data['name']); |
|
77 | - } |
|
74 | + $cats = array(); |
|
75 | + while ($data=Database::fetch_array($result)) { |
|
76 | + $cats[] = array ($data['id'], $data['name']); |
|
77 | + } |
|
78 | 78 | |
79 | - return $cats; |
|
80 | - } |
|
79 | + return $cats; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * Has anyone used this learnpath yet ? |
|
85 | - */ |
|
86 | - public function has_results() |
|
87 | - { |
|
88 | - $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
89 | - $sql = "SELECT count(id) AS number FROM $tbl_stats |
|
83 | + /** |
|
84 | + * Has anyone used this learnpath yet ? |
|
85 | + */ |
|
86 | + public function has_results() |
|
87 | + { |
|
88 | + $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
89 | + $sql = "SELECT count(id) AS number FROM $tbl_stats |
|
90 | 90 | WHERE c_id = ".$this->course_id." AND lp_id = ".$this->get_ref_id(); |
91 | - $result = Database::query($sql); |
|
92 | - $number = Database::fetch_array($result,'NUM'); |
|
93 | - return ($number[0] != 0); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get the progress of this learnpath. Only the last attempt are taken into account. |
|
98 | - * @param $stud_id student id (default: all students who have results - then the average is returned) |
|
99 | - * @return array (score, max) if student is given |
|
100 | - * array (sum of scores, number of scores) otherwise |
|
101 | - * or null if no scores available |
|
102 | - */ |
|
103 | - public function calc_score($stud_id = null, $type = null) |
|
104 | - { |
|
105 | - $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
106 | - $session_id = api_get_session_id(); |
|
107 | - |
|
108 | - $sql = "SELECT * FROM $tbl_stats |
|
91 | + $result = Database::query($sql); |
|
92 | + $number = Database::fetch_array($result,'NUM'); |
|
93 | + return ($number[0] != 0); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get the progress of this learnpath. Only the last attempt are taken into account. |
|
98 | + * @param $stud_id student id (default: all students who have results - then the average is returned) |
|
99 | + * @return array (score, max) if student is given |
|
100 | + * array (sum of scores, number of scores) otherwise |
|
101 | + * or null if no scores available |
|
102 | + */ |
|
103 | + public function calc_score($stud_id = null, $type = null) |
|
104 | + { |
|
105 | + $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
106 | + $session_id = api_get_session_id(); |
|
107 | + |
|
108 | + $sql = "SELECT * FROM $tbl_stats |
|
109 | 109 | WHERE |
110 | 110 | c_id = ".$this->course_id." AND |
111 | 111 | lp_id = ".$this->get_ref_id()." AND |
112 | 112 | session_id = $session_id "; |
113 | 113 | |
114 | - if (isset($stud_id)) |
|
115 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
116 | - |
|
117 | - // order by id, that way the student's first attempt is accessed first |
|
118 | - $sql .= ' ORDER BY view_count DESC'; |
|
119 | - |
|
120 | - $scores = Database::query($sql); |
|
121 | - // for 1 student |
|
122 | - if (isset($stud_id)) { |
|
123 | - if ($data = Database::fetch_assoc($scores)) { |
|
124 | - return array ($data['progress'], 100); |
|
125 | - } else |
|
126 | - return null; |
|
127 | - } else { |
|
128 | - // all students -> get average |
|
129 | - $students = array(); // user list, needed to make sure we only |
|
130 | - // take first attempts into account |
|
131 | - $rescount = 0; |
|
132 | - $sum = 0; |
|
133 | - $bestResult = 0; |
|
134 | - $sumResult = 0; |
|
135 | - while ($data = Database::fetch_array($scores)) { |
|
136 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
137 | - $students[$data['user_id']] = $data['progress']; |
|
138 | - $rescount++; |
|
139 | - $sum += $data['progress'] / 100; |
|
140 | - $sumResult += $data['progress']; |
|
141 | - |
|
142 | - if ($data['progress'] > $bestResult) { |
|
143 | - $bestResult = $data['progress']; |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - if ($rescount == 0) { |
|
149 | - return null; |
|
150 | - } else { |
|
151 | - |
|
152 | - switch ($type) { |
|
153 | - case 'best': |
|
154 | - return array($bestResult, 100); |
|
155 | - break; |
|
156 | - case 'average': |
|
157 | - return array($sumResult/$rescount, 100); |
|
158 | - break; |
|
159 | - case 'ranking': |
|
160 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
161 | - break; |
|
162 | - default: |
|
163 | - return array($sum, $rescount); |
|
164 | - break; |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Get URL where to go to if the user clicks on the link. |
|
172 | - */ |
|
173 | - public function get_link() |
|
174 | - { |
|
175 | - $session_id = api_get_session_id(); |
|
176 | - $url = api_get_path(WEB_PATH).'main/newscorm/lp_controller.php?'.api_get_cidreq_params($this->get_course_code(), $session_id).'&gradebook=view'; |
|
177 | - |
|
178 | - if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) { |
|
179 | - $url .= '&action=view&lp_id='.$this->get_ref_id(); |
|
180 | - } else { |
|
181 | - $url .= '&action=build&lp_id='.$this->get_ref_id(); |
|
182 | - } |
|
183 | - return $url; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Get name to display: same as learnpath title |
|
188 | - */ |
|
189 | - public function get_name() |
|
190 | - { |
|
191 | - $data = $this->get_learnpath_data(); |
|
192 | - return $data['name']; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Get description to display: same as learnpath description |
|
197 | - */ |
|
198 | - public function get_description() |
|
199 | - { |
|
200 | - $data = $this->get_learnpath_data(); |
|
201 | - return $data['description']; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Check if this still links to a learnpath |
|
206 | - */ |
|
207 | - public function is_valid_link() { |
|
208 | - $sql = 'SELECT count(id) FROM '.$this->get_learnpath_table().' |
|
114 | + if (isset($stud_id)) |
|
115 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
116 | + |
|
117 | + // order by id, that way the student's first attempt is accessed first |
|
118 | + $sql .= ' ORDER BY view_count DESC'; |
|
119 | + |
|
120 | + $scores = Database::query($sql); |
|
121 | + // for 1 student |
|
122 | + if (isset($stud_id)) { |
|
123 | + if ($data = Database::fetch_assoc($scores)) { |
|
124 | + return array ($data['progress'], 100); |
|
125 | + } else |
|
126 | + return null; |
|
127 | + } else { |
|
128 | + // all students -> get average |
|
129 | + $students = array(); // user list, needed to make sure we only |
|
130 | + // take first attempts into account |
|
131 | + $rescount = 0; |
|
132 | + $sum = 0; |
|
133 | + $bestResult = 0; |
|
134 | + $sumResult = 0; |
|
135 | + while ($data = Database::fetch_array($scores)) { |
|
136 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
137 | + $students[$data['user_id']] = $data['progress']; |
|
138 | + $rescount++; |
|
139 | + $sum += $data['progress'] / 100; |
|
140 | + $sumResult += $data['progress']; |
|
141 | + |
|
142 | + if ($data['progress'] > $bestResult) { |
|
143 | + $bestResult = $data['progress']; |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + if ($rescount == 0) { |
|
149 | + return null; |
|
150 | + } else { |
|
151 | + |
|
152 | + switch ($type) { |
|
153 | + case 'best': |
|
154 | + return array($bestResult, 100); |
|
155 | + break; |
|
156 | + case 'average': |
|
157 | + return array($sumResult/$rescount, 100); |
|
158 | + break; |
|
159 | + case 'ranking': |
|
160 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
161 | + break; |
|
162 | + default: |
|
163 | + return array($sum, $rescount); |
|
164 | + break; |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Get URL where to go to if the user clicks on the link. |
|
172 | + */ |
|
173 | + public function get_link() |
|
174 | + { |
|
175 | + $session_id = api_get_session_id(); |
|
176 | + $url = api_get_path(WEB_PATH).'main/newscorm/lp_controller.php?'.api_get_cidreq_params($this->get_course_code(), $session_id).'&gradebook=view'; |
|
177 | + |
|
178 | + if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) { |
|
179 | + $url .= '&action=view&lp_id='.$this->get_ref_id(); |
|
180 | + } else { |
|
181 | + $url .= '&action=build&lp_id='.$this->get_ref_id(); |
|
182 | + } |
|
183 | + return $url; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Get name to display: same as learnpath title |
|
188 | + */ |
|
189 | + public function get_name() |
|
190 | + { |
|
191 | + $data = $this->get_learnpath_data(); |
|
192 | + return $data['name']; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Get description to display: same as learnpath description |
|
197 | + */ |
|
198 | + public function get_description() |
|
199 | + { |
|
200 | + $data = $this->get_learnpath_data(); |
|
201 | + return $data['description']; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Check if this still links to a learnpath |
|
206 | + */ |
|
207 | + public function is_valid_link() { |
|
208 | + $sql = 'SELECT count(id) FROM '.$this->get_learnpath_table().' |
|
209 | 209 | WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; |
210 | - $result = Database::query($sql); |
|
211 | - $number = Database::fetch_row($result,'NUM'); |
|
212 | - return ($number[0] != 0); |
|
213 | - } |
|
214 | - |
|
215 | - public function get_type_name() |
|
216 | - { |
|
217 | - return get_lang('LearningPaths'); |
|
218 | - } |
|
219 | - |
|
220 | - public function needs_name_and_description() |
|
221 | - { |
|
222 | - return false; |
|
223 | - } |
|
224 | - |
|
225 | - public function needs_max() |
|
226 | - { |
|
227 | - return false; |
|
228 | - } |
|
229 | - |
|
230 | - public function needs_results() |
|
231 | - { |
|
232 | - return false; |
|
233 | - } |
|
234 | - |
|
235 | - public function is_allowed_to_change_name() |
|
236 | - { |
|
237 | - return false; |
|
238 | - } |
|
239 | - |
|
240 | - // INTERNAL FUNCTIONS |
|
241 | - |
|
242 | - /** |
|
243 | - * Lazy load function to get the database table of the learnpath |
|
244 | - */ |
|
245 | - private function get_learnpath_table() |
|
246 | - { |
|
247 | - $this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN); |
|
248 | - return $this->learnpath_table; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Lazy load function to get the database contents of this learnpath |
|
253 | - */ |
|
254 | - private function get_learnpath_data() |
|
255 | - { |
|
256 | - if (!isset($this->learnpath_data)) { |
|
257 | - $sql = 'SELECT * FROM '.$this->get_learnpath_table().' |
|
210 | + $result = Database::query($sql); |
|
211 | + $number = Database::fetch_row($result,'NUM'); |
|
212 | + return ($number[0] != 0); |
|
213 | + } |
|
214 | + |
|
215 | + public function get_type_name() |
|
216 | + { |
|
217 | + return get_lang('LearningPaths'); |
|
218 | + } |
|
219 | + |
|
220 | + public function needs_name_and_description() |
|
221 | + { |
|
222 | + return false; |
|
223 | + } |
|
224 | + |
|
225 | + public function needs_max() |
|
226 | + { |
|
227 | + return false; |
|
228 | + } |
|
229 | + |
|
230 | + public function needs_results() |
|
231 | + { |
|
232 | + return false; |
|
233 | + } |
|
234 | + |
|
235 | + public function is_allowed_to_change_name() |
|
236 | + { |
|
237 | + return false; |
|
238 | + } |
|
239 | + |
|
240 | + // INTERNAL FUNCTIONS |
|
241 | + |
|
242 | + /** |
|
243 | + * Lazy load function to get the database table of the learnpath |
|
244 | + */ |
|
245 | + private function get_learnpath_table() |
|
246 | + { |
|
247 | + $this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN); |
|
248 | + return $this->learnpath_table; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Lazy load function to get the database contents of this learnpath |
|
253 | + */ |
|
254 | + private function get_learnpath_data() |
|
255 | + { |
|
256 | + if (!isset($this->learnpath_data)) { |
|
257 | + $sql = 'SELECT * FROM '.$this->get_learnpath_table().' |
|
258 | 258 | WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; |
259 | - $result = Database::query($sql); |
|
260 | - $this->learnpath_data = Database::fetch_array($result); |
|
261 | - } |
|
262 | - return $this->learnpath_data; |
|
263 | - } |
|
264 | - |
|
265 | - public function get_icon_name() |
|
266 | - { |
|
267 | - return 'learnpath'; |
|
268 | - } |
|
259 | + $result = Database::query($sql); |
|
260 | + $this->learnpath_data = Database::fetch_array($result); |
|
261 | + } |
|
262 | + return $this->learnpath_data; |
|
263 | + } |
|
264 | + |
|
265 | + public function get_icon_name() |
|
266 | + { |
|
267 | + return 'learnpath'; |
|
268 | + } |
|
269 | 269 | } |
@@ -32,6 +32,8 @@ discard block |
||
32 | 32 | * @param array $evals |
33 | 33 | * @param array $links |
34 | 34 | * @param null $addparams |
35 | + * @param boolean $showTeacherView |
|
36 | + * @param integer $userId |
|
35 | 37 | */ |
36 | 38 | public function __construct( |
37 | 39 | $currentcat, |
@@ -895,7 +897,7 @@ discard block |
||
895 | 897 | |
896 | 898 | /** |
897 | 899 | * @param $item |
898 | - * @return mixed |
|
900 | + * @return string|null |
|
899 | 901 | */ |
900 | 902 | private function build_course_code($item) |
901 | 903 | { |
@@ -72,6 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Get actual array data |
75 | + * @param integer $count |
|
75 | 76 | * @return array 2-dimensional array - each array contains the elements: |
76 | 77 | * 0: eval/link object |
77 | 78 | * 1: item name |
@@ -285,7 +286,7 @@ discard block |
||
285 | 286 | |
286 | 287 | /** |
287 | 288 | * @param $item |
288 | - * @param $ignore_score_color |
|
289 | + * @param boolean $ignore_score_color |
|
289 | 290 | * @return string |
290 | 291 | */ |
291 | 292 | private function build_average_column($item, $ignore_score_color) |
@@ -306,7 +307,7 @@ discard block |
||
306 | 307 | |
307 | 308 | /** |
308 | 309 | * @param $item |
309 | - * @param $ignore_score_color |
|
310 | + * @param boolean $ignore_score_color |
|
310 | 311 | * @return string |
311 | 312 | */ |
312 | 313 | private function build_result_column($item, $ignore_score_color) |
@@ -323,7 +324,7 @@ discard block |
||
323 | 324 | |
324 | 325 | /** |
325 | 326 | * @param $item |
326 | - * @param $ignore_score_color |
|
327 | + * @param boolean $ignore_score_color |
|
327 | 328 | * @return string |
328 | 329 | */ |
329 | 330 | private function build_mask_column($item, $ignore_score_color) |
@@ -339,7 +340,7 @@ discard block |
||
339 | 340 | |
340 | 341 | /** |
341 | 342 | * @param $coursecode |
342 | - * @return mixed |
|
343 | + * @return string |
|
343 | 344 | */ |
344 | 345 | private function get_course_name_from_code_cached($coursecode) |
345 | 346 | { |
@@ -10,28 +10,28 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class UserDataGenerator |
12 | 12 | { |
13 | - // Sorting types constants |
|
14 | - const UDG_SORT_TYPE = 1; |
|
15 | - const UDG_SORT_NAME = 2; |
|
16 | - const UDG_SORT_COURSE = 4; |
|
17 | - const UDG_SORT_CATEGORY = 8; |
|
18 | - const UDG_SORT_AVERAGE = 16; |
|
19 | - const UDG_SORT_SCORE = 32; |
|
20 | - const UDG_SORT_MASK = 64; |
|
21 | - |
|
22 | - const UDG_SORT_ASC = 128; |
|
23 | - const UDG_SORT_DESC = 256; |
|
24 | - |
|
25 | - private $items; |
|
26 | - private $userid; |
|
27 | - |
|
28 | - private $coursecodecache; |
|
29 | - private $categorycache; |
|
30 | - private $scorecache; |
|
31 | - private $avgcache; |
|
32 | - |
|
33 | - public function __construct($userid, $evals = array(), $links = array()) |
|
34 | - { |
|
13 | + // Sorting types constants |
|
14 | + const UDG_SORT_TYPE = 1; |
|
15 | + const UDG_SORT_NAME = 2; |
|
16 | + const UDG_SORT_COURSE = 4; |
|
17 | + const UDG_SORT_CATEGORY = 8; |
|
18 | + const UDG_SORT_AVERAGE = 16; |
|
19 | + const UDG_SORT_SCORE = 32; |
|
20 | + const UDG_SORT_MASK = 64; |
|
21 | + |
|
22 | + const UDG_SORT_ASC = 128; |
|
23 | + const UDG_SORT_DESC = 256; |
|
24 | + |
|
25 | + private $items; |
|
26 | + private $userid; |
|
27 | + |
|
28 | + private $coursecodecache; |
|
29 | + private $categorycache; |
|
30 | + private $scorecache; |
|
31 | + private $avgcache; |
|
32 | + |
|
33 | + public function __construct($userid, $evals = array(), $links = array()) |
|
34 | + { |
|
35 | 35 | $this->userid = $userid; |
36 | 36 | $evals_filtered = array(); |
37 | 37 | $result = array(); |
@@ -62,330 +62,330 @@ discard block |
||
62 | 62 | $this->avgcache = null; |
63 | 63 | } |
64 | 64 | |
65 | - /** |
|
66 | - * Get total number of items (rows) |
|
67 | - */ |
|
68 | - public function get_total_items_count() |
|
69 | - { |
|
70 | - return count($this->items); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Get actual array data |
|
75 | - * @return array 2-dimensional array - each array contains the elements: |
|
76 | - * 0: eval/link object |
|
77 | - * 1: item name |
|
78 | - * 2: course name |
|
79 | - * 3: category name |
|
80 | - * 4: average score |
|
81 | - * 5: student's score |
|
82 | - * 6: student's score as custom display (only if custom scoring enabled) |
|
83 | - */ |
|
84 | - public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false) |
|
85 | - { |
|
86 | - // do some checks on count, redefine if invalid value |
|
87 | - if (!isset($count)) { |
|
88 | - $count = count ($this->items) - $start; |
|
89 | - } |
|
90 | - if ($count < 0) { |
|
91 | - $count = 0; |
|
92 | - } |
|
93 | - $allitems = $this->items; |
|
94 | - |
|
95 | - // sort users array |
|
96 | - if ($sorting & self :: UDG_SORT_TYPE) { |
|
97 | - usort($allitems, array('UserDataGenerator', 'sort_by_type')); |
|
98 | - }elseif ($sorting & self :: UDG_SORT_NAME) { |
|
99 | - usort($allitems, array('UserDataGenerator', 'sort_by_name')); |
|
100 | - } elseif ($sorting & self :: UDG_SORT_COURSE) { |
|
101 | - usort($allitems, array('UserDataGenerator', 'sort_by_course')); |
|
102 | - } elseif ($sorting & self :: UDG_SORT_CATEGORY) { |
|
103 | - usort($allitems, array('UserDataGenerator', 'sort_by_category')); |
|
104 | - } elseif ($sorting & self :: UDG_SORT_AVERAGE) { |
|
105 | - // if user sorts on average scores, first calculate them and cache them |
|
106 | - foreach ($allitems as $item) { |
|
107 | - $this->avgcache[$item->get_item_type() . $item->get_id()]= $item->calc_score(); |
|
108 | - } |
|
109 | - usort($allitems, array('UserDataGenerator', 'sort_by_average')); |
|
110 | - } elseif ($sorting & self :: UDG_SORT_SCORE) { |
|
111 | - // if user sorts on student's scores, first calculate them and cache them |
|
112 | - foreach ($allitems as $item) { |
|
113 | - $this->scorecache[$item->get_item_type() . $item->get_id()] |
|
114 | - = $item->calc_score($this->userid); |
|
115 | - } |
|
116 | - usort($allitems, array('UserDataGenerator', 'sort_by_score')); |
|
117 | - } elseif ($sorting & self :: UDG_SORT_MASK) { |
|
118 | - // if user sorts on student's masks, first calculate scores and cache them |
|
119 | - foreach ($allitems as $item) { |
|
120 | - $this->scorecache[$item->get_item_type() . $item->get_id()] |
|
121 | - = $item->calc_score($this->userid); |
|
122 | - } |
|
123 | - usort($allitems, array('UserDataGenerator', 'sort_by_mask')); |
|
124 | - } |
|
125 | - |
|
126 | - if ($sorting & self :: UDG_SORT_DESC) { |
|
127 | - $allitems = array_reverse($allitems); |
|
128 | - } |
|
129 | - // select the items we have to display |
|
130 | - $visibleitems = array_slice($allitems, $start, $count); |
|
131 | - |
|
132 | - // fill score cache if not done yet |
|
133 | - if (!isset ($this->scorecache)) { |
|
134 | - foreach ($visibleitems as $item) { |
|
135 | - $this->scorecache[$item->get_item_type() . $item->get_id()] |
|
136 | - = $item->calc_score($this->userid); |
|
137 | - } |
|
138 | - |
|
139 | - } |
|
140 | - // generate the data to display |
|
141 | - $scoredisplay = ScoreDisplay :: instance(); |
|
142 | - $data = array(); |
|
143 | - foreach ($visibleitems as $item) { |
|
144 | - $row = array (); |
|
145 | - $row[] = $item; |
|
146 | - $row[] = $item->get_name(); |
|
147 | - $row[] = $this->build_course_name($item); |
|
148 | - $row[] = $this->build_category_name($item); |
|
149 | - $row[] = $this->build_average_column($item, $ignore_score_color); |
|
150 | - $row[] = $this->build_result_column($item, $ignore_score_color); |
|
151 | - if ($scoredisplay->is_custom()) |
|
152 | - $row[] = $this->build_mask_column($item, $ignore_score_color); |
|
153 | - $data[] = $row; |
|
154 | - } |
|
155 | - return $data; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param $item1 |
|
160 | - * @param $item2 |
|
161 | - * @return int |
|
162 | - */ |
|
163 | - function sort_by_type($item1, $item2) |
|
164 | - { |
|
165 | - if ($item1->get_item_type() == $item2->get_item_type()) { |
|
166 | - return $this->sort_by_name($item1,$item2); |
|
167 | - } else { |
|
168 | - return ($item1->get_item_type() < $item2->get_item_type() ? -1 : 1); |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @param $item1 |
|
174 | - * @param $item2 |
|
175 | - * @return int |
|
176 | - */ |
|
177 | - function sort_by_course($item1, $item2) |
|
178 | - { |
|
179 | - $name1 = api_strtolower($this->get_course_name_from_code_cached($item1->get_course_code())); |
|
180 | - $name2 = api_strtolower($this->get_course_name_from_code_cached($item2->get_course_code())); |
|
181 | - return api_strnatcmp($name1, $name2); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @param $item1 |
|
186 | - * @param $item2 |
|
187 | - * @return int |
|
188 | - */ |
|
189 | - function sort_by_category($item1, $item2) |
|
190 | - { |
|
191 | - $cat1 = $this->get_category_cached($item1->get_category_id()); |
|
192 | - $cat2 = $this->get_category_cached($item2->get_category_id()); |
|
193 | - $name1 = api_strtolower($this->get_category_name_to_display($cat1)); |
|
194 | - $name2 = api_strtolower($this->get_category_name_to_display($cat2)); |
|
195 | - |
|
196 | - return api_strnatcmp($name1, $name2); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param $item1 |
|
201 | - * @param $item2 |
|
202 | - * @return int |
|
203 | - */ |
|
204 | - function sort_by_name($item1, $item2) |
|
205 | - { |
|
206 | - return api_strnatcmp($item1->get_name(),$item2->get_name()); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @param $item1 |
|
211 | - * @param $item2 |
|
212 | - * @return int |
|
213 | - */ |
|
214 | - function sort_by_average($item1, $item2) |
|
215 | - { |
|
216 | - $score1 = $this->avgcache[$item1->get_item_type() . $item1->get_id()]; |
|
217 | - $score2 = $this->avgcache[$item2->get_item_type() . $item2->get_id()]; |
|
218 | - |
|
219 | - return $this->compare_scores($score1, $score2); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @param $item1 |
|
224 | - * @param $item2 |
|
225 | - * @return int |
|
226 | - */ |
|
227 | - function sort_by_score($item1, $item2) |
|
228 | - { |
|
229 | - $score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()]; |
|
230 | - $score2 = $this->scorecache[$item2->get_item_type() . $item2->get_id()]; |
|
231 | - |
|
232 | - return $this->compare_scores($score1, $score2); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * @param $item1 |
|
237 | - * @param $item2 |
|
238 | - * @return int |
|
239 | - */ |
|
240 | - function sort_by_mask($item1, $item2) |
|
241 | - { |
|
242 | - $score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()]; |
|
243 | - $score2 = $this->scorecache[$item2->get_item_type() . $item2->get_id()]; |
|
244 | - |
|
245 | - return ScoreDisplay :: compare_scores_by_custom_display($score1, $score2); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * @param $score1 |
|
250 | - * @param $score2 |
|
251 | - * @return int |
|
252 | - */ |
|
253 | - function compare_scores($score1, $score2) |
|
254 | - { |
|
255 | - if (!isset($score1)) { |
|
256 | - return (isset($score2) ? 1 : 0); |
|
257 | - } elseif (!isset($score2)) { |
|
258 | - return -1; |
|
259 | - } elseif (($score1[0]/$score1[1]) == ($score2[0]/$score2[1])) { |
|
260 | - return 0; |
|
261 | - } else { |
|
262 | - return (($score1[0]/$score1[1]) < ($score2[0]/$score2[1]) ? -1 : 1); |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * @param $item |
|
268 | - * @return mixed |
|
269 | - */ |
|
270 | - private function build_course_name($item) |
|
271 | - { |
|
272 | - return $this->get_course_name_from_code_cached($item->get_course_code()); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * @param $item |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - private function build_category_name($item) |
|
280 | - { |
|
281 | - $cat = $this->get_category_cached($item->get_category_id()); |
|
282 | - |
|
283 | - return $this->get_category_name_to_display($cat); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @param $item |
|
288 | - * @param $ignore_score_color |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - private function build_average_column($item, $ignore_score_color) |
|
292 | - { |
|
293 | - if (isset($this->avgcache)) { |
|
294 | - $avgscore = $this->avgcache[$item->get_item_type() . $item->get_id()]; |
|
295 | - } else { |
|
296 | - $avgscore = $item->calc_score(); |
|
297 | - } |
|
298 | - |
|
299 | - $scoredisplay = ScoreDisplay :: instance(); |
|
300 | - $displaytype = SCORE_AVERAGE; |
|
301 | - /*if ($ignore_score_color) |
|
65 | + /** |
|
66 | + * Get total number of items (rows) |
|
67 | + */ |
|
68 | + public function get_total_items_count() |
|
69 | + { |
|
70 | + return count($this->items); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Get actual array data |
|
75 | + * @return array 2-dimensional array - each array contains the elements: |
|
76 | + * 0: eval/link object |
|
77 | + * 1: item name |
|
78 | + * 2: course name |
|
79 | + * 3: category name |
|
80 | + * 4: average score |
|
81 | + * 5: student's score |
|
82 | + * 6: student's score as custom display (only if custom scoring enabled) |
|
83 | + */ |
|
84 | + public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false) |
|
85 | + { |
|
86 | + // do some checks on count, redefine if invalid value |
|
87 | + if (!isset($count)) { |
|
88 | + $count = count ($this->items) - $start; |
|
89 | + } |
|
90 | + if ($count < 0) { |
|
91 | + $count = 0; |
|
92 | + } |
|
93 | + $allitems = $this->items; |
|
94 | + |
|
95 | + // sort users array |
|
96 | + if ($sorting & self :: UDG_SORT_TYPE) { |
|
97 | + usort($allitems, array('UserDataGenerator', 'sort_by_type')); |
|
98 | + }elseif ($sorting & self :: UDG_SORT_NAME) { |
|
99 | + usort($allitems, array('UserDataGenerator', 'sort_by_name')); |
|
100 | + } elseif ($sorting & self :: UDG_SORT_COURSE) { |
|
101 | + usort($allitems, array('UserDataGenerator', 'sort_by_course')); |
|
102 | + } elseif ($sorting & self :: UDG_SORT_CATEGORY) { |
|
103 | + usort($allitems, array('UserDataGenerator', 'sort_by_category')); |
|
104 | + } elseif ($sorting & self :: UDG_SORT_AVERAGE) { |
|
105 | + // if user sorts on average scores, first calculate them and cache them |
|
106 | + foreach ($allitems as $item) { |
|
107 | + $this->avgcache[$item->get_item_type() . $item->get_id()]= $item->calc_score(); |
|
108 | + } |
|
109 | + usort($allitems, array('UserDataGenerator', 'sort_by_average')); |
|
110 | + } elseif ($sorting & self :: UDG_SORT_SCORE) { |
|
111 | + // if user sorts on student's scores, first calculate them and cache them |
|
112 | + foreach ($allitems as $item) { |
|
113 | + $this->scorecache[$item->get_item_type() . $item->get_id()] |
|
114 | + = $item->calc_score($this->userid); |
|
115 | + } |
|
116 | + usort($allitems, array('UserDataGenerator', 'sort_by_score')); |
|
117 | + } elseif ($sorting & self :: UDG_SORT_MASK) { |
|
118 | + // if user sorts on student's masks, first calculate scores and cache them |
|
119 | + foreach ($allitems as $item) { |
|
120 | + $this->scorecache[$item->get_item_type() . $item->get_id()] |
|
121 | + = $item->calc_score($this->userid); |
|
122 | + } |
|
123 | + usort($allitems, array('UserDataGenerator', 'sort_by_mask')); |
|
124 | + } |
|
125 | + |
|
126 | + if ($sorting & self :: UDG_SORT_DESC) { |
|
127 | + $allitems = array_reverse($allitems); |
|
128 | + } |
|
129 | + // select the items we have to display |
|
130 | + $visibleitems = array_slice($allitems, $start, $count); |
|
131 | + |
|
132 | + // fill score cache if not done yet |
|
133 | + if (!isset ($this->scorecache)) { |
|
134 | + foreach ($visibleitems as $item) { |
|
135 | + $this->scorecache[$item->get_item_type() . $item->get_id()] |
|
136 | + = $item->calc_score($this->userid); |
|
137 | + } |
|
138 | + |
|
139 | + } |
|
140 | + // generate the data to display |
|
141 | + $scoredisplay = ScoreDisplay :: instance(); |
|
142 | + $data = array(); |
|
143 | + foreach ($visibleitems as $item) { |
|
144 | + $row = array (); |
|
145 | + $row[] = $item; |
|
146 | + $row[] = $item->get_name(); |
|
147 | + $row[] = $this->build_course_name($item); |
|
148 | + $row[] = $this->build_category_name($item); |
|
149 | + $row[] = $this->build_average_column($item, $ignore_score_color); |
|
150 | + $row[] = $this->build_result_column($item, $ignore_score_color); |
|
151 | + if ($scoredisplay->is_custom()) |
|
152 | + $row[] = $this->build_mask_column($item, $ignore_score_color); |
|
153 | + $data[] = $row; |
|
154 | + } |
|
155 | + return $data; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param $item1 |
|
160 | + * @param $item2 |
|
161 | + * @return int |
|
162 | + */ |
|
163 | + function sort_by_type($item1, $item2) |
|
164 | + { |
|
165 | + if ($item1->get_item_type() == $item2->get_item_type()) { |
|
166 | + return $this->sort_by_name($item1,$item2); |
|
167 | + } else { |
|
168 | + return ($item1->get_item_type() < $item2->get_item_type() ? -1 : 1); |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @param $item1 |
|
174 | + * @param $item2 |
|
175 | + * @return int |
|
176 | + */ |
|
177 | + function sort_by_course($item1, $item2) |
|
178 | + { |
|
179 | + $name1 = api_strtolower($this->get_course_name_from_code_cached($item1->get_course_code())); |
|
180 | + $name2 = api_strtolower($this->get_course_name_from_code_cached($item2->get_course_code())); |
|
181 | + return api_strnatcmp($name1, $name2); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @param $item1 |
|
186 | + * @param $item2 |
|
187 | + * @return int |
|
188 | + */ |
|
189 | + function sort_by_category($item1, $item2) |
|
190 | + { |
|
191 | + $cat1 = $this->get_category_cached($item1->get_category_id()); |
|
192 | + $cat2 = $this->get_category_cached($item2->get_category_id()); |
|
193 | + $name1 = api_strtolower($this->get_category_name_to_display($cat1)); |
|
194 | + $name2 = api_strtolower($this->get_category_name_to_display($cat2)); |
|
195 | + |
|
196 | + return api_strnatcmp($name1, $name2); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param $item1 |
|
201 | + * @param $item2 |
|
202 | + * @return int |
|
203 | + */ |
|
204 | + function sort_by_name($item1, $item2) |
|
205 | + { |
|
206 | + return api_strnatcmp($item1->get_name(),$item2->get_name()); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @param $item1 |
|
211 | + * @param $item2 |
|
212 | + * @return int |
|
213 | + */ |
|
214 | + function sort_by_average($item1, $item2) |
|
215 | + { |
|
216 | + $score1 = $this->avgcache[$item1->get_item_type() . $item1->get_id()]; |
|
217 | + $score2 = $this->avgcache[$item2->get_item_type() . $item2->get_id()]; |
|
218 | + |
|
219 | + return $this->compare_scores($score1, $score2); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @param $item1 |
|
224 | + * @param $item2 |
|
225 | + * @return int |
|
226 | + */ |
|
227 | + function sort_by_score($item1, $item2) |
|
228 | + { |
|
229 | + $score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()]; |
|
230 | + $score2 = $this->scorecache[$item2->get_item_type() . $item2->get_id()]; |
|
231 | + |
|
232 | + return $this->compare_scores($score1, $score2); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * @param $item1 |
|
237 | + * @param $item2 |
|
238 | + * @return int |
|
239 | + */ |
|
240 | + function sort_by_mask($item1, $item2) |
|
241 | + { |
|
242 | + $score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()]; |
|
243 | + $score2 = $this->scorecache[$item2->get_item_type() . $item2->get_id()]; |
|
244 | + |
|
245 | + return ScoreDisplay :: compare_scores_by_custom_display($score1, $score2); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * @param $score1 |
|
250 | + * @param $score2 |
|
251 | + * @return int |
|
252 | + */ |
|
253 | + function compare_scores($score1, $score2) |
|
254 | + { |
|
255 | + if (!isset($score1)) { |
|
256 | + return (isset($score2) ? 1 : 0); |
|
257 | + } elseif (!isset($score2)) { |
|
258 | + return -1; |
|
259 | + } elseif (($score1[0]/$score1[1]) == ($score2[0]/$score2[1])) { |
|
260 | + return 0; |
|
261 | + } else { |
|
262 | + return (($score1[0]/$score1[1]) < ($score2[0]/$score2[1]) ? -1 : 1); |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * @param $item |
|
268 | + * @return mixed |
|
269 | + */ |
|
270 | + private function build_course_name($item) |
|
271 | + { |
|
272 | + return $this->get_course_name_from_code_cached($item->get_course_code()); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * @param $item |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + private function build_category_name($item) |
|
280 | + { |
|
281 | + $cat = $this->get_category_cached($item->get_category_id()); |
|
282 | + |
|
283 | + return $this->get_category_name_to_display($cat); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @param $item |
|
288 | + * @param $ignore_score_color |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + private function build_average_column($item, $ignore_score_color) |
|
292 | + { |
|
293 | + if (isset($this->avgcache)) { |
|
294 | + $avgscore = $this->avgcache[$item->get_item_type() . $item->get_id()]; |
|
295 | + } else { |
|
296 | + $avgscore = $item->calc_score(); |
|
297 | + } |
|
298 | + |
|
299 | + $scoredisplay = ScoreDisplay :: instance(); |
|
300 | + $displaytype = SCORE_AVERAGE; |
|
301 | + /*if ($ignore_score_color) |
|
302 | 302 | $displaytype |= SCORE_IGNORE_SPLIT; |
303 | 303 | */ |
304 | - return $scoredisplay->display_score($avgscore, $displaytype); |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * @param $item |
|
309 | - * @param $ignore_score_color |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - private function build_result_column($item, $ignore_score_color) |
|
313 | - { |
|
314 | - $studscore = $this->scorecache[$item->get_item_type() . $item->get_id()]; |
|
315 | - $scoredisplay = ScoreDisplay :: instance(); |
|
316 | - $displaytype = SCORE_DIV_PERCENT; |
|
317 | - if ($ignore_score_color) { |
|
318 | - $displaytype |= SCORE_IGNORE_SPLIT; |
|
319 | - } |
|
320 | - |
|
321 | - return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_DEFAULT); |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @param $item |
|
326 | - * @param $ignore_score_color |
|
327 | - * @return string |
|
328 | - */ |
|
329 | - private function build_mask_column($item, $ignore_score_color) |
|
330 | - { |
|
331 | - $studscore = $this->scorecache[$item->get_item_type() . $item->get_id()]; |
|
332 | - $scoredisplay = ScoreDisplay :: instance(); |
|
333 | - $displaytype = SCORE_DIV_PERCENT; |
|
334 | - if ($ignore_score_color) { |
|
335 | - $displaytype |= SCORE_IGNORE_SPLIT; |
|
336 | - } |
|
337 | - return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_CUSTOM); |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * @param $coursecode |
|
342 | - * @return mixed |
|
343 | - */ |
|
344 | - private function get_course_name_from_code_cached($coursecode) |
|
345 | - { |
|
346 | - if (isset ($this->coursecodecache) |
|
347 | - && isset ($this->coursecodecache[$coursecode])) { |
|
348 | - return $this->coursecodecache[$coursecode]; |
|
349 | - } else { |
|
350 | - $name = CourseManager::getCourseNameFromCode($coursecode); |
|
351 | - $this->coursecodecache[$coursecode] = $name; |
|
352 | - return $name; |
|
353 | - } |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * @param $category_id |
|
358 | - * @return null |
|
359 | - */ |
|
360 | - private function get_category_cached($category_id) |
|
361 | - { |
|
362 | - if (isset ($this->categorycache) |
|
363 | - && isset ($this->categorycache[$category_id])) { |
|
364 | - return $this->categorycache[$category_id]; |
|
365 | - }else { |
|
366 | - $cat = Category::load($category_id); |
|
367 | - if (isset($cat)){ |
|
368 | - $this->categorycache[$category_id] = $cat[0]; |
|
369 | - return $cat[0]; |
|
370 | - }else |
|
371 | - return null; |
|
372 | - } |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * @param $cat |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - private function get_category_name_to_display($cat) |
|
380 | - { |
|
381 | - if (isset($cat)) { |
|
382 | - if ($cat->get_parent_id() == '0' || $cat->get_parent_id() == null){ |
|
383 | - return ''; |
|
384 | - } else { |
|
385 | - return $cat->get_name(); |
|
386 | - } |
|
387 | - } else { |
|
388 | - return ''; |
|
389 | - } |
|
390 | - } |
|
304 | + return $scoredisplay->display_score($avgscore, $displaytype); |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * @param $item |
|
309 | + * @param $ignore_score_color |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + private function build_result_column($item, $ignore_score_color) |
|
313 | + { |
|
314 | + $studscore = $this->scorecache[$item->get_item_type() . $item->get_id()]; |
|
315 | + $scoredisplay = ScoreDisplay :: instance(); |
|
316 | + $displaytype = SCORE_DIV_PERCENT; |
|
317 | + if ($ignore_score_color) { |
|
318 | + $displaytype |= SCORE_IGNORE_SPLIT; |
|
319 | + } |
|
320 | + |
|
321 | + return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_DEFAULT); |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @param $item |
|
326 | + * @param $ignore_score_color |
|
327 | + * @return string |
|
328 | + */ |
|
329 | + private function build_mask_column($item, $ignore_score_color) |
|
330 | + { |
|
331 | + $studscore = $this->scorecache[$item->get_item_type() . $item->get_id()]; |
|
332 | + $scoredisplay = ScoreDisplay :: instance(); |
|
333 | + $displaytype = SCORE_DIV_PERCENT; |
|
334 | + if ($ignore_score_color) { |
|
335 | + $displaytype |= SCORE_IGNORE_SPLIT; |
|
336 | + } |
|
337 | + return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_CUSTOM); |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * @param $coursecode |
|
342 | + * @return mixed |
|
343 | + */ |
|
344 | + private function get_course_name_from_code_cached($coursecode) |
|
345 | + { |
|
346 | + if (isset ($this->coursecodecache) |
|
347 | + && isset ($this->coursecodecache[$coursecode])) { |
|
348 | + return $this->coursecodecache[$coursecode]; |
|
349 | + } else { |
|
350 | + $name = CourseManager::getCourseNameFromCode($coursecode); |
|
351 | + $this->coursecodecache[$coursecode] = $name; |
|
352 | + return $name; |
|
353 | + } |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * @param $category_id |
|
358 | + * @return null |
|
359 | + */ |
|
360 | + private function get_category_cached($category_id) |
|
361 | + { |
|
362 | + if (isset ($this->categorycache) |
|
363 | + && isset ($this->categorycache[$category_id])) { |
|
364 | + return $this->categorycache[$category_id]; |
|
365 | + }else { |
|
366 | + $cat = Category::load($category_id); |
|
367 | + if (isset($cat)){ |
|
368 | + $this->categorycache[$category_id] = $cat[0]; |
|
369 | + return $cat[0]; |
|
370 | + }else |
|
371 | + return null; |
|
372 | + } |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * @param $cat |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + private function get_category_name_to_display($cat) |
|
380 | + { |
|
381 | + if (isset($cat)) { |
|
382 | + if ($cat->get_parent_id() == '0' || $cat->get_parent_id() == null){ |
|
383 | + return ''; |
|
384 | + } else { |
|
385 | + return $cat->get_name(); |
|
386 | + } |
|
387 | + } else { |
|
388 | + return ''; |
|
389 | + } |
|
390 | + } |
|
391 | 391 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | - * @return array |
|
21 | + * @return string[] |
|
22 | 22 | */ |
23 | 23 | public static function get_tags() |
24 | 24 | { |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param string $course_code |
41 | 41 | * @param int $session_id |
42 | 42 | * |
43 | - * @return mixed |
|
43 | + * @return string |
|
44 | 44 | */ |
45 | 45 | public static function parse_content($userId, $content, $course_code, $session_id = 0) |
46 | 46 | { |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | * @param array uploaded file $_FILES |
350 | 350 | * @param string Comment describing the attachment |
351 | 351 | * @param bool $sendToUsersInSession |
352 | - * @return int false on failure, ID of the announcement on success |
|
352 | + * @return false|string false on failure, ID of the announcement on success |
|
353 | 353 | */ |
354 | 354 | public static function add_announcement( |
355 | 355 | $emailTitle, |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * @param $to_users |
461 | 461 | * @param array $file |
462 | 462 | * @param string $file_comment |
463 | - * @return bool|int |
|
463 | + * @return false|string |
|
464 | 464 | */ |
465 | 465 | public static function add_group_announcement( |
466 | 466 | $emailTitle, |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | |
700 | 700 | /** |
701 | 701 | * @param int $insert_id |
702 | - * @return bool |
|
702 | + * @return false|null |
|
703 | 703 | */ |
704 | 704 | public static function update_mail_sent($insert_id) |
705 | 705 | { |
@@ -719,6 +719,7 @@ discard block |
||
719 | 719 | * Gets all announcements from a user by course |
720 | 720 | * @param string course db |
721 | 721 | * @param int user id |
722 | + * @param integer $user_id |
|
722 | 723 | * @return array html with the content and count of announcements or false otherwise |
723 | 724 | */ |
724 | 725 | public static function get_all_annoucement_by_user_course($course_code, $user_id) |
@@ -1184,6 +1185,7 @@ discard block |
||
1184 | 1185 | * has been sent to |
1185 | 1186 | * @param string The tool (announcement, agenda, ...) |
1186 | 1187 | * @param int ID of the element of the corresponding type |
1188 | + * @param string $tool |
|
1187 | 1189 | * @return array Array of users and groups to whom the element has been sent |
1188 | 1190 | */ |
1189 | 1191 | public static function sent_to($tool, $id) |
@@ -1308,6 +1310,8 @@ discard block |
||
1308 | 1310 | * @param int attach id |
1309 | 1311 | * @param array uploaded file $_FILES |
1310 | 1312 | * @param string file comment |
1313 | + * @param integer $id_attach |
|
1314 | + * @param string $file_comment |
|
1311 | 1315 | * @return int |
1312 | 1316 | */ |
1313 | 1317 | public static function edit_announcement_attachment_file($id_attach, $file, $file_comment) |
@@ -1510,7 +1510,7 @@ |
||
1510 | 1510 | ip.to_user_id=$user_id OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) |
1511 | 1511 | ) "; |
1512 | 1512 | } else { |
1513 | - $cond_user_id = " AND ( |
|
1513 | + $cond_user_id = " AND ( |
|
1514 | 1514 | ip.to_user_id=$user_id OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".api_get_group_id().")) |
1515 | 1515 | )"; |
1516 | 1516 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | /** |
214 | 214 | * Displays the tools of a certain category. |
215 | 215 | * |
216 | - * @return void |
|
216 | + * @return string |
|
217 | 217 | * @param string $course_tool_category contains the category of tools to display: |
218 | 218 | * "Public", "PublicButHide", "courseAdmin", "claroAdmin" |
219 | 219 | */ |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | * @param array $all_tools_list List of tools as returned by get_tools_category() |
651 | 651 | * @param bool $rows |
652 | 652 | * |
653 | - * @return void |
|
653 | + * @return string |
|
654 | 654 | */ |
655 | 655 | public static function show_tools_category($all_tools_list, $rows = false) |
656 | 656 | { |
@@ -1194,6 +1194,7 @@ discard block |
||
1194 | 1194 | |
1195 | 1195 | /** |
1196 | 1196 | * Show a toolbar with shortcuts to the course tool |
1197 | + * @param integer $orientation |
|
1197 | 1198 | */ |
1198 | 1199 | public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL) |
1199 | 1200 | { |
@@ -351,6 +351,12 @@ |
||
351 | 351 | |
352 | 352 | /** |
353 | 353 | * Additional functions needed for fast integration |
354 | + * @param integer $status |
|
355 | + * @param string $section |
|
356 | + * @param string $title |
|
357 | + * @param string $url |
|
358 | + * @param string|null $formatter |
|
359 | + * @param string $comment |
|
354 | 360 | */ |
355 | 361 | public function build_setting($status, $section, $title, $url, $current_value, $expected_value, $formatter, $comment, $img_path = null) { |
356 | 362 | switch ($status) { |
@@ -401,19 +401,19 @@ |
||
401 | 401 | |
402 | 402 | public function format_yes_no_optional($value) |
403 | 403 | { |
404 | - $return = ''; |
|
405 | - switch($value) { |
|
406 | - case 0: |
|
407 | - $return = get_lang('No'); |
|
408 | - break; |
|
409 | - case 1: |
|
410 | - $return = get_lang('Yes'); |
|
411 | - break; |
|
412 | - case 2: |
|
413 | - $return = get_lang('Optional'); |
|
414 | - break; |
|
415 | - } |
|
416 | - return $return; |
|
404 | + $return = ''; |
|
405 | + switch($value) { |
|
406 | + case 0: |
|
407 | + $return = get_lang('No'); |
|
408 | + break; |
|
409 | + case 1: |
|
410 | + $return = get_lang('Yes'); |
|
411 | + break; |
|
412 | + case 2: |
|
413 | + $return = get_lang('Optional'); |
|
414 | + break; |
|
415 | + } |
|
416 | + return $return; |
|
417 | 417 | |
418 | 418 | } |
419 | 419 |
@@ -1255,6 +1255,7 @@ discard block |
||
1255 | 1255 | |
1256 | 1256 | /** |
1257 | 1257 | * Validates the time control key |
1258 | + * @param integer $exercise_id |
|
1258 | 1259 | */ |
1259 | 1260 | public static function exercise_time_control_is_valid( |
1260 | 1261 | $exercise_id, |
@@ -1388,7 +1389,7 @@ discard block |
||
1388 | 1389 | * @param int $in_direction |
1389 | 1390 | * @param string $in_hotpot_path |
1390 | 1391 | * @param bool $in_get_count |
1391 | - * @param null $where_condition |
|
1392 | + * @param string $where_condition |
|
1392 | 1393 | * @return array|int |
1393 | 1394 | */ |
1394 | 1395 | public static function get_exam_results_hotpotatoes_data( |
@@ -2179,7 +2180,7 @@ discard block |
||
2179 | 2180 | /** |
2180 | 2181 | * Return true if pass_pourcentage activated (we use the pass pourcentage feature |
2181 | 2182 | * return false if pass_percentage = 0 (we don't use the pass pourcentage feature |
2182 | - * @param $in_pass_pourcentage |
|
2183 | + * @param string $in_pass_pourcentage |
|
2183 | 2184 | * @return boolean |
2184 | 2185 | * In this version, pass_percentage and show_success_message are disabled if |
2185 | 2186 | * pass_percentage is set to 0 |
@@ -2192,7 +2193,7 @@ discard block |
||
2192 | 2193 | /** |
2193 | 2194 | * Converts a numeric value in a percentage example 0.66666 to 66.67 % |
2194 | 2195 | * @param $value |
2195 | - * @return float Converted number |
|
2196 | + * @return string Converted number |
|
2196 | 2197 | */ |
2197 | 2198 | public static function convert_to_percentage($value) |
2198 | 2199 | { |
@@ -2208,7 +2209,7 @@ discard block |
||
2208 | 2209 | * @param float $score |
2209 | 2210 | * @param float $weight |
2210 | 2211 | * @deprecated seem not to be used |
2211 | - * @return float the score rounded converted to the new range |
|
2212 | + * @return string|null the score rounded converted to the new range |
|
2212 | 2213 | */ |
2213 | 2214 | public static function convert_score($score, $weight) |
2214 | 2215 | { |
@@ -2759,6 +2760,7 @@ discard block |
||
2759 | 2760 | * @param int exercise id |
2760 | 2761 | * @param int $courseId |
2761 | 2762 | * @param int session id |
2763 | + * @param integer $user_count |
|
2762 | 2764 | * @return float Best average score |
2763 | 2765 | */ |
2764 | 2766 | public static function get_best_average_score_by_exercise( |
@@ -3198,8 +3200,9 @@ discard block |
||
3198 | 3200 | } |
3199 | 3201 | |
3200 | 3202 | /** |
3201 | - * @param array $answer |
|
3203 | + * @param string|null $answer |
|
3202 | 3204 | * @param string $user_answer |
3205 | + * @param string|null $current_answer |
|
3203 | 3206 | * @return array |
3204 | 3207 | */ |
3205 | 3208 | public static function check_fill_in_blanks($answer, $user_answer, $current_answer) |
@@ -3805,7 +3808,7 @@ discard block |
||
3805 | 3808 | |
3806 | 3809 | /** |
3807 | 3810 | * @param int $countLetter |
3808 | - * @return mixed |
|
3811 | + * @return string |
|
3809 | 3812 | */ |
3810 | 3813 | public static function detectInputAppropriateClass($countLetter) |
3811 | 3814 | { |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * @return array |
|
126 | + * @return string[] |
|
127 | 127 | */ |
128 | 128 | public static function getValidExtraFieldTypes() |
129 | 129 | { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | /** |
201 | 201 | * @param array $conditions |
202 | - * @param null $order_field_options_by |
|
202 | + * @param string $order_field_options_by |
|
203 | 203 | * |
204 | 204 | * @return array |
205 | 205 | */ |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | /** |
238 | 238 | * @param string $variable |
239 | 239 | * |
240 | - * @return array|bool |
|
240 | + * @return integer |
|
241 | 241 | */ |
242 | 242 | public function get_handler_field_info_by_field_variable($variable) |
243 | 243 | { |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | /** |
320 | 320 | * @param string $handler |
321 | 321 | * |
322 | - * @return array |
|
322 | + * @return string[] |
|
323 | 323 | */ |
324 | 324 | public static function get_extra_fields_by_handler($handler) |
325 | 325 | { |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
499 | - * @return array |
|
499 | + * @return string[] |
|
500 | 500 | */ |
501 | 501 | public function get_field_types() |
502 | 502 | { |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | /** |
507 | 507 | * @param int $id |
508 | 508 | * |
509 | - * @return null |
|
509 | + * @return string|null |
|
510 | 510 | */ |
511 | 511 | public function get_field_type_by_id($id) |
512 | 512 | { |
@@ -691,7 +691,6 @@ discard block |
||
691 | 691 | * @param FormValidator $form |
692 | 692 | * @param array $extraData |
693 | 693 | * @param bool $admin_permissions |
694 | - * @param int $user_id |
|
695 | 694 | * @param array $extra |
696 | 695 | * @param int $itemId |
697 | 696 | * @param array $exclude variables of extra field to exclude |
@@ -1592,7 +1591,7 @@ discard block |
||
1592 | 1591 | } |
1593 | 1592 | |
1594 | 1593 | /** |
1595 | - * @return array |
|
1594 | + * @return string[] |
|
1596 | 1595 | */ |
1597 | 1596 | public function getJqgridColumnNames() |
1598 | 1597 | { |
@@ -1832,7 +1831,7 @@ discard block |
||
1832 | 1831 | } |
1833 | 1832 | |
1834 | 1833 | /** |
1835 | - * @param array $columns |
|
1834 | + * @param string[] $columns |
|
1836 | 1835 | * @param array $column_model |
1837 | 1836 | * @param array $extraFields |
1838 | 1837 | * @return array |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | 'changeable', |
20 | 20 | 'filter', |
21 | 21 | 'extra_field_type', |
22 | - /* Enable this when field_loggeable is introduced as a table field (2.0) |
|
22 | + /* Enable this when field_loggeable is introduced as a table field (2.0) |
|
23 | 23 | 'field_loggeable', |
24 | 24 | */ |
25 | 25 | 'created_at' |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | * France:Paris;Bretagne;Marseille;Lyon|Belgique:Bruxelles;Namur;Liège;Bruges|Peru:Lima;Piura; |
557 | 557 | * into |
558 | 558 | * array( |
559 | - * 'France' => |
|
559 | + * 'France' => |
|
560 | 560 | * array('Paris', 'Bregtane', 'Marseille'), |
561 | 561 | * 'Belgique' => |
562 | 562 | * array('Namur', 'Liège') |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | foreach ($orderFields as $order) { |
762 | 762 | foreach ($extra as $field_details) { |
763 | 763 | if ($order == $field_details['variable']) { |
764 | - $newOrder[] = $field_details; |
|
764 | + $newOrder[] = $field_details; |
|
765 | 765 | } |
766 | 766 | } |
767 | 767 | } |