@@ -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_CODE_PATH) . 'lp/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_CODE_PATH) . 'lp/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 | } |
@@ -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 | { |
@@ -9,7 +9,6 @@ |
||
| 9 | 9 | { |
| 10 | 10 | /** |
| 11 | 11 | * @param $value array Uploaded file info (from $_FILES) |
| 12 | - * @param null $options |
|
| 13 | 12 | * @return bool |
| 14 | 13 | */ |
| 15 | 14 | public function validate($elementValue, $maxSize) |
@@ -7,22 +7,22 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class HTML_QuickForm_Rule_MaxFileSize extends HTML_QuickForm_Rule |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @param $value array Uploaded file info (from $_FILES) |
|
| 12 | - * @param null $options |
|
| 13 | - * @return bool |
|
| 14 | - */ |
|
| 15 | - public function validate($elementValue, $maxSize) |
|
| 16 | - { |
|
| 17 | - if (!empty($elementValue['error']) && |
|
| 18 | - (UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error']) |
|
| 19 | - ) { |
|
| 20 | - return false; |
|
| 21 | - } |
|
| 22 | - if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { |
|
| 23 | - return true; |
|
| 24 | - } |
|
| 10 | + /** |
|
| 11 | + * @param $value array Uploaded file info (from $_FILES) |
|
| 12 | + * @param null $options |
|
| 13 | + * @return bool |
|
| 14 | + */ |
|
| 15 | + public function validate($elementValue, $maxSize) |
|
| 16 | + { |
|
| 17 | + if (!empty($elementValue['error']) && |
|
| 18 | + (UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error']) |
|
| 19 | + ) { |
|
| 20 | + return false; |
|
| 21 | + } |
|
| 22 | + if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { |
|
| 23 | + return true; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - return ($maxSize >= @filesize($elementValue['tmp_name'])); |
|
| 27 | - } |
|
| 26 | + return ($maxSize >= @filesize($elementValue['tmp_name'])); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | * |
| 17 | 17 | * @param string Mobile phone number to be validated |
| 18 | 18 | * @param string Not using it. Just to respect the declaration |
| 19 | - * @return boolean Returns true if valid, false otherwise. |
|
| 19 | + * @return integer Returns true if valid, false otherwise. |
|
| 20 | 20 | */ |
| 21 | 21 | function validate($mobilePhoneNumber, $options = null) |
| 22 | 22 | { |
@@ -456,6 +456,10 @@ discard block |
||
| 456 | 456 | |
| 457 | 457 | |
| 458 | 458 | // Add warning(s) to $this->warnings[] |
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * @param string $message |
|
| 462 | + */ |
|
| 459 | 463 | public function warning($message) { |
| 460 | 464 | |
| 461 | 465 | if (is_array($message)) { |
@@ -482,6 +486,11 @@ discard block |
||
| 482 | 486 | |
| 483 | 487 | |
| 484 | 488 | // Convert string between charsets -- iconv() wrapper |
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * @param string $out_charset |
|
| 492 | + * @param string $string |
|
| 493 | + */ |
|
| 485 | 494 | public function iconv($in_charset, $out_charset, $string, $drop01 = false) { |
| 486 | 495 | |
| 487 | 496 | if ($drop01 && ($string === "\x00" || $string === "\x01")) { |
@@ -509,6 +518,9 @@ discard block |
||
| 509 | 518 | |
| 510 | 519 | |
| 511 | 520 | |
| 521 | + /** |
|
| 522 | + * @param string $name |
|
| 523 | + */ |
|
| 512 | 524 | public function include_module($name) { |
| 513 | 525 | |
| 514 | 526 | if (!file_exists($this->include_path.'module.'.$name.'.php')) { |
@@ -1342,6 +1354,10 @@ discard block |
||
| 1342 | 1354 | |
| 1343 | 1355 | |
| 1344 | 1356 | // Convert Big Endian byte string to int - max 32 bits |
| 1357 | + |
|
| 1358 | + /** |
|
| 1359 | + * @param string $byte_word |
|
| 1360 | + */ |
|
| 1345 | 1361 | public static function BigEndian2Int($byte_word, $signed = false) { |
| 1346 | 1362 | |
| 1347 | 1363 | $int_value = 0; |
@@ -1391,6 +1407,9 @@ discard block |
||
| 1391 | 1407 | |
| 1392 | 1408 | |
| 1393 | 1409 | |
| 1410 | + /** |
|
| 1411 | + * @param string $byte_word |
|
| 1412 | + */ |
|
| 1394 | 1413 | public static function BigEndian2Float($byte_word) { |
| 1395 | 1414 | |
| 1396 | 1415 | // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic |
@@ -1478,6 +1497,9 @@ discard block |
||
| 1478 | 1497 | |
| 1479 | 1498 | |
| 1480 | 1499 | |
| 1500 | + /** |
|
| 1501 | + * @param string $binary_numerator |
|
| 1502 | + */ |
|
| 1481 | 1503 | public static function DecimalBinary2Float($binary_numerator) { |
| 1482 | 1504 | $numerator = bindec($binary_numerator); |
| 1483 | 1505 | $denominator = bindec('1'.str_repeat('0', strlen($binary_numerator))); |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | $class = new $class_name($this); |
| 301 | 301 | |
| 302 | 302 | try { |
| 303 | - $this->option_analyze and $class->Analyze(); |
|
| 303 | + $this->option_analyze and $class->Analyze(); |
|
| 304 | 304 | } |
| 305 | 305 | catch (getid3_exception $e) { |
| 306 | 306 | throw $e; |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | // CalculateReplayGain() { |
| 384 | 384 | if (@$this->info['replay_gain']) { |
| 385 | 385 | if (!@$this->info['replay_gain']['reference_volume']) { |
| 386 | - $this->info['replay_gain']['reference_volume'] = 89; |
|
| 386 | + $this->info['replay_gain']['reference_volume'] = 89; |
|
| 387 | 387 | } |
| 388 | 388 | if (isset($this->info['replay_gain']['track']['adjustment'])) { |
| 389 | 389 | $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment']; |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | |
| 404 | 404 | // ProcessAudioStreams() { |
| 405 | 405 | if (@!$this->info['audio']['streams'] && (@$this->info['audio']['bitrate'] || @$this->info['audio']['channels'] || @$this->info['audio']['sample_rate'])) { |
| 406 | - foreach ($this->info['audio'] as $key => $value) { |
|
| 406 | + foreach ($this->info['audio'] as $key => $value) { |
|
| 407 | 407 | if ($key != 'streams') { |
| 408 | 408 | $this->info['audio']['streams'][0][$key] = $value; |
| 409 | 409 | } |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | 'group' => 'audio', |
| 545 | 545 | 'module' => 'ac3', |
| 546 | 546 | 'mime_type' => 'audio/ac3', |
| 547 | - ), |
|
| 547 | + ), |
|
| 548 | 548 | |
| 549 | 549 | // AAC - audio - Advanced Audio Coding (AAC) - ADIF format |
| 550 | 550 | 'adif' => array ( |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | 'module' => 'aac_adif', |
| 554 | 554 | 'mime_type' => 'application/octet-stream', |
| 555 | 555 | 'fail_ape' => 'WARNING', |
| 556 | - ), |
|
| 556 | + ), |
|
| 557 | 557 | |
| 558 | 558 | |
| 559 | 559 | // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3) |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | 'module' => 'aac_adts', |
| 564 | 564 | 'mime_type' => 'application/octet-stream', |
| 565 | 565 | 'fail_ape' => 'WARNING', |
| 566 | - ), |
|
| 566 | + ), |
|
| 567 | 567 | |
| 568 | 568 | |
| 569 | 569 | // AU - audio - NeXT/Sun AUdio (AU) |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | 'group' => 'audio', |
| 573 | 573 | 'module' => 'au', |
| 574 | 574 | 'mime_type' => 'audio/basic', |
| 575 | - ), |
|
| 575 | + ), |
|
| 576 | 576 | |
| 577 | 577 | // AVR - audio - Audio Visual Research |
| 578 | 578 | 'avr' => array ( |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | 'group' => 'audio', |
| 581 | 581 | 'module' => 'avr', |
| 582 | 582 | 'mime_type' => 'application/octet-stream', |
| 583 | - ), |
|
| 583 | + ), |
|
| 584 | 584 | |
| 585 | 585 | // BONK - audio - Bonk v0.9+ |
| 586 | 586 | 'bonk' => array ( |
@@ -588,15 +588,15 @@ discard block |
||
| 588 | 588 | 'group' => 'audio', |
| 589 | 589 | 'module' => 'bonk', |
| 590 | 590 | 'mime_type' => 'audio/xmms-bonk', |
| 591 | - ), |
|
| 591 | + ), |
|
| 592 | 592 | |
| 593 | 593 | // DTS - audio - Dolby Theatre System |
| 594 | - 'dts' => array( |
|
| 595 | - 'pattern' => '^\x7F\xFE\x80\x01', |
|
| 596 | - 'group' => 'audio', |
|
| 597 | - 'module' => 'dts', |
|
| 598 | - 'mime_type' => 'audio/dts', |
|
| 599 | - ), |
|
| 594 | + 'dts' => array( |
|
| 595 | + 'pattern' => '^\x7F\xFE\x80\x01', |
|
| 596 | + 'group' => 'audio', |
|
| 597 | + 'module' => 'dts', |
|
| 598 | + 'mime_type' => 'audio/dts', |
|
| 599 | + ), |
|
| 600 | 600 | |
| 601 | 601 | // FLAC - audio - Free Lossless Audio Codec |
| 602 | 602 | 'flac' => array ( |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | 'group' => 'audio', |
| 605 | 605 | 'module' => 'xiph', |
| 606 | 606 | 'mime_type' => 'audio/x-flac', |
| 607 | - ), |
|
| 607 | + ), |
|
| 608 | 608 | |
| 609 | 609 | // LA - audio - Lossless Audio (LA) |
| 610 | 610 | 'la' => array ( |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | 'group' => 'audio', |
| 613 | 613 | 'module' => 'la', |
| 614 | 614 | 'mime_type' => 'application/octet-stream', |
| 615 | - ), |
|
| 615 | + ), |
|
| 616 | 616 | |
| 617 | 617 | // LPAC - audio - Lossless Predictive Audio Compression (LPAC) |
| 618 | 618 | 'lpac' => array ( |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | 'group' => 'audio', |
| 621 | 621 | 'module' => 'lpac', |
| 622 | 622 | 'mime_type' => 'application/octet-stream', |
| 623 | - ), |
|
| 623 | + ), |
|
| 624 | 624 | |
| 625 | 625 | // MIDI - audio - MIDI (Musical Instrument Digital Interface) |
| 626 | 626 | 'midi' => array ( |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | 'group' => 'audio', |
| 629 | 629 | 'module' => 'midi', |
| 630 | 630 | 'mime_type' => 'audio/midi', |
| 631 | - ), |
|
| 631 | + ), |
|
| 632 | 632 | |
| 633 | 633 | // MAC - audio - Monkey's Audio Compressor |
| 634 | 634 | 'mac' => array ( |
@@ -636,31 +636,31 @@ discard block |
||
| 636 | 636 | 'group' => 'audio', |
| 637 | 637 | 'module' => 'monkey', |
| 638 | 638 | 'mime_type' => 'application/octet-stream', |
| 639 | - ), |
|
| 639 | + ), |
|
| 640 | 640 | |
| 641 | 641 | // MOD - audio - MODule (assorted sub-formats) |
| 642 | 642 | 'mod' => array ( |
| 643 | 643 | 'pattern' => '^.{1080}(M.K.|[5-9]CHN|[1-3][0-9]CH)', |
| 644 | 644 | 'mime_type' => 'audio/mod', |
| 645 | - ), |
|
| 645 | + ), |
|
| 646 | 646 | |
| 647 | 647 | // MOD - audio - MODule (Impulse Tracker) |
| 648 | 648 | 'it' => array ( |
| 649 | 649 | 'pattern' => '^IMPM', |
| 650 | 650 | 'mime_type' => 'audio/it', |
| 651 | - ), |
|
| 651 | + ), |
|
| 652 | 652 | |
| 653 | 653 | // MOD - audio - MODule (eXtended Module, various sub-formats) |
| 654 | 654 | 'xm' => array ( |
| 655 | 655 | 'pattern' => '^Extended Module', |
| 656 | 656 | 'mime_type' => 'audio/xm', |
| 657 | - ), |
|
| 657 | + ), |
|
| 658 | 658 | |
| 659 | 659 | // MOD - audio - MODule (ScreamTracker) |
| 660 | 660 | 's3m' => array ( |
| 661 | 661 | 'pattern' => '^.{44}SCRM', |
| 662 | 662 | 'mime_type' => 'audio/s3m', |
| 663 | - ), |
|
| 663 | + ), |
|
| 664 | 664 | |
| 665 | 665 | // MPC - audio - Musepack / MPEGplus SV7+ |
| 666 | 666 | 'mpc' => array ( |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | 'group' => 'audio', |
| 669 | 669 | 'module' => 'mpc', |
| 670 | 670 | 'mime_type' => 'audio/x-musepack', |
| 671 | - ), |
|
| 671 | + ), |
|
| 672 | 672 | |
| 673 | 673 | // MPC - audio - Musepack / MPEGplus SV4-6 |
| 674 | 674 | 'mpc_old' => array ( |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | 'group' => 'audio', |
| 677 | 677 | 'module' => 'mpc_old', |
| 678 | 678 | 'mime_type' => 'application/octet-stream', |
| 679 | - ), |
|
| 679 | + ), |
|
| 680 | 680 | |
| 681 | 681 | |
| 682 | 682 | // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS) |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | 'group' => 'audio', |
| 686 | 686 | 'module' => 'mp3', |
| 687 | 687 | 'mime_type' => 'audio/mpeg', |
| 688 | - ), |
|
| 688 | + ), |
|
| 689 | 689 | |
| 690 | 690 | // OFR - audio - OptimFROG |
| 691 | 691 | 'ofr' => array ( |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | 'group' => 'audio', |
| 694 | 694 | 'module' => 'optimfrog', |
| 695 | 695 | 'mime_type' => 'application/octet-stream', |
| 696 | - ), |
|
| 696 | + ), |
|
| 697 | 697 | |
| 698 | 698 | // RKAU - audio - RKive AUdio compressor |
| 699 | 699 | 'rkau' => array ( |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | 'group' => 'audio', |
| 702 | 702 | 'module' => 'rkau', |
| 703 | 703 | 'mime_type' => 'application/octet-stream', |
| 704 | - ), |
|
| 704 | + ), |
|
| 705 | 705 | |
| 706 | 706 | // SHN - audio - Shorten |
| 707 | 707 | 'shn' => array ( |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | 'mime_type' => 'audio/xmms-shn', |
| 712 | 712 | 'fail_id3' => 'ERROR', |
| 713 | 713 | 'fail_ape' => 'ERROR', |
| 714 | - ), |
|
| 714 | + ), |
|
| 715 | 715 | |
| 716 | 716 | // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org) |
| 717 | 717 | 'tta' => array ( |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | 'group' => 'audio', |
| 720 | 720 | 'module' => 'tta', |
| 721 | 721 | 'mime_type' => 'application/octet-stream', |
| 722 | - ), |
|
| 722 | + ), |
|
| 723 | 723 | |
| 724 | 724 | // VOC - audio - Creative Voice (VOC) |
| 725 | 725 | 'voc' => array ( |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | 'group' => 'audio', |
| 728 | 728 | 'module' => 'voc', |
| 729 | 729 | 'mime_type' => 'audio/voc', |
| 730 | - ), |
|
| 730 | + ), |
|
| 731 | 731 | |
| 732 | 732 | // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF) |
| 733 | 733 | 'vqf' => array ( |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | 'group' => 'audio', |
| 736 | 736 | 'module' => 'vqf', |
| 737 | 737 | 'mime_type' => 'application/octet-stream', |
| 738 | - ), |
|
| 738 | + ), |
|
| 739 | 739 | |
| 740 | 740 | // WV - audio - WavPack (v4.0+) |
| 741 | 741 | 'vw' => array( |
@@ -743,7 +743,7 @@ discard block |
||
| 743 | 743 | 'group' => 'audio', |
| 744 | 744 | 'module' => 'wavpack', |
| 745 | 745 | 'mime_type' => 'application/octet-stream', |
| 746 | - ), |
|
| 746 | + ), |
|
| 747 | 747 | |
| 748 | 748 | |
| 749 | 749 | // Audio-Video formats |
@@ -754,13 +754,13 @@ discard block |
||
| 754 | 754 | 'group' => 'audio-video', |
| 755 | 755 | 'module' => 'asf', |
| 756 | 756 | 'mime_type' => 'video/x-ms-asf', |
| 757 | - ), |
|
| 757 | + ), |
|
| 758 | 758 | |
| 759 | 759 | // BINK - audio/video - Bink / Smacker |
| 760 | 760 | 'bink' => array( |
| 761 | 761 | 'pattern' => '^(BIK|SMK)', |
| 762 | 762 | 'mime_type' => 'application/octet-stream', |
| 763 | - ), |
|
| 763 | + ), |
|
| 764 | 764 | |
| 765 | 765 | // FLV - audio/video - FLash Video |
| 766 | 766 | 'flv' => array( |
@@ -768,13 +768,13 @@ discard block |
||
| 768 | 768 | 'group' => 'audio-video', |
| 769 | 769 | 'module' => 'flv', |
| 770 | 770 | 'mime_type' => 'video/x-flv', |
| 771 | - ), |
|
| 771 | + ), |
|
| 772 | 772 | |
| 773 | 773 | // MKAV - audio/video - Mastroka |
| 774 | 774 | 'matroska' => array ( |
| 775 | 775 | 'pattern' => '^\x1A\x45\xDF\xA3', |
| 776 | 776 | 'mime_type' => 'application/octet-stream', |
| 777 | - ), |
|
| 777 | + ), |
|
| 778 | 778 | |
| 779 | 779 | // MPEG - audio/video - MPEG (Moving Pictures Experts Group) |
| 780 | 780 | 'mpeg' => array ( |
@@ -782,7 +782,7 @@ discard block |
||
| 782 | 782 | 'group' => 'audio-video', |
| 783 | 783 | 'module' => 'mpeg', |
| 784 | 784 | 'mime_type' => 'video/mpeg', |
| 785 | - ), |
|
| 785 | + ), |
|
| 786 | 786 | |
| 787 | 787 | // NSV - audio/video - Nullsoft Streaming Video (NSV) |
| 788 | 788 | 'nsv' => array ( |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | 'group' => 'audio-video', |
| 791 | 791 | 'module' => 'nsv', |
| 792 | 792 | 'mime_type' => 'application/octet-stream', |
| 793 | - ), |
|
| 793 | + ), |
|
| 794 | 794 | |
| 795 | 795 | // Ogg - audio/video - Ogg (Ogg Vorbis, OggFLAC, Speex, Ogg Theora(*), Ogg Tarkin(*)) |
| 796 | 796 | 'ogg' => array ( |
@@ -800,7 +800,7 @@ discard block |
||
| 800 | 800 | 'mime_type' => 'application/ogg', |
| 801 | 801 | 'fail_id3' => 'WARNING', |
| 802 | 802 | 'fail_ape' => 'WARNING', |
| 803 | - ), |
|
| 803 | + ), |
|
| 804 | 804 | |
| 805 | 805 | // QT - audio/video - Quicktime |
| 806 | 806 | 'quicktime' => array ( |
@@ -808,7 +808,7 @@ discard block |
||
| 808 | 808 | 'group' => 'audio-video', |
| 809 | 809 | 'module' => 'quicktime', |
| 810 | 810 | 'mime_type' => 'video/quicktime', |
| 811 | - ), |
|
| 811 | + ), |
|
| 812 | 812 | |
| 813 | 813 | // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF) |
| 814 | 814 | 'riff' => array ( |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | 'module' => 'riff', |
| 818 | 818 | 'mime_type' => 'audio/x-wave', |
| 819 | 819 | 'fail_ape' => 'WARNING', |
| 820 | - ), |
|
| 820 | + ), |
|
| 821 | 821 | |
| 822 | 822 | // Real - audio/video - RealAudio, RealVideo |
| 823 | 823 | 'real' => array ( |
@@ -825,7 +825,7 @@ discard block |
||
| 825 | 825 | 'group' => 'audio-video', |
| 826 | 826 | 'module' => 'real', |
| 827 | 827 | 'mime_type' => 'audio/x-realaudio', |
| 828 | - ), |
|
| 828 | + ), |
|
| 829 | 829 | |
| 830 | 830 | // SWF - audio/video - ShockWave Flash |
| 831 | 831 | 'swf' => array ( |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | 'group' => 'audio-video', |
| 834 | 834 | 'module' => 'swf', |
| 835 | 835 | 'mime_type' => 'application/x-shockwave-flash', |
| 836 | - ), |
|
| 836 | + ), |
|
| 837 | 837 | |
| 838 | 838 | |
| 839 | 839 | // Still-Image formats |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | 'mime_type' => 'image/bmp', |
| 847 | 847 | 'fail_id3' => 'ERROR', |
| 848 | 848 | 'fail_ape' => 'ERROR', |
| 849 | - ), |
|
| 849 | + ), |
|
| 850 | 850 | |
| 851 | 851 | // GIF - still image - Graphics Interchange Format |
| 852 | 852 | 'gif' => array ( |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | 'mime_type' => 'image/gif', |
| 857 | 857 | 'fail_id3' => 'ERROR', |
| 858 | 858 | 'fail_ape' => 'ERROR', |
| 859 | - ), |
|
| 859 | + ), |
|
| 860 | 860 | |
| 861 | 861 | // JPEG - still image - Joint Photographic Experts Group (JPEG) |
| 862 | 862 | 'jpeg' => array ( |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | 'mime_type' => 'image/jpeg', |
| 867 | 867 | 'fail_id3' => 'ERROR', |
| 868 | 868 | 'fail_ape' => 'ERROR', |
| 869 | - ), |
|
| 869 | + ), |
|
| 870 | 870 | |
| 871 | 871 | // PCD - still image - Kodak Photo CD |
| 872 | 872 | 'pcd' => array ( |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | 'mime_type' => 'image/x-photo-cd', |
| 877 | 877 | 'fail_id3' => 'ERROR', |
| 878 | 878 | 'fail_ape' => 'ERROR', |
| 879 | - ), |
|
| 879 | + ), |
|
| 880 | 880 | |
| 881 | 881 | |
| 882 | 882 | // PNG - still image - Portable Network Graphics (PNG) |
@@ -887,16 +887,16 @@ discard block |
||
| 887 | 887 | 'mime_type' => 'image/png', |
| 888 | 888 | 'fail_id3' => 'ERROR', |
| 889 | 889 | 'fail_ape' => 'ERROR', |
| 890 | - ), |
|
| 890 | + ), |
|
| 891 | 891 | |
| 892 | 892 | |
| 893 | 893 | // SVG - still image - Scalable Vector Graphics (SVG) |
| 894 | - 'svg' => array( |
|
| 895 | - 'pattern' => '<!DOCTYPE svg PUBLIC ', |
|
| 896 | - 'mime_type' => 'image/svg+xml', |
|
| 897 | - 'fail_id3' => 'ERROR', |
|
| 898 | - 'fail_ape' => 'ERROR', |
|
| 899 | - ), |
|
| 894 | + 'svg' => array( |
|
| 895 | + 'pattern' => '<!DOCTYPE svg PUBLIC ', |
|
| 896 | + 'mime_type' => 'image/svg+xml', |
|
| 897 | + 'fail_id3' => 'ERROR', |
|
| 898 | + 'fail_ape' => 'ERROR', |
|
| 899 | + ), |
|
| 900 | 900 | |
| 901 | 901 | |
| 902 | 902 | // TIFF - still image - Tagged Information File Format (TIFF) |
@@ -907,7 +907,7 @@ discard block |
||
| 907 | 907 | 'mime_type' => 'image/tiff', |
| 908 | 908 | 'fail_id3' => 'ERROR', |
| 909 | 909 | 'fail_ape' => 'ERROR', |
| 910 | - ), |
|
| 910 | + ), |
|
| 911 | 911 | |
| 912 | 912 | |
| 913 | 913 | // Data formats |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | 'mime_type' => 'application/octet-stream', |
| 918 | 918 | 'fail_id3' => 'ERROR', |
| 919 | 919 | 'fail_ape' => 'ERROR', |
| 920 | - ), |
|
| 920 | + ), |
|
| 921 | 921 | |
| 922 | 922 | // ISO - data - International Standards Organization (ISO) CD-ROM Image |
| 923 | 923 | 'iso' => array ( |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | 'mime_type' => 'application/octet-stream', |
| 928 | 928 | 'fail_id3' => 'ERROR', |
| 929 | 929 | 'fail_ape' => 'ERROR', |
| 930 | - ), |
|
| 930 | + ), |
|
| 931 | 931 | |
| 932 | 932 | // RAR - data - RAR compressed data |
| 933 | 933 | 'rar' => array( |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | 'mime_type' => 'application/octet-stream', |
| 936 | 936 | 'fail_id3' => 'ERROR', |
| 937 | 937 | 'fail_ape' => 'ERROR', |
| 938 | - ), |
|
| 938 | + ), |
|
| 939 | 939 | |
| 940 | 940 | // SZIP - audio - SZIP compressed data |
| 941 | 941 | 'szip' => array ( |
@@ -945,7 +945,7 @@ discard block |
||
| 945 | 945 | 'mime_type' => 'application/octet-stream', |
| 946 | 946 | 'fail_id3' => 'ERROR', |
| 947 | 947 | 'fail_ape' => 'ERROR', |
| 948 | - ), |
|
| 948 | + ), |
|
| 949 | 949 | |
| 950 | 950 | // TAR - data - TAR compressed data |
| 951 | 951 | 'tar' => array( |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | 'mime_type' => 'application/x-tar', |
| 956 | 956 | 'fail_id3' => 'ERROR', |
| 957 | 957 | 'fail_ape' => 'ERROR', |
| 958 | - ), |
|
| 958 | + ), |
|
| 959 | 959 | |
| 960 | 960 | // GZIP - data - GZIP compressed data |
| 961 | 961 | 'gz' => array( |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | 'mime_type' => 'application/x-gzip', |
| 966 | 966 | 'fail_id3' => 'ERROR', |
| 967 | 967 | 'fail_ape' => 'ERROR', |
| 968 | - ), |
|
| 968 | + ), |
|
| 969 | 969 | |
| 970 | 970 | |
| 971 | 971 | // ZIP - data - ZIP compressed data |
@@ -976,33 +976,33 @@ discard block |
||
| 976 | 976 | 'mime_type' => 'application/zip', |
| 977 | 977 | 'fail_id3' => 'ERROR', |
| 978 | 978 | 'fail_ape' => 'ERROR', |
| 979 | - ), |
|
| 979 | + ), |
|
| 980 | 980 | |
| 981 | 981 | |
| 982 | 982 | // PAR2 - data - Parity Volume Set Specification 2.0 |
| 983 | 983 | 'par2' => array ( |
| 984 | - 'pattern' => '^PAR2\x00PKT', |
|
| 985 | - 'mime_type' => 'application/octet-stream', |
|
| 986 | - 'fail_id3' => 'ERROR', |
|
| 987 | - 'fail_ape' => 'ERROR', |
|
| 988 | - ), |
|
| 984 | + 'pattern' => '^PAR2\x00PKT', |
|
| 985 | + 'mime_type' => 'application/octet-stream', |
|
| 986 | + 'fail_id3' => 'ERROR', |
|
| 987 | + 'fail_ape' => 'ERROR', |
|
| 988 | + ), |
|
| 989 | 989 | |
| 990 | 990 | |
| 991 | - // PDF - data - Portable Document Format |
|
| 992 | - 'pdf' => array( |
|
| 991 | + // PDF - data - Portable Document Format |
|
| 992 | + 'pdf' => array( |
|
| 993 | 993 | 'pattern' => '^\x25PDF', |
| 994 | 994 | 'mime_type' => 'application/pdf', |
| 995 | 995 | 'fail_id3' => 'ERROR', |
| 996 | 996 | 'fail_ape' => 'ERROR', |
| 997 | - ), |
|
| 997 | + ), |
|
| 998 | 998 | |
| 999 | - // DOC - data - Microsoft Word |
|
| 1000 | - 'msoffice' => array( |
|
| 999 | + // DOC - data - Microsoft Word |
|
| 1000 | + 'msoffice' => array( |
|
| 1001 | 1001 | 'pattern' => '^\xD0\xCF\x11\xE0', // D0CF11E == DOCFILE == Microsoft Office Document |
| 1002 | 1002 | 'mime_type' => 'application/octet-stream', |
| 1003 | 1003 | 'fail_id3' => 'ERROR', |
| 1004 | 1004 | 'fail_ape' => 'ERROR', |
| 1005 | - ), |
|
| 1005 | + ), |
|
| 1006 | 1006 | ); |
| 1007 | 1007 | |
| 1008 | 1008 | return $format_info; |
@@ -1393,99 +1393,99 @@ discard block |
||
| 1393 | 1393 | |
| 1394 | 1394 | public static function BigEndian2Float($byte_word) { |
| 1395 | 1395 | |
| 1396 | - // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic |
|
| 1397 | - // http://www.psc.edu/general/software/packages/ieee/ieee.html |
|
| 1398 | - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html |
|
| 1396 | + // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic |
|
| 1397 | + // http://www.psc.edu/general/software/packages/ieee/ieee.html |
|
| 1398 | + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html |
|
| 1399 | 1399 | |
| 1400 | - $bit_word = getid3_lib::BigEndian2Bin($byte_word); |
|
| 1401 | - if (!$bit_word) { |
|
| 1400 | + $bit_word = getid3_lib::BigEndian2Bin($byte_word); |
|
| 1401 | + if (!$bit_word) { |
|
| 1402 | 1402 | return 0; |
| 1403 | 1403 | } |
| 1404 | - $sign_bit = $bit_word{0}; |
|
| 1405 | - |
|
| 1406 | - switch (strlen($byte_word) * 8) { |
|
| 1407 | - case 32: |
|
| 1408 | - $exponent_bits = 8; |
|
| 1409 | - $fraction_bits = 23; |
|
| 1410 | - break; |
|
| 1411 | - |
|
| 1412 | - case 64: |
|
| 1413 | - $exponent_bits = 11; |
|
| 1414 | - $fraction_bits = 52; |
|
| 1415 | - break; |
|
| 1416 | - |
|
| 1417 | - case 80: |
|
| 1418 | - // 80-bit Apple SANE format |
|
| 1419 | - // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/ |
|
| 1420 | - $exponent_string = substr($bit_word, 1, 15); |
|
| 1421 | - $is_normalized = intval($bit_word{16}); |
|
| 1422 | - $fraction_string = substr($bit_word, 17, 63); |
|
| 1423 | - $exponent = pow(2, getid3_lib::Bin2Dec($exponent_string) - 16383); |
|
| 1424 | - $fraction = $is_normalized + getid3_lib::DecimalBinary2Float($fraction_string); |
|
| 1425 | - $float_value = $exponent * $fraction; |
|
| 1426 | - if ($sign_bit == '1') { |
|
| 1427 | - $float_value *= -1; |
|
| 1428 | - } |
|
| 1429 | - return $float_value; |
|
| 1430 | - break; |
|
| 1431 | - |
|
| 1432 | - default: |
|
| 1433 | - return false; |
|
| 1434 | - break; |
|
| 1435 | - } |
|
| 1436 | - $exponent_string = substr($bit_word, 1, $exponent_bits); |
|
| 1437 | - $fraction_string = substr($bit_word, $exponent_bits + 1, $fraction_bits); |
|
| 1438 | - $exponent = bindec($exponent_string); |
|
| 1439 | - $fraction = bindec($fraction_string); |
|
| 1440 | - |
|
| 1441 | - if (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction != 0)) { |
|
| 1442 | - // Not a Number |
|
| 1443 | - $float_value = false; |
|
| 1444 | - } elseif (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction == 0)) { |
|
| 1445 | - if ($sign_bit == '1') { |
|
| 1446 | - $float_value = '-infinity'; |
|
| 1447 | - } else { |
|
| 1448 | - $float_value = '+infinity'; |
|
| 1449 | - } |
|
| 1450 | - } elseif (($exponent == 0) && ($fraction == 0)) { |
|
| 1451 | - if ($sign_bit == '1') { |
|
| 1452 | - $float_value = -0; |
|
| 1453 | - } else { |
|
| 1454 | - $float_value = 0; |
|
| 1455 | - } |
|
| 1456 | - $float_value = ($sign_bit ? 0 : -0); |
|
| 1457 | - } elseif (($exponent == 0) && ($fraction != 0)) { |
|
| 1458 | - // These are 'unnormalized' values |
|
| 1459 | - $float_value = pow(2, (-1 * (pow(2, $exponent_bits - 1) - 2))) * getid3_lib::DecimalBinary2Float($fraction_string); |
|
| 1460 | - if ($sign_bit == '1') { |
|
| 1461 | - $float_value *= -1; |
|
| 1462 | - } |
|
| 1463 | - } elseif ($exponent != 0) { |
|
| 1464 | - $float_value = pow(2, ($exponent - (pow(2, $exponent_bits - 1) - 1))) * (1 + getid3_lib::DecimalBinary2Float($fraction_string)); |
|
| 1465 | - if ($sign_bit == '1') { |
|
| 1466 | - $float_value *= -1; |
|
| 1467 | - } |
|
| 1468 | - } |
|
| 1469 | - return (float) $float_value; |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - |
|
| 1473 | - |
|
| 1474 | - public static function LittleEndian2Float($byte_word) { |
|
| 1475 | - |
|
| 1476 | - return getid3_lib::BigEndian2Float(strrev($byte_word)); |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - public static function DecimalBinary2Float($binary_numerator) { |
|
| 1482 | - $numerator = bindec($binary_numerator); |
|
| 1483 | - $denominator = bindec('1'.str_repeat('0', strlen($binary_numerator))); |
|
| 1484 | - return ($numerator / $denominator); |
|
| 1485 | - } |
|
| 1486 | - |
|
| 1487 | - |
|
| 1488 | - public static function PrintHexBytes($string, $hex=true, $spaces=true, $html_safe=true) { |
|
| 1404 | + $sign_bit = $bit_word{0}; |
|
| 1405 | + |
|
| 1406 | + switch (strlen($byte_word) * 8) { |
|
| 1407 | + case 32: |
|
| 1408 | + $exponent_bits = 8; |
|
| 1409 | + $fraction_bits = 23; |
|
| 1410 | + break; |
|
| 1411 | + |
|
| 1412 | + case 64: |
|
| 1413 | + $exponent_bits = 11; |
|
| 1414 | + $fraction_bits = 52; |
|
| 1415 | + break; |
|
| 1416 | + |
|
| 1417 | + case 80: |
|
| 1418 | + // 80-bit Apple SANE format |
|
| 1419 | + // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/ |
|
| 1420 | + $exponent_string = substr($bit_word, 1, 15); |
|
| 1421 | + $is_normalized = intval($bit_word{16}); |
|
| 1422 | + $fraction_string = substr($bit_word, 17, 63); |
|
| 1423 | + $exponent = pow(2, getid3_lib::Bin2Dec($exponent_string) - 16383); |
|
| 1424 | + $fraction = $is_normalized + getid3_lib::DecimalBinary2Float($fraction_string); |
|
| 1425 | + $float_value = $exponent * $fraction; |
|
| 1426 | + if ($sign_bit == '1') { |
|
| 1427 | + $float_value *= -1; |
|
| 1428 | + } |
|
| 1429 | + return $float_value; |
|
| 1430 | + break; |
|
| 1431 | + |
|
| 1432 | + default: |
|
| 1433 | + return false; |
|
| 1434 | + break; |
|
| 1435 | + } |
|
| 1436 | + $exponent_string = substr($bit_word, 1, $exponent_bits); |
|
| 1437 | + $fraction_string = substr($bit_word, $exponent_bits + 1, $fraction_bits); |
|
| 1438 | + $exponent = bindec($exponent_string); |
|
| 1439 | + $fraction = bindec($fraction_string); |
|
| 1440 | + |
|
| 1441 | + if (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction != 0)) { |
|
| 1442 | + // Not a Number |
|
| 1443 | + $float_value = false; |
|
| 1444 | + } elseif (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction == 0)) { |
|
| 1445 | + if ($sign_bit == '1') { |
|
| 1446 | + $float_value = '-infinity'; |
|
| 1447 | + } else { |
|
| 1448 | + $float_value = '+infinity'; |
|
| 1449 | + } |
|
| 1450 | + } elseif (($exponent == 0) && ($fraction == 0)) { |
|
| 1451 | + if ($sign_bit == '1') { |
|
| 1452 | + $float_value = -0; |
|
| 1453 | + } else { |
|
| 1454 | + $float_value = 0; |
|
| 1455 | + } |
|
| 1456 | + $float_value = ($sign_bit ? 0 : -0); |
|
| 1457 | + } elseif (($exponent == 0) && ($fraction != 0)) { |
|
| 1458 | + // These are 'unnormalized' values |
|
| 1459 | + $float_value = pow(2, (-1 * (pow(2, $exponent_bits - 1) - 2))) * getid3_lib::DecimalBinary2Float($fraction_string); |
|
| 1460 | + if ($sign_bit == '1') { |
|
| 1461 | + $float_value *= -1; |
|
| 1462 | + } |
|
| 1463 | + } elseif ($exponent != 0) { |
|
| 1464 | + $float_value = pow(2, ($exponent - (pow(2, $exponent_bits - 1) - 1))) * (1 + getid3_lib::DecimalBinary2Float($fraction_string)); |
|
| 1465 | + if ($sign_bit == '1') { |
|
| 1466 | + $float_value *= -1; |
|
| 1467 | + } |
|
| 1468 | + } |
|
| 1469 | + return (float) $float_value; |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + |
|
| 1473 | + |
|
| 1474 | + public static function LittleEndian2Float($byte_word) { |
|
| 1475 | + |
|
| 1476 | + return getid3_lib::BigEndian2Float(strrev($byte_word)); |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + public static function DecimalBinary2Float($binary_numerator) { |
|
| 1482 | + $numerator = bindec($binary_numerator); |
|
| 1483 | + $denominator = bindec('1'.str_repeat('0', strlen($binary_numerator))); |
|
| 1484 | + return ($numerator / $denominator); |
|
| 1485 | + } |
|
| 1486 | + |
|
| 1487 | + |
|
| 1488 | + public static function PrintHexBytes($string, $hex=true, $spaces=true, $html_safe=true) { |
|
| 1489 | 1489 | |
| 1490 | 1490 | $return_string = ''; |
| 1491 | 1491 | for ($i = 0; $i < strlen($string); $i++) { |