@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | - * @return float |
|
80 | + * @return integer|null |
|
81 | 81 | */ |
82 | 82 | public function get_certificate_min_score() |
83 | 83 | { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | - * @return mixed |
|
100 | + * @return integer |
|
101 | 101 | */ |
102 | 102 | public function get_parent_id() |
103 | 103 | { |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | - * @return mixed |
|
108 | + * @return integer |
|
109 | 109 | */ |
110 | 110 | public function get_weight() |
111 | 111 | { |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * @return mixed |
|
124 | + * @return boolean |
|
125 | 125 | */ |
126 | 126 | public function is_visible() |
127 | 127 | { |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
247 | - * @return null |
|
247 | + * @return null|integer |
|
248 | 248 | */ |
249 | 249 | public function get_grade_model_id() |
250 | 250 | { |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
490 | - * @param $result |
|
490 | + * @param Doctrine\DBAL\Driver\Statement|null $result |
|
491 | 491 | * |
492 | 492 | * @return array |
493 | 493 | */ |
@@ -863,7 +863,8 @@ discard block |
||
863 | 863 | |
864 | 864 | /** |
865 | 865 | * Calculate the score of this category |
866 | - * @param $stud_id student id (default: all students - then the average is returned) |
|
866 | + * @param integer $stud_id student id (default: all students - then the average is returned) |
|
867 | + * @param integer $session_id |
|
867 | 868 | * @return array (score sum, weight sum) |
868 | 869 | * or null if no scores available |
869 | 870 | */ |
@@ -1122,6 +1123,9 @@ discard block |
||
1122 | 1123 | * @param int student id |
1123 | 1124 | * @param string Course code |
1124 | 1125 | * @param int Session id |
1126 | + * @param integer $stud_id |
|
1127 | + * @param string $course_code |
|
1128 | + * @param integer $session_id |
|
1125 | 1129 | */ |
1126 | 1130 | public function get_root_categories_for_student($stud_id, $course_code = null, $session_id = null) |
1127 | 1131 | { |
@@ -1202,6 +1206,9 @@ discard block |
||
1202 | 1206 | * @param int user id (to return everything, use 'null' here) |
1203 | 1207 | * @param string course code (optional) |
1204 | 1208 | * @param int session id (optional) |
1209 | + * @param integer $user_id |
|
1210 | + * @param string $course_code |
|
1211 | + * @param integer $session_id |
|
1205 | 1212 | */ |
1206 | 1213 | public function get_root_categories_for_teacher($user_id, $course_code = null, $session_id = null) |
1207 | 1214 | { |
@@ -1300,6 +1307,7 @@ discard block |
||
1300 | 1307 | |
1301 | 1308 | /** |
1302 | 1309 | * Internal function used by get_target_categories() |
1310 | + * @param integer $level |
|
1303 | 1311 | */ |
1304 | 1312 | private function add_target_subcategories($targets, $level, $catid) |
1305 | 1313 | { |
@@ -1399,6 +1407,8 @@ discard block |
||
1399 | 1407 | |
1400 | 1408 | /** |
1401 | 1409 | * Internal function used by get_tree() |
1410 | + * @param integer $level |
|
1411 | + * @param null|integer $visible |
|
1402 | 1412 | */ |
1403 | 1413 | private function add_subtree ($targets, $level, $catid, $visible) |
1404 | 1414 | { |
@@ -1416,6 +1426,7 @@ discard block |
||
1416 | 1426 | |
1417 | 1427 | /** |
1418 | 1428 | * Generate an array of courses that a teacher hasn't created a category for. |
1429 | + * @param integer $user_id |
|
1419 | 1430 | * @return array 2-dimensional array - every element contains 2 subelements (code, title) |
1420 | 1431 | */ |
1421 | 1432 | public function get_not_created_course_categories ($user_id) |
@@ -1450,6 +1461,7 @@ discard block |
||
1450 | 1461 | |
1451 | 1462 | /** |
1452 | 1463 | * Generate an array of all courses that a teacher is admin of. |
1464 | + * @param integer $user_id |
|
1453 | 1465 | * @return array 2-dimensional array - every element contains 2 subelements (code, title) |
1454 | 1466 | */ |
1455 | 1467 | public function get_all_courses ($user_id) |
@@ -1530,7 +1542,7 @@ discard block |
||
1530 | 1542 | /** |
1531 | 1543 | * Retrieve all categories inside a course independent category |
1532 | 1544 | * that should be visible to a student. |
1533 | - * @param $cat_id parent category |
|
1545 | + * @param integer $cat_id parent category |
|
1534 | 1546 | * @param $stud_id student id |
1535 | 1547 | * @param $cats optional: if defined, the categories will be added to this array |
1536 | 1548 | */ |
@@ -1851,7 +1863,7 @@ discard block |
||
1851 | 1863 | * the platform administrator. |
1852 | 1864 | * @param int locked 1 or unlocked 0 |
1853 | 1865 | |
1854 | - * @return bool |
|
1866 | + * @return boolean|null |
|
1855 | 1867 | * */ |
1856 | 1868 | public function lock($locked) |
1857 | 1869 | { |
@@ -2282,7 +2294,7 @@ discard block |
||
2282 | 2294 | * @param float $score The achieved score |
2283 | 2295 | * @param int $userId The user id |
2284 | 2296 | * @param int $categoryId The gradebook category |
2285 | - * @return int The insert id |
|
2297 | + * @return false|string The insert id |
|
2286 | 2298 | */ |
2287 | 2299 | public static function registerCurrentScore($score, $userId, $categoryId) |
2288 | 2300 | { |
@@ -1571,7 +1571,6 @@ discard block |
||
1571 | 1571 | * @param string $course_code Course code (optional) |
1572 | 1572 | * @param int $session_id Session ID (optional) |
1573 | 1573 | * @param bool $order |
1574 | - |
|
1575 | 1574 | * @return array Array of subcategories |
1576 | 1575 | */ |
1577 | 1576 | public function get_subcategories($stud_id = null, $course_code = null, $session_id = null, $order = null) |
@@ -1850,7 +1849,6 @@ discard block |
||
1850 | 1849 | * This function, locks a category , only one who can unlock it is |
1851 | 1850 | * the platform administrator. |
1852 | 1851 | * @param int locked 1 or unlocked 0 |
1853 | - |
|
1854 | 1852 | * @return bool |
1855 | 1853 | * */ |
1856 | 1854 | public function lock($locked) |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function set_session_id($session_id = 0) |
201 | 201 | { |
202 | - $this->session_id = (int)$session_id; |
|
202 | + $this->session_id = (int) $session_id; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | $skills = $this->get_skills(); |
289 | 289 | $skill_select = array(); |
290 | 290 | if (!empty($skills)) { |
291 | - foreach($skills as $skill) { |
|
291 | + foreach ($skills as $skill) { |
|
292 | 292 | $skill_select[$skill['id']] = $skill['name']; |
293 | 293 | } |
294 | 294 | } |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public static function load_session_categories($id = null, $session_id = null) |
324 | 324 | { |
325 | - if (isset($id) && (int)$id === 0) { |
|
325 | + if (isset($id) && (int) $id === 0) { |
|
326 | 326 | $cats = array(); |
327 | 327 | $cats[] = Category::create_root_category(); |
328 | 328 | return $cats; |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | if (!empty($session_id)) { |
336 | 336 | $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); |
337 | 337 | $sql = 'SELECT id, course_code |
338 | - FROM '.$tbl_grade_categories. ' |
|
338 | + FROM '.$tbl_grade_categories.' |
|
339 | 339 | WHERE session_id = '.$session_id; |
340 | 340 | $result_session = Database::query($sql); |
341 | 341 | if (Database::num_rows($result_session) > 0) { |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | ) { |
376 | 376 | //if the category given is explicitly 0 (not null), then create |
377 | 377 | // a root category object (in memory) |
378 | - if (isset($id) && (int)$id === 0) { |
|
378 | + if (isset($id) && (int) $id === 0) { |
|
379 | 379 | $cats = array(); |
380 | 380 | $cats[] = Category::create_root_category(); |
381 | 381 | |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | $sql = 'SELECT * FROM '.$tbl_grade_categories; |
387 | 387 | $paramcount = 0; |
388 | 388 | if (isset($id)) { |
389 | - $sql.= ' WHERE id = '.intval($id); |
|
390 | - $paramcount ++; |
|
389 | + $sql .= ' WHERE id = '.intval($id); |
|
390 | + $paramcount++; |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | if (isset($user_id)) { |
@@ -423,10 +423,10 @@ discard block |
||
423 | 423 | if (empty($session_id)) { |
424 | 424 | $sql .= ' AND (session_id IS NULL OR session_id = 0) '; |
425 | 425 | } else { |
426 | - $sql .= ' AND session_id = '.(int)$session_id.' '; |
|
426 | + $sql .= ' AND session_id = '.(int) $session_id.' '; |
|
427 | 427 | } |
428 | 428 | //} |
429 | - $paramcount ++; |
|
429 | + $paramcount++; |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | if (isset($parent_id)) { |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | $default_weight = $default_weight_setting; |
599 | 599 | } |
600 | 600 | foreach ($components as $component) { |
601 | - $gradebook = new Gradebook(); |
|
601 | + $gradebook = new Gradebook(); |
|
602 | 602 | $params = array(); |
603 | 603 | |
604 | 604 | $params['name'] = $component['acronym']; |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | } |
616 | 616 | } |
617 | 617 | |
618 | - $gradebook= new Gradebook(); |
|
618 | + $gradebook = new Gradebook(); |
|
619 | 619 | $gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false)); |
620 | 620 | |
621 | 621 | return $id; |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | $params['description'] = $component['title']; |
681 | 681 | $params['user_id'] = api_get_user_id(); |
682 | 682 | $params['parent_id'] = $this->id; |
683 | - $params['weight'] = $component['percentage']/100*$default_weight; |
|
683 | + $params['weight'] = $component['percentage'] / 100 * $default_weight; |
|
684 | 684 | $params['session_id'] = api_get_session_id(); |
685 | 685 | $params['course_code'] = $this->get_course_code(); |
686 | 686 | |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
693 | - $gradebook= new Gradebook(); |
|
693 | + $gradebook = new Gradebook(); |
|
694 | 694 | $gradebook->update_skills_to_gradebook( |
695 | 695 | $this->id, |
696 | 696 | $this->get_skills(false), |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | if (!empty($links)) { |
711 | 711 | foreach ($links as $link_item) { |
712 | 712 | if (isset($link_item)) { |
713 | - $new_item_weight = $new_weight * $link_item->get_weight() / $old_weight; |
|
713 | + $new_item_weight = $new_weight * $link_item->get_weight() / $old_weight; |
|
714 | 714 | $link_item->set_weight($new_item_weight); |
715 | 715 | $link_item->save(); |
716 | 716 | } |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | visible=3'; |
752 | 752 | $res = Database::query($sql); |
753 | 753 | $option = Database::fetch_array($res, 'ASSOC'); |
754 | - if ($option['num']>=1) { |
|
754 | + if ($option['num'] >= 1) { |
|
755 | 755 | return ' <span class="resource-deleted">( '.get_lang('ResourceDeleted').' )</span>'; |
756 | 756 | } else { |
757 | 757 | return false; |
@@ -812,9 +812,9 @@ discard block |
||
812 | 812 | $sql .= ' AND user_id = '.api_get_user_id(); |
813 | 813 | } |
814 | 814 | if (!isset ($parent)) { |
815 | - $sql.= ' AND parent_id is null'; |
|
815 | + $sql .= ' AND parent_id is null'; |
|
816 | 816 | } else { |
817 | - $sql.= ' AND parent_id = '.intval($parent); |
|
817 | + $sql .= ' AND parent_id = '.intval($parent); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | $result = Database::query($sql); |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | } |
913 | 913 | |
914 | 914 | if (isset($score) && !empty($score[1]) && !empty($catweight)) { |
915 | - $ressum += $score[0]/$score[1] * $catweight; |
|
915 | + $ressum += $score[0] / $score[1] * $catweight; |
|
916 | 916 | } |
917 | 917 | } |
918 | 918 | } |
@@ -1001,7 +1001,7 @@ discard block |
||
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | if (isset($score) && !empty($score[1]) && !empty($catweight)) { |
1004 | - $ressum += $score[0]/$score[1] * $catweight; |
|
1004 | + $ressum += $score[0] / $score[1] * $catweight; |
|
1005 | 1005 | |
1006 | 1006 | if ($ressum > $bestResult) { |
1007 | 1007 | $bestResult = $ressum; |
@@ -1140,7 +1140,7 @@ discard block |
||
1140 | 1140 | // session, we don't check his registration to these, but this |
1141 | 1141 | // could be an improvement |
1142 | 1142 | if (!empty($session_id)) { |
1143 | - $sql .= " AND course_code = '".Database::escape_string($course_code)."' AND session_id = ".(int)$session_id; |
|
1143 | + $sql .= " AND course_code = '".Database::escape_string($course_code)."' AND session_id = ".(int) $session_id; |
|
1144 | 1144 | } else { |
1145 | 1145 | $sql .= " AND course_code = '".Database::escape_string($course_code)."' AND session_id is null OR session_id=0"; |
1146 | 1146 | } |
@@ -1164,9 +1164,9 @@ discard block |
||
1164 | 1164 | // could be an improvement |
1165 | 1165 | $sql .= " AND course_code = '".Database::escape_string($course_code)."'"; |
1166 | 1166 | if (!empty($session_id)) { |
1167 | - $sql .= " AND session_id = ".(int)$session_id; |
|
1167 | + $sql .= " AND session_id = ".(int) $session_id; |
|
1168 | 1168 | } else { |
1169 | - $sql .="AND session_id IS NULL OR session_id=0"; |
|
1169 | + $sql .= "AND session_id IS NULL OR session_id=0"; |
|
1170 | 1170 | } |
1171 | 1171 | } else { |
1172 | 1172 | $sql .= ' AND course_code IN |
@@ -1180,10 +1180,10 @@ discard block |
||
1180 | 1180 | )'; |
1181 | 1181 | } |
1182 | 1182 | }elseif (api_is_platform_admin()) { |
1183 | - if (isset($session_id) && $session_id!=0) { |
|
1184 | - $sql.=' AND session_id='.intval($session_id); |
|
1183 | + if (isset($session_id) && $session_id != 0) { |
|
1184 | + $sql .= ' AND session_id='.intval($session_id); |
|
1185 | 1185 | } else { |
1186 | - $sql.=' AND coalesce(session_id,0)=0'; |
|
1186 | + $sql .= ' AND coalesce(session_id,0)=0'; |
|
1187 | 1187 | } |
1188 | 1188 | } |
1189 | 1189 | $result = Database::query($sql); |
@@ -1191,7 +1191,7 @@ discard block |
||
1191 | 1191 | |
1192 | 1192 | // course independent categories |
1193 | 1193 | if (empty($course_code)) { |
1194 | - $cats = Category::get_independent_categories_with_result_for_student (0, $stud_id, $cats); |
|
1194 | + $cats = Category::get_independent_categories_with_result_for_student(0, $stud_id, $cats); |
|
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | return $cats; |
@@ -1206,7 +1206,7 @@ discard block |
||
1206 | 1206 | public function get_root_categories_for_teacher($user_id, $course_code = null, $session_id = null) |
1207 | 1207 | { |
1208 | 1208 | if ($user_id == null) { |
1209 | - return Category::load(null,null,$course_code,0,null,$session_id); |
|
1209 | + return Category::load(null, null, $course_code, 0, null, $session_id); |
|
1210 | 1210 | } |
1211 | 1211 | |
1212 | 1212 | $courseTable = Database :: get_main_table(TABLE_MAIN_COURSE); |
@@ -1218,7 +1218,7 @@ discard block |
||
1218 | 1218 | if (!empty($course_code)) { |
1219 | 1219 | $sql .= " AND course_code = '".Database::escape_string($course_code)."' "; |
1220 | 1220 | if (!empty($session_id)) { |
1221 | - $sql .= " AND session_id = ".(int)$session_id; |
|
1221 | + $sql .= " AND session_id = ".(int) $session_id; |
|
1222 | 1222 | } |
1223 | 1223 | } else { |
1224 | 1224 | $sql .= ' AND course_code in |
@@ -1234,7 +1234,7 @@ discard block |
||
1234 | 1234 | $cats = Category::create_category_objects_from_sql_result($result); |
1235 | 1235 | // course independent categories |
1236 | 1236 | if (isset($course_code)) { |
1237 | - $indcats = Category::load(null,$user_id,$course_code,0,null,$session_id); |
|
1237 | + $indcats = Category::load(null, $user_id, $course_code, 0, null, $session_id); |
|
1238 | 1238 | $cats = array_merge($cats, $indcats); |
1239 | 1239 | } |
1240 | 1240 | |
@@ -1277,20 +1277,20 @@ discard block |
||
1277 | 1277 | $targets[] = $root; |
1278 | 1278 | |
1279 | 1279 | if (isset($this->course_code) && !empty($this->course_code)) { |
1280 | - $crscats = Category::load(null,null,$this->course_code,0); |
|
1280 | + $crscats = Category::load(null, null, $this->course_code, 0); |
|
1281 | 1281 | foreach ($crscats as $cat) { |
1282 | 1282 | if ($this->can_be_moved_to_cat($cat)) { |
1283 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
1284 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
1283 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
1284 | + $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); |
|
1285 | 1285 | } |
1286 | 1286 | } |
1287 | 1287 | } |
1288 | 1288 | |
1289 | - $indcats = Category::load(null,$user,0,0); |
|
1289 | + $indcats = Category::load(null, $user, 0, 0); |
|
1290 | 1290 | foreach ($indcats as $cat) { |
1291 | 1291 | if ($this->can_be_moved_to_cat($cat)) { |
1292 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
1293 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
1292 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
1293 | + $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); |
|
1294 | 1294 | } |
1295 | 1295 | } |
1296 | 1296 | |
@@ -1303,11 +1303,11 @@ discard block |
||
1303 | 1303 | */ |
1304 | 1304 | private function add_target_subcategories($targets, $level, $catid) |
1305 | 1305 | { |
1306 | - $subcats = Category::load(null,null,null,$catid); |
|
1306 | + $subcats = Category::load(null, null, null, $catid); |
|
1307 | 1307 | foreach ($subcats as $cat) { |
1308 | 1308 | if ($this->can_be_moved_to_cat($cat)) { |
1309 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
1310 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
1309 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
1310 | + $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); |
|
1311 | 1311 | } |
1312 | 1312 | } |
1313 | 1313 | |
@@ -1320,7 +1320,7 @@ discard block |
||
1320 | 1320 | * Impossible when origin and target are the same... children won't be processed |
1321 | 1321 | * either. (a category can't be moved to one of its own children) |
1322 | 1322 | */ |
1323 | - private function can_be_moved_to_cat ($cat) |
|
1323 | + private function can_be_moved_to_cat($cat) |
|
1324 | 1324 | { |
1325 | 1325 | return $cat->get_id() != $this->get_id(); |
1326 | 1326 | } |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | { |
1350 | 1350 | $cats = Category::load(null, null, null, $this->id, null); |
1351 | 1351 | $evals = Evaluation::load(null, null, null, $this->id, null); |
1352 | - $links = LinkFactory::load(null,null,null,null,null,$this->id,null); |
|
1352 | + $links = LinkFactory::load(null, null, null, null, null, $this->id, null); |
|
1353 | 1353 | |
1354 | 1354 | foreach ($cats as $cat) { |
1355 | 1355 | $cat->set_course_code($this->get_course_code()); |
@@ -1382,15 +1382,15 @@ discard block |
||
1382 | 1382 | $user = (api_is_platform_admin() ? null : api_get_user_id()); |
1383 | 1383 | $cats = Category::get_root_categories_for_teacher($user); |
1384 | 1384 | foreach ($cats as $cat) { |
1385 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
1386 | - $targets = Category::add_subtree($targets, $level+1, $cat->get_id(),null); |
|
1385 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
1386 | + $targets = Category::add_subtree($targets, $level + 1, $cat->get_id(), null); |
|
1387 | 1387 | } |
1388 | 1388 | } else { |
1389 | 1389 | // student |
1390 | 1390 | $cats = Category::get_root_categories_for_student(api_get_user_id()); |
1391 | 1391 | foreach ($cats as $cat) { |
1392 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
1393 | - $targets = Category::add_subtree($targets, $level+1, $cat->get_id(), 1); |
|
1392 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
1393 | + $targets = Category::add_subtree($targets, $level + 1, $cat->get_id(), 1); |
|
1394 | 1394 | } |
1395 | 1395 | } |
1396 | 1396 | |
@@ -1400,14 +1400,14 @@ discard block |
||
1400 | 1400 | /** |
1401 | 1401 | * Internal function used by get_tree() |
1402 | 1402 | */ |
1403 | - private function add_subtree ($targets, $level, $catid, $visible) |
|
1403 | + private function add_subtree($targets, $level, $catid, $visible) |
|
1404 | 1404 | { |
1405 | - $subcats = Category::load(null,null,null,$catid,$visible); |
|
1405 | + $subcats = Category::load(null, null, null, $catid, $visible); |
|
1406 | 1406 | |
1407 | 1407 | if (!empty($subcats)) { |
1408 | 1408 | foreach ($subcats as $cat) { |
1409 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
1410 | - $targets = Category::add_subtree($targets, $level+1, $cat->get_id(),$visible); |
|
1409 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
1410 | + $targets = Category::add_subtree($targets, $level + 1, $cat->get_id(), $visible); |
|
1411 | 1411 | } |
1412 | 1412 | } |
1413 | 1413 | |
@@ -1418,7 +1418,7 @@ discard block |
||
1418 | 1418 | * Generate an array of courses that a teacher hasn't created a category for. |
1419 | 1419 | * @return array 2-dimensional array - every element contains 2 subelements (code, title) |
1420 | 1420 | */ |
1421 | - public function get_not_created_course_categories ($user_id) |
|
1421 | + public function get_not_created_course_categories($user_id) |
|
1422 | 1422 | { |
1423 | 1423 | $tbl_main_courses = Database :: get_main_table(TABLE_MAIN_COURSE); |
1424 | 1424 | $tbl_main_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
@@ -1440,9 +1440,9 @@ discard block |
||
1440 | 1440 | )'; |
1441 | 1441 | $result = Database::query($sql); |
1442 | 1442 | |
1443 | - $cats=array(); |
|
1444 | - while ($data=Database::fetch_array($result)) { |
|
1445 | - $cats[] = array ($data['code'], $data['title']); |
|
1443 | + $cats = array(); |
|
1444 | + while ($data = Database::fetch_array($result)) { |
|
1445 | + $cats[] = array($data['code'], $data['title']); |
|
1446 | 1446 | } |
1447 | 1447 | |
1448 | 1448 | return $cats; |
@@ -1452,7 +1452,7 @@ discard block |
||
1452 | 1452 | * Generate an array of all courses that a teacher is admin of. |
1453 | 1453 | * @return array 2-dimensional array - every element contains 2 subelements (code, title) |
1454 | 1454 | */ |
1455 | - public function get_all_courses ($user_id) |
|
1455 | + public function get_all_courses($user_id) |
|
1456 | 1456 | { |
1457 | 1457 | $tbl_main_courses = Database :: get_main_table(TABLE_MAIN_COURSE); |
1458 | 1458 | $tbl_main_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
@@ -1466,7 +1466,7 @@ discard block |
||
1466 | 1466 | $result = Database::query($sql); |
1467 | 1467 | $cats = array(); |
1468 | 1468 | while ($data = Database::fetch_array($result)) { |
1469 | - $cats[] = array ($data['code'], $data['title']); |
|
1469 | + $cats[] = array($data['code'], $data['title']); |
|
1470 | 1470 | } |
1471 | 1471 | |
1472 | 1472 | return $cats; |
@@ -1479,7 +1479,7 @@ discard block |
||
1479 | 1479 | { |
1480 | 1480 | $cats = Category::load(null, null, null, $this->id, null); |
1481 | 1481 | $evals = Evaluation::load(null, null, null, $this->id, null); |
1482 | - $links = LinkFactory::load(null,null,null,null,null,$this->id,null); |
|
1482 | + $links = LinkFactory::load(null, null, null, null, null, $this->id, null); |
|
1483 | 1483 | if (!empty($cats)) { |
1484 | 1484 | foreach ($cats as $cat) { |
1485 | 1485 | $cat->set_visible($this->is_visible()); |
@@ -1834,7 +1834,7 @@ discard block |
||
1834 | 1834 | * @param string $name_mask search string |
1835 | 1835 | * @return array category objects matching the search criterium |
1836 | 1836 | */ |
1837 | - public function find_category($name_mask,$allcat) |
|
1837 | + public function find_category($name_mask, $allcat) |
|
1838 | 1838 | { |
1839 | 1839 | $foundcats = array(); |
1840 | 1840 | foreach ($allcat as $search_cat) { |
@@ -1877,9 +1877,9 @@ discard block |
||
1877 | 1877 | } |
1878 | 1878 | } |
1879 | 1879 | |
1880 | - $link_to_lock= $this->get_links(); |
|
1880 | + $link_to_lock = $this->get_links(); |
|
1881 | 1881 | if (!empty($link_to_lock)) { |
1882 | - foreach ($link_to_lock as $item ) { |
|
1882 | + foreach ($link_to_lock as $item) { |
|
1883 | 1883 | $item->lock($locked); |
1884 | 1884 | } |
1885 | 1885 | } |
@@ -1968,7 +1968,7 @@ discard block |
||
1968 | 1968 | return [ |
1969 | 1969 | 'badge_link' => Display::url( |
1970 | 1970 | get_lang('DownloadBadges'), |
1971 | - api_get_path(WEB_CODE_PATH) . "gradebook/get_badges.php?user=$user_id", |
|
1971 | + api_get_path(WEB_CODE_PATH)."gradebook/get_badges.php?user=$user_id", |
|
1972 | 1972 | array( |
1973 | 1973 | 'target' => '_blank', |
1974 | 1974 | 'class' => 'btn btn-default' |
@@ -2002,7 +2002,7 @@ discard block |
||
2002 | 2002 | $fileWasGenerated = $certificate_obj->html_file_is_generated(); |
2003 | 2003 | |
2004 | 2004 | if (!empty($fileWasGenerated)) { |
2005 | - $url = api_get_path(WEB_PATH) . 'certificates/index.php?id=' . $my_certificate['id']; |
|
2005 | + $url = api_get_path(WEB_PATH).'certificates/index.php?id='.$my_certificate['id']; |
|
2006 | 2006 | |
2007 | 2007 | $certificates = Display::url( |
2008 | 2008 | Display::returnFontAwesomeIcon('download').' '.get_lang('DownloadCertificate'), |
@@ -2025,7 +2025,7 @@ discard block |
||
2025 | 2025 | |
2026 | 2026 | $hideExportLink = api_get_setting('hide_certificate_export_link'); |
2027 | 2027 | $hideExportLinkStudent = api_get_setting('hide_certificate_export_link_students'); |
2028 | - if ($hideExportLink === 'true' || (api_is_student() && $hideExportLinkStudent === 'true') ) { |
|
2028 | + if ($hideExportLink === 'true' || (api_is_student() && $hideExportLinkStudent === 'true')) { |
|
2029 | 2029 | $exportToPDF = null; |
2030 | 2030 | } |
2031 | 2031 | |
@@ -2038,7 +2038,7 @@ discard block |
||
2038 | 2038 | if ($skillToolEnabled && $userHasSkills) { |
2039 | 2039 | $html['badge_link'] = Display::url( |
2040 | 2040 | get_lang('DownloadBadges'), |
2041 | - api_get_path(WEB_CODE_PATH) . "gradebook/get_badges.php?user=$user_id", |
|
2041 | + api_get_path(WEB_CODE_PATH)."gradebook/get_badges.php?user=$user_id", |
|
2042 | 2042 | array( |
2043 | 2043 | 'target' => '_blank', |
2044 | 2044 | 'class' => 'btn btn-default' |
@@ -2098,7 +2098,7 @@ discard block |
||
2098 | 2098 | $certificate_obj = new Certificate($value_certificate['id']); |
2099 | 2099 | $certificate_obj->generate(array('hide_print_button' => true)); |
2100 | 2100 | if ($certificate_obj->html_file_is_generated()) { |
2101 | - $certificate_path_list[]= $certificate_obj->html_file; |
|
2101 | + $certificate_path_list[] = $certificate_obj->html_file; |
|
2102 | 2102 | } |
2103 | 2103 | } |
2104 | 2104 | } |
@@ -1179,7 +1179,7 @@ |
||
1179 | 1179 | cu.status = '.COURSEMANAGER.' |
1180 | 1180 | )'; |
1181 | 1181 | } |
1182 | - }elseif (api_is_platform_admin()) { |
|
1182 | + } elseif (api_is_platform_admin()) { |
|
1183 | 1183 | if (isset($session_id) && $session_id!=0) { |
1184 | 1184 | $sql.=' AND session_id='.intval($session_id); |
1185 | 1185 | } else { |
@@ -81,6 +81,9 @@ discard block |
||
81 | 81 | return $this->name; |
82 | 82 | } |
83 | 83 | |
84 | + /** |
|
85 | + * @return string |
|
86 | + */ |
|
84 | 87 | public function get_description() |
85 | 88 | { |
86 | 89 | return $this->description; |
@@ -208,7 +211,7 @@ discard block |
||
208 | 211 | * @param int $user_id user id (evaluation owner) |
209 | 212 | * @param string $course_code course code |
210 | 213 | * @param int $category_id parent category |
211 | - * @param $visible visible |
|
214 | + * @param integer $visible visible |
|
212 | 215 | */ |
213 | 216 | public static function load( |
214 | 217 | $id = null, |
@@ -270,7 +273,7 @@ discard block |
||
270 | 273 | |
271 | 274 | |
272 | 275 | /** |
273 | - * @param array $result |
|
276 | + * @param Doctrine\DBAL\Driver\Statement|null $result |
|
274 | 277 | * @return array |
275 | 278 | */ |
276 | 279 | private static function create_evaluation_objects_from_sql_result($result) |
@@ -658,6 +661,7 @@ discard block |
||
658 | 661 | |
659 | 662 | /** |
660 | 663 | * Internal function used by get_target_categories() |
664 | + * @param integer $level |
|
661 | 665 | */ |
662 | 666 | private function add_target_subcategories($targets, $level, $catid) |
663 | 667 | { |
@@ -9,364 +9,364 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class Evaluation implements GradebookItem |
11 | 11 | { |
12 | - private $id; |
|
13 | - private $name; |
|
14 | - private $description; |
|
15 | - private $user_id; |
|
16 | - private $course_code; |
|
17 | - /** @var Category */ |
|
18 | - private $category; |
|
19 | - private $created_at; |
|
20 | - private $weight; |
|
21 | - private $eval_max; |
|
22 | - private $visible; |
|
23 | - private $sessionId; |
|
24 | - public $studentList; |
|
25 | - |
|
26 | - /** |
|
27 | - * Construct |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return Category |
|
35 | - */ |
|
36 | - public function getCategory() |
|
37 | - { |
|
38 | - return $this->category; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param Category $category |
|
43 | - */ |
|
44 | - public function setCategory($category) |
|
45 | - { |
|
46 | - $this->category = $category; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @return int |
|
51 | - */ |
|
52 | - public function get_category_id() |
|
53 | - { |
|
54 | - return $this->category->get_id(); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param int $category_id |
|
59 | - */ |
|
60 | - public function set_category_id($category_id) |
|
61 | - { |
|
62 | - $categories = Category::load($category_id); |
|
63 | - if (isset($categories[0])) { |
|
64 | - $this->setCategory($categories[0]); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return int |
|
70 | - */ |
|
71 | - public function get_id() |
|
72 | - { |
|
73 | - return $this->id; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function get_name() |
|
80 | - { |
|
81 | - return $this->name; |
|
82 | - } |
|
83 | - |
|
84 | - public function get_description() |
|
85 | - { |
|
86 | - return $this->description; |
|
87 | - } |
|
88 | - |
|
89 | - public function get_user_id() |
|
90 | - { |
|
91 | - return $this->user_id; |
|
92 | - } |
|
93 | - |
|
94 | - public function get_course_code() |
|
95 | - { |
|
96 | - return $this->course_code; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @return int |
|
101 | - */ |
|
102 | - public function getSessionId() |
|
103 | - { |
|
104 | - return $this->sessionId; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param int $sessionId |
|
109 | - */ |
|
110 | - public function setSessionId($sessionId) |
|
111 | - { |
|
112 | - $this->sessionId = intval($sessionId); |
|
113 | - } |
|
114 | - |
|
115 | - public function get_date() |
|
116 | - { |
|
117 | - return $this->created_at; |
|
118 | - } |
|
119 | - |
|
120 | - public function get_weight() |
|
121 | - { |
|
122 | - return $this->weight; |
|
123 | - } |
|
124 | - |
|
125 | - public function get_max() |
|
126 | - { |
|
127 | - return $this->eval_max; |
|
128 | - } |
|
129 | - |
|
130 | - public function get_type() |
|
131 | - { |
|
132 | - return $this->type; |
|
133 | - } |
|
134 | - |
|
135 | - public function is_visible() |
|
136 | - { |
|
137 | - return $this->visible; |
|
138 | - } |
|
139 | - |
|
140 | - public function get_locked() |
|
141 | - { |
|
142 | - return $this->locked; |
|
143 | - } |
|
144 | - |
|
145 | - public function is_locked() |
|
146 | - { |
|
147 | - return isset($this->locked) && $this->locked == 1 ? true : false; |
|
148 | - } |
|
149 | - |
|
150 | - public function set_id($id) |
|
151 | - { |
|
152 | - $this->id = $id; |
|
153 | - } |
|
154 | - |
|
155 | - public function set_name($name) |
|
156 | - { |
|
157 | - $this->name = $name; |
|
158 | - } |
|
159 | - |
|
160 | - public function set_description($description) |
|
161 | - { |
|
162 | - $this->description = $description; |
|
163 | - } |
|
164 | - |
|
165 | - public function set_user_id($user_id) |
|
166 | - { |
|
167 | - $this->user_id = $user_id; |
|
168 | - } |
|
169 | - |
|
170 | - public function set_course_code($course_code) |
|
171 | - { |
|
172 | - $this->course_code = $course_code; |
|
173 | - } |
|
174 | - |
|
175 | - public function set_date($date) |
|
176 | - { |
|
177 | - $this->created_at = $date; |
|
178 | - } |
|
179 | - |
|
180 | - public function set_weight($weight) |
|
181 | - { |
|
182 | - $this->weight = $weight; |
|
183 | - } |
|
184 | - |
|
185 | - public function set_max($max) |
|
186 | - { |
|
187 | - $this->eval_max = $max; |
|
188 | - } |
|
189 | - |
|
190 | - public function set_visible($visible) |
|
191 | - { |
|
192 | - $this->visible = $visible; |
|
193 | - } |
|
194 | - |
|
195 | - public function set_type($type) |
|
196 | - { |
|
197 | - $this->type = $type; |
|
198 | - } |
|
199 | - |
|
200 | - public function set_locked($locked) |
|
201 | - { |
|
202 | - $this->locked = $locked; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Retrieve evaluations and return them as an array of Evaluation objects |
|
207 | - * @param int $id evaluation id |
|
208 | - * @param int $user_id user id (evaluation owner) |
|
209 | - * @param string $course_code course code |
|
210 | - * @param int $category_id parent category |
|
211 | - * @param $visible visible |
|
212 | - */ |
|
213 | - public static function load( |
|
214 | - $id = null, |
|
215 | - $user_id = null, |
|
216 | - $course_code = null, |
|
217 | - $category_id = null, |
|
218 | - $visible = null, |
|
219 | - $locked = null |
|
220 | - ) { |
|
221 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
222 | - $sql = 'SELECT * FROM '.$tbl_grade_evaluations; |
|
223 | - $paramcount = 0; |
|
224 | - |
|
225 | - if (isset ($id)) { |
|
226 | - $sql.= ' WHERE id = '.intval($id); |
|
227 | - $paramcount ++; |
|
228 | - } |
|
229 | - |
|
230 | - if (isset ($user_id)) { |
|
231 | - if ($paramcount != 0) $sql .= ' AND'; |
|
232 | - else $sql .= ' WHERE'; |
|
233 | - $sql .= ' user_id = '.intval($user_id); |
|
234 | - $paramcount ++; |
|
235 | - } |
|
236 | - |
|
237 | - if (isset ($course_code) && $course_code <> '-1') { |
|
238 | - if ($paramcount != 0) $sql .= ' AND'; |
|
239 | - else $sql .= ' WHERE'; |
|
240 | - $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
|
241 | - $paramcount ++; |
|
242 | - } |
|
243 | - |
|
244 | - if (isset ($category_id)) { |
|
245 | - if ($paramcount != 0) $sql .= ' AND'; |
|
246 | - else $sql .= ' WHERE'; |
|
247 | - $sql .= ' category_id = '.intval($category_id); |
|
248 | - $paramcount ++; |
|
249 | - } |
|
250 | - |
|
251 | - if (isset ($visible)) { |
|
252 | - if ($paramcount != 0) $sql .= ' AND'; |
|
253 | - else $sql .= ' WHERE'; |
|
254 | - $sql .= ' visible = '.intval($visible); |
|
255 | - $paramcount ++; |
|
256 | - } |
|
257 | - |
|
258 | - if (isset ($locked)) { |
|
259 | - if ($paramcount != 0) $sql .= ' AND'; |
|
260 | - else $sql .= ' WHERE'; |
|
261 | - $sql .= ' locked = '.intval($locked); |
|
262 | - } |
|
263 | - |
|
264 | - $result = Database::query($sql); |
|
265 | - $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
266 | - |
|
267 | - return $alleval; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @param array $result |
|
274 | - * @return array |
|
275 | - */ |
|
276 | - private static function create_evaluation_objects_from_sql_result($result) |
|
277 | - { |
|
278 | - $alleval = array(); |
|
279 | - if (Database::num_rows($result)) { |
|
280 | - while ($data = Database::fetch_array($result)) { |
|
281 | - $eval= new Evaluation(); |
|
282 | - $eval->set_id($data['id']); |
|
283 | - $eval->set_name($data['name']); |
|
284 | - $eval->set_description($data['description']); |
|
285 | - $eval->set_user_id($data['user_id']); |
|
286 | - $eval->set_course_code($data['course_code']); |
|
287 | - $eval->set_category_id($data['category_id']); |
|
288 | - $eval->set_date(api_get_local_time($data['created_at'])); |
|
289 | - $eval->set_weight($data['weight']); |
|
290 | - $eval->set_max($data['max']); |
|
291 | - $eval->set_visible($data['visible']); |
|
292 | - $eval->set_type($data['type']); |
|
293 | - $eval->set_locked($data['locked']); |
|
294 | - $eval->setSessionId(api_get_session_id()); |
|
295 | - |
|
296 | - $alleval[] = $eval; |
|
297 | - } |
|
298 | - } |
|
299 | - |
|
300 | - return $alleval; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Insert this evaluation into the database |
|
305 | - */ |
|
306 | - public function add() |
|
307 | - { |
|
308 | - if (isset($this->name) && |
|
309 | - isset($this->user_id) && |
|
310 | - isset($this->weight) && |
|
311 | - isset ($this->eval_max) && |
|
312 | - isset($this->visible) |
|
313 | - ) { |
|
314 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
315 | - |
|
316 | - $sql = 'INSERT INTO '.$tbl_grade_evaluations |
|
317 | - .' (name, user_id, weight, max, visible'; |
|
318 | - if (isset($this->description)) { |
|
319 | - $sql .= ',description'; |
|
320 | - } |
|
321 | - if (isset($this->course_code)) { |
|
322 | - $sql .= ', course_code'; |
|
323 | - } |
|
324 | - if (isset($this->category)) { |
|
325 | - $sql .= ', category_id'; |
|
326 | - } |
|
327 | - $sql .= ', created_at'; |
|
328 | - $sql .= ',type'; |
|
329 | - $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" |
|
330 | - .','.intval($this->get_user_id()) |
|
331 | - .','.floatval($this->get_weight()) |
|
332 | - .','.intval($this->get_max()) |
|
333 | - .','.intval($this->is_visible()); |
|
334 | - if (isset($this->description)) { |
|
335 | - $sql .= ",'".Database::escape_string($this->get_description())."'"; |
|
336 | - } |
|
337 | - if (isset($this->course_code)) { |
|
338 | - $sql .= ",'".Database::escape_string($this->get_course_code())."'"; |
|
339 | - } |
|
340 | - if (isset($this->category)) { |
|
341 | - $sql .= ','.intval($this->get_category_id()); |
|
342 | - } |
|
343 | - if (empty($this->type)) { |
|
344 | - $this->type = 'evaluation'; |
|
345 | - } |
|
346 | - $sql .= ", '".api_get_utc_datetime()."'"; |
|
347 | - $sql .= ',\''.Database::escape_string($this->type).'\''; |
|
348 | - $sql .= ")"; |
|
349 | - |
|
350 | - Database::query($sql); |
|
351 | - $this->set_id(Database::insert_id()); |
|
352 | - } else { |
|
353 | - die('Error in Evaluation add: required field empty'); |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * @param int $idevaluation |
|
359 | - */ |
|
360 | - public function add_evaluation_log($idevaluation) |
|
361 | - { |
|
362 | - if (!empty($idevaluation)) { |
|
363 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
364 | - $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
|
365 | - $eval = new Evaluation(); |
|
366 | - $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
367 | - $arreval = get_object_vars($dateobject[0]); |
|
368 | - if (!empty($arreval['id'])) { |
|
369 | - $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
|
12 | + private $id; |
|
13 | + private $name; |
|
14 | + private $description; |
|
15 | + private $user_id; |
|
16 | + private $course_code; |
|
17 | + /** @var Category */ |
|
18 | + private $category; |
|
19 | + private $created_at; |
|
20 | + private $weight; |
|
21 | + private $eval_max; |
|
22 | + private $visible; |
|
23 | + private $sessionId; |
|
24 | + public $studentList; |
|
25 | + |
|
26 | + /** |
|
27 | + * Construct |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return Category |
|
35 | + */ |
|
36 | + public function getCategory() |
|
37 | + { |
|
38 | + return $this->category; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param Category $category |
|
43 | + */ |
|
44 | + public function setCategory($category) |
|
45 | + { |
|
46 | + $this->category = $category; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @return int |
|
51 | + */ |
|
52 | + public function get_category_id() |
|
53 | + { |
|
54 | + return $this->category->get_id(); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param int $category_id |
|
59 | + */ |
|
60 | + public function set_category_id($category_id) |
|
61 | + { |
|
62 | + $categories = Category::load($category_id); |
|
63 | + if (isset($categories[0])) { |
|
64 | + $this->setCategory($categories[0]); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return int |
|
70 | + */ |
|
71 | + public function get_id() |
|
72 | + { |
|
73 | + return $this->id; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function get_name() |
|
80 | + { |
|
81 | + return $this->name; |
|
82 | + } |
|
83 | + |
|
84 | + public function get_description() |
|
85 | + { |
|
86 | + return $this->description; |
|
87 | + } |
|
88 | + |
|
89 | + public function get_user_id() |
|
90 | + { |
|
91 | + return $this->user_id; |
|
92 | + } |
|
93 | + |
|
94 | + public function get_course_code() |
|
95 | + { |
|
96 | + return $this->course_code; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @return int |
|
101 | + */ |
|
102 | + public function getSessionId() |
|
103 | + { |
|
104 | + return $this->sessionId; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param int $sessionId |
|
109 | + */ |
|
110 | + public function setSessionId($sessionId) |
|
111 | + { |
|
112 | + $this->sessionId = intval($sessionId); |
|
113 | + } |
|
114 | + |
|
115 | + public function get_date() |
|
116 | + { |
|
117 | + return $this->created_at; |
|
118 | + } |
|
119 | + |
|
120 | + public function get_weight() |
|
121 | + { |
|
122 | + return $this->weight; |
|
123 | + } |
|
124 | + |
|
125 | + public function get_max() |
|
126 | + { |
|
127 | + return $this->eval_max; |
|
128 | + } |
|
129 | + |
|
130 | + public function get_type() |
|
131 | + { |
|
132 | + return $this->type; |
|
133 | + } |
|
134 | + |
|
135 | + public function is_visible() |
|
136 | + { |
|
137 | + return $this->visible; |
|
138 | + } |
|
139 | + |
|
140 | + public function get_locked() |
|
141 | + { |
|
142 | + return $this->locked; |
|
143 | + } |
|
144 | + |
|
145 | + public function is_locked() |
|
146 | + { |
|
147 | + return isset($this->locked) && $this->locked == 1 ? true : false; |
|
148 | + } |
|
149 | + |
|
150 | + public function set_id($id) |
|
151 | + { |
|
152 | + $this->id = $id; |
|
153 | + } |
|
154 | + |
|
155 | + public function set_name($name) |
|
156 | + { |
|
157 | + $this->name = $name; |
|
158 | + } |
|
159 | + |
|
160 | + public function set_description($description) |
|
161 | + { |
|
162 | + $this->description = $description; |
|
163 | + } |
|
164 | + |
|
165 | + public function set_user_id($user_id) |
|
166 | + { |
|
167 | + $this->user_id = $user_id; |
|
168 | + } |
|
169 | + |
|
170 | + public function set_course_code($course_code) |
|
171 | + { |
|
172 | + $this->course_code = $course_code; |
|
173 | + } |
|
174 | + |
|
175 | + public function set_date($date) |
|
176 | + { |
|
177 | + $this->created_at = $date; |
|
178 | + } |
|
179 | + |
|
180 | + public function set_weight($weight) |
|
181 | + { |
|
182 | + $this->weight = $weight; |
|
183 | + } |
|
184 | + |
|
185 | + public function set_max($max) |
|
186 | + { |
|
187 | + $this->eval_max = $max; |
|
188 | + } |
|
189 | + |
|
190 | + public function set_visible($visible) |
|
191 | + { |
|
192 | + $this->visible = $visible; |
|
193 | + } |
|
194 | + |
|
195 | + public function set_type($type) |
|
196 | + { |
|
197 | + $this->type = $type; |
|
198 | + } |
|
199 | + |
|
200 | + public function set_locked($locked) |
|
201 | + { |
|
202 | + $this->locked = $locked; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Retrieve evaluations and return them as an array of Evaluation objects |
|
207 | + * @param int $id evaluation id |
|
208 | + * @param int $user_id user id (evaluation owner) |
|
209 | + * @param string $course_code course code |
|
210 | + * @param int $category_id parent category |
|
211 | + * @param $visible visible |
|
212 | + */ |
|
213 | + public static function load( |
|
214 | + $id = null, |
|
215 | + $user_id = null, |
|
216 | + $course_code = null, |
|
217 | + $category_id = null, |
|
218 | + $visible = null, |
|
219 | + $locked = null |
|
220 | + ) { |
|
221 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
222 | + $sql = 'SELECT * FROM '.$tbl_grade_evaluations; |
|
223 | + $paramcount = 0; |
|
224 | + |
|
225 | + if (isset ($id)) { |
|
226 | + $sql.= ' WHERE id = '.intval($id); |
|
227 | + $paramcount ++; |
|
228 | + } |
|
229 | + |
|
230 | + if (isset ($user_id)) { |
|
231 | + if ($paramcount != 0) $sql .= ' AND'; |
|
232 | + else $sql .= ' WHERE'; |
|
233 | + $sql .= ' user_id = '.intval($user_id); |
|
234 | + $paramcount ++; |
|
235 | + } |
|
236 | + |
|
237 | + if (isset ($course_code) && $course_code <> '-1') { |
|
238 | + if ($paramcount != 0) $sql .= ' AND'; |
|
239 | + else $sql .= ' WHERE'; |
|
240 | + $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
|
241 | + $paramcount ++; |
|
242 | + } |
|
243 | + |
|
244 | + if (isset ($category_id)) { |
|
245 | + if ($paramcount != 0) $sql .= ' AND'; |
|
246 | + else $sql .= ' WHERE'; |
|
247 | + $sql .= ' category_id = '.intval($category_id); |
|
248 | + $paramcount ++; |
|
249 | + } |
|
250 | + |
|
251 | + if (isset ($visible)) { |
|
252 | + if ($paramcount != 0) $sql .= ' AND'; |
|
253 | + else $sql .= ' WHERE'; |
|
254 | + $sql .= ' visible = '.intval($visible); |
|
255 | + $paramcount ++; |
|
256 | + } |
|
257 | + |
|
258 | + if (isset ($locked)) { |
|
259 | + if ($paramcount != 0) $sql .= ' AND'; |
|
260 | + else $sql .= ' WHERE'; |
|
261 | + $sql .= ' locked = '.intval($locked); |
|
262 | + } |
|
263 | + |
|
264 | + $result = Database::query($sql); |
|
265 | + $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
266 | + |
|
267 | + return $alleval; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @param array $result |
|
274 | + * @return array |
|
275 | + */ |
|
276 | + private static function create_evaluation_objects_from_sql_result($result) |
|
277 | + { |
|
278 | + $alleval = array(); |
|
279 | + if (Database::num_rows($result)) { |
|
280 | + while ($data = Database::fetch_array($result)) { |
|
281 | + $eval= new Evaluation(); |
|
282 | + $eval->set_id($data['id']); |
|
283 | + $eval->set_name($data['name']); |
|
284 | + $eval->set_description($data['description']); |
|
285 | + $eval->set_user_id($data['user_id']); |
|
286 | + $eval->set_course_code($data['course_code']); |
|
287 | + $eval->set_category_id($data['category_id']); |
|
288 | + $eval->set_date(api_get_local_time($data['created_at'])); |
|
289 | + $eval->set_weight($data['weight']); |
|
290 | + $eval->set_max($data['max']); |
|
291 | + $eval->set_visible($data['visible']); |
|
292 | + $eval->set_type($data['type']); |
|
293 | + $eval->set_locked($data['locked']); |
|
294 | + $eval->setSessionId(api_get_session_id()); |
|
295 | + |
|
296 | + $alleval[] = $eval; |
|
297 | + } |
|
298 | + } |
|
299 | + |
|
300 | + return $alleval; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Insert this evaluation into the database |
|
305 | + */ |
|
306 | + public function add() |
|
307 | + { |
|
308 | + if (isset($this->name) && |
|
309 | + isset($this->user_id) && |
|
310 | + isset($this->weight) && |
|
311 | + isset ($this->eval_max) && |
|
312 | + isset($this->visible) |
|
313 | + ) { |
|
314 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
315 | + |
|
316 | + $sql = 'INSERT INTO '.$tbl_grade_evaluations |
|
317 | + .' (name, user_id, weight, max, visible'; |
|
318 | + if (isset($this->description)) { |
|
319 | + $sql .= ',description'; |
|
320 | + } |
|
321 | + if (isset($this->course_code)) { |
|
322 | + $sql .= ', course_code'; |
|
323 | + } |
|
324 | + if (isset($this->category)) { |
|
325 | + $sql .= ', category_id'; |
|
326 | + } |
|
327 | + $sql .= ', created_at'; |
|
328 | + $sql .= ',type'; |
|
329 | + $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" |
|
330 | + .','.intval($this->get_user_id()) |
|
331 | + .','.floatval($this->get_weight()) |
|
332 | + .','.intval($this->get_max()) |
|
333 | + .','.intval($this->is_visible()); |
|
334 | + if (isset($this->description)) { |
|
335 | + $sql .= ",'".Database::escape_string($this->get_description())."'"; |
|
336 | + } |
|
337 | + if (isset($this->course_code)) { |
|
338 | + $sql .= ",'".Database::escape_string($this->get_course_code())."'"; |
|
339 | + } |
|
340 | + if (isset($this->category)) { |
|
341 | + $sql .= ','.intval($this->get_category_id()); |
|
342 | + } |
|
343 | + if (empty($this->type)) { |
|
344 | + $this->type = 'evaluation'; |
|
345 | + } |
|
346 | + $sql .= ", '".api_get_utc_datetime()."'"; |
|
347 | + $sql .= ',\''.Database::escape_string($this->type).'\''; |
|
348 | + $sql .= ")"; |
|
349 | + |
|
350 | + Database::query($sql); |
|
351 | + $this->set_id(Database::insert_id()); |
|
352 | + } else { |
|
353 | + die('Error in Evaluation add: required field empty'); |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * @param int $idevaluation |
|
359 | + */ |
|
360 | + public function add_evaluation_log($idevaluation) |
|
361 | + { |
|
362 | + if (!empty($idevaluation)) { |
|
363 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
364 | + $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
|
365 | + $eval = new Evaluation(); |
|
366 | + $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
367 | + $arreval = get_object_vars($dateobject[0]); |
|
368 | + if (!empty($arreval['id'])) { |
|
369 | + $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
|
370 | 370 | WHERE id='.$arreval['id']; |
371 | 371 | $rs = Database::query($sql); |
372 | 372 | $row_old_weight = Database::fetch_array($rs, 'ASSOC'); |
@@ -382,425 +382,425 @@ discard block |
||
382 | 382 | 'user_id_log' => api_get_user_id() |
383 | 383 | ]; |
384 | 384 | Database::insert($tbl_grade_linkeval_log, $params); |
385 | - } |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Update the properties of this evaluation in the database |
|
391 | - */ |
|
392 | - public function save() |
|
393 | - { |
|
394 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
395 | - $sql = 'UPDATE '.$tbl_grade_evaluations |
|
396 | - ." SET name = '".Database::escape_string($this->get_name())."'" |
|
397 | - .', description = '; |
|
398 | - if (isset($this->description)) { |
|
399 | - $sql .= "'".Database::escape_string($this->get_description())."'"; |
|
400 | - }else { |
|
401 | - $sql .= 'null'; |
|
402 | - } |
|
403 | - $sql .= ', user_id = '.intval($this->get_user_id()) |
|
404 | - .', course_code = '; |
|
405 | - if (isset($this->course_code)) { |
|
406 | - $sql .= "'".Database::escape_string($this->get_course_code())."'"; |
|
407 | - } else { |
|
408 | - $sql .= 'null'; |
|
409 | - } |
|
410 | - $sql .= ', category_id = '; |
|
411 | - if (isset($this->category)) { |
|
412 | - $sql .= intval($this->get_category_id()); |
|
413 | - } else { |
|
414 | - $sql .= 'null'; |
|
415 | - } |
|
416 | - $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" ' |
|
417 | - .', max = '.intval($this->get_max()) |
|
418 | - .', visible = '.intval($this->is_visible()) |
|
419 | - .' WHERE id = '.intval($this->id); |
|
420 | - //recorded history |
|
421 | - |
|
422 | - $eval_log = new Evaluation(); |
|
423 | - $eval_log->add_evaluation_log($this->id); |
|
424 | - Database::query($sql); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Delete this evaluation from the database |
|
429 | - */ |
|
430 | - public function delete() |
|
431 | - { |
|
432 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
433 | - $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); |
|
434 | - Database::query($sql); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Check if an evaluation name (with the same parent category) already exists |
|
439 | - * @param $name name to check (if not given, the name property of this object will be checked) |
|
440 | - * @param $parent parent category |
|
441 | - */ |
|
442 | - public function does_name_exist($name, $parent) |
|
443 | - { |
|
444 | - if (!isset ($name)) { |
|
445 | - $name = $this->name; |
|
446 | - $parent = $this->category; |
|
447 | - } |
|
448 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
449 | - $sql = 'SELECT count(id) AS number' |
|
450 | - .' FROM '.$tbl_grade_evaluations |
|
451 | - ." WHERE name = '".Database::escape_string($name)."'"; |
|
452 | - |
|
453 | - if (api_is_allowed_to_edit()) { |
|
454 | - $parent = Category::load($parent); |
|
455 | - $code = $parent[0]->get_course_code(); |
|
456 | - $courseInfo = api_get_course_info($code); |
|
457 | - $courseId = $courseInfo['real_id']; |
|
458 | - |
|
459 | - if (isset($code) && $code != '0') { |
|
460 | - $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
|
461 | - $sql .= ' AND user_id IN ( |
|
385 | + } |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Update the properties of this evaluation in the database |
|
391 | + */ |
|
392 | + public function save() |
|
393 | + { |
|
394 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
395 | + $sql = 'UPDATE '.$tbl_grade_evaluations |
|
396 | + ." SET name = '".Database::escape_string($this->get_name())."'" |
|
397 | + .', description = '; |
|
398 | + if (isset($this->description)) { |
|
399 | + $sql .= "'".Database::escape_string($this->get_description())."'"; |
|
400 | + }else { |
|
401 | + $sql .= 'null'; |
|
402 | + } |
|
403 | + $sql .= ', user_id = '.intval($this->get_user_id()) |
|
404 | + .', course_code = '; |
|
405 | + if (isset($this->course_code)) { |
|
406 | + $sql .= "'".Database::escape_string($this->get_course_code())."'"; |
|
407 | + } else { |
|
408 | + $sql .= 'null'; |
|
409 | + } |
|
410 | + $sql .= ', category_id = '; |
|
411 | + if (isset($this->category)) { |
|
412 | + $sql .= intval($this->get_category_id()); |
|
413 | + } else { |
|
414 | + $sql .= 'null'; |
|
415 | + } |
|
416 | + $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" ' |
|
417 | + .', max = '.intval($this->get_max()) |
|
418 | + .', visible = '.intval($this->is_visible()) |
|
419 | + .' WHERE id = '.intval($this->id); |
|
420 | + //recorded history |
|
421 | + |
|
422 | + $eval_log = new Evaluation(); |
|
423 | + $eval_log->add_evaluation_log($this->id); |
|
424 | + Database::query($sql); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Delete this evaluation from the database |
|
429 | + */ |
|
430 | + public function delete() |
|
431 | + { |
|
432 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
433 | + $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); |
|
434 | + Database::query($sql); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Check if an evaluation name (with the same parent category) already exists |
|
439 | + * @param $name name to check (if not given, the name property of this object will be checked) |
|
440 | + * @param $parent parent category |
|
441 | + */ |
|
442 | + public function does_name_exist($name, $parent) |
|
443 | + { |
|
444 | + if (!isset ($name)) { |
|
445 | + $name = $this->name; |
|
446 | + $parent = $this->category; |
|
447 | + } |
|
448 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
449 | + $sql = 'SELECT count(id) AS number' |
|
450 | + .' FROM '.$tbl_grade_evaluations |
|
451 | + ." WHERE name = '".Database::escape_string($name)."'"; |
|
452 | + |
|
453 | + if (api_is_allowed_to_edit()) { |
|
454 | + $parent = Category::load($parent); |
|
455 | + $code = $parent[0]->get_course_code(); |
|
456 | + $courseInfo = api_get_course_info($code); |
|
457 | + $courseId = $courseInfo['real_id']; |
|
458 | + |
|
459 | + if (isset($code) && $code != '0') { |
|
460 | + $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
|
461 | + $sql .= ' AND user_id IN ( |
|
462 | 462 | SELECT user_id FROM '.$main_course_user_table.' |
463 | 463 | WHERE |
464 | 464 | c_id = '.$courseId.' AND |
465 | 465 | status = '.COURSEMANAGER.' |
466 | 466 | )'; |
467 | - } else { |
|
468 | - $sql .= ' AND user_id = '.api_get_user_id(); |
|
469 | - } |
|
470 | - |
|
471 | - }else { |
|
472 | - $sql .= ' AND user_id = '.api_get_user_id(); |
|
473 | - } |
|
474 | - |
|
475 | - if (!isset ($parent)) { |
|
476 | - $sql.= ' AND category_id is null'; |
|
477 | - } else { |
|
478 | - $sql.= ' AND category_id = '.intval($parent); |
|
479 | - } |
|
480 | - $result = Database::query($sql); |
|
481 | - $number=Database::fetch_row($result); |
|
482 | - |
|
483 | - return $number[0] != 0; |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Are there any results for this evaluation yet ? |
|
488 | - * The 'max' property should not be changed then. |
|
489 | - */ |
|
490 | - public function has_results() |
|
491 | - { |
|
492 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
493 | - $sql = 'SELECT count(id) AS number |
|
467 | + } else { |
|
468 | + $sql .= ' AND user_id = '.api_get_user_id(); |
|
469 | + } |
|
470 | + |
|
471 | + }else { |
|
472 | + $sql .= ' AND user_id = '.api_get_user_id(); |
|
473 | + } |
|
474 | + |
|
475 | + if (!isset ($parent)) { |
|
476 | + $sql.= ' AND category_id is null'; |
|
477 | + } else { |
|
478 | + $sql.= ' AND category_id = '.intval($parent); |
|
479 | + } |
|
480 | + $result = Database::query($sql); |
|
481 | + $number=Database::fetch_row($result); |
|
482 | + |
|
483 | + return $number[0] != 0; |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Are there any results for this evaluation yet ? |
|
488 | + * The 'max' property should not be changed then. |
|
489 | + */ |
|
490 | + public function has_results() |
|
491 | + { |
|
492 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
493 | + $sql = 'SELECT count(id) AS number |
|
494 | 494 | FROM '.$tbl_grade_results.' |
495 | 495 | WHERE evaluation_id = '.intval($this->id); |
496 | - $result = Database::query($sql); |
|
497 | - $number=Database::fetch_row($result); |
|
498 | - |
|
499 | - return ($number[0] != 0); |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Delete all results for this evaluation |
|
504 | - */ |
|
505 | - public function delete_results() |
|
506 | - { |
|
507 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
508 | - $sql = 'DELETE FROM '.$tbl_grade_results.' |
|
496 | + $result = Database::query($sql); |
|
497 | + $number=Database::fetch_row($result); |
|
498 | + |
|
499 | + return ($number[0] != 0); |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Delete all results for this evaluation |
|
504 | + */ |
|
505 | + public function delete_results() |
|
506 | + { |
|
507 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
508 | + $sql = 'DELETE FROM '.$tbl_grade_results.' |
|
509 | 509 | WHERE evaluation_id = '.intval($this->id); |
510 | - Database::query($sql); |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * Delete this evaluation and all underlying results. |
|
515 | - */ |
|
516 | - public function delete_with_results() |
|
517 | - { |
|
518 | - $this->delete_results(); |
|
519 | - $this->delete(); |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * Check if the given score is possible for this evaluation |
|
524 | - */ |
|
525 | - public function is_valid_score($score) |
|
526 | - { |
|
527 | - return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * Calculate the score of this evaluation |
|
532 | - * @param int $stud_id (default: all students who have results for this eval - then the average is returned) |
|
533 | - * @param string $type (best, average, ranking) |
|
534 | - * @return array (score, max) if student is given |
|
535 | - * array (sum of scores, number of scores) otherwise |
|
536 | - * or null if no scores available |
|
537 | - */ |
|
538 | - public function calc_score($stud_id = null, $type = null) |
|
539 | - { |
|
510 | + Database::query($sql); |
|
511 | + } |
|
512 | + |
|
513 | + /** |
|
514 | + * Delete this evaluation and all underlying results. |
|
515 | + */ |
|
516 | + public function delete_with_results() |
|
517 | + { |
|
518 | + $this->delete_results(); |
|
519 | + $this->delete(); |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * Check if the given score is possible for this evaluation |
|
524 | + */ |
|
525 | + public function is_valid_score($score) |
|
526 | + { |
|
527 | + return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * Calculate the score of this evaluation |
|
532 | + * @param int $stud_id (default: all students who have results for this eval - then the average is returned) |
|
533 | + * @param string $type (best, average, ranking) |
|
534 | + * @return array (score, max) if student is given |
|
535 | + * array (sum of scores, number of scores) otherwise |
|
536 | + * or null if no scores available |
|
537 | + */ |
|
538 | + public function calc_score($stud_id = null, $type = null) |
|
539 | + { |
|
540 | 540 | $useSession = true; |
541 | - if (isset($stud_id) && empty($type)) { |
|
542 | - $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; |
|
543 | - $data = Session::read('calc_score'); |
|
541 | + if (isset($stud_id) && empty($type)) { |
|
542 | + $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; |
|
543 | + $data = Session::read('calc_score'); |
|
544 | 544 | $results = isset($data[$key]) ? $data[$key] : null; |
545 | 545 | |
546 | 546 | if ($useSession == false) { |
547 | 547 | $results = null; |
548 | 548 | } |
549 | - if (empty($results)) { |
|
550 | - $results = Result::load(null, $stud_id, $this->id); |
|
551 | - Session::write('calc_score', array($key => $results)); |
|
552 | - } |
|
553 | - |
|
554 | - $score = 0; |
|
555 | - /** @var Result $res */ |
|
556 | - foreach ($results as $res) { |
|
557 | - $score = $res->get_score(); |
|
558 | - } |
|
559 | - |
|
560 | - return array($score, $this->get_max()); |
|
561 | - } else { |
|
562 | - |
|
563 | - $count = 0; |
|
564 | - $sum = 0; |
|
565 | - $bestResult = 0; |
|
566 | - $weight = 0; |
|
567 | - $sumResult = 0; |
|
568 | - |
|
569 | - $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id; |
|
549 | + if (empty($results)) { |
|
550 | + $results = Result::load(null, $stud_id, $this->id); |
|
551 | + Session::write('calc_score', array($key => $results)); |
|
552 | + } |
|
553 | + |
|
554 | + $score = 0; |
|
555 | + /** @var Result $res */ |
|
556 | + foreach ($results as $res) { |
|
557 | + $score = $res->get_score(); |
|
558 | + } |
|
559 | + |
|
560 | + return array($score, $this->get_max()); |
|
561 | + } else { |
|
562 | + |
|
563 | + $count = 0; |
|
564 | + $sum = 0; |
|
565 | + $bestResult = 0; |
|
566 | + $weight = 0; |
|
567 | + $sumResult = 0; |
|
568 | + |
|
569 | + $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id; |
|
570 | 570 | $data = Session::read('calc_score'); |
571 | 571 | $allResults = isset($data[$key]) ? $data[$key] : null; |
572 | 572 | if ($useSession == false) { |
573 | 573 | $allResults = null; |
574 | 574 | } |
575 | - if (empty($allResults)) { |
|
576 | - $allResults = Result::load(null, null, $this->id); |
|
577 | - Session::write($key, $allResults); |
|
578 | - } |
|
579 | - |
|
580 | - $students = array(); |
|
581 | - /** @var Result $res */ |
|
582 | - foreach ($allResults as $res) { |
|
583 | - $score = $res->get_score(); |
|
584 | - if (!empty($score) || $score == '0') { |
|
585 | - $count++; |
|
586 | - $sum += $score / $this->get_max(); |
|
587 | - $sumResult += $score; |
|
588 | - if ($score > $bestResult) { |
|
589 | - $bestResult = $score; |
|
590 | - } |
|
591 | - $weight = $this->get_max(); |
|
592 | - } |
|
593 | - $students[$res->get_user_id()] = $score; |
|
594 | - } |
|
595 | - |
|
596 | - if (empty($count)) { |
|
597 | - return null; |
|
598 | - } |
|
599 | - |
|
600 | - switch ($type) { |
|
601 | - case 'best': |
|
602 | - return array($bestResult, $weight); |
|
603 | - break; |
|
604 | - case 'average': |
|
605 | - return array($sumResult/$count, $weight); |
|
606 | - break; |
|
607 | - case 'ranking': |
|
575 | + if (empty($allResults)) { |
|
576 | + $allResults = Result::load(null, null, $this->id); |
|
577 | + Session::write($key, $allResults); |
|
578 | + } |
|
579 | + |
|
580 | + $students = array(); |
|
581 | + /** @var Result $res */ |
|
582 | + foreach ($allResults as $res) { |
|
583 | + $score = $res->get_score(); |
|
584 | + if (!empty($score) || $score == '0') { |
|
585 | + $count++; |
|
586 | + $sum += $score / $this->get_max(); |
|
587 | + $sumResult += $score; |
|
588 | + if ($score > $bestResult) { |
|
589 | + $bestResult = $score; |
|
590 | + } |
|
591 | + $weight = $this->get_max(); |
|
592 | + } |
|
593 | + $students[$res->get_user_id()] = $score; |
|
594 | + } |
|
595 | + |
|
596 | + if (empty($count)) { |
|
597 | + return null; |
|
598 | + } |
|
599 | + |
|
600 | + switch ($type) { |
|
601 | + case 'best': |
|
602 | + return array($bestResult, $weight); |
|
603 | + break; |
|
604 | + case 'average': |
|
605 | + return array($sumResult/$count, $weight); |
|
606 | + break; |
|
607 | + case 'ranking': |
|
608 | 608 | $students = array(); |
609 | 609 | /** @var Result $res */ |
610 | 610 | foreach ($allResults as $res) { |
611 | 611 | $score = $res->get_score(); |
612 | 612 | $students[$res->get_user_id()] = $score; |
613 | 613 | } |
614 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
615 | - break; |
|
616 | - default: |
|
617 | - return array($sum, $count); |
|
618 | - break; |
|
619 | - } |
|
620 | - } |
|
621 | - } |
|
622 | - |
|
623 | - /** |
|
624 | - * Generate an array of possible categories where this evaluation can be moved to. |
|
625 | - * Notice: its own parent will be included in the list: it's up to the frontend |
|
626 | - * to disable this element. |
|
627 | - * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
|
628 | - */ |
|
629 | - public function get_target_categories() |
|
630 | - { |
|
631 | - // - course independent evaluation |
|
632 | - // -> movable to root or other course independent categories |
|
633 | - // - evaluation inside a course |
|
634 | - // -> movable to root, independent categories or categories inside the course |
|
635 | - $user = (api_is_platform_admin() ? null : api_get_user_id()); |
|
636 | - $targets = array(); |
|
637 | - $level = 0; |
|
638 | - |
|
639 | - $root = array(0, get_lang('RootCat'), $level); |
|
640 | - $targets[] = $root; |
|
641 | - |
|
642 | - if (isset($this->course_code) && !empty($this->course_code)) { |
|
643 | - $crscats = Category::load(null,null,$this->course_code,0); |
|
644 | - foreach ($crscats as $cat) { |
|
645 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
646 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
647 | - } |
|
648 | - } |
|
649 | - |
|
650 | - $indcats = Category::load(null,$user,0,0); |
|
651 | - foreach ($indcats as $cat) { |
|
652 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
653 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
654 | - } |
|
655 | - |
|
656 | - return $targets; |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Internal function used by get_target_categories() |
|
661 | - */ |
|
662 | - private function add_target_subcategories($targets, $level, $catid) |
|
663 | - { |
|
664 | - $subcats = Category::load(null,null,null,$catid); |
|
665 | - foreach ($subcats as $cat) { |
|
666 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
667 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
668 | - } |
|
669 | - return $targets; |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Move this evaluation to the given category. |
|
674 | - * If this evaluation moves from inside a course to outside, |
|
675 | - * its course code is also changed. |
|
676 | - */ |
|
677 | - public function move_to_cat($cat) |
|
678 | - { |
|
679 | - $this->set_category_id($cat->get_id()); |
|
680 | - if ($this->get_course_code() != $cat->get_course_code()) { |
|
681 | - $this->set_course_code($cat->get_course_code()); |
|
682 | - } |
|
683 | - $this->save(); |
|
684 | - } |
|
685 | - |
|
686 | - /** |
|
687 | - * Retrieve evaluations where a student has results for |
|
688 | - * and return them as an array of Evaluation objects |
|
689 | - * @param int $cat_id parent category (use 'null' to retrieve them in all categories) |
|
690 | - * @param int $stud_id student id |
|
691 | - */ |
|
692 | - public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id) |
|
693 | - { |
|
694 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
695 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
696 | - |
|
697 | - $sql = 'SELECT * FROM '.$tbl_grade_evaluations.' |
|
614 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
615 | + break; |
|
616 | + default: |
|
617 | + return array($sum, $count); |
|
618 | + break; |
|
619 | + } |
|
620 | + } |
|
621 | + } |
|
622 | + |
|
623 | + /** |
|
624 | + * Generate an array of possible categories where this evaluation can be moved to. |
|
625 | + * Notice: its own parent will be included in the list: it's up to the frontend |
|
626 | + * to disable this element. |
|
627 | + * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
|
628 | + */ |
|
629 | + public function get_target_categories() |
|
630 | + { |
|
631 | + // - course independent evaluation |
|
632 | + // -> movable to root or other course independent categories |
|
633 | + // - evaluation inside a course |
|
634 | + // -> movable to root, independent categories or categories inside the course |
|
635 | + $user = (api_is_platform_admin() ? null : api_get_user_id()); |
|
636 | + $targets = array(); |
|
637 | + $level = 0; |
|
638 | + |
|
639 | + $root = array(0, get_lang('RootCat'), $level); |
|
640 | + $targets[] = $root; |
|
641 | + |
|
642 | + if (isset($this->course_code) && !empty($this->course_code)) { |
|
643 | + $crscats = Category::load(null,null,$this->course_code,0); |
|
644 | + foreach ($crscats as $cat) { |
|
645 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
646 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
647 | + } |
|
648 | + } |
|
649 | + |
|
650 | + $indcats = Category::load(null,$user,0,0); |
|
651 | + foreach ($indcats as $cat) { |
|
652 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
653 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
654 | + } |
|
655 | + |
|
656 | + return $targets; |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Internal function used by get_target_categories() |
|
661 | + */ |
|
662 | + private function add_target_subcategories($targets, $level, $catid) |
|
663 | + { |
|
664 | + $subcats = Category::load(null,null,null,$catid); |
|
665 | + foreach ($subcats as $cat) { |
|
666 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
667 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
668 | + } |
|
669 | + return $targets; |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Move this evaluation to the given category. |
|
674 | + * If this evaluation moves from inside a course to outside, |
|
675 | + * its course code is also changed. |
|
676 | + */ |
|
677 | + public function move_to_cat($cat) |
|
678 | + { |
|
679 | + $this->set_category_id($cat->get_id()); |
|
680 | + if ($this->get_course_code() != $cat->get_course_code()) { |
|
681 | + $this->set_course_code($cat->get_course_code()); |
|
682 | + } |
|
683 | + $this->save(); |
|
684 | + } |
|
685 | + |
|
686 | + /** |
|
687 | + * Retrieve evaluations where a student has results for |
|
688 | + * and return them as an array of Evaluation objects |
|
689 | + * @param int $cat_id parent category (use 'null' to retrieve them in all categories) |
|
690 | + * @param int $stud_id student id |
|
691 | + */ |
|
692 | + public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id) |
|
693 | + { |
|
694 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
695 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
696 | + |
|
697 | + $sql = 'SELECT * FROM '.$tbl_grade_evaluations.' |
|
698 | 698 | WHERE id IN ( |
699 | 699 | SELECT evaluation_id FROM '.$tbl_grade_results.' |
700 | 700 | WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL |
701 | 701 | )'; |
702 | - if (!api_is_allowed_to_edit()) { |
|
703 | - $sql .= ' AND visible = 1'; |
|
704 | - } |
|
705 | - if (isset($cat_id)) { |
|
706 | - $sql .= ' AND category_id = '.intval($cat_id); |
|
707 | - } else { |
|
708 | - $sql .= ' AND category_id >= 0'; |
|
709 | - } |
|
710 | - |
|
711 | - $result = Database::query($sql); |
|
712 | - $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
713 | - |
|
714 | - return $alleval; |
|
715 | - } |
|
716 | - |
|
717 | - /** |
|
718 | - * Get a list of students that do not have a result record for this evaluation |
|
719 | - */ |
|
720 | - public function get_not_subscribed_students($first_letter_user = '') |
|
721 | - { |
|
722 | - $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
723 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
724 | - |
|
725 | - $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
|
726 | - ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'" |
|
727 | - .' AND status = '.STUDENT |
|
728 | - .' AND user_id NOT IN' |
|
729 | - .' (SELECT user_id FROM '.$tbl_grade_results |
|
730 | - .' WHERE evaluation_id = '.intval($this->id) |
|
731 | - .' )' |
|
732 | - .' ORDER BY lastname'; |
|
733 | - |
|
734 | - $result = Database::query($sql); |
|
735 | - $users = Database::store_result($result); |
|
736 | - |
|
737 | - return $users; |
|
738 | - } |
|
739 | - |
|
740 | - /** |
|
741 | - * Find evaluations by name |
|
742 | - * @param string $name_mask search string |
|
743 | - * @return array evaluation objects matching the search criterium |
|
744 | - * @todo can be written more efficiently using a new (but very complex) sql query |
|
745 | - */ |
|
746 | - public function find_evaluations($name_mask,$selectcat) |
|
747 | - { |
|
748 | - $rootcat = Category::load($selectcat); |
|
749 | - $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
|
750 | - $foundevals = array(); |
|
751 | - foreach ($evals as $eval) { |
|
752 | - if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { |
|
753 | - $foundevals[] = $eval; |
|
754 | - } |
|
755 | - } |
|
756 | - return $foundevals; |
|
757 | - } |
|
758 | - |
|
759 | - public function get_item_type() |
|
760 | - { |
|
761 | - return 'E'; |
|
762 | - } |
|
763 | - |
|
764 | - public function get_icon_name() |
|
765 | - { |
|
766 | - return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
|
767 | - } |
|
768 | - |
|
769 | - /** |
|
770 | - * Locks an evaluation, only one who can unlock it is the platform administrator. |
|
771 | - * @param int locked 1 or unlocked 0 |
|
772 | - * |
|
773 | - **/ |
|
774 | - function lock($locked) |
|
775 | - { |
|
776 | - $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
777 | - $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; |
|
778 | - Database::query($sql); |
|
779 | - } |
|
780 | - |
|
781 | - function check_lock_permissions() |
|
782 | - { |
|
783 | - if (api_is_platform_admin()) { |
|
784 | - return true; |
|
785 | - } else { |
|
786 | - if ($this->is_locked()) { |
|
787 | - api_not_allowed(); |
|
788 | - } |
|
789 | - } |
|
790 | - } |
|
791 | - |
|
792 | - function delete_linked_data() |
|
793 | - { |
|
794 | - |
|
795 | - } |
|
702 | + if (!api_is_allowed_to_edit()) { |
|
703 | + $sql .= ' AND visible = 1'; |
|
704 | + } |
|
705 | + if (isset($cat_id)) { |
|
706 | + $sql .= ' AND category_id = '.intval($cat_id); |
|
707 | + } else { |
|
708 | + $sql .= ' AND category_id >= 0'; |
|
709 | + } |
|
710 | + |
|
711 | + $result = Database::query($sql); |
|
712 | + $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
713 | + |
|
714 | + return $alleval; |
|
715 | + } |
|
716 | + |
|
717 | + /** |
|
718 | + * Get a list of students that do not have a result record for this evaluation |
|
719 | + */ |
|
720 | + public function get_not_subscribed_students($first_letter_user = '') |
|
721 | + { |
|
722 | + $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
723 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
724 | + |
|
725 | + $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
|
726 | + ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'" |
|
727 | + .' AND status = '.STUDENT |
|
728 | + .' AND user_id NOT IN' |
|
729 | + .' (SELECT user_id FROM '.$tbl_grade_results |
|
730 | + .' WHERE evaluation_id = '.intval($this->id) |
|
731 | + .' )' |
|
732 | + .' ORDER BY lastname'; |
|
733 | + |
|
734 | + $result = Database::query($sql); |
|
735 | + $users = Database::store_result($result); |
|
736 | + |
|
737 | + return $users; |
|
738 | + } |
|
739 | + |
|
740 | + /** |
|
741 | + * Find evaluations by name |
|
742 | + * @param string $name_mask search string |
|
743 | + * @return array evaluation objects matching the search criterium |
|
744 | + * @todo can be written more efficiently using a new (but very complex) sql query |
|
745 | + */ |
|
746 | + public function find_evaluations($name_mask,$selectcat) |
|
747 | + { |
|
748 | + $rootcat = Category::load($selectcat); |
|
749 | + $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
|
750 | + $foundevals = array(); |
|
751 | + foreach ($evals as $eval) { |
|
752 | + if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { |
|
753 | + $foundevals[] = $eval; |
|
754 | + } |
|
755 | + } |
|
756 | + return $foundevals; |
|
757 | + } |
|
758 | + |
|
759 | + public function get_item_type() |
|
760 | + { |
|
761 | + return 'E'; |
|
762 | + } |
|
763 | + |
|
764 | + public function get_icon_name() |
|
765 | + { |
|
766 | + return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
|
767 | + } |
|
768 | + |
|
769 | + /** |
|
770 | + * Locks an evaluation, only one who can unlock it is the platform administrator. |
|
771 | + * @param int locked 1 or unlocked 0 |
|
772 | + * |
|
773 | + **/ |
|
774 | + function lock($locked) |
|
775 | + { |
|
776 | + $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
777 | + $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; |
|
778 | + Database::query($sql); |
|
779 | + } |
|
780 | + |
|
781 | + function check_lock_permissions() |
|
782 | + { |
|
783 | + if (api_is_platform_admin()) { |
|
784 | + return true; |
|
785 | + } else { |
|
786 | + if ($this->is_locked()) { |
|
787 | + api_not_allowed(); |
|
788 | + } |
|
789 | + } |
|
790 | + } |
|
791 | + |
|
792 | + function delete_linked_data() |
|
793 | + { |
|
794 | + |
|
795 | + } |
|
796 | 796 | |
797 | 797 | public function getStudentList() |
798 | 798 | { |
799 | 799 | return $this->studentList; |
800 | 800 | } |
801 | 801 | |
802 | - public function setStudentList($list) |
|
803 | - { |
|
804 | - $this->studentList = $list; |
|
805 | - } |
|
802 | + public function setStudentList($list) |
|
803 | + { |
|
804 | + $this->studentList = $list; |
|
805 | + } |
|
806 | 806 | } |
@@ -223,36 +223,36 @@ discard block |
||
223 | 223 | $paramcount = 0; |
224 | 224 | |
225 | 225 | if (isset ($id)) { |
226 | - $sql.= ' WHERE id = '.intval($id); |
|
227 | - $paramcount ++; |
|
226 | + $sql .= ' WHERE id = '.intval($id); |
|
227 | + $paramcount++; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | if (isset ($user_id)) { |
231 | 231 | if ($paramcount != 0) $sql .= ' AND'; |
232 | 232 | else $sql .= ' WHERE'; |
233 | 233 | $sql .= ' user_id = '.intval($user_id); |
234 | - $paramcount ++; |
|
234 | + $paramcount++; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | if (isset ($course_code) && $course_code <> '-1') { |
238 | 238 | if ($paramcount != 0) $sql .= ' AND'; |
239 | 239 | else $sql .= ' WHERE'; |
240 | 240 | $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
241 | - $paramcount ++; |
|
241 | + $paramcount++; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | if (isset ($category_id)) { |
245 | 245 | if ($paramcount != 0) $sql .= ' AND'; |
246 | 246 | else $sql .= ' WHERE'; |
247 | 247 | $sql .= ' category_id = '.intval($category_id); |
248 | - $paramcount ++; |
|
248 | + $paramcount++; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | if (isset ($visible)) { |
252 | 252 | if ($paramcount != 0) $sql .= ' AND'; |
253 | 253 | else $sql .= ' WHERE'; |
254 | 254 | $sql .= ' visible = '.intval($visible); |
255 | - $paramcount ++; |
|
255 | + $paramcount++; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | if (isset ($locked)) { |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $alleval = array(); |
279 | 279 | if (Database::num_rows($result)) { |
280 | 280 | while ($data = Database::fetch_array($result)) { |
281 | - $eval= new Evaluation(); |
|
281 | + $eval = new Evaluation(); |
|
282 | 282 | $eval->set_id($data['id']); |
283 | 283 | $eval->set_name($data['name']); |
284 | 284 | $eval->set_description($data['description']); |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
364 | 364 | $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
365 | 365 | $eval = new Evaluation(); |
366 | - $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
366 | + $dateobject = $eval->load($idevaluation, null, null, null, null); |
|
367 | 367 | $arreval = get_object_vars($dateobject[0]); |
368 | 368 | if (!empty($arreval['id'])) { |
369 | 369 | $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | .', description = '; |
398 | 398 | if (isset($this->description)) { |
399 | 399 | $sql .= "'".Database::escape_string($this->get_description())."'"; |
400 | - }else { |
|
400 | + } else { |
|
401 | 401 | $sql .= 'null'; |
402 | 402 | } |
403 | 403 | $sql .= ', user_id = '.intval($this->get_user_id()) |
@@ -468,17 +468,17 @@ discard block |
||
468 | 468 | $sql .= ' AND user_id = '.api_get_user_id(); |
469 | 469 | } |
470 | 470 | |
471 | - }else { |
|
471 | + } else { |
|
472 | 472 | $sql .= ' AND user_id = '.api_get_user_id(); |
473 | 473 | } |
474 | 474 | |
475 | 475 | if (!isset ($parent)) { |
476 | - $sql.= ' AND category_id is null'; |
|
476 | + $sql .= ' AND category_id is null'; |
|
477 | 477 | } else { |
478 | - $sql.= ' AND category_id = '.intval($parent); |
|
478 | + $sql .= ' AND category_id = '.intval($parent); |
|
479 | 479 | } |
480 | 480 | $result = Database::query($sql); |
481 | - $number=Database::fetch_row($result); |
|
481 | + $number = Database::fetch_row($result); |
|
482 | 482 | |
483 | 483 | return $number[0] != 0; |
484 | 484 | } |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | FROM '.$tbl_grade_results.' |
495 | 495 | WHERE evaluation_id = '.intval($this->id); |
496 | 496 | $result = Database::query($sql); |
497 | - $number=Database::fetch_row($result); |
|
497 | + $number = Database::fetch_row($result); |
|
498 | 498 | |
499 | 499 | return ($number[0] != 0); |
500 | 500 | } |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | $results = isset($data[$key]) ? $data[$key] : null; |
545 | 545 | |
546 | 546 | if ($useSession == false) { |
547 | - $results = null; |
|
547 | + $results = null; |
|
548 | 548 | } |
549 | 549 | if (empty($results)) { |
550 | 550 | $results = Result::load(null, $stud_id, $this->id); |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | $data = Session::read('calc_score'); |
571 | 571 | $allResults = isset($data[$key]) ? $data[$key] : null; |
572 | 572 | if ($useSession == false) { |
573 | - $allResults = null; |
|
573 | + $allResults = null; |
|
574 | 574 | } |
575 | 575 | if (empty($allResults)) { |
576 | 576 | $allResults = Result::load(null, null, $this->id); |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | return array($bestResult, $weight); |
603 | 603 | break; |
604 | 604 | case 'average': |
605 | - return array($sumResult/$count, $weight); |
|
605 | + return array($sumResult / $count, $weight); |
|
606 | 606 | break; |
607 | 607 | case 'ranking': |
608 | 608 | $students = array(); |
@@ -640,17 +640,17 @@ discard block |
||
640 | 640 | $targets[] = $root; |
641 | 641 | |
642 | 642 | if (isset($this->course_code) && !empty($this->course_code)) { |
643 | - $crscats = Category::load(null,null,$this->course_code,0); |
|
643 | + $crscats = Category::load(null, null, $this->course_code, 0); |
|
644 | 644 | foreach ($crscats as $cat) { |
645 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
646 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
645 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
646 | + $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); |
|
647 | 647 | } |
648 | 648 | } |
649 | 649 | |
650 | - $indcats = Category::load(null,$user,0,0); |
|
650 | + $indcats = Category::load(null, $user, 0, 0); |
|
651 | 651 | foreach ($indcats as $cat) { |
652 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
653 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
652 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
653 | + $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | return $targets; |
@@ -661,10 +661,10 @@ discard block |
||
661 | 661 | */ |
662 | 662 | private function add_target_subcategories($targets, $level, $catid) |
663 | 663 | { |
664 | - $subcats = Category::load(null,null,null,$catid); |
|
664 | + $subcats = Category::load(null, null, null, $catid); |
|
665 | 665 | foreach ($subcats as $cat) { |
666 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
667 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
666 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
667 | + $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); |
|
668 | 668 | } |
669 | 669 | return $targets; |
670 | 670 | } |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | * @return array evaluation objects matching the search criterium |
744 | 744 | * @todo can be written more efficiently using a new (but very complex) sql query |
745 | 745 | */ |
746 | - public function find_evaluations($name_mask,$selectcat) |
|
746 | + public function find_evaluations($name_mask, $selectcat) |
|
747 | 747 | { |
748 | 748 | $rootcat = Category::load($selectcat); |
749 | 749 | $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
@@ -228,36 +228,51 @@ discard block |
||
228 | 228 | } |
229 | 229 | |
230 | 230 | if (isset ($user_id)) { |
231 | - if ($paramcount != 0) $sql .= ' AND'; |
|
232 | - else $sql .= ' WHERE'; |
|
231 | + if ($paramcount != 0) { |
|
232 | + $sql .= ' AND'; |
|
233 | + } else { |
|
234 | + $sql .= ' WHERE'; |
|
235 | + } |
|
233 | 236 | $sql .= ' user_id = '.intval($user_id); |
234 | 237 | $paramcount ++; |
235 | 238 | } |
236 | 239 | |
237 | 240 | if (isset ($course_code) && $course_code <> '-1') { |
238 | - if ($paramcount != 0) $sql .= ' AND'; |
|
239 | - else $sql .= ' WHERE'; |
|
241 | + if ($paramcount != 0) { |
|
242 | + $sql .= ' AND'; |
|
243 | + } else { |
|
244 | + $sql .= ' WHERE'; |
|
245 | + } |
|
240 | 246 | $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
241 | 247 | $paramcount ++; |
242 | 248 | } |
243 | 249 | |
244 | 250 | if (isset ($category_id)) { |
245 | - if ($paramcount != 0) $sql .= ' AND'; |
|
246 | - else $sql .= ' WHERE'; |
|
251 | + if ($paramcount != 0) { |
|
252 | + $sql .= ' AND'; |
|
253 | + } else { |
|
254 | + $sql .= ' WHERE'; |
|
255 | + } |
|
247 | 256 | $sql .= ' category_id = '.intval($category_id); |
248 | 257 | $paramcount ++; |
249 | 258 | } |
250 | 259 | |
251 | 260 | if (isset ($visible)) { |
252 | - if ($paramcount != 0) $sql .= ' AND'; |
|
253 | - else $sql .= ' WHERE'; |
|
261 | + if ($paramcount != 0) { |
|
262 | + $sql .= ' AND'; |
|
263 | + } else { |
|
264 | + $sql .= ' WHERE'; |
|
265 | + } |
|
254 | 266 | $sql .= ' visible = '.intval($visible); |
255 | 267 | $paramcount ++; |
256 | 268 | } |
257 | 269 | |
258 | 270 | if (isset ($locked)) { |
259 | - if ($paramcount != 0) $sql .= ' AND'; |
|
260 | - else $sql .= ' WHERE'; |
|
271 | + if ($paramcount != 0) { |
|
272 | + $sql .= ' AND'; |
|
273 | + } else { |
|
274 | + $sql .= ' WHERE'; |
|
275 | + } |
|
261 | 276 | $sql .= ' locked = '.intval($locked); |
262 | 277 | } |
263 | 278 | |
@@ -397,7 +412,7 @@ discard block |
||
397 | 412 | .', description = '; |
398 | 413 | if (isset($this->description)) { |
399 | 414 | $sql .= "'".Database::escape_string($this->get_description())."'"; |
400 | - }else { |
|
415 | + } else { |
|
401 | 416 | $sql .= 'null'; |
402 | 417 | } |
403 | 418 | $sql .= ', user_id = '.intval($this->get_user_id()) |
@@ -468,7 +483,7 @@ discard block |
||
468 | 483 | $sql .= ' AND user_id = '.api_get_user_id(); |
469 | 484 | } |
470 | 485 | |
471 | - }else { |
|
486 | + } else { |
|
472 | 487 | $sql .= ' AND user_id = '.api_get_user_id(); |
473 | 488 | } |
474 | 489 |
@@ -372,7 +372,7 @@ |
||
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
375 | - * @return array|string |
|
375 | + * @return string |
|
376 | 376 | */ |
377 | 377 | public function get_type_name() |
378 | 378 | { |
@@ -194,13 +194,13 @@ discard block |
||
194 | 194 | in exercice/exercice.php, look for note-query-exe-results marker*/ |
195 | 195 | $session_id = api_get_session_id(); |
196 | 196 | $courseId = $this->getCourseId(); |
197 | - $exercise = new Exercise($courseId); |
|
197 | + $exercise = new Exercise($courseId); |
|
198 | 198 | $exercise->read($this->get_ref_id()); |
199 | 199 | |
200 | 200 | if (!$this->is_hp) { |
201 | 201 | |
202 | - if ($exercise->exercise_was_added_in_lp == false) { |
|
203 | - $sql = "SELECT * FROM $tblStats |
|
202 | + if ($exercise->exercise_was_added_in_lp == false) { |
|
203 | + $sql = "SELECT * FROM $tblStats |
|
204 | 204 | WHERE |
205 | 205 | exe_exo_id = ".intval($this->get_ref_id())." AND |
206 | 206 | orig_lp_id = 0 AND |
@@ -209,15 +209,15 @@ discard block |
||
209 | 209 | session_id = $session_id AND |
210 | 210 | c_id = $courseId |
211 | 211 | "; |
212 | - } else { |
|
213 | - $lpId = null; |
|
214 | - if (!empty($exercise->lpList)) { |
|
215 | - // Taking only the first LP |
|
216 | - $lpId = current($exercise->lpList); |
|
217 | - $lpId = $lpId['lp_id']; |
|
218 | - } |
|
219 | - |
|
220 | - $sql = "SELECT * FROM $tblStats |
|
212 | + } else { |
|
213 | + $lpId = null; |
|
214 | + if (!empty($exercise->lpList)) { |
|
215 | + // Taking only the first LP |
|
216 | + $lpId = current($exercise->lpList); |
|
217 | + $lpId = $lpId['lp_id']; |
|
218 | + } |
|
219 | + |
|
220 | + $sql = "SELECT * FROM $tblStats |
|
221 | 221 | WHERE |
222 | 222 | exe_exo_id = ".intval($this->get_ref_id())." AND |
223 | 223 | orig_lp_id = $lpId AND |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | session_id = $session_id AND |
226 | 226 | c_id = $courseId |
227 | 227 | "; |
228 | - } |
|
228 | + } |
|
229 | 229 | |
230 | 230 | if (!empty($stud_id) && $type != 'ranking') { |
231 | 231 | $sql .= " AND exe_user_id = $stud_id "; |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | |
52 | 52 | $result = Database::query($sql); |
53 | 53 | $cats = array(); |
54 | - while ($data=Database::fetch_array($result)) { |
|
55 | - $cats[] = array ($data['id'], $data['title']); |
|
54 | + while ($data = Database::fetch_array($result)) { |
|
55 | + $cats[] = array($data['id'], $data['title']); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | return $cats; |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | $cats = array(); |
117 | 117 | if (isset($result)) { |
118 | 118 | if (Database::num_rows($result) > 0) { |
119 | - while ($data=Database::fetch_array($result)) { |
|
120 | - $cats[] = array ($data['id'], $data['title']); |
|
119 | + while ($data = Database::fetch_array($result)) { |
|
120 | + $cats[] = array($data['id'], $data['title']); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | 125 | if (isset($result2)) { |
126 | 126 | if (Database::num_rows($result2) > 0) { |
127 | - while ($row=Database::fetch_array($result2)) { |
|
127 | + while ($row = Database::fetch_array($result2)) { |
|
128 | 128 | /*$path = $data['path']; |
129 | 129 | $fname = GetQuizName($path,$documentPath); |
130 | 130 | $cats[] = array ($data['id'], $fname);*/ |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | WHERE |
171 | 171 | session_id = $session_id AND |
172 | 172 | c_id = $course_id AND |
173 | - exe_exo_id = ".(int)$this->get_ref_id(); |
|
173 | + exe_exo_id = ".(int) $this->get_ref_id(); |
|
174 | 174 | $result = Database::query($sql); |
175 | - $number=Database::fetch_row($result); |
|
175 | + $number = Database::fetch_row($result); |
|
176 | 176 | return ($number[0] != 0); |
177 | 177 | } |
178 | 178 | |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | } else { |
255 | 255 | // all students -> get average |
256 | 256 | // normal way of getting the info |
257 | - $students = array(); // user list, needed to make sure we only |
|
257 | + $students = array(); // user list, needed to make sure we only |
|
258 | 258 | // take first attempts into account |
259 | 259 | $student_count = 0; |
260 | 260 | $sum = 0; |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | /*if (empty($count)) { |
290 | 290 | return null; |
291 | 291 | }*/ |
292 | - return array($sumResult/$count , $weight); |
|
292 | + return array($sumResult / $count, $weight); |
|
293 | 293 | break; |
294 | 294 | case 'ranking': |
295 | 295 | return AbstractLink::getCurrentUserRanking($stud_id, $students); |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | $session_id = api_get_session_id(); |
320 | 320 | |
321 | 321 | $url = api_get_path(WEB_CODE_PATH).'gradebook/exercise_jump.php?session_id='.$session_id.'&cidReq='.$this->get_course_code().'&gradebook=view&exerciseId='.$this->get_ref_id().'&type='.$this->get_type(); |
322 | - if ((!api_is_allowed_to_edit() && $this->calc_score(api_get_user_id()) == null) || $status_user!=1) { |
|
322 | + if ((!api_is_allowed_to_edit() && $this->calc_score(api_get_user_id()) == null) || $status_user != 1) { |
|
323 | 323 | $url .= '&doexercise='.$this->get_ref_id(); |
324 | 324 | } |
325 | 325 | |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | public function is_valid_link() |
365 | 365 | { |
366 | 366 | $sql = 'SELECT count(id) from '.$this->get_exercise_table().' |
367 | - WHERE c_id = '.$this->course_id.' AND id = '.(int)$this->get_ref_id().' '; |
|
367 | + WHERE c_id = '.$this->course_id.' AND id = '.(int) $this->get_ref_id().' '; |
|
368 | 368 | $result = Database::query($sql); |
369 | 369 | $number = Database::fetch_row($result); |
370 | 370 |
@@ -121,7 +121,7 @@ |
||
121 | 121 | |
122 | 122 | /** |
123 | 123 | * Has anyone done this exercise yet ? |
124 | - * @return int |
|
124 | + * @return boolean |
|
125 | 125 | */ |
126 | 126 | public function has_results() |
127 | 127 | { |
@@ -10,54 +10,54 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class ForumThreadLink extends AbstractLink |
12 | 12 | { |
13 | - private $forum_thread_table = null; |
|
14 | - private $itemprop_table = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct(); |
|
22 | - $this->set_type(LINK_FORUM_THREAD); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function get_type_name() |
|
29 | - { |
|
30 | - return get_lang('ForumThreads'); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function is_allowed_to_change_name() |
|
37 | - { |
|
38 | - return false; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | - */ |
|
45 | - public function get_not_created_links() |
|
46 | - { |
|
47 | - if (empty($this->course_code)) { |
|
48 | - die('Error in get_not_created_links() : course code not set'); |
|
49 | - } |
|
50 | - |
|
51 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | - |
|
53 | - $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table() |
|
54 | - .' forum_thread WHERE thread_id NOT IN' |
|
55 | - .' (SELECT ref_id FROM '.$tbl_grade_links |
|
56 | - .' WHERE type = '.LINK_FORUM_THREAD |
|
57 | - ." AND c_id = ".intval($this->course_id) |
|
58 | - .') AND forum_thread.session_id='.api_get_session_id().''; |
|
59 | - |
|
60 | - $result = Database::query($sql); |
|
13 | + private $forum_thread_table = null; |
|
14 | + private $itemprop_table = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct(); |
|
22 | + $this->set_type(LINK_FORUM_THREAD); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function get_type_name() |
|
29 | + { |
|
30 | + return get_lang('ForumThreads'); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function is_allowed_to_change_name() |
|
37 | + { |
|
38 | + return false; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | + */ |
|
45 | + public function get_not_created_links() |
|
46 | + { |
|
47 | + if (empty($this->course_code)) { |
|
48 | + die('Error in get_not_created_links() : course code not set'); |
|
49 | + } |
|
50 | + |
|
51 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | + |
|
53 | + $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table() |
|
54 | + .' forum_thread WHERE thread_id NOT IN' |
|
55 | + .' (SELECT ref_id FROM '.$tbl_grade_links |
|
56 | + .' WHERE type = '.LINK_FORUM_THREAD |
|
57 | + ." AND c_id = ".intval($this->course_id) |
|
58 | + .') AND forum_thread.session_id='.api_get_session_id().''; |
|
59 | + |
|
60 | + $result = Database::query($sql); |
|
61 | 61 | |
62 | 62 | $cats = array(); |
63 | 63 | while ($data = Database::fetch_array($result)) { |
@@ -72,29 +72,29 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | return $cats; |
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Generate an array of all exercises available. |
|
79 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | - */ |
|
81 | - public function get_all_links() |
|
82 | - { |
|
83 | - if (empty($this->course_code)) { |
|
84 | - die('Error in get_not_created_links() : course code not set'); |
|
85 | - } |
|
86 | - |
|
87 | - $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
88 | - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
89 | - $session_id = api_get_session_id(); |
|
90 | - |
|
91 | - if ($session_id) { |
|
92 | - $session_condition = 'tl.session_id='.api_get_session_id(); |
|
93 | - } else { |
|
94 | - $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
95 | - } |
|
96 | - |
|
97 | - $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Generate an array of all exercises available. |
|
79 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | + */ |
|
81 | + public function get_all_links() |
|
82 | + { |
|
83 | + if (empty($this->course_code)) { |
|
84 | + die('Error in get_not_created_links() : course code not set'); |
|
85 | + } |
|
86 | + |
|
87 | + $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
88 | + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
89 | + $session_id = api_get_session_id(); |
|
90 | + |
|
91 | + if ($session_id) { |
|
92 | + $session_condition = 'tl.session_id='.api_get_session_id(); |
|
93 | + } else { |
|
94 | + $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
95 | + } |
|
96 | + |
|
97 | + $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
98 | 98 | FROM '.$tbl_grade_links.' tl INNER JOIN '.$tbl_item_property.' ip |
99 | 99 | ON (tl.thread_id = ip.ref AND tl.c_id = ip.c_id ) |
100 | 100 | WHERE |
@@ -105,24 +105,24 @@ discard block |
||
105 | 105 | '.$session_condition.' |
106 | 106 | '; |
107 | 107 | |
108 | - $result = Database::query($sql); |
|
108 | + $result = Database::query($sql); |
|
109 | 109 | |
110 | - while ($data = Database::fetch_array($result)) { |
|
111 | - if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){ |
|
112 | - $cats[] = array ($data['thread_id'], $data['thread_title_qualify']); |
|
113 | - } else { |
|
114 | - $cats[] = array ($data['thread_id'], $data['thread_title']); |
|
115 | - } |
|
116 | - } |
|
117 | - $my_cats = isset($cats) ? $cats : null; |
|
110 | + while ($data = Database::fetch_array($result)) { |
|
111 | + if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){ |
|
112 | + $cats[] = array ($data['thread_id'], $data['thread_title_qualify']); |
|
113 | + } else { |
|
114 | + $cats[] = array ($data['thread_id'], $data['thread_title']); |
|
115 | + } |
|
116 | + } |
|
117 | + $my_cats = isset($cats) ? $cats : null; |
|
118 | 118 | |
119 | - return $my_cats; |
|
120 | - } |
|
119 | + return $my_cats; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | /** |
123 | - * Has anyone done this exercise yet ? |
|
124 | - * @return int |
|
125 | - */ |
|
123 | + * Has anyone done this exercise yet ? |
|
124 | + * @return int |
|
125 | + */ |
|
126 | 126 | public function has_results() |
127 | 127 | { |
128 | 128 | $table = Database :: get_course_table(TABLE_FORUM_POST); |
@@ -134,40 +134,40 @@ discard block |
||
134 | 134 | $number = Database::fetch_row($result); |
135 | 135 | |
136 | 136 | return $number[0] != 0; |
137 | - } |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param int $stud_id |
|
139 | + /** |
|
140 | + * @param int $stud_id |
|
141 | 141 | * @param string $type |
142 | 142 | * |
143 | - * @return array|null |
|
144 | - */ |
|
145 | - public function calc_score($stud_id = null, $type = null) |
|
146 | - { |
|
143 | + * @return array|null |
|
144 | + */ |
|
145 | + public function calc_score($stud_id = null, $type = null) |
|
146 | + { |
|
147 | 147 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
148 | 148 | $threadInfo = get_thread_information($this->get_ref_id()); |
149 | 149 | |
150 | - $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
150 | + $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
151 | 151 | |
152 | - $sql = 'SELECT thread_qualify_max |
|
152 | + $sql = 'SELECT thread_qualify_max |
|
153 | 153 | FROM '.Database :: get_course_table(TABLE_FORUM_THREAD)." |
154 | 154 | WHERE c_id = ".$this->course_id." AND thread_id = '".$this->get_ref_id()."'"; |
155 | - $query = Database::query($sql); |
|
156 | - $assignment = Database::fetch_array($query); |
|
155 | + $query = Database::query($sql); |
|
156 | + $assignment = Database::fetch_array($query); |
|
157 | 157 | |
158 | - $sql = "SELECT * FROM $thread_qualify |
|
158 | + $sql = "SELECT * FROM $thread_qualify |
|
159 | 159 | WHERE c_id = ".$this->course_id." AND thread_id = ".$this->get_ref_id(); |
160 | - if (isset($stud_id)) { |
|
161 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
162 | - } |
|
160 | + if (isset($stud_id)) { |
|
161 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
162 | + } |
|
163 | 163 | |
164 | - // order by id, that way the student's first attempt is accessed first |
|
165 | - $sql .= ' ORDER BY qualify_time DESC'; |
|
164 | + // order by id, that way the student's first attempt is accessed first |
|
165 | + $sql .= ' ORDER BY qualify_time DESC'; |
|
166 | 166 | |
167 | - $scores = Database::query($sql); |
|
167 | + $scores = Database::query($sql); |
|
168 | 168 | |
169 | - // for 1 student |
|
170 | - if (isset($stud_id)) { |
|
169 | + // for 1 student |
|
170 | + if (isset($stud_id)) { |
|
171 | 171 | if ($threadInfo['thread_peer_qualify'] == 0) { |
172 | 172 | // Classic way of calculate score |
173 | 173 | if ($data = Database::fetch_array($scores)) { |
@@ -195,174 +195,174 @@ discard block |
||
195 | 195 | } |
196 | 196 | return [$score/$counter, $assignment['thread_qualify_max']]; |
197 | 197 | } |
198 | - } else { |
|
199 | - // All students -> get average |
|
200 | - $students = array(); // user list, needed to make sure we only |
|
201 | - // take first attempts into account |
|
202 | - $counter = 0; |
|
203 | - $sum = 0; |
|
204 | - $bestResult = 0; |
|
205 | - $weight = 0; |
|
206 | - $sumResult = 0; |
|
207 | - |
|
208 | - while ($data = Database::fetch_array($scores)) { |
|
209 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
210 | - if ($assignment['thread_qualify_max'] != 0) { |
|
211 | - $students[$data['user_id']] = $data['qualify']; |
|
212 | - $counter++; |
|
213 | - $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
214 | - $sumResult += $data['qualify']; |
|
215 | - if ($data['qualify'] > $bestResult) { |
|
216 | - $bestResult = $data['qualify']; |
|
217 | - } |
|
218 | - $weight = $assignment['thread_qualify_max']; |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - if ($counter == 0) { |
|
224 | - return null; |
|
225 | - } else { |
|
226 | - switch ($type) { |
|
227 | - case 'best': |
|
228 | - return array($bestResult, $weight); |
|
229 | - break; |
|
230 | - case 'average': |
|
231 | - return array($sumResult/$counter, $weight); |
|
232 | - break; |
|
233 | - case 'ranking': |
|
234 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
235 | - break; |
|
236 | - default: |
|
237 | - return array($sum, $counter); |
|
238 | - break; |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Lazy load function to get the database table of the student publications |
|
246 | - */ |
|
247 | - private function get_forum_thread_table() |
|
248 | - { |
|
249 | - return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
250 | - } |
|
251 | - |
|
252 | - public function needs_name_and_description() |
|
253 | - { |
|
254 | - return false; |
|
255 | - } |
|
256 | - |
|
257 | - public function needs_max() |
|
258 | - { |
|
259 | - return false; |
|
260 | - } |
|
261 | - |
|
262 | - public function needs_results() |
|
263 | - { |
|
264 | - return false; |
|
265 | - } |
|
198 | + } else { |
|
199 | + // All students -> get average |
|
200 | + $students = array(); // user list, needed to make sure we only |
|
201 | + // take first attempts into account |
|
202 | + $counter = 0; |
|
203 | + $sum = 0; |
|
204 | + $bestResult = 0; |
|
205 | + $weight = 0; |
|
206 | + $sumResult = 0; |
|
207 | + |
|
208 | + while ($data = Database::fetch_array($scores)) { |
|
209 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
210 | + if ($assignment['thread_qualify_max'] != 0) { |
|
211 | + $students[$data['user_id']] = $data['qualify']; |
|
212 | + $counter++; |
|
213 | + $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
214 | + $sumResult += $data['qualify']; |
|
215 | + if ($data['qualify'] > $bestResult) { |
|
216 | + $bestResult = $data['qualify']; |
|
217 | + } |
|
218 | + $weight = $assignment['thread_qualify_max']; |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + if ($counter == 0) { |
|
224 | + return null; |
|
225 | + } else { |
|
226 | + switch ($type) { |
|
227 | + case 'best': |
|
228 | + return array($bestResult, $weight); |
|
229 | + break; |
|
230 | + case 'average': |
|
231 | + return array($sumResult/$counter, $weight); |
|
232 | + break; |
|
233 | + case 'ranking': |
|
234 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
235 | + break; |
|
236 | + default: |
|
237 | + return array($sum, $counter); |
|
238 | + break; |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Lazy load function to get the database table of the student publications |
|
246 | + */ |
|
247 | + private function get_forum_thread_table() |
|
248 | + { |
|
249 | + return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
250 | + } |
|
251 | + |
|
252 | + public function needs_name_and_description() |
|
253 | + { |
|
254 | + return false; |
|
255 | + } |
|
256 | + |
|
257 | + public function needs_max() |
|
258 | + { |
|
259 | + return false; |
|
260 | + } |
|
261 | + |
|
262 | + public function needs_results() |
|
263 | + { |
|
264 | + return false; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | /** |
268 | 268 | * @return string |
269 | 269 | */ |
270 | - public function get_name() |
|
271 | - { |
|
272 | - $this->get_exercise_data(); |
|
273 | - $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
274 | - $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
275 | - if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
276 | - return $this->exercise_data['thread_title_qualify']; |
|
277 | - } else { |
|
278 | - return $thread_title; |
|
279 | - } |
|
280 | - } |
|
270 | + public function get_name() |
|
271 | + { |
|
272 | + $this->get_exercise_data(); |
|
273 | + $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
274 | + $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
275 | + if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
276 | + return $this->exercise_data['thread_title_qualify']; |
|
277 | + } else { |
|
278 | + return $thread_title; |
|
279 | + } |
|
280 | + } |
|
281 | 281 | |
282 | 282 | /** |
283 | 283 | * @return string |
284 | 284 | */ |
285 | - public function get_description() |
|
286 | - { |
|
287 | - return '';//$this->exercise_data['description']; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Check if this still links to an exercise |
|
292 | - */ |
|
293 | - public function is_valid_link() |
|
294 | - { |
|
295 | - $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
285 | + public function get_description() |
|
286 | + { |
|
287 | + return '';//$this->exercise_data['description']; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Check if this still links to an exercise |
|
292 | + */ |
|
293 | + public function is_valid_link() |
|
294 | + { |
|
295 | + $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
296 | 296 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().''; |
297 | - $result = Database::query($sql); |
|
298 | - $number = Database::fetch_row($result); |
|
299 | - return ($number[0] != 0); |
|
300 | - } |
|
301 | - |
|
302 | - public function get_test_id() |
|
303 | - { |
|
304 | - return 'DEBUG:ID'; |
|
305 | - } |
|
306 | - |
|
307 | - public function get_link() |
|
308 | - { |
|
309 | - //it was extracts the forum id |
|
310 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
297 | + $result = Database::query($sql); |
|
298 | + $number = Database::fetch_row($result); |
|
299 | + return ($number[0] != 0); |
|
300 | + } |
|
301 | + |
|
302 | + public function get_test_id() |
|
303 | + { |
|
304 | + return 'DEBUG:ID'; |
|
305 | + } |
|
306 | + |
|
307 | + public function get_link() |
|
308 | + { |
|
309 | + //it was extracts the forum id |
|
310 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
311 | 311 | WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".api_get_session_id().""; |
312 | - $result = Database::query($sql); |
|
313 | - $row = Database::fetch_array($result,'ASSOC'); |
|
314 | - $forum_id=$row['forum_id']; |
|
315 | - |
|
316 | - $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
317 | - return $url; |
|
318 | - } |
|
319 | - |
|
320 | - private function get_exercise_data() |
|
321 | - { |
|
322 | - $session_id = api_get_session_id(); |
|
323 | - if ($session_id) { |
|
324 | - $session_condition = 'session_id='.api_get_session_id(); |
|
325 | - } else { |
|
326 | - $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
327 | - } |
|
328 | - |
|
329 | - if (!isset($this->exercise_data)) { |
|
330 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
312 | + $result = Database::query($sql); |
|
313 | + $row = Database::fetch_array($result,'ASSOC'); |
|
314 | + $forum_id=$row['forum_id']; |
|
315 | + |
|
316 | + $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
317 | + return $url; |
|
318 | + } |
|
319 | + |
|
320 | + private function get_exercise_data() |
|
321 | + { |
|
322 | + $session_id = api_get_session_id(); |
|
323 | + if ($session_id) { |
|
324 | + $session_condition = 'session_id='.api_get_session_id(); |
|
325 | + } else { |
|
326 | + $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
327 | + } |
|
328 | + |
|
329 | + if (!isset($this->exercise_data)) { |
|
330 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
331 | 331 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND '.$session_condition; |
332 | - $query = Database::query($sql); |
|
333 | - $this->exercise_data = Database::fetch_array($query); |
|
334 | - } |
|
335 | - return $this->exercise_data; |
|
336 | - } |
|
337 | - |
|
338 | - public function get_icon_name() |
|
339 | - { |
|
340 | - return 'forum'; |
|
341 | - } |
|
342 | - |
|
343 | - function save_linked_data() |
|
344 | - { |
|
345 | - $weight = (float)$this->get_weight(); |
|
346 | - $ref_id = $this->get_ref_id(); |
|
347 | - |
|
348 | - if (!empty($ref_id)) { |
|
349 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
332 | + $query = Database::query($sql); |
|
333 | + $this->exercise_data = Database::fetch_array($query); |
|
334 | + } |
|
335 | + return $this->exercise_data; |
|
336 | + } |
|
337 | + |
|
338 | + public function get_icon_name() |
|
339 | + { |
|
340 | + return 'forum'; |
|
341 | + } |
|
342 | + |
|
343 | + function save_linked_data() |
|
344 | + { |
|
345 | + $weight = (float)$this->get_weight(); |
|
346 | + $ref_id = $this->get_ref_id(); |
|
347 | + |
|
348 | + if (!empty($ref_id)) { |
|
349 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
350 | 350 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
351 | - Database::query($sql); |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - function delete_linked_data() |
|
356 | - { |
|
357 | - $ref_id = $this->get_ref_id(); |
|
358 | - if (!empty($ref_id)) { |
|
359 | - //Cleans forum |
|
360 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
351 | + Database::query($sql); |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + function delete_linked_data() |
|
356 | + { |
|
357 | + $ref_id = $this->get_ref_id(); |
|
358 | + if (!empty($ref_id)) { |
|
359 | + //Cleans forum |
|
360 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
361 | 361 | thread_qualify_max = 0, |
362 | 362 | thread_weight = 0, |
363 | 363 | thread_title_qualify = "" |
364 | 364 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
365 | - Database::query($sql); |
|
366 | - } |
|
367 | - } |
|
365 | + Database::query($sql); |
|
366 | + } |
|
367 | + } |
|
368 | 368 | } |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | die('Error in get_not_created_links() : course code not set'); |
85 | 85 | } |
86 | 86 | |
87 | - $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
88 | - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
87 | + $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
88 | + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
89 | 89 | $session_id = api_get_session_id(); |
90 | 90 | |
91 | 91 | if ($session_id) { |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | $result = Database::query($sql); |
109 | 109 | |
110 | 110 | while ($data = Database::fetch_array($result)) { |
111 | - if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){ |
|
112 | - $cats[] = array ($data['thread_id'], $data['thread_title_qualify']); |
|
111 | + if (isset($data['thread_title_qualify']) and $data['thread_title_qualify'] != "") { |
|
112 | + $cats[] = array($data['thread_id'], $data['thread_title_qualify']); |
|
113 | 113 | } else { |
114 | - $cats[] = array ($data['thread_id'], $data['thread_title']); |
|
114 | + $cats[] = array($data['thread_id'], $data['thread_title']); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | $my_cats = isset($cats) ? $cats : null; |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | if (empty($counter) || $counter <= 2) { |
194 | 194 | return array(0, $assignment['thread_qualify_max']); |
195 | 195 | } |
196 | - return [$score/$counter, $assignment['thread_qualify_max']]; |
|
196 | + return [$score / $counter, $assignment['thread_qualify_max']]; |
|
197 | 197 | } |
198 | 198 | } else { |
199 | 199 | // All students -> get average |
200 | - $students = array(); // user list, needed to make sure we only |
|
200 | + $students = array(); // user list, needed to make sure we only |
|
201 | 201 | // take first attempts into account |
202 | 202 | $counter = 0; |
203 | 203 | $sum = 0; |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | return array($bestResult, $weight); |
229 | 229 | break; |
230 | 230 | case 'average': |
231 | - return array($sumResult/$counter, $weight); |
|
231 | + return array($sumResult / $counter, $weight); |
|
232 | 232 | break; |
233 | 233 | case 'ranking': |
234 | 234 | return AbstractLink::getCurrentUserRanking($stud_id, $students); |
@@ -270,9 +270,9 @@ discard block |
||
270 | 270 | public function get_name() |
271 | 271 | { |
272 | 272 | $this->get_exercise_data(); |
273 | - $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
274 | - $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
275 | - if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
273 | + $thread_title = isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
274 | + $thread_title_qualify = isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
275 | + if (isset($thread_title_qualify) && $thread_title_qualify != "") { |
|
276 | 276 | return $this->exercise_data['thread_title_qualify']; |
277 | 277 | } else { |
278 | 278 | return $thread_title; |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | */ |
285 | 285 | public function get_description() |
286 | 286 | { |
287 | - return '';//$this->exercise_data['description']; |
|
287 | + return ''; //$this->exercise_data['description']; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
311 | 311 | WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".api_get_session_id().""; |
312 | 312 | $result = Database::query($sql); |
313 | - $row = Database::fetch_array($result,'ASSOC'); |
|
314 | - $forum_id=$row['forum_id']; |
|
313 | + $row = Database::fetch_array($result, 'ASSOC'); |
|
314 | + $forum_id = $row['forum_id']; |
|
315 | 315 | |
316 | 316 | $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
317 | 317 | return $url; |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | |
343 | 343 | function save_linked_data() |
344 | 344 | { |
345 | - $weight = (float)$this->get_weight(); |
|
345 | + $weight = (float) $this->get_weight(); |
|
346 | 346 | $ref_id = $this->get_ref_id(); |
347 | 347 | |
348 | 348 | if (!empty($ref_id)) { |
@@ -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 |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | |
44 | 44 | $result = Database::query($sql); |
45 | 45 | |
46 | - $cats=array(); |
|
47 | - while ($data=Database::fetch_array($result)) { |
|
48 | - $cats[] = array ($data['id'], $data['name']); |
|
46 | + $cats = array(); |
|
47 | + while ($data = Database::fetch_array($result)) { |
|
48 | + $cats[] = array($data['id'], $data['name']); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return $cats; |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | $result = Database::query($sql); |
73 | 73 | |
74 | 74 | $cats = array(); |
75 | - while ($data=Database::fetch_array($result)) { |
|
76 | - $cats[] = array ($data['id'], $data['name']); |
|
75 | + while ($data = Database::fetch_array($result)) { |
|
76 | + $cats[] = array($data['id'], $data['name']); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | return $cats; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 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 | 91 | $result = Database::query($sql); |
92 | - $number = Database::fetch_array($result,'NUM'); |
|
92 | + $number = Database::fetch_array($result, 'NUM'); |
|
93 | 93 | return ($number[0] != 0); |
94 | 94 | } |
95 | 95 | |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | // for 1 student |
122 | 122 | if (isset($stud_id)) { |
123 | 123 | if ($data = Database::fetch_array($scores)) { |
124 | - return array ($data['progress'], 100); |
|
124 | + return array($data['progress'], 100); |
|
125 | 125 | } else |
126 | 126 | return null; |
127 | 127 | } else { |
128 | 128 | // all students -> get average |
129 | - $students = array(); // user list, needed to make sure we only |
|
129 | + $students = array(); // user list, needed to make sure we only |
|
130 | 130 | // take first attempts into account |
131 | 131 | $rescount = 0; |
132 | 132 | $sum = 0; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | return array($bestResult, 100); |
155 | 155 | break; |
156 | 156 | case 'average': |
157 | - return array($sumResult/$rescount, 100); |
|
157 | + return array($sumResult / $rescount, 100); |
|
158 | 158 | break; |
159 | 159 | case 'ranking': |
160 | 160 | return AbstractLink::getCurrentUserRanking($stud_id, $students); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 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 | 209 | $result = Database::query($sql); |
210 | - $number = Database::fetch_row($result,'NUM'); |
|
210 | + $number = Database::fetch_row($result, 'NUM'); |
|
211 | 211 | return ($number[0] != 0); |
212 | 212 | } |
213 | 213 |
@@ -29,8 +29,9 @@ discard block |
||
29 | 29 | public function get_not_created_links() |
30 | 30 | { |
31 | 31 | return false; |
32 | - if (empty($this->course_code)) |
|
33 | - die('Error in get_not_created_links() : course code not set'); |
|
32 | + if (empty($this->course_code)) { |
|
33 | + die('Error in get_not_created_links() : course code not set'); |
|
34 | + } |
|
34 | 35 | |
35 | 36 | $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
36 | 37 | |
@@ -57,8 +58,9 @@ discard block |
||
57 | 58 | */ |
58 | 59 | public function get_all_links() |
59 | 60 | { |
60 | - if (empty($this->course_code)) |
|
61 | - die('Error in get_not_created_links() : course code not set'); |
|
61 | + if (empty($this->course_code)) { |
|
62 | + die('Error in get_not_created_links() : course code not set'); |
|
63 | + } |
|
62 | 64 | |
63 | 65 | $session_id = api_get_session_id(); |
64 | 66 | if (empty($session_id)) { |
@@ -111,8 +113,9 @@ discard block |
||
111 | 113 | lp_id = ".$this->get_ref_id()." AND |
112 | 114 | session_id = $session_id "; |
113 | 115 | |
114 | - if (isset($stud_id)) |
|
115 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
116 | + if (isset($stud_id)) { |
|
117 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
118 | + } |
|
116 | 119 | |
117 | 120 | // order by id, that way the student's first attempt is accessed first |
118 | 121 | $sql .= ' ORDER BY view_count DESC'; |
@@ -122,8 +125,9 @@ discard block |
||
122 | 125 | if (isset($stud_id)) { |
123 | 126 | if ($data = Database::fetch_array($scores)) { |
124 | 127 | return array ($data['progress'], 100); |
125 | - } else |
|
126 | - return null; |
|
128 | + } else { |
|
129 | + return null; |
|
130 | + } |
|
127 | 131 | } else { |
128 | 132 | // all students -> get average |
129 | 133 | $students = array(); // user list, needed to make sure we only |
@@ -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 | } |
@@ -59,6 +59,9 @@ |
||
59 | 59 | $this->evaluation = $evaluation_id; |
60 | 60 | } |
61 | 61 | |
62 | + /** |
|
63 | + * @param string $creation_date |
|
64 | + */ |
|
62 | 65 | public function set_date($creation_date) |
63 | 66 | { |
64 | 67 | $this->created_at = $creation_date; |
@@ -90,23 +90,23 @@ discard block |
||
90 | 90 | if (is_null($id) && is_null($user_id) && !is_null($evaluation_id)) { |
91 | 91 | // Verified_if_exist_evaluation |
92 | 92 | $sql = 'SELECT COUNT(*) AS count |
93 | - FROM ' . $tbl_grade_results . ' |
|
94 | - WHERE evaluation_id="' . Database::escape_string($evaluation_id) . '";'; |
|
93 | + FROM ' . $tbl_grade_results.' |
|
94 | + WHERE evaluation_id="' . Database::escape_string($evaluation_id).'";'; |
|
95 | 95 | $result = Database::query($sql); |
96 | 96 | $existEvaluation = Database::result($result, 0, 0); |
97 | 97 | |
98 | 98 | if ($existEvaluation != 0) { |
99 | 99 | if ($sessionId) { |
100 | 100 | $sql = 'SELECT c_id, user_id as user_id, status |
101 | - FROM ' . $tbl_session_rel_course_user . ' |
|
101 | + FROM ' . $tbl_session_rel_course_user.' |
|
102 | 102 | WHERE |
103 | 103 | status= 0 AND |
104 | - c_id = "' . api_get_course_int_id() . '" AND |
|
104 | + c_id = "' . api_get_course_int_id().'" AND |
|
105 | 105 | session_id = ' . $sessionId; |
106 | 106 | } else { |
107 | 107 | $sql = 'SELECT c_id, user_id, status |
108 | - FROM ' . $tbl_course_rel_course . ' |
|
109 | - WHERE status ="' . STUDENT . '" AND c_id = "' . api_get_course_int_id() . '" '; |
|
108 | + FROM ' . $tbl_course_rel_course.' |
|
109 | + WHERE status ="' . STUDENT.'" AND c_id = "'.api_get_course_int_id().'" '; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $res_course_rel_user = Database::query($sql); |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | $current_date = api_get_utc_datetime(); |
117 | 117 | for ($i = 0; $i < count($list_user_course_list); $i++) { |
118 | 118 | $sql_verified = 'SELECT COUNT(*) AS count |
119 | - FROM ' . $tbl_grade_results . ' |
|
119 | + FROM ' . $tbl_grade_results.' |
|
120 | 120 | WHERE |
121 | - user_id="' . intval($list_user_course_list[$i]['user_id']) . '" AND |
|
122 | - evaluation_id="' . intval($evaluation_id) . '";'; |
|
121 | + user_id="' . intval($list_user_course_list[$i]['user_id']).'" AND |
|
122 | + evaluation_id="' . intval($evaluation_id).'";'; |
|
123 | 123 | $res_verified = Database::query($sql_verified); |
124 | 124 | $info_verified = Database::result($res_verified, 0, 0); |
125 | 125 | if ($info_verified == 0) { |
126 | - $sql_insert = 'INSERT INTO ' . $tbl_grade_results . '(user_id,evaluation_id,created_at,score) |
|
127 | - VALUES ("' . intval($list_user_course_list[$i]['user_id']) . '","' . intval($evaluation_id) . '","' . $current_date . '",0);'; |
|
126 | + $sql_insert = 'INSERT INTO '.$tbl_grade_results.'(user_id,evaluation_id,created_at,score) |
|
127 | + VALUES ("' . intval($list_user_course_list[$i]['user_id']).'","'.intval($evaluation_id).'","'.$current_date.'",0);'; |
|
128 | 128 | Database::query($sql_insert); |
129 | 129 | } |
130 | 130 | } |
@@ -148,16 +148,16 @@ discard block |
||
148 | 148 | |
149 | 149 | $paramcount = 0; |
150 | 150 | if (!empty($id)) { |
151 | - $sql.= ' WHERE gr.id = ' . intval($id); |
|
152 | - $paramcount ++; |
|
151 | + $sql .= ' WHERE gr.id = '.intval($id); |
|
152 | + $paramcount++; |
|
153 | 153 | } |
154 | 154 | if (!empty($user_id)) { |
155 | 155 | if ($paramcount != 0) |
156 | 156 | $sql .= ' AND'; |
157 | 157 | else |
158 | 158 | $sql .= ' WHERE'; |
159 | - $sql .= ' gr.user_id = ' . intval($user_id); |
|
160 | - $paramcount ++; |
|
159 | + $sql .= ' gr.user_id = '.intval($user_id); |
|
160 | + $paramcount++; |
|
161 | 161 | } |
162 | 162 | if (!empty($evaluation_id)) { |
163 | 163 | if ($paramcount != 0) { |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | } else { |
166 | 166 | $sql .= ' WHERE'; |
167 | 167 | } |
168 | - $sql .= ' gr.evaluation_id = ' . intval($evaluation_id); |
|
169 | - $paramcount ++; |
|
168 | + $sql .= ' gr.evaluation_id = '.intval($evaluation_id); |
|
169 | + $paramcount++; |
|
170 | 170 | } |
171 | 171 | $sql .= ' ORDER BY u.lastname, u.firstname'; |
172 | 172 | $result = Database::query($sql); |
@@ -191,17 +191,17 @@ discard block |
||
191 | 191 | { |
192 | 192 | if (isset($this->user_id) && isset($this->evaluation)) { |
193 | 193 | $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
194 | - $sql = "INSERT INTO " . $tbl_grade_results |
|
194 | + $sql = "INSERT INTO ".$tbl_grade_results |
|
195 | 195 | . " (user_id, evaluation_id, |
196 | 196 | created_at"; |
197 | 197 | if (isset($this->score)) { |
198 | 198 | $sql .= ",score"; |
199 | 199 | } |
200 | 200 | $sql .= ") VALUES |
201 | - (" . (int) $this->get_user_id() . ", " . (int) $this->get_evaluation_id() |
|
202 | - . ", '" . $this->get_date() . "' "; |
|
201 | + (" . (int) $this->get_user_id().", ".(int) $this->get_evaluation_id() |
|
202 | + . ", '".$this->get_date()."' "; |
|
203 | 203 | if (isset($this->score)) { |
204 | - $sql .= ", " . $this->get_score(); |
|
204 | + $sql .= ", ".$this->get_score(); |
|
205 | 205 | } |
206 | 206 | $sql .= ")"; |
207 | 207 | Database::query($sql); |
@@ -222,16 +222,16 @@ discard block |
||
222 | 222 | $arr_result = $result->load(null, $userid, $evaluationid); |
223 | 223 | $arr = get_object_vars($arr_result[0]); |
224 | 224 | |
225 | - $sql = 'INSERT INTO ' . $tbl_grade_results_log |
|
225 | + $sql = 'INSERT INTO '.$tbl_grade_results_log |
|
226 | 226 | . ' (id_result,user_id, evaluation_id,created_at'; |
227 | 227 | if (isset($arr['score'])) { |
228 | 228 | $sql .= ',score'; |
229 | 229 | } |
230 | 230 | $sql .= ') VALUES |
231 | - (' . (int) $arr['id'] . ',' . (int) $arr['user_id'] . ', ' . (int) $arr['evaluation'] |
|
232 | - . ", '" . api_get_utc_datetime() . "'"; |
|
231 | + (' . (int) $arr['id'].','.(int) $arr['user_id'].', '.(int) $arr['evaluation'] |
|
232 | + . ", '".api_get_utc_datetime()."'"; |
|
233 | 233 | if (isset($arr['score'])) { |
234 | - $sql .= ', ' . $arr['score']; |
|
234 | + $sql .= ', '.$arr['score']; |
|
235 | 235 | } |
236 | 236 | $sql .= ')'; |
237 | 237 | |
@@ -247,16 +247,16 @@ discard block |
||
247 | 247 | public function save() |
248 | 248 | { |
249 | 249 | $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
250 | - $sql = 'UPDATE ' . $tbl_grade_results . ' |
|
250 | + $sql = 'UPDATE '.$tbl_grade_results.' |
|
251 | 251 | SET user_id = ' . $this->get_user_id() |
252 | - . ', evaluation_id = ' . $this->get_evaluation_id() |
|
252 | + . ', evaluation_id = '.$this->get_evaluation_id() |
|
253 | 253 | . ', score = '; |
254 | 254 | if (isset($this->score)) { |
255 | 255 | $sql .= $this->get_score(); |
256 | 256 | } else { |
257 | 257 | $sql .= 'null'; |
258 | 258 | } |
259 | - $sql .= ' WHERE id = ' . $this->id; |
|
259 | + $sql .= ' WHERE id = '.$this->id; |
|
260 | 260 | // no need to update creation date |
261 | 261 | Database::query($sql); |
262 | 262 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | public function delete() |
268 | 268 | { |
269 | 269 | $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
270 | - $sql = 'DELETE FROM ' . $tbl_grade_results . ' WHERE id = ' . $this->id; |
|
270 | + $sql = 'DELETE FROM '.$tbl_grade_results.' WHERE id = '.$this->id; |
|
271 | 271 | Database::query($sql); |
272 | 272 | } |
273 | 273 | } |
@@ -152,10 +152,11 @@ |
||
152 | 152 | $paramcount ++; |
153 | 153 | } |
154 | 154 | if (!empty($user_id)) { |
155 | - if ($paramcount != 0) |
|
156 | - $sql .= ' AND'; |
|
157 | - else |
|
158 | - $sql .= ' WHERE'; |
|
155 | + if ($paramcount != 0) { |
|
156 | + $sql .= ' AND'; |
|
157 | + } else { |
|
158 | + $sql .= ' WHERE'; |
|
159 | + } |
|
159 | 160 | $sql .= ' gr.user_id = ' . intval($user_id); |
160 | 161 | $paramcount ++; |
161 | 162 | } |
@@ -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 | { |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $this->set_additional_parameters($addparams); |
72 | 72 | } |
73 | 73 | |
74 | - $column= 0; |
|
74 | + $column = 0; |
|
75 | 75 | if ($this->teacherView) { |
76 | 76 | if ($this->exportToPdf == false) { |
77 | 77 | $this->set_header($column++, '', '', 'width="25px"'); |
@@ -283,13 +283,13 @@ discard block |
||
283 | 283 | $main_categories[$item->get_id()]['name'] = $item->get_name(); |
284 | 284 | } else { |
285 | 285 | $name = $this->build_name_link($item, $type); |
286 | - $row[] = $invisibility_span_open.$name. $invisibility_span_close; |
|
286 | + $row[] = $invisibility_span_open.$name.$invisibility_span_close; |
|
287 | 287 | $main_categories[$item->get_id()]['name'] = $name; |
288 | 288 | } |
289 | 289 | |
290 | 290 | $this->dataForGraph['categories'][] = $item->get_name(); |
291 | 291 | |
292 | - $main_categories[$item->get_id()]['weight']= $item->get_weight(); |
|
292 | + $main_categories[$item->get_id()]['weight'] = $item->get_weight(); |
|
293 | 293 | $total_categories_weight += $item->get_weight(); |
294 | 294 | |
295 | 295 | // Description. |
@@ -309,9 +309,9 @@ discard block |
||
309 | 309 | ); |
310 | 310 | |
311 | 311 | if ($this->teacherView) { |
312 | - $row[] = $invisibility_span_open .Display::tag('p', $weight, array('class' => 'score')).$invisibility_span_close; |
|
312 | + $row[] = $invisibility_span_open.Display::tag('p', $weight, array('class' => 'score')).$invisibility_span_close; |
|
313 | 313 | } else { |
314 | - $row[] = $invisibility_span_open .$weight.$invisibility_span_close; |
|
314 | + $row[] = $invisibility_span_open.$weight.$invisibility_span_close; |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | $category_weight = $item->get_weight(); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | |
338 | 338 | if (!empty($score[1])) { |
339 | 339 | $completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT); |
340 | - $score = $score[0]/$score[1]*$item->get_weight(); |
|
340 | + $score = $score[0] / $score[1] * $item->get_weight(); |
|
341 | 341 | $score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE); |
342 | 342 | $scoreToDisplay = Display::tip($score, $completeScore); |
343 | 343 | } else { |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | $totalResultAverageValue = strip_tags($scoredisplay->display_score($totalResult, SCORE_AVERAGE)); |
374 | 374 | $this->dataForGraph['my_result'][] = (float) str_replace('%', '', $totalResultAverageValue); |
375 | 375 | $totalAverageValue = strip_tags($scoredisplay->display_score($totalAverage, SCORE_AVERAGE)); |
376 | - $this->dataForGraph['average'][] = (float) str_replace('%', '', $totalAverageValue); |
|
376 | + $this->dataForGraph['average'][] = (float) str_replace('%', '', $totalAverageValue); |
|
377 | 377 | // Ranking |
378 | 378 | $row[] = $ranking; |
379 | 379 | // Best |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | $row[] = $this->build_type_column($item, array('style' => 'padding-left:5px')); |
457 | 457 | |
458 | 458 | // Name. |
459 | - $row[] = $invisibility_span_open." ".$this->build_name_link($item, $type) . $invisibility_span_close; |
|
459 | + $row[] = $invisibility_span_open." ".$this->build_name_link($item, $type).$invisibility_span_close; |
|
460 | 460 | |
461 | 461 | // Description. |
462 | 462 | if ($this->exportToPdf == false) { |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | // Students get the results and certificates columns |
495 | 495 | $eval_n_links = array_merge($alleval, $alllink); |
496 | 496 | |
497 | - if (count($eval_n_links)> 0) { |
|
497 | + if (count($eval_n_links) > 0) { |
|
498 | 498 | $value_data = isset($data[4]) ? $data[4] : null; |
499 | 499 | |
500 | 500 | if (!is_null($value_data)) { |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | $row = array( |
594 | 594 | null, |
595 | 595 | null, |
596 | - '<strong>' . get_lang('Total') . '</strong>', |
|
596 | + '<strong>'.get_lang('Total').'</strong>', |
|
597 | 597 | null, |
598 | 598 | $total |
599 | 599 | ); |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | if ($this->exportToPdf) { |
664 | 664 | $row = array( |
665 | 665 | null, |
666 | - '<h3>' . get_lang('Total') . '</h3>', |
|
666 | + '<h3>'.get_lang('Total').'</h3>', |
|
667 | 667 | $main_weight, |
668 | 668 | $totalResult, |
669 | 669 | $totalRanking, |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | } else { |
674 | 674 | $row = array( |
675 | 675 | null, |
676 | - '<h3>' . get_lang('Total') . '</h3>', |
|
676 | + '<h3>'.get_lang('Total').'</h3>', |
|
677 | 677 | null, |
678 | 678 | $main_weight, |
679 | 679 | $totalResult, |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | } |
689 | 689 | |
690 | 690 | // Warning messages |
691 | - $view = isset($_GET['view']) ? $_GET['view']: null; |
|
691 | + $view = isset($_GET['view']) ? $_GET['view'] : null; |
|
692 | 692 | |
693 | 693 | if ($this->teacherView) { |
694 | 694 | if (isset($_GET['selectcat']) && |
@@ -701,14 +701,14 @@ discard block |
||
701 | 701 | $weight_category = intval($this->build_weight($category[0])); |
702 | 702 | |
703 | 703 | $course_code = $this->build_course_code($category[0]); |
704 | - $weight_total_links = round($weight_total_links); |
|
704 | + $weight_total_links = round($weight_total_links); |
|
705 | 705 | |
706 | 706 | if ($weight_total_links > $weight_category || |
707 | 707 | $weight_total_links < $weight_category || |
708 | 708 | $weight_total_links > $weight_category |
709 | 709 | ) { |
710 | 710 | $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category); |
711 | - $modify_icons = '<a href="gradebook_edit_cat.php?editcat='.$id_cat.'&cidReq='.$course_code.'&id_session='.api_get_session_id().'">'. |
|
711 | + $modify_icons = '<a href="gradebook_edit_cat.php?editcat='.$id_cat.'&cidReq='.$course_code.'&id_session='.api_get_session_id().'">'. |
|
712 | 712 | Display::return_icon('edit.png', $warning_message, array(), ICON_SIZE_SMALL).'</a>'; |
713 | 713 | $warning_message .= $modify_icons; |
714 | 714 | Display::display_warning_message($warning_message, false); |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | ); |
722 | 722 | |
723 | 723 | if (!empty($content_html)) { |
724 | - $new_content = explode('</head>',$content_html['content']); |
|
724 | + $new_content = explode('</head>', $content_html['content']); |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | if (empty($new_content[0])) { |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | is_array($course_codes) |
756 | 756 | ) { |
757 | 757 | $warning_message = ''; |
758 | - for ($x = 0; $x<count($weight_categories);$x++) { |
|
758 | + for ($x = 0; $x < count($weight_categories); $x++) { |
|
759 | 759 | $weight_category = intval($weight_categories[$x]); |
760 | 760 | $certificate_min_score = intval($certificate_min_scores[$x]); |
761 | 761 | $course_code = $course_codes[$x]; |
@@ -763,12 +763,12 @@ discard block |
||
763 | 763 | if (empty($certificate_min_score) || |
764 | 764 | ($certificate_min_score > $weight_category) |
765 | 765 | ) { |
766 | - $warning_message .= $course_code .' - '.get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan').' '.$weight_category.'<br />'; |
|
766 | + $warning_message .= $course_code.' - '.get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan').' '.$weight_category.'<br />'; |
|
767 | 767 | } |
768 | 768 | } |
769 | 769 | |
770 | 770 | if (!empty($warning_message)) { |
771 | - Display::display_warning_message($warning_message,false); |
|
771 | + Display::display_warning_message($warning_message, false); |
|
772 | 772 | } |
773 | 773 | } |
774 | 774 | } |
@@ -812,15 +812,15 @@ discard block |
||
812 | 812 | $pChart->Antialias = FALSE; |
813 | 813 | |
814 | 814 | /* Add a border to the picture */ |
815 | - $pChart->drawRectangle(0,0,$xSize-10,$ySize-10,array("R"=>0,"G"=>0,"B"=>0)); |
|
815 | + $pChart->drawRectangle(0, 0, $xSize - 10, $ySize - 10, array("R"=>0, "G"=>0, "B"=>0)); |
|
816 | 816 | |
817 | - $pChart->drawText(10,16,get_lang('Results'),array("FontSize"=>11,"Align"=>TEXT_ALIGN_BOTTOMLEFT)); |
|
817 | + $pChart->drawText(10, 16, get_lang('Results'), array("FontSize"=>11, "Align"=>TEXT_ALIGN_BOTTOMLEFT)); |
|
818 | 818 | |
819 | - $pChart->setGraphArea(50, 30, $xSize-50, $ySize-50); |
|
819 | + $pChart->setGraphArea(50, 30, $xSize - 50, $ySize - 50); |
|
820 | 820 | |
821 | 821 | $pChart->setFontProperties( |
822 | 822 | array( |
823 | - 'FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', |
|
823 | + 'FontName' => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf', |
|
824 | 824 | 'FontSize' => 10, |
825 | 825 | ) |
826 | 826 | ); |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | |
841 | 841 | /* Draw the line chart */ |
842 | 842 | $pChart->drawLineChart(); |
843 | - $pChart->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80)); |
|
843 | + $pChart->drawPlotChart(array("DisplayValues"=>TRUE, "PlotBorder"=>TRUE, "BorderSize"=>2, "Surrounding"=>-60, "BorderAlpha"=>80)); |
|
844 | 844 | |
845 | 845 | /* Write the chart legend */ |
846 | 846 | $pChart->drawLegend( |
@@ -860,13 +860,13 @@ discard block |
||
860 | 860 | $chartHash = $myCache->getHash($dataSet); |
861 | 861 | |
862 | 862 | $myCache->writeToCache($chartHash, $pChart); |
863 | - $imgSysPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; |
|
863 | + $imgSysPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash; |
|
864 | 864 | $myCache->saveFromCache($chartHash, $imgSysPath); |
865 | - $imgWebPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; |
|
865 | + $imgWebPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash; |
|
866 | 866 | |
867 | 867 | if (file_exists($imgSysPath)) { |
868 | 868 | $result = '<div id="contentArea" style="text-align: center;" >'; |
869 | - $result .= '<img src="' . $imgWebPath.'" >'; |
|
869 | + $result .= '<img src="'.$imgWebPath.'" >'; |
|
870 | 870 | $result .= '</div>'; |
871 | 871 | return $result; |
872 | 872 | } |
@@ -911,13 +911,13 @@ discard block |
||
911 | 911 | switch ($item->get_item_type()) { |
912 | 912 | // category |
913 | 913 | case 'C' : |
914 | - return 'CATE' . $item->get_id(); |
|
914 | + return 'CATE'.$item->get_id(); |
|
915 | 915 | // evaluation |
916 | 916 | case 'E' : |
917 | - return 'EVAL' . $item->get_id(); |
|
917 | + return 'EVAL'.$item->get_id(); |
|
918 | 918 | // link |
919 | 919 | case 'L' : |
920 | - return 'LINK' . $item->get_id(); |
|
920 | + return 'LINK'.$item->get_id(); |
|
921 | 921 | } |
922 | 922 | } |
923 | 923 | |
@@ -945,20 +945,20 @@ discard block |
||
945 | 945 | switch ($item->get_item_type()) { |
946 | 946 | // category |
947 | 947 | case 'C' : |
948 | - $prms_uri='?selectcat=' . $item->get_id() . '&view='.$view; |
|
948 | + $prms_uri = '?selectcat='.$item->get_id().'&view='.$view; |
|
949 | 949 | |
950 | 950 | if (isset($_GET['isStudentView'])) { |
951 | - if ( isset($is_student) || ( isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) { |
|
952 | - $prms_uri=$prms_uri.'&isStudentView='.Security::remove_XSS($_GET['isStudentView']); |
|
951 | + if (isset($is_student) || (isset($_SESSION['studentview']) && $_SESSION['studentview'] == 'studentview')) { |
|
952 | + $prms_uri = $prms_uri.'&isStudentView='.Security::remove_XSS($_GET['isStudentView']); |
|
953 | 953 | } |
954 | 954 | } |
955 | 955 | |
956 | 956 | $cat = new Category(); |
957 | - $show_message=$cat->show_message_resource_delete($item->get_course_code()); |
|
957 | + $show_message = $cat->show_message_resource_delete($item->get_course_code()); |
|
958 | 958 | return ' <a href="'.Security::remove_XSS($_SESSION['gradebook_dest']).$prms_uri.'">' |
959 | 959 | . $item->get_name() |
960 | 960 | . '</a>' |
961 | - . ($item->is_course() ? ' [' . $item->get_course_code() . ']'.$show_message : ''); |
|
961 | + . ($item->is_course() ? ' ['.$item->get_course_code().']'.$show_message : ''); |
|
962 | 962 | // evaluation |
963 | 963 | case 'E' : |
964 | 964 | $cat = new Category(); |
@@ -966,10 +966,10 @@ discard block |
||
966 | 966 | $show_message = $cat->show_message_resource_delete($course_id); |
967 | 967 | |
968 | 968 | // course/platform admin can go to the view_results page |
969 | - if (api_is_allowed_to_edit() && $show_message===false) { |
|
969 | + if (api_is_allowed_to_edit() && $show_message === false) { |
|
970 | 970 | if ($item->get_type() == 'presence') { |
971 | 971 | return ' ' |
972 | - . '<a href="gradebook_view_result.php?cidReq='.$course_id.'&selecteval=' . $item->get_id() . '">' |
|
972 | + . '<a href="gradebook_view_result.php?cidReq='.$course_id.'&selecteval='.$item->get_id().'">' |
|
973 | 973 | . $item->get_name() |
974 | 974 | . '</a>'; |
975 | 975 | } else { |
@@ -978,20 +978,20 @@ discard block |
||
978 | 978 | $extra = ''; |
979 | 979 | } |
980 | 980 | return ' ' |
981 | - . '<a href="gradebook_view_result.php?' . api_get_cidreq() . '&selecteval=' . $item->get_id() . '">' |
|
981 | + . '<a href="gradebook_view_result.php?'.api_get_cidreq().'&selecteval='.$item->get_id().'">' |
|
982 | 982 | . $item->get_name() |
983 | 983 | . '</a> '.$extra; |
984 | 984 | } |
985 | - } elseif (ScoreDisplay :: instance()->is_custom() && $show_message===false) { |
|
985 | + } elseif (ScoreDisplay :: instance()->is_custom() && $show_message === false) { |
|
986 | 986 | // students can go to the statistics page (if custom display enabled) |
987 | 987 | return ' ' |
988 | - . '<a href="gradebook_statistics.php?' . api_get_cidreq() . '&selecteval=' . $item->get_id() . '">' |
|
988 | + . '<a href="gradebook_statistics.php?'.api_get_cidreq().'&selecteval='.$item->get_id().'">' |
|
989 | 989 | . $item->get_name() |
990 | 990 | . '</a>'; |
991 | 991 | |
992 | 992 | } elseif ($show_message === false && !api_is_allowed_to_edit() && !ScoreDisplay :: instance()->is_custom()) { |
993 | 993 | return ' ' |
994 | - . '<a href="gradebook_statistics.php?' . api_get_cidreq() . '&selecteval=' . $item->get_id() . '">' |
|
994 | + . '<a href="gradebook_statistics.php?'.api_get_cidreq().'&selecteval='.$item->get_id().'">' |
|
995 | 995 | . $item->get_name() |
996 | 996 | . '</a>'; |
997 | 997 | } else { |
@@ -1006,7 +1006,7 @@ discard block |
||
1006 | 1006 | $url = $item->get_link(); |
1007 | 1007 | |
1008 | 1008 | if (isset($url) && $show_message === false) { |
1009 | - $text = ' <a href="' . $item->get_link() . '">' |
|
1009 | + $text = ' <a href="'.$item->get_link().'">' |
|
1010 | 1010 | . $item->get_name() |
1011 | 1011 | . '</a>'; |
1012 | 1012 | } else { |
@@ -256,10 +256,11 @@ |
||
256 | 256 | } |
257 | 257 | |
258 | 258 | // Categories. |
259 | - if (!empty($data_array)) |
|
260 | - foreach ($data_array as $data) { |
|
259 | + if (!empty($data_array)) { |
|
260 | + foreach ($data_array as $data) { |
|
261 | 261 | // list of items inside the gradebook (exercises, lps, forums, etc) |
262 | 262 | $row = array(); |
263 | + } |
|
263 | 264 | /** @var AbstractLink $item */ |
264 | 265 | $item = $mainCategory = $data[0]; |
265 | 266 |
@@ -124,8 +124,8 @@ |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | - * @param $link |
|
128 | - * @param $courseCode |
|
127 | + * @param integer $link |
|
128 | + * @param null|string $courseCode |
|
129 | 129 | * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|null|StudentPublicationLink|SurveyLink |
130 | 130 | */ |
131 | 131 | private function createLink($link, $courseCode) |
@@ -10,133 +10,133 @@ |
||
10 | 10 | */ |
11 | 11 | class LinkForm extends FormValidator |
12 | 12 | { |
13 | - const TYPE_CREATE = 1; |
|
14 | - const TYPE_MOVE = 2; |
|
15 | - /** @var Category */ |
|
16 | - private $category_object; |
|
17 | - private $link_object; |
|
18 | - private $extra; |
|
13 | + const TYPE_CREATE = 1; |
|
14 | + const TYPE_MOVE = 2; |
|
15 | + /** @var Category */ |
|
16 | + private $category_object; |
|
17 | + private $link_object; |
|
18 | + private $extra; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Builds a form containing form items based on a given parameter |
|
22 | - * @param int form_type 1=choose link |
|
23 | - * @param obj cat_obj the category object |
|
24 | - * @param string form name |
|
25 | - * @param method |
|
26 | - * @param action |
|
27 | - */ |
|
28 | - public function LinkForm( |
|
29 | - $form_type, |
|
30 | - $category_object, |
|
31 | - $link_object, |
|
32 | - $form_name, |
|
33 | - $method = 'post', |
|
34 | - $action = null, |
|
35 | - $extra = null |
|
36 | - ) { |
|
37 | - parent :: __construct($form_name, $method, $action); |
|
20 | + /** |
|
21 | + * Builds a form containing form items based on a given parameter |
|
22 | + * @param int form_type 1=choose link |
|
23 | + * @param obj cat_obj the category object |
|
24 | + * @param string form name |
|
25 | + * @param method |
|
26 | + * @param action |
|
27 | + */ |
|
28 | + public function LinkForm( |
|
29 | + $form_type, |
|
30 | + $category_object, |
|
31 | + $link_object, |
|
32 | + $form_name, |
|
33 | + $method = 'post', |
|
34 | + $action = null, |
|
35 | + $extra = null |
|
36 | + ) { |
|
37 | + parent :: __construct($form_name, $method, $action); |
|
38 | 38 | |
39 | - if (isset ($category_object)) { |
|
40 | - $this->category_object = $category_object; |
|
41 | - } else { |
|
42 | - if (isset($link_object)) { |
|
43 | - $this->link_object = $link_object; |
|
44 | - } |
|
45 | - } |
|
39 | + if (isset ($category_object)) { |
|
40 | + $this->category_object = $category_object; |
|
41 | + } else { |
|
42 | + if (isset($link_object)) { |
|
43 | + $this->link_object = $link_object; |
|
44 | + } |
|
45 | + } |
|
46 | 46 | |
47 | - if (isset ($extra)) { |
|
48 | - $this->extra = $extra; |
|
49 | - } |
|
50 | - if ($form_type == self :: TYPE_CREATE) { |
|
51 | - $this->build_create(); |
|
52 | - } elseif ($form_type == self :: TYPE_MOVE) { |
|
53 | - $this->build_move(); |
|
54 | - } |
|
55 | - } |
|
47 | + if (isset ($extra)) { |
|
48 | + $this->extra = $extra; |
|
49 | + } |
|
50 | + if ($form_type == self :: TYPE_CREATE) { |
|
51 | + $this->build_create(); |
|
52 | + } elseif ($form_type == self :: TYPE_MOVE) { |
|
53 | + $this->build_move(); |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - protected function build_move() |
|
58 | - { |
|
59 | - $renderer =& $this->defaultRenderer(); |
|
60 | - $renderer->setCustomElementTemplate('<span>{element}</span> '); |
|
61 | - $this->addElement('static',null,null,'"'.$this->link_object->get_name().'" '); |
|
62 | - $this->addElement('static',null,null,get_lang('MoveTo').' : '); |
|
63 | - $select = $this->addElement('select','move_cat',null,null); |
|
64 | - $line = ''; |
|
65 | - foreach ($this->link_object->get_target_categories() as $cat) { |
|
66 | - for ($i=0;$i<$cat[2];$i++) { |
|
67 | - $line .= '—'; |
|
68 | - } |
|
69 | - $select->addoption($line.' '.$cat[1],$cat[0]); |
|
70 | - $line = ''; |
|
71 | - } |
|
72 | - $this->addElement('submit', null, get_lang('Ok')); |
|
73 | - } |
|
57 | + protected function build_move() |
|
58 | + { |
|
59 | + $renderer =& $this->defaultRenderer(); |
|
60 | + $renderer->setCustomElementTemplate('<span>{element}</span> '); |
|
61 | + $this->addElement('static',null,null,'"'.$this->link_object->get_name().'" '); |
|
62 | + $this->addElement('static',null,null,get_lang('MoveTo').' : '); |
|
63 | + $select = $this->addElement('select','move_cat',null,null); |
|
64 | + $line = ''; |
|
65 | + foreach ($this->link_object->get_target_categories() as $cat) { |
|
66 | + for ($i=0;$i<$cat[2];$i++) { |
|
67 | + $line .= '—'; |
|
68 | + } |
|
69 | + $select->addoption($line.' '.$cat[1],$cat[0]); |
|
70 | + $line = ''; |
|
71 | + } |
|
72 | + $this->addElement('submit', null, get_lang('Ok')); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Builds the form |
|
77 | - */ |
|
78 | - protected function build_create() |
|
79 | - { |
|
80 | - $this->addElement('header', get_lang('MakeLink')); |
|
81 | - $select = $this->addElement( |
|
82 | - 'select', |
|
83 | - 'select_link', |
|
84 | - get_lang('ChooseLink'), |
|
85 | - null, |
|
86 | - array('onchange' => 'document.create_link.submit()') |
|
87 | - ); |
|
75 | + /** |
|
76 | + * Builds the form |
|
77 | + */ |
|
78 | + protected function build_create() |
|
79 | + { |
|
80 | + $this->addElement('header', get_lang('MakeLink')); |
|
81 | + $select = $this->addElement( |
|
82 | + 'select', |
|
83 | + 'select_link', |
|
84 | + get_lang('ChooseLink'), |
|
85 | + null, |
|
86 | + array('onchange' => 'document.create_link.submit()') |
|
87 | + ); |
|
88 | 88 | |
89 | - $linkTypes = LinkFactory::get_all_types(); |
|
89 | + $linkTypes = LinkFactory::get_all_types(); |
|
90 | 90 | |
91 | - $select->addoption('['.get_lang('ChooseLink').']', 0); |
|
91 | + $select->addoption('['.get_lang('ChooseLink').']', 0); |
|
92 | 92 | |
93 | - $courseCode = $this->category_object->get_course_code(); |
|
93 | + $courseCode = $this->category_object->get_course_code(); |
|
94 | 94 | |
95 | - foreach ($linkTypes as $linkType) { |
|
96 | - // The hot potatoe link will be added "inside" the exercise option. |
|
97 | - if ($linkType == LINK_HOTPOTATOES) { |
|
98 | - continue; |
|
99 | - } |
|
100 | - $link = $this->createLink($linkType, $courseCode); |
|
101 | - // disable this element if the link works with a dropdownlist |
|
102 | - // and if there are no links left |
|
103 | - if (!$link->needs_name_and_description() && count($link->get_all_links()) == '0') { |
|
104 | - $select->addoption($link->get_type_name(), $linkType, 'disabled'); |
|
105 | - } else { |
|
106 | - if ($link->get_type() == LINK_EXERCISE) { |
|
107 | - // Adding exercise |
|
108 | - $select->addoption($link->get_type_name(), $linkType); |
|
109 | - // Adding hot potatoes |
|
110 | - $linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode); |
|
111 | - $select->addoption( |
|
112 | - ' '.$linkHot->get_type_name(), |
|
113 | - LINK_HOTPOTATOES |
|
114 | - ); |
|
115 | - } else { |
|
116 | - $select->addoption($link->get_type_name(), $linkType); |
|
117 | - } |
|
118 | - } |
|
119 | - } |
|
95 | + foreach ($linkTypes as $linkType) { |
|
96 | + // The hot potatoe link will be added "inside" the exercise option. |
|
97 | + if ($linkType == LINK_HOTPOTATOES) { |
|
98 | + continue; |
|
99 | + } |
|
100 | + $link = $this->createLink($linkType, $courseCode); |
|
101 | + // disable this element if the link works with a dropdownlist |
|
102 | + // and if there are no links left |
|
103 | + if (!$link->needs_name_and_description() && count($link->get_all_links()) == '0') { |
|
104 | + $select->addoption($link->get_type_name(), $linkType, 'disabled'); |
|
105 | + } else { |
|
106 | + if ($link->get_type() == LINK_EXERCISE) { |
|
107 | + // Adding exercise |
|
108 | + $select->addoption($link->get_type_name(), $linkType); |
|
109 | + // Adding hot potatoes |
|
110 | + $linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode); |
|
111 | + $select->addoption( |
|
112 | + ' '.$linkHot->get_type_name(), |
|
113 | + LINK_HOTPOTATOES |
|
114 | + ); |
|
115 | + } else { |
|
116 | + $select->addoption($link->get_type_name(), $linkType); |
|
117 | + } |
|
118 | + } |
|
119 | + } |
|
120 | 120 | |
121 | - if (isset($this->extra)) { |
|
122 | - $this->setDefaults(array('select_link' => $this->extra)); |
|
123 | - } |
|
124 | - } |
|
121 | + if (isset($this->extra)) { |
|
122 | + $this->setDefaults(array('select_link' => $this->extra)); |
|
123 | + } |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @param $link |
|
128 | - * @param $courseCode |
|
129 | - * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|null|StudentPublicationLink|SurveyLink |
|
130 | - */ |
|
131 | - private function createLink($link, $courseCode) |
|
132 | - { |
|
133 | - $link = LinkFactory::create($link); |
|
134 | - if (!empty($courseCode)) { |
|
135 | - $link->set_course_code($courseCode); |
|
136 | - } elseif(!empty($_GET['course_code'])) { |
|
137 | - $link->set_course_code(Database::escape_string($_GET['course_code'], null, false)); |
|
138 | - } |
|
126 | + /** |
|
127 | + * @param $link |
|
128 | + * @param $courseCode |
|
129 | + * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|null|StudentPublicationLink|SurveyLink |
|
130 | + */ |
|
131 | + private function createLink($link, $courseCode) |
|
132 | + { |
|
133 | + $link = LinkFactory::create($link); |
|
134 | + if (!empty($courseCode)) { |
|
135 | + $link->set_course_code($courseCode); |
|
136 | + } elseif(!empty($_GET['course_code'])) { |
|
137 | + $link->set_course_code(Database::escape_string($_GET['course_code'], null, false)); |
|
138 | + } |
|
139 | 139 | |
140 | - return $link; |
|
141 | - } |
|
140 | + return $link; |
|
141 | + } |
|
142 | 142 | } |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | |
57 | 57 | protected function build_move() |
58 | 58 | { |
59 | - $renderer =& $this->defaultRenderer(); |
|
59 | + $renderer = & $this->defaultRenderer(); |
|
60 | 60 | $renderer->setCustomElementTemplate('<span>{element}</span> '); |
61 | - $this->addElement('static',null,null,'"'.$this->link_object->get_name().'" '); |
|
62 | - $this->addElement('static',null,null,get_lang('MoveTo').' : '); |
|
63 | - $select = $this->addElement('select','move_cat',null,null); |
|
61 | + $this->addElement('static', null, null, '"'.$this->link_object->get_name().'" '); |
|
62 | + $this->addElement('static', null, null, get_lang('MoveTo').' : '); |
|
63 | + $select = $this->addElement('select', 'move_cat', null, null); |
|
64 | 64 | $line = ''; |
65 | 65 | foreach ($this->link_object->get_target_categories() as $cat) { |
66 | - for ($i=0;$i<$cat[2];$i++) { |
|
66 | + for ($i = 0; $i < $cat[2]; $i++) { |
|
67 | 67 | $line .= '—'; |
68 | 68 | } |
69 | - $select->addoption($line.' '.$cat[1],$cat[0]); |
|
69 | + $select->addoption($line.' '.$cat[1], $cat[0]); |
|
70 | 70 | $line = ''; |
71 | 71 | } |
72 | 72 | $this->addElement('submit', null, get_lang('Ok')); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $link = LinkFactory::create($link); |
134 | 134 | if (!empty($courseCode)) { |
135 | 135 | $link->set_course_code($courseCode); |
136 | - } elseif(!empty($_GET['course_code'])) { |
|
136 | + } elseif (!empty($_GET['course_code'])) { |
|
137 | 137 | $link->set_course_code(Database::escape_string($_GET['course_code'], null, false)); |
138 | 138 | } |
139 | 139 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param array $evals |
31 | 31 | * @param array $links |
32 | 32 | * @param array $params |
33 | - * @param null $mainCourseCategory |
|
33 | + * @param Category|null $mainCourseCategory |
|
34 | 34 | */ |
35 | 35 | public function FlatViewDataGenerator( |
36 | 36 | $users = array(), |
@@ -276,6 +276,8 @@ discard block |
||
276 | 276 | |
277 | 277 | /** |
278 | 278 | * Get actual array data |
279 | + * @param integer $users_count |
|
280 | + * @param integer $items_count |
|
279 | 281 | * @return array 2-dimensional array - each array contains the elements: |
280 | 282 | * 0: user id |
281 | 283 | * 1: user lastname |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | isset($this->params['only_subcat']) && |
115 | 115 | $this->params['only_subcat'] == $this->category->get_id() |
116 | 116 | ) { |
117 | - $main_weight = $this->category->get_weight(); |
|
117 | + $main_weight = $this->category->get_weight(); |
|
118 | 118 | $grade_model_id = $this->category->get_grade_model_id(); |
119 | 119 | } else { |
120 | - $main_cat = Category::load($parent_id, null, null); |
|
120 | + $main_cat = Category::load($parent_id, null, null); |
|
121 | 121 | $main_weight = $main_cat[0]->get_weight(); |
122 | 122 | $grade_model_id = $main_cat[0]->get_grade_model_id(); |
123 | 123 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $list = []; |
200 | 200 | $list['items'] = $finalList; |
201 | 201 | $list['header'] = '<center>'.$mainHeader.'</center>'; |
202 | - $headers[]= $list; |
|
202 | + $headers[] = $list; |
|
203 | 203 | } else { |
204 | 204 | $headers[] = '<center>'.$mainHeader.'</center>'; |
205 | 205 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | (isset($this->params['only_total_category']) && |
210 | 210 | $this->params['only_total_category'] == false) |
211 | 211 | ) { |
212 | - for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) { |
|
212 | + for ($count = 0; ($count < $items_count) && ($items_start + $count < count($this->evals_links)); $count++) { |
|
213 | 213 | /** @var AbstractLink $item */ |
214 | 214 | $item = $this->evals_links[$count + $items_start]; |
215 | 215 | $weight = round(100 * $item->get_weight() / $main_weight, 1); |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | !in_array($item->get_id(), $evaluationsAdded) |
228 | 228 | ) { |
229 | 229 | $weight = round(100 * $item->get_weight() / $main_weight, 1); |
230 | - $headers[] = $item->get_name() . ' ' . $weight . ' % '; |
|
230 | + $headers[] = $item->get_name().' '.$weight.' % '; |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | if (!isset($items_count)) { |
267 | 267 | $items_count = count($this->evals_links) - $items_start; |
268 | 268 | } |
269 | - for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) { |
|
269 | + for ($count = 0; ($count < $items_count) && ($items_start + $count < count($this->evals_links)); $count++) { |
|
270 | 270 | $item = $this->evals_links [$count + $items_start]; |
271 | 271 | $headers[] = $item->get_name(); |
272 | 272 | } |
@@ -293,13 +293,13 @@ discard block |
||
293 | 293 | ) { |
294 | 294 | // Do some checks on users/items counts, redefine if invalid values |
295 | 295 | if (!isset($users_count)) { |
296 | - $users_count = count ($this->users) - $users_start; |
|
296 | + $users_count = count($this->users) - $users_start; |
|
297 | 297 | } |
298 | 298 | if ($users_count < 0) { |
299 | 299 | $users_count = 0; |
300 | 300 | } |
301 | 301 | if (!isset($items_count)) { |
302 | - $items_count = count ($this->evals) + count ($this->links) - $items_start; |
|
302 | + $items_count = count($this->evals) + count($this->links) - $items_start; |
|
303 | 303 | } |
304 | 304 | if ($items_count < 0) { |
305 | 305 | $items_count = 0; |
@@ -312,10 +312,10 @@ discard block |
||
312 | 312 | |
313 | 313 | // sort users array |
314 | 314 | if ($users_sorting & self :: FVDG_SORT_LASTNAME) { |
315 | - usort($userTable, array('FlatViewDataGenerator','sort_by_last_name')); |
|
315 | + usort($userTable, array('FlatViewDataGenerator', 'sort_by_last_name')); |
|
316 | 316 | |
317 | 317 | } elseif ($users_sorting & self :: FVDG_SORT_FIRSTNAME) { |
318 | - usort($userTable, array('FlatViewDataGenerator','sort_by_first_name')); |
|
318 | + usort($userTable, array('FlatViewDataGenerator', 'sort_by_first_name')); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | if ($users_sorting & self :: FVDG_SORT_DESC) { |
@@ -356,10 +356,10 @@ discard block |
||
356 | 356 | $parent_id = $this->category->get_parent_id(); |
357 | 357 | |
358 | 358 | if ($parent_id == 0 or $this->params['only_subcat'] == $this->category->get_id()) { |
359 | - $main_weight = $this->category->get_weight(); |
|
359 | + $main_weight = $this->category->get_weight(); |
|
360 | 360 | $grade_model_id = $this->category->get_grade_model_id(); |
361 | 361 | } else { |
362 | - $main_cat = Category::load($parent_id, null, null); |
|
362 | + $main_cat = Category::load($parent_id, null, null); |
|
363 | 363 | $main_weight = $main_cat[0]->get_weight(); |
364 | 364 | $grade_model_id = $main_cat[0]->get_grade_model_id(); |
365 | 365 | } |
@@ -471,11 +471,11 @@ discard block |
||
471 | 471 | $divide = $score[1] == 0 ? 1 : $score[1]; |
472 | 472 | |
473 | 473 | $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()]; |
474 | - $item_value = $score[0]/$divide*$main_weight; |
|
474 | + $item_value = $score[0] / $divide * $main_weight; |
|
475 | 475 | |
476 | 476 | // Fixing total when using one or multiple gradebooks |
477 | - $percentage = $sub_cat->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight(); |
|
478 | - $item_value = $percentage*$item_value; |
|
477 | + $percentage = $sub_cat->get_weight() / ($sub_cat_percentage) * $sub_cat_percentage / $this->category->get_weight(); |
|
478 | + $item_value = $percentage * $item_value; |
|
479 | 479 | $item_total += $sub_cat->get_weight(); |
480 | 480 | /* |
481 | 481 | if ($convert_using_the_global_weight) { |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | if ($convert_using_the_global_weight) { |
522 | 522 | //$item_total = $main_weight; |
523 | 523 | } |
524 | - } else { |
|
524 | + } else { |
|
525 | 525 | // All evaluations |
526 | 526 | $result = $this->parseEvaluations( |
527 | 527 | $user_id, |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | // Sub cat weight |
629 | 629 | //$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()]; |
630 | 630 | |
631 | - $item_value = isset($score[0]) ? $score[0]/$divide : 0; |
|
631 | + $item_value = isset($score[0]) ? $score[0] / $divide : 0; |
|
632 | 632 | |
633 | 633 | // Fixing total when using one or multiple gradebooks. |
634 | 634 | if (empty($parentCategoryIdFilter)) { |
@@ -710,11 +710,11 @@ discard block |
||
710 | 710 | $data = array(); |
711 | 711 | |
712 | 712 | foreach ($selected_users as $user) { |
713 | - $row = array (); |
|
714 | - for ($count=0;$count < count($this->evals_links); $count++) { |
|
713 | + $row = array(); |
|
714 | + for ($count = 0; $count < count($this->evals_links); $count++) { |
|
715 | 715 | $item = $this->evals_links [$count]; |
716 | 716 | $score = $item->calc_score($user[0]); |
717 | - $porcent_score = isset($score[1]) && $score[1] > 0 ? ($score[0]*100)/$score[1] :0; |
|
717 | + $porcent_score = isset($score[1]) && $score[1] > 0 ? ($score[0] * 100) / $score[1] : 0; |
|
718 | 718 | $row[$item->get_name()] = $porcent_score; |
719 | 719 | } |
720 | 720 | $data[$user[0]] = $row; |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | $tmp = array(); |
727 | 727 | foreach ($items as $item => $value) { |
728 | 728 | $tmp[] = $item; |
729 | - if (in_array($item,$tmp)) { |
|
729 | + if (in_array($item, $tmp)) { |
|
730 | 730 | $data_by_item[$item][$uid] = $value; |
731 | 731 | } |
732 | 732 | } |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | */ |
738 | 738 | $result = array(); |
739 | 739 | foreach ($data_by_item as $k => $v) { |
740 | - $average = round(array_sum($v)/count($v)); |
|
740 | + $average = round(array_sum($v) / count($v)); |
|
741 | 741 | arsort($v); |
742 | 742 | $maximum = array_shift($v); |
743 | 743 | $minimum = array_pop($v); |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | $minimum = 0; |
747 | 747 | } |
748 | 748 | |
749 | - $summary= array( |
|
749 | + $summary = array( |
|
750 | 750 | 'max' => $maximum, |
751 | 751 | 'min' => $minimum, |
752 | 752 | 'avg' => $average |
@@ -763,32 +763,32 @@ discard block |
||
763 | 763 | public function get_data_to_graph() |
764 | 764 | { |
765 | 765 | // do some checks on users/items counts, redefine if invalid values |
766 | - $usertable = array (); |
|
766 | + $usertable = array(); |
|
767 | 767 | foreach ($this->users as $user) { |
768 | 768 | $usertable[] = $user; |
769 | 769 | } |
770 | 770 | // sort users array |
771 | - usort($usertable, array ('FlatViewDataGenerator','sort_by_first_name')); |
|
771 | + usort($usertable, array('FlatViewDataGenerator', 'sort_by_first_name')); |
|
772 | 772 | |
773 | - $data = array (); |
|
773 | + $data = array(); |
|
774 | 774 | |
775 | 775 | $selected_users = $usertable; |
776 | 776 | foreach ($selected_users as $user) { |
777 | - $row = array (); |
|
778 | - $row[] = $user[0]; // user id |
|
777 | + $row = array(); |
|
778 | + $row[] = $user[0]; // user id |
|
779 | 779 | $item_value = 0; |
780 | 780 | $item_total = 0; |
781 | 781 | |
782 | - for ($count=0;$count < count($this->evals_links); $count++) { |
|
782 | + for ($count = 0; $count < count($this->evals_links); $count++) { |
|
783 | 783 | $item = $this->evals_links[$count]; |
784 | 784 | $score = $item->calc_score($user[0]); |
785 | 785 | |
786 | - $divide =( ($score[1])==0 ) ? 1 : $score[1]; |
|
787 | - $item_value += $score[0]/$divide*$item->get_weight(); |
|
786 | + $divide = (($score[1]) == 0) ? 1 : $score[1]; |
|
787 | + $item_value += $score[0] / $divide * $item->get_weight(); |
|
788 | 788 | $item_total += $item->get_weight(); |
789 | 789 | |
790 | 790 | |
791 | - $score_denom = ($score[1]==0) ? 1 : $score[1]; |
|
791 | + $score_denom = ($score[1] == 0) ? 1 : $score[1]; |
|
792 | 792 | $score_final = ($score[0] / $score_denom) * 100; |
793 | 793 | $row[] = $score_final; |
794 | 794 | } |
@@ -814,15 +814,15 @@ discard block |
||
814 | 814 | $usertable[] = $user; |
815 | 815 | } |
816 | 816 | // sort users array |
817 | - usort($usertable, array ('FlatViewDataGenerator','sort_by_first_name')); |
|
817 | + usort($usertable, array('FlatViewDataGenerator', 'sort_by_first_name')); |
|
818 | 818 | |
819 | 819 | // generate actual data array |
820 | 820 | $scoredisplay = ScoreDisplay :: instance(); |
821 | 821 | $data = array(); |
822 | 822 | $selected_users = $usertable; |
823 | 823 | foreach ($selected_users as $user) { |
824 | - $row = array (); |
|
825 | - $row[] = $user[0]; // user id |
|
824 | + $row = array(); |
|
825 | + $row[] = $user[0]; // user id |
|
826 | 826 | $item_value = 0; |
827 | 827 | $item_total = 0; |
828 | 828 | $final_score = 0; |
@@ -843,8 +843,8 @@ discard block |
||
843 | 843 | $divide = $score[1] == 0 ? 1 : $score[1]; |
844 | 844 | |
845 | 845 | //$sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()]; |
846 | - $item_value = $score[0]/$divide*$main_weight; |
|
847 | - $item_total += $sub_cat->get_weight(); |
|
846 | + $item_value = $score[0] / $divide * $main_weight; |
|
847 | + $item_total += $sub_cat->get_weight(); |
|
848 | 848 | |
849 | 849 | $row[] = array( |
850 | 850 | $item_value, |
@@ -861,23 +861,23 @@ discard block |
||
861 | 861 | trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true)) |
862 | 862 | ); |
863 | 863 | } else { |
864 | - for ($count=0;$count < count($this->evals_links); $count++) { |
|
864 | + for ($count = 0; $count < count($this->evals_links); $count++) { |
|
865 | 865 | $item = $this->evals_links [$count]; |
866 | 866 | $score = $item->calc_score($user[0]); |
867 | 867 | $divide = ($score[1]) == 0 ? 1 : $score[1]; |
868 | 868 | $item_value += $score[0] / $divide * $item->get_weight(); |
869 | - $item_total+=$item->get_weight(); |
|
870 | - $score_denom=($score[1]==0) ? 1 : $score[1]; |
|
869 | + $item_total += $item->get_weight(); |
|
870 | + $score_denom = ($score[1] == 0) ? 1 : $score[1]; |
|
871 | 871 | $score_final = ($score[0] / $score_denom) * 100; |
872 | - $row[] = array ($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM,null, true))); |
|
872 | + $row[] = array($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM, null, true))); |
|
873 | 873 | |
874 | 874 | } |
875 | - $total_score=array($item_value,$item_total); |
|
875 | + $total_score = array($item_value, $item_total); |
|
876 | 876 | $score_final = ($item_value / $item_total) * 100; |
877 | 877 | if ($displayWarning) { |
878 | - Display::display_warning_message( Display::display_warning_message($total_score[1])); |
|
878 | + Display::display_warning_message(Display::display_warning_message($total_score[1])); |
|
879 | 879 | } |
880 | - $row[] =array ($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); |
|
880 | + $row[] = array($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); |
|
881 | 881 | } |
882 | 882 | |
883 | 883 | $data[] = $row; |