@@ -173,7 +173,7 @@ |
||
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | 175 | * @param array $file |
| 176 | - * @return bool|string |
|
| 176 | + * @return string|false |
|
| 177 | 177 | */ |
| 178 | 178 | public static function import_uploaded_file($file) |
| 179 | 179 | { |
@@ -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,260 +9,260 @@ |
||
| 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 | - $url = api_get_path(WEB_PATH).'main/newscorm/lp_controller.php?cidReq='.$this->get_course_code().'&gradebook=view'; |
|
| 176 | - $session_id = api_get_session_id(); |
|
| 177 | - if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) { |
|
| 178 | - $url .= '&action=view&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
| 179 | - } else { |
|
| 180 | - $url .= '&action=build&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
| 181 | - } |
|
| 182 | - return $url; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Get name to display: same as learnpath title |
|
| 187 | - */ |
|
| 188 | - public function get_name() |
|
| 189 | - { |
|
| 190 | - $data = $this->get_learnpath_data(); |
|
| 191 | - return $data['name']; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Get description to display: same as learnpath description |
|
| 196 | - */ |
|
| 197 | - public function get_description() |
|
| 198 | - { |
|
| 199 | - $data = $this->get_learnpath_data(); |
|
| 200 | - return $data['description']; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Check if this still links to a learnpath |
|
| 205 | - */ |
|
| 206 | - public function is_valid_link() { |
|
| 207 | - $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 | + $url = api_get_path(WEB_PATH).'main/newscorm/lp_controller.php?cidReq='.$this->get_course_code().'&gradebook=view'; |
|
| 176 | + $session_id = api_get_session_id(); |
|
| 177 | + if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) { |
|
| 178 | + $url .= '&action=view&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
| 179 | + } else { |
|
| 180 | + $url .= '&action=build&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
| 181 | + } |
|
| 182 | + return $url; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Get name to display: same as learnpath title |
|
| 187 | + */ |
|
| 188 | + public function get_name() |
|
| 189 | + { |
|
| 190 | + $data = $this->get_learnpath_data(); |
|
| 191 | + return $data['name']; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Get description to display: same as learnpath description |
|
| 196 | + */ |
|
| 197 | + public function get_description() |
|
| 198 | + { |
|
| 199 | + $data = $this->get_learnpath_data(); |
|
| 200 | + return $data['description']; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Check if this still links to a learnpath |
|
| 205 | + */ |
|
| 206 | + public function is_valid_link() { |
|
| 207 | + $sql = 'SELECT count(id) FROM '.$this->get_learnpath_table().' |
|
| 208 | 208 | WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; |
| 209 | - $result = Database::query($sql); |
|
| 210 | - $number = Database::fetch_row($result,'NUM'); |
|
| 211 | - return ($number[0] != 0); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - public function get_type_name() |
|
| 215 | - { |
|
| 216 | - return get_lang('LearningPaths'); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - public function needs_name_and_description() |
|
| 220 | - { |
|
| 221 | - return false; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - public function needs_max() |
|
| 225 | - { |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - public function needs_results() |
|
| 230 | - { |
|
| 231 | - return false; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - public function is_allowed_to_change_name() |
|
| 235 | - { |
|
| 236 | - return false; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - // INTERNAL FUNCTIONS |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Lazy load function to get the database table of the learnpath |
|
| 243 | - */ |
|
| 244 | - private function get_learnpath_table() |
|
| 245 | - { |
|
| 246 | - $this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN); |
|
| 247 | - return $this->learnpath_table; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Lazy load function to get the database contents of this learnpath |
|
| 252 | - */ |
|
| 253 | - private function get_learnpath_data() |
|
| 254 | - { |
|
| 255 | - if (!isset($this->learnpath_data)) { |
|
| 256 | - $sql = 'SELECT * FROM '.$this->get_learnpath_table().' |
|
| 209 | + $result = Database::query($sql); |
|
| 210 | + $number = Database::fetch_row($result,'NUM'); |
|
| 211 | + return ($number[0] != 0); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + public function get_type_name() |
|
| 215 | + { |
|
| 216 | + return get_lang('LearningPaths'); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + public function needs_name_and_description() |
|
| 220 | + { |
|
| 221 | + return false; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + public function needs_max() |
|
| 225 | + { |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + public function needs_results() |
|
| 230 | + { |
|
| 231 | + return false; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + public function is_allowed_to_change_name() |
|
| 235 | + { |
|
| 236 | + return false; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + // INTERNAL FUNCTIONS |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Lazy load function to get the database table of the learnpath |
|
| 243 | + */ |
|
| 244 | + private function get_learnpath_table() |
|
| 245 | + { |
|
| 246 | + $this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN); |
|
| 247 | + return $this->learnpath_table; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Lazy load function to get the database contents of this learnpath |
|
| 252 | + */ |
|
| 253 | + private function get_learnpath_data() |
|
| 254 | + { |
|
| 255 | + if (!isset($this->learnpath_data)) { |
|
| 256 | + $sql = 'SELECT * FROM '.$this->get_learnpath_table().' |
|
| 257 | 257 | WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; |
| 258 | - $result = Database::query($sql); |
|
| 259 | - $this->learnpath_data = Database::fetch_array($result); |
|
| 260 | - } |
|
| 261 | - return $this->learnpath_data; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - public function get_icon_name() |
|
| 265 | - { |
|
| 266 | - return 'learnpath'; |
|
| 267 | - } |
|
| 258 | + $result = Database::query($sql); |
|
| 259 | + $this->learnpath_data = Database::fetch_array($result); |
|
| 260 | + } |
|
| 261 | + return $this->learnpath_data; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + public function get_icon_name() |
|
| 265 | + { |
|
| 266 | + return 'learnpath'; |
|
| 267 | + } |
|
| 268 | 268 | } |
@@ -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 UserDataGenerator($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 UserDataGenerator($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 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | - * @return array |
|
| 35 | + * @return string[] |
|
| 36 | 36 | */ |
| 37 | 37 | public static function toolList() |
| 38 | 38 | { |
@@ -290,7 +290,6 @@ discard block |
||
| 290 | 290 | * 'page_nr' = The page to display |
| 291 | 291 | * 'hide_navigation' = true to hide the navigation |
| 292 | 292 | * @param array $query_vars Additional variables to add in the query-string |
| 293 | - * @param array $form actions Additional variables to add in the query-string |
|
| 294 | 293 | * @param mixed An array with bool values to know which columns show. |
| 295 | 294 | * i.e: $visibility_options= array(true, false) we will only show the first column |
| 296 | 295 | * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing |
@@ -331,7 +330,6 @@ discard block |
||
| 331 | 330 | * 'page_nr' = The page to display |
| 332 | 331 | * 'hide_navigation' = true to hide the navigation |
| 333 | 332 | * @param array $query_vars Additional variables to add in the query-string |
| 334 | - * @param array $form actions Additional variables to add in the query-string |
|
| 335 | 333 | * @param mixed An array with bool values to know which columns show. i.e: |
| 336 | 334 | * $visibility_options= array(true, false) we will only show the first column |
| 337 | 335 | * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing |
@@ -388,10 +386,11 @@ discard block |
||
| 388 | 386 | * 'per_page' = number of items to show per page |
| 389 | 387 | * 'page_nr' = The page to display |
| 390 | 388 | * @param array $query_vars Additional variables to add in the query-string |
| 391 | - * @param array $column_show Array of binaries 1= show columns 0. hide a column |
|
| 389 | + * @param integer[] $column_show Array of binaries 1= show columns 0. hide a column |
|
| 392 | 390 | * @param array $column_order An array of integers that let us decide how the columns are going to be sort. |
| 393 | 391 | * i.e: $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column |
| 394 | 392 | * @param array $form_actions Set optional forms actions |
| 393 | + * @param string $table_name |
|
| 395 | 394 | * |
| 396 | 395 | * @author Julio Montoya |
| 397 | 396 | */ |
@@ -444,7 +443,7 @@ discard block |
||
| 444 | 443 | * @param bool $filter (true) or not (false) |
| 445 | 444 | * @param bool $returnValue |
| 446 | 445 | * |
| 447 | - * @return void |
|
| 446 | + * @return string|null |
|
| 448 | 447 | */ |
| 449 | 448 | public static function display_normal_message($message, $filter = true, $returnValue = false) |
| 450 | 449 | { |
@@ -474,7 +473,7 @@ discard block |
||
| 474 | 473 | /** |
| 475 | 474 | * Displays an confirmation message. Use this if something has been done successfully |
| 476 | 475 | * @param bool Filter (true) or not (false) |
| 477 | - * @return void |
|
| 476 | + * @return string|null |
|
| 478 | 477 | */ |
| 479 | 478 | public static function display_confirmation_message ($message, $filter = true, $returnValue = false) |
| 480 | 479 | { |
@@ -491,7 +490,7 @@ discard block |
||
| 491 | 490 | * @param string $message - include any additional html |
| 492 | 491 | * tags if you need them |
| 493 | 492 | * @param bool Filter (true) or not (false) |
| 494 | - * @return void |
|
| 493 | + * @return string|null |
|
| 495 | 494 | */ |
| 496 | 495 | public static function display_error_message ($message, $filter = true, $returnValue = false) |
| 497 | 496 | { |
@@ -681,6 +680,7 @@ discard block |
||
| 681 | 680 | * @param string The alt text (probably a language variable) |
| 682 | 681 | * @param array additional attributes (for instance height, width, onclick, ...) |
| 683 | 682 | * @param integer The wanted width of the icon (to be looked for in the corresponding img/icons/ folder) |
| 683 | + * @param string $image |
|
| 684 | 684 | * @return void |
| 685 | 685 | */ |
| 686 | 686 | public static function display_icon( |
@@ -881,6 +881,7 @@ discard block |
||
| 881 | 881 | /** |
| 882 | 882 | * Displays an HTML input tag |
| 883 | 883 | * |
| 884 | + * @param string $type |
|
| 884 | 885 | */ |
| 885 | 886 | public static function input($type, $name, $value, $attributes = array()) |
| 886 | 887 | { |
@@ -897,8 +898,8 @@ discard block |
||
| 897 | 898 | } |
| 898 | 899 | |
| 899 | 900 | /** |
| 900 | - * @param $name |
|
| 901 | - * @param $value |
|
| 901 | + * @param string $name |
|
| 902 | + * @param string $value |
|
| 902 | 903 | * @param array $attributes |
| 903 | 904 | * @return string |
| 904 | 905 | */ |
@@ -913,6 +914,7 @@ discard block |
||
| 913 | 914 | /** |
| 914 | 915 | * Displays an HTML select tag |
| 915 | 916 | * |
| 917 | + * @param string $blank_item_text |
|
| 916 | 918 | */ |
| 917 | 919 | public static function select( |
| 918 | 920 | $name, |
@@ -983,6 +985,8 @@ discard block |
||
| 983 | 985 | * @param array content that will be showed |
| 984 | 986 | * @param string the id of the container of the tab in the example "tabs" |
| 985 | 987 | * @param array attributes for the ul |
| 988 | + * @param string[] $header_list |
|
| 989 | + * @param string[] $content_list |
|
| 986 | 990 | * |
| 987 | 991 | */ |
| 988 | 992 | public static function tabs($header_list, $content_list, $id = 'tabs', $attributes = array(), $ul_attributes = array()) |
@@ -1029,7 +1033,7 @@ discard block |
||
| 1029 | 1033 | |
| 1030 | 1034 | /** |
| 1031 | 1035 | * @param $headers |
| 1032 | - * @param null $selected |
|
| 1036 | + * @param integer $selected |
|
| 1033 | 1037 | * |
| 1034 | 1038 | * @return string |
| 1035 | 1039 | */ |
@@ -1067,6 +1071,7 @@ discard block |
||
| 1067 | 1071 | * As you can see both function use the same "my_grid_name" this is very important otherwise nothing will work |
| 1068 | 1072 | * |
| 1069 | 1073 | * @param string the div id, this value must be the same with the first parameter of Display::grid_js() |
| 1074 | + * @param string $div_id |
|
| 1070 | 1075 | * @return string html |
| 1071 | 1076 | * |
| 1072 | 1077 | */ |
@@ -1622,6 +1627,8 @@ discard block |
||
| 1622 | 1627 | * @param string url that will be added (for jquery see hot_courses.tpl) |
| 1623 | 1628 | * @param string point info array see function CourseManager::get_course_ranking() |
| 1624 | 1629 | * @param bool add a div wrapper |
| 1630 | + * @param string $id |
|
| 1631 | + * @param string $url |
|
| 1625 | 1632 | * @todo use templates |
| 1626 | 1633 | **/ |
| 1627 | 1634 | public static function return_rating_system($id, $url, $point_info = array(), $add_div_wrapper = true) |
@@ -1717,6 +1724,9 @@ discard block |
||
| 1717 | 1724 | return '<'.$size.'>'.Security::remove_XSS($title).'</'.$size.'>'; |
| 1718 | 1725 | } |
| 1719 | 1726 | |
| 1727 | + /** |
|
| 1728 | + * @param string $title |
|
| 1729 | + */ |
|
| 1720 | 1730 | public static function page_subheader2($title, $second_title = null) |
| 1721 | 1731 | { |
| 1722 | 1732 | return self::page_header($title, $second_title, 'h4'); |
@@ -1947,6 +1957,7 @@ discard block |
||
| 1947 | 1957 | |
| 1948 | 1958 | /** |
| 1949 | 1959 | * @todo use twig |
| 1960 | + * @param string $title |
|
| 1950 | 1961 | */ |
| 1951 | 1962 | public static function group_button($title, $elements) |
| 1952 | 1963 | { |
@@ -2164,9 +2175,9 @@ discard block |
||
| 2164 | 2175 | |
| 2165 | 2176 | /** |
| 2166 | 2177 | * @param int $id |
| 2167 | - * @param array $content |
|
| 2178 | + * @param string[] $content |
|
| 2168 | 2179 | * @param int $col |
| 2169 | - * @param bool|true $right |
|
| 2180 | + * @param boolean $right |
|
| 2170 | 2181 | * @return string |
| 2171 | 2182 | */ |
| 2172 | 2183 | public static function toolbarAction($id, $content = array(), $col = 2, $right = true) |
@@ -2248,10 +2259,10 @@ discard block |
||
| 2248 | 2259 | /** |
| 2249 | 2260 | * @param string $title |
| 2250 | 2261 | * @param string $content |
| 2251 | - * @param null $id |
|
| 2262 | + * @param string $id |
|
| 2252 | 2263 | * @param array $params |
| 2253 | - * @param null $idAccordion |
|
| 2254 | - * @param null $idCollapse |
|
| 2264 | + * @param string $idAccordion |
|
| 2265 | + * @param string $idCollapse |
|
| 2255 | 2266 | * @param bool|true $open |
| 2256 | 2267 | * @param bool|false $fullClickable |
| 2257 | 2268 | * @return null|string |
@@ -49,12 +49,12 @@ discard block |
||
| 49 | 49 | ); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Displays the page header |
|
| 54 | - * @param string The name of the page (will be showed in the page title) |
|
| 55 | - * @param string Optional help file name |
|
| 56 | - * @param string $page_header |
|
| 57 | - */ |
|
| 52 | + /** |
|
| 53 | + * Displays the page header |
|
| 54 | + * @param string The name of the page (will be showed in the page title) |
|
| 55 | + * @param string Optional help file name |
|
| 56 | + * @param string $page_header |
|
| 57 | + */ |
|
| 58 | 58 | public static function display_header($tool_name ='', $help = null, $page_header = null) |
| 59 | 59 | { |
| 60 | 60 | $origin = api_get_origin(); |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | */ |
| 449 | 449 | public static function display_normal_message($message, $filter = true, $returnValue = false) |
| 450 | 450 | { |
| 451 | - $message = self::return_message($message, 'normal', $filter); |
|
| 451 | + $message = self::return_message($message, 'normal', $filter); |
|
| 452 | 452 | if ($returnValue) { |
| 453 | 453 | return $message; |
| 454 | 454 | } else { |
@@ -524,22 +524,22 @@ discard block |
||
| 524 | 524 | public static function return_message($message, $type = 'normal', $filter = true) |
| 525 | 525 | { |
| 526 | 526 | if ($filter) { |
| 527 | - $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding()); |
|
| 527 | + $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding()); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | $class = ""; |
| 531 | 531 | switch($type) { |
| 532 | 532 | case 'warning': |
| 533 | 533 | $class .= 'alert alert-warning'; |
| 534 | - break; |
|
| 534 | + break; |
|
| 535 | 535 | case 'error': |
| 536 | 536 | $class .= 'alert alert-danger'; |
| 537 | - break; |
|
| 537 | + break; |
|
| 538 | 538 | case 'confirmation': |
| 539 | 539 | case 'confirm': |
| 540 | 540 | case 'success': |
| 541 | 541 | $class .= 'alert alert-success'; |
| 542 | - break; |
|
| 542 | + break; |
|
| 543 | 543 | case 'normal': |
| 544 | 544 | default: |
| 545 | 545 | $class .= 'alert alert-info'; |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | * @param array additional attributes (for instance height, width, onclick, ...) |
| 683 | 683 | * @param integer The wanted width of the icon (to be looked for in the corresponding img/icons/ folder) |
| 684 | 684 | * @return void |
| 685 | - */ |
|
| 685 | + */ |
|
| 686 | 686 | public static function display_icon( |
| 687 | 687 | $image, |
| 688 | 688 | $alt_text = '', |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | * @author Julio Montoya 2010 Function improved, adding image constants |
| 706 | 706 | * @author Yannick Warnier 2011 Added size handler |
| 707 | 707 | * @version Feb 2011 |
| 708 | - */ |
|
| 708 | + */ |
|
| 709 | 709 | public static function return_icon( |
| 710 | 710 | $image, |
| 711 | 711 | $alt_text = '', |
@@ -884,14 +884,14 @@ discard block |
||
| 884 | 884 | */ |
| 885 | 885 | public static function input($type, $name, $value, $attributes = array()) |
| 886 | 886 | { |
| 887 | - if (isset($type)) { |
|
| 888 | - $attributes['type']= $type; |
|
| 889 | - } |
|
| 890 | - if (isset($name)) { |
|
| 891 | - $attributes['name']= $name; |
|
| 892 | - } |
|
| 893 | - if (isset($value)) { |
|
| 894 | - $attributes['value']= $value; |
|
| 887 | + if (isset($type)) { |
|
| 888 | + $attributes['type']= $type; |
|
| 889 | + } |
|
| 890 | + if (isset($name)) { |
|
| 891 | + $attributes['name']= $name; |
|
| 892 | + } |
|
| 893 | + if (isset($value)) { |
|
| 894 | + $attributes['value']= $value; |
|
| 895 | 895 | } |
| 896 | 896 | return self::tag('input', '', $attributes); |
| 897 | 897 | } |
@@ -904,10 +904,10 @@ discard block |
||
| 904 | 904 | */ |
| 905 | 905 | public static function button($name, $value, $attributes = array()) |
| 906 | 906 | { |
| 907 | - if (!empty($name)) { |
|
| 907 | + if (!empty($name)) { |
|
| 908 | 908 | $attributes['name'] = $name; |
| 909 | - } |
|
| 910 | - return self::tag('button', $value, $attributes); |
|
| 909 | + } |
|
| 910 | + return self::tag('button', $value, $attributes); |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | * in the $htmlHeadXtra variable before the display_header |
| 975 | 975 | * Add this script |
| 976 | 976 | * @example |
| 977 | - * <script> |
|
| 977 | + * <script> |
|
| 978 | 978 | $(function() { |
| 979 | 979 | $( "#tabs" ).tabs(); |
| 980 | 980 | }); |
@@ -1035,20 +1035,20 @@ discard block |
||
| 1035 | 1035 | */ |
| 1036 | 1036 | public static function tabsOnlyLink($headers, $selected = null) |
| 1037 | 1037 | { |
| 1038 | - $id = uniqid(); |
|
| 1039 | - $i = 1; |
|
| 1040 | - $lis = null; |
|
| 1041 | - foreach ($headers as $item) { |
|
| 1038 | + $id = uniqid(); |
|
| 1039 | + $i = 1; |
|
| 1040 | + $lis = null; |
|
| 1041 | + foreach ($headers as $item) { |
|
| 1042 | 1042 | $class = null; |
| 1043 | 1043 | if ($i == $selected) { |
| 1044 | 1044 | $class = 'active'; |
| 1045 | 1045 | } |
| 1046 | - $item = self::tag( |
|
| 1047 | - 'a', |
|
| 1048 | - $item['content'], |
|
| 1049 | - array('id' => $id.'-'.$i, 'href' => $item['url']) |
|
| 1050 | - ); |
|
| 1051 | - $lis .= self::tag('li', $item, array('class' => $class)); |
|
| 1046 | + $item = self::tag( |
|
| 1047 | + 'a', |
|
| 1048 | + $item['content'], |
|
| 1049 | + array('id' => $id.'-'.$i, 'href' => $item['url']) |
|
| 1050 | + ); |
|
| 1051 | + $lis .= self::tag('li', $item, array('class' => $class)); |
|
| 1052 | 1052 | $i++; |
| 1053 | 1053 | } |
| 1054 | 1054 | return self::tag('ul', $lis, array('class' => 'nav nav-tabs tabs-margin')); |
@@ -1260,8 +1260,8 @@ discard block |
||
| 1260 | 1260 | */ |
| 1261 | 1261 | public static function table($headers, $rows, $attributes = array()) |
| 1262 | 1262 | { |
| 1263 | - if (empty($attributes)) { |
|
| 1264 | - $attributes['class'] = 'data_table'; |
|
| 1263 | + if (empty($attributes)) { |
|
| 1264 | + $attributes['class'] = 'data_table'; |
|
| 1265 | 1265 | } |
| 1266 | 1266 | $table = new HTML_Table($attributes); |
| 1267 | 1267 | $row = 0; |
@@ -1269,17 +1269,17 @@ discard block |
||
| 1269 | 1269 | |
| 1270 | 1270 | // Course headers |
| 1271 | 1271 | if (!empty($headers)) { |
| 1272 | - foreach ($headers as $item) { |
|
| 1273 | - $table->setHeaderContents($row, $column, $item); |
|
| 1274 | - $column++; |
|
| 1275 | - } |
|
| 1276 | - $row = 1; |
|
| 1277 | - $column = 0; |
|
| 1272 | + foreach ($headers as $item) { |
|
| 1273 | + $table->setHeaderContents($row, $column, $item); |
|
| 1274 | + $column++; |
|
| 1275 | + } |
|
| 1276 | + $row = 1; |
|
| 1277 | + $column = 0; |
|
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | if (!empty($rows)) { |
| 1281 | - foreach($rows as $content) { |
|
| 1282 | - $table->setCellContents($row, $column, $content); |
|
| 1281 | + foreach($rows as $content) { |
|
| 1282 | + $table->setCellContents($row, $column, $content); |
|
| 1283 | 1283 | $row++; |
| 1284 | 1284 | } |
| 1285 | 1285 | } |
@@ -1385,7 +1385,7 @@ discard block |
||
| 1385 | 1385 | //$item_property['tool'] != TOOL_DROPBOX && |
| 1386 | 1386 | $item_property['tool'] != TOOL_NOTEBOOK && |
| 1387 | 1387 | $item_property['tool'] != TOOL_CHAT) |
| 1388 | - ) |
|
| 1388 | + ) |
|
| 1389 | 1389 | ) |
| 1390 | 1390 | // Take only what's visible or "invisible but where the user is a teacher" or where the visibility is unset. |
| 1391 | 1391 | && ($item_property['visibility'] == '1' |
@@ -1401,7 +1401,7 @@ discard block |
||
| 1401 | 1401 | ($item_property['to_user_id'] != $user_id) && |
| 1402 | 1402 | (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'], $group_ids))) |
| 1403 | 1403 | ) { |
| 1404 | - continue; |
|
| 1404 | + continue; |
|
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | 1407 | // If it's a survey, make sure the user's invited. Otherwise drop it. |
@@ -1620,21 +1620,21 @@ discard block |
||
| 1620 | 1620 | * |
| 1621 | 1621 | * @param string id of the rating ul element |
| 1622 | 1622 | * @param string url that will be added (for jquery see hot_courses.tpl) |
| 1623 | - * @param string point info array see function CourseManager::get_course_ranking() |
|
| 1624 | - * @param bool add a div wrapper |
|
| 1625 | - * @todo use templates |
|
| 1623 | + * @param string point info array see function CourseManager::get_course_ranking() |
|
| 1624 | + * @param bool add a div wrapper |
|
| 1625 | + * @todo use templates |
|
| 1626 | 1626 | **/ |
| 1627 | 1627 | public static function return_rating_system($id, $url, $point_info = array(), $add_div_wrapper = true) |
| 1628 | 1628 | { |
| 1629 | - $number_of_users_who_voted = isset($point_info['users_who_voted']) ? $point_info['users_who_voted'] : null; |
|
| 1630 | - $percentage = isset($point_info['point_average']) ? $point_info['point_average'] : 0; |
|
| 1629 | + $number_of_users_who_voted = isset($point_info['users_who_voted']) ? $point_info['users_who_voted'] : null; |
|
| 1630 | + $percentage = isset($point_info['point_average']) ? $point_info['point_average'] : 0; |
|
| 1631 | 1631 | |
| 1632 | - if (!empty($percentage)) { |
|
| 1632 | + if (!empty($percentage)) { |
|
| 1633 | 1633 | $percentage = $percentage*125/100; |
| 1634 | 1634 | } |
| 1635 | - $accesses = isset($point_info['accesses']) ? $point_info['accesses'] : 0; |
|
| 1635 | + $accesses = isset($point_info['accesses']) ? $point_info['accesses'] : 0; |
|
| 1636 | 1636 | |
| 1637 | - $star_label = sprintf(get_lang('XStarsOutOf5'), $point_info['point_average_star']); |
|
| 1637 | + $star_label = sprintf(get_lang('XStarsOutOf5'), $point_info['point_average_star']); |
|
| 1638 | 1638 | |
| 1639 | 1639 | $html = '<ul id="'.$id.'" class="star-rating"> |
| 1640 | 1640 | <li class="current-rating" style="width:'.$percentage.'px;"></li> |
@@ -1645,26 +1645,26 @@ discard block |
||
| 1645 | 1645 | <li><a href="javascript:void(0);" data-link="'.$url.'&star=5" title="'.$star_label.'" class="five-stars">5</a></li> |
| 1646 | 1646 | </ul>'; |
| 1647 | 1647 | |
| 1648 | - $labels = array(); |
|
| 1648 | + $labels = array(); |
|
| 1649 | 1649 | |
| 1650 | - $labels[]= $number_of_users_who_voted == 1 ? $number_of_users_who_voted.' '.get_lang('Vote') : $number_of_users_who_voted.' '.get_lang('Votes'); |
|
| 1651 | - $labels[]= $accesses == 1 ? $accesses.' '.get_lang('Visit') : $accesses.' '.get_lang('Visits'); |
|
| 1652 | - if (!empty($number_of_users_who_voted)) { |
|
| 1653 | - $labels[]= get_lang('Average').' '.$point_info['point_average_star'].'/5'; |
|
| 1654 | - } |
|
| 1650 | + $labels[]= $number_of_users_who_voted == 1 ? $number_of_users_who_voted.' '.get_lang('Vote') : $number_of_users_who_voted.' '.get_lang('Votes'); |
|
| 1651 | + $labels[]= $accesses == 1 ? $accesses.' '.get_lang('Visit') : $accesses.' '.get_lang('Visits'); |
|
| 1652 | + if (!empty($number_of_users_who_voted)) { |
|
| 1653 | + $labels[]= get_lang('Average').' '.$point_info['point_average_star'].'/5'; |
|
| 1654 | + } |
|
| 1655 | 1655 | |
| 1656 | - $labels[]= $point_info['user_vote'] ? get_lang('YourVote').' ['.$point_info['user_vote'].']' : get_lang('YourVote'). ' [?] '; |
|
| 1656 | + $labels[]= $point_info['user_vote'] ? get_lang('YourVote').' ['.$point_info['user_vote'].']' : get_lang('YourVote'). ' [?] '; |
|
| 1657 | 1657 | |
| 1658 | - if (!$add_div_wrapper && api_is_anonymous()) { |
|
| 1659 | - $labels[]= Display::tag('span', get_lang('LoginToVote'), array('class' => 'error')); |
|
| 1660 | - } |
|
| 1658 | + if (!$add_div_wrapper && api_is_anonymous()) { |
|
| 1659 | + $labels[]= Display::tag('span', get_lang('LoginToVote'), array('class' => 'error')); |
|
| 1660 | + } |
|
| 1661 | 1661 | |
| 1662 | 1662 | $html .= Display::div(implode(' | ', $labels) , array('id' => 'vote_label_'.$id, 'class' => 'vote_label_info')); |
| 1663 | 1663 | $html .= ' '.Display::span(' ', array('id' => 'vote_label2_'.$id)); |
| 1664 | 1664 | |
| 1665 | 1665 | if ($add_div_wrapper) { |
| 1666 | - $html = Display::div($html, array('id' => 'rating_wrapper_'.$id)); |
|
| 1667 | - } |
|
| 1666 | + $html = Display::div($html, array('id' => 'rating_wrapper_'.$id)); |
|
| 1667 | + } |
|
| 1668 | 1668 | |
| 1669 | 1669 | return $html; |
| 1670 | 1670 | } |
@@ -1702,8 +1702,8 @@ discard block |
||
| 1702 | 1702 | return self::page_header($title, $second_title); |
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | - public static function page_subheader_and_translate($title, $second_title = null) |
|
| 1706 | - { |
|
| 1705 | + public static function page_subheader_and_translate($title, $second_title = null) |
|
| 1706 | + { |
|
| 1707 | 1707 | $title = get_lang($title); |
| 1708 | 1708 | return self::page_subheader($title, $second_title); |
| 1709 | 1709 | } |