| Conditions | 139 |
| Paths | > 20000 |
| Total Lines | 744 |
| Code Lines | 483 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 1110 | public function returnCoursesAndSessions( |
||
| 1111 | $user_id, |
||
| 1112 | $showSessions = true, |
||
| 1113 | $categoryCodeFilter = '', |
||
| 1114 | $useUserLanguageFilterIfAvailable = true, |
||
| 1115 | $loadHistory = false |
||
| 1116 | ) { |
||
| 1117 | $gameModeIsActive = api_get_setting('gamification_mode'); |
||
| 1118 | $viewGridCourses = api_get_configuration_value('view_grid_courses'); |
||
| 1119 | $showSimpleSessionInfo = api_get_configuration_value('show_simple_session_info'); |
||
| 1120 | $coursesWithoutCategoryTemplate = '/user_portal/classic_courses_without_category.tpl'; |
||
| 1121 | $coursesWithCategoryTemplate = '/user_portal/classic_courses_with_category.tpl'; |
||
| 1122 | $showAllSessions = true === api_get_configuration_value('show_all_sessions_on_my_course_page'); |
||
| 1123 | |||
| 1124 | if ($loadHistory) { |
||
| 1125 | // Load sessions in category in *history* |
||
| 1126 | $session_categories = UserManager::get_sessions_by_category($user_id, true); |
||
| 1127 | } else { |
||
| 1128 | // Load sessions in category |
||
| 1129 | $session_categories = UserManager::get_sessions_by_category($user_id, false); |
||
| 1130 | } |
||
| 1131 | |||
| 1132 | $sessionCount = 0; |
||
| 1133 | $courseCount = 0; |
||
| 1134 | |||
| 1135 | // Student info code check (shows student progress information on |
||
| 1136 | // courses list |
||
| 1137 | $studentInfo = api_get_configuration_value('course_student_info'); |
||
| 1138 | |||
| 1139 | $studentInfoProgress = !empty($studentInfo['progress']) && true === $studentInfo['progress']; |
||
| 1140 | $studentInfoScore = !empty($studentInfo['score']) && true === $studentInfo['score']; |
||
| 1141 | $studentInfoCertificate = !empty($studentInfo['certificate']) && true === $studentInfo['certificate']; |
||
| 1142 | $courseCompleteList = []; |
||
| 1143 | $coursesInCategoryCount = 0; |
||
| 1144 | $coursesNotInCategoryCount = 0; |
||
| 1145 | $listCourse = ''; |
||
| 1146 | $specialCourseList = ''; |
||
| 1147 | |||
| 1148 | // If we're not in the history view... |
||
| 1149 | if (false === $loadHistory) { |
||
| 1150 | // Display special courses. |
||
| 1151 | $specialCourses = CourseManager::returnSpecialCourses( |
||
| 1152 | $user_id, |
||
| 1153 | $this->load_directories_preview, |
||
| 1154 | $useUserLanguageFilterIfAvailable |
||
| 1155 | ); |
||
| 1156 | |||
| 1157 | // Display courses. |
||
| 1158 | /*$courses = CourseManager::returnCourses( |
||
| 1159 | $user_id, |
||
| 1160 | $this->load_directories_preview, |
||
| 1161 | $useUserLanguageFilterIfAvailable |
||
| 1162 | );*/ |
||
| 1163 | $courses = []; |
||
| 1164 | |||
| 1165 | // Course option (show student progress) |
||
| 1166 | // This code will add new variables (Progress, Score, Certificate) |
||
| 1167 | if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) { |
||
| 1168 | if (!empty($specialCourses)) { |
||
| 1169 | foreach ($specialCourses as $key => $specialCourseInfo) { |
||
| 1170 | if ($studentInfoProgress) { |
||
| 1171 | $progress = Tracking::get_avg_student_progress( |
||
| 1172 | $user_id, |
||
| 1173 | $specialCourseInfo['course_code'] |
||
| 1174 | ); |
||
| 1175 | $specialCourses[$key]['student_info']['progress'] = false === $progress ? null : $progress; |
||
| 1176 | } |
||
| 1177 | |||
| 1178 | if ($studentInfoScore) { |
||
| 1179 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1180 | $user_id, |
||
| 1181 | $specialCourseInfo['course_code'], |
||
| 1182 | [] |
||
| 1183 | ); |
||
| 1184 | $specialCourses[$key]['student_info']['score'] = $percentage_score; |
||
| 1185 | } |
||
| 1186 | |||
| 1187 | if ($studentInfoCertificate) { |
||
| 1188 | $category = Category::load( |
||
| 1189 | null, |
||
| 1190 | null, |
||
| 1191 | $specialCourseInfo['course_code'], |
||
| 1192 | null, |
||
| 1193 | null, |
||
| 1194 | null |
||
| 1195 | ); |
||
| 1196 | $specialCourses[$key]['student_info']['certificate'] = null; |
||
| 1197 | if (isset($category[0])) { |
||
| 1198 | if ($category[0]->is_certificate_available($user_id)) { |
||
| 1199 | $specialCourses[$key]['student_info']['certificate'] = Display::label( |
||
| 1200 | get_lang('Yes'), |
||
| 1201 | 'success' |
||
| 1202 | ); |
||
| 1203 | } else { |
||
| 1204 | $specialCourses[$key]['student_info']['certificate'] = Display::label( |
||
| 1205 | get_lang('No'), |
||
| 1206 | 'danger' |
||
| 1207 | ); |
||
| 1208 | } |
||
| 1209 | } |
||
| 1210 | } |
||
| 1211 | } |
||
| 1212 | } |
||
| 1213 | |||
| 1214 | if (isset($courses['in_category'])) { |
||
| 1215 | foreach ($courses['in_category'] as $key1 => $value) { |
||
| 1216 | if (isset($courses['in_category'][$key1]['courses'])) { |
||
| 1217 | foreach ($courses['in_category'][$key1]['courses'] as $key2 => $courseInCatInfo) { |
||
| 1218 | $courseCode = $courseInCatInfo['course_code']; |
||
| 1219 | if ($studentInfoProgress) { |
||
| 1220 | $progress = Tracking::get_avg_student_progress( |
||
| 1221 | $user_id, |
||
| 1222 | $courseCode |
||
| 1223 | ); |
||
| 1224 | $courses['in_category'][$key1]['courses'][$key2]['student_info']['progress'] = false === $progress ? null : $progress; |
||
| 1225 | } |
||
| 1226 | |||
| 1227 | if ($studentInfoScore) { |
||
| 1228 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1229 | $user_id, |
||
| 1230 | $courseCode, |
||
| 1231 | [] |
||
| 1232 | ); |
||
| 1233 | $courses['in_category'][$key1]['courses'][$key2]['student_info']['score'] = $percentage_score; |
||
| 1234 | } |
||
| 1235 | |||
| 1236 | if ($studentInfoCertificate) { |
||
| 1237 | $category = Category::load( |
||
| 1238 | null, |
||
| 1239 | null, |
||
| 1240 | $courseCode, |
||
| 1241 | null, |
||
| 1242 | null, |
||
| 1243 | null |
||
| 1244 | ); |
||
| 1245 | $courses['in_category'][$key1]['student_info']['certificate'] = null; |
||
| 1246 | $isCertificateAvailable = $category[0]->is_certificate_available($user_id); |
||
| 1247 | if (isset($category[0])) { |
||
| 1248 | if ($viewGridCourses) { |
||
| 1249 | if ($isCertificateAvailable) { |
||
| 1250 | $courses['in_category'][$key1]['student_info']['certificate'] = get_lang( |
||
| 1251 | 'Yes' |
||
| 1252 | ); |
||
| 1253 | } else { |
||
| 1254 | $courses['in_category'][$key1]['student_info']['certificate'] = get_lang( |
||
| 1255 | 'No' |
||
| 1256 | ); |
||
| 1257 | } |
||
| 1258 | } else { |
||
| 1259 | if ($isCertificateAvailable) { |
||
| 1260 | $courses['in_category'][$key1]['student_info']['certificate'] = Display::label( |
||
| 1261 | get_lang('Yes'), |
||
| 1262 | 'success' |
||
| 1263 | ); |
||
| 1264 | } else { |
||
| 1265 | $courses['in_category'][$key1]['student_info']['certificate'] = Display::label( |
||
| 1266 | get_lang('No'), |
||
| 1267 | 'danger' |
||
| 1268 | ); |
||
| 1269 | } |
||
| 1270 | } |
||
| 1271 | } |
||
| 1272 | } |
||
| 1273 | } |
||
| 1274 | } |
||
| 1275 | } |
||
| 1276 | } |
||
| 1277 | |||
| 1278 | if (isset($courses['not_category'])) { |
||
| 1279 | foreach ($courses['not_category'] as $key => $courseNotInCatInfo) { |
||
| 1280 | $courseCode = $courseNotInCatInfo['course_code']; |
||
| 1281 | if ($studentInfoProgress) { |
||
| 1282 | $progress = Tracking::get_avg_student_progress( |
||
| 1283 | $user_id, |
||
| 1284 | $courseCode |
||
| 1285 | ); |
||
| 1286 | $courses['not_category'][$key]['student_info']['progress'] = false === $progress ? null : $progress; |
||
| 1287 | } |
||
| 1288 | |||
| 1289 | if ($studentInfoScore) { |
||
| 1290 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1291 | $user_id, |
||
| 1292 | $courseCode, |
||
| 1293 | [] |
||
| 1294 | ); |
||
| 1295 | $courses['not_category'][$key]['student_info']['score'] = $percentage_score; |
||
| 1296 | } |
||
| 1297 | |||
| 1298 | if ($studentInfoCertificate) { |
||
| 1299 | $category = Category::load( |
||
| 1300 | null, |
||
| 1301 | null, |
||
| 1302 | $courseCode, |
||
| 1303 | null, |
||
| 1304 | null, |
||
| 1305 | null |
||
| 1306 | ); |
||
| 1307 | $courses['not_category'][$key]['student_info']['certificate'] = null; |
||
| 1308 | |||
| 1309 | if (isset($category[0])) { |
||
| 1310 | $certificateAvailable = $category[0]->is_certificate_available($user_id); |
||
| 1311 | if ($viewGridCourses) { |
||
| 1312 | if ($certificateAvailable) { |
||
| 1313 | $courses['not_category'][$key]['student_info']['certificate'] = get_lang('Yes'); |
||
| 1314 | } else { |
||
| 1315 | $courses['not_category'][$key]['student_info']['certificate'] = get_lang('No'); |
||
| 1316 | } |
||
| 1317 | } else { |
||
| 1318 | if ($certificateAvailable) { |
||
| 1319 | $courses['not_category'][$key]['student_info']['certificate'] = Display::label( |
||
| 1320 | get_lang('Yes'), |
||
| 1321 | 'success' |
||
| 1322 | ); |
||
| 1323 | } else { |
||
| 1324 | $courses['not_category'][$key]['student_info']['certificate'] = Display::label( |
||
| 1325 | get_lang('No'), |
||
| 1326 | 'danger' |
||
| 1327 | ); |
||
| 1328 | } |
||
| 1329 | } |
||
| 1330 | } |
||
| 1331 | } |
||
| 1332 | } |
||
| 1333 | } |
||
| 1334 | } |
||
| 1335 | |||
| 1336 | if ($viewGridCourses) { |
||
| 1337 | $coursesWithoutCategoryTemplate = '/user_portal/grid_courses_without_category.tpl'; |
||
| 1338 | $coursesWithCategoryTemplate = '/user_portal/grid_courses_with_category.tpl'; |
||
| 1339 | } |
||
| 1340 | |||
| 1341 | if ($specialCourses) { |
||
| 1342 | if ($categoryCodeFilter) { |
||
| 1343 | $specialCourses = self::filterByCategory($specialCourses, $categoryCodeFilter); |
||
| 1344 | } |
||
| 1345 | $this->tpl->assign('courses', $specialCourses); |
||
| 1346 | $specialCourseList = $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate)); |
||
| 1347 | $courseCompleteList = array_merge($courseCompleteList, $specialCourses); |
||
| 1348 | } |
||
| 1349 | |||
| 1350 | if ($courses['in_category'] || $courses['not_category']) { |
||
| 1351 | foreach ($courses['in_category'] as $courseData) { |
||
| 1352 | if (!empty($courseData['courses'])) { |
||
| 1353 | $coursesInCategoryCount += count($courseData['courses']); |
||
| 1354 | $courseCompleteList = array_merge($courseCompleteList, $courseData['courses']); |
||
| 1355 | } |
||
| 1356 | } |
||
| 1357 | |||
| 1358 | $coursesNotInCategoryCount += count($courses['not_category']); |
||
| 1359 | $courseCompleteList = array_merge($courseCompleteList, $courses['not_category']); |
||
| 1360 | |||
| 1361 | if ($categoryCodeFilter) { |
||
| 1362 | $courses['in_category'] = self::filterByCategory( |
||
| 1363 | $courses['in_category'], |
||
| 1364 | $categoryCodeFilter |
||
| 1365 | ); |
||
| 1366 | $courses['not_category'] = self::filterByCategory( |
||
| 1367 | $courses['not_category'], |
||
| 1368 | $categoryCodeFilter |
||
| 1369 | ); |
||
| 1370 | } |
||
| 1371 | |||
| 1372 | $this->tpl->assign('courses', $courses['not_category']); |
||
| 1373 | $this->tpl->assign('categories', $courses['in_category']); |
||
| 1374 | |||
| 1375 | $listCourse = $this->tpl->fetch($this->tpl->get_template($coursesWithCategoryTemplate)); |
||
| 1376 | $listCourse .= $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate)); |
||
| 1377 | } |
||
| 1378 | |||
| 1379 | $courseCount = count($specialCourses) + $coursesInCategoryCount + $coursesNotInCategoryCount; |
||
| 1380 | } |
||
| 1381 | |||
| 1382 | $sessions_with_category = ''; |
||
| 1383 | $sessions_with_no_category = ''; |
||
| 1384 | $collapsable = api_get_configuration_value('allow_user_session_collapsable'); |
||
| 1385 | $collapsableLink = ''; |
||
| 1386 | if ($collapsable) { |
||
| 1387 | $collapsableLink = api_get_path(WEB_PATH).'user_portal.php?action=collapse_session'; |
||
| 1388 | } |
||
| 1389 | |||
| 1390 | $extraFieldValue = new ExtraFieldValue('session'); |
||
| 1391 | if ($showSessions) { |
||
| 1392 | $coursesListSessionStyle = api_get_configuration_value('courses_list_session_title_link'); |
||
| 1393 | $coursesListSessionStyle = false === $coursesListSessionStyle ? 1 : $coursesListSessionStyle; |
||
| 1394 | if (api_is_drh()) { |
||
| 1395 | $coursesListSessionStyle = 1; |
||
| 1396 | } |
||
| 1397 | |||
| 1398 | $portalShowDescription = 'true' === api_get_setting('show_session_description'); |
||
| 1399 | |||
| 1400 | // Declared listSession variable |
||
| 1401 | $listSession = []; |
||
| 1402 | // Get timestamp in UTC to compare to DB values (in UTC by convention) |
||
| 1403 | $session_now = strtotime(api_get_utc_datetime(time())); |
||
| 1404 | if (is_array($session_categories)) { |
||
| 1405 | foreach ($session_categories as $session_category) { |
||
| 1406 | $session_category_id = $session_category['session_category']['id']; |
||
| 1407 | // Sessions and courses that are not in a session category |
||
| 1408 | if (empty($session_category_id) && |
||
| 1409 | isset($session_category['sessions']) |
||
| 1410 | ) { |
||
| 1411 | // Independent sessions |
||
| 1412 | foreach ($session_category['sessions'] as $session) { |
||
| 1413 | $session_id = $session['session_id']; |
||
| 1414 | |||
| 1415 | // Don't show empty sessions. |
||
| 1416 | if (count($session['courses']) < 1) { |
||
| 1417 | continue; |
||
| 1418 | } |
||
| 1419 | |||
| 1420 | // Courses inside the current session. |
||
| 1421 | $date_session_start = $session['access_start_date']; |
||
| 1422 | $date_session_end = $session['access_end_date']; |
||
| 1423 | $coachAccessStartDate = $session['coach_access_start_date']; |
||
| 1424 | $coachAccessEndDate = $session['coach_access_end_date']; |
||
| 1425 | $count_courses_session = 0; |
||
| 1426 | |||
| 1427 | // Loop course content |
||
| 1428 | $html_courses_session = []; |
||
| 1429 | $atLeastOneCourseIsVisible = false; |
||
| 1430 | $markAsOld = false; |
||
| 1431 | $markAsFuture = false; |
||
| 1432 | |||
| 1433 | foreach ($session['courses'] as $course) { |
||
| 1434 | $is_coach_course = api_is_coach($session_id, $course['real_id']); |
||
| 1435 | $allowed_time = 0; |
||
| 1436 | $allowedEndTime = true; |
||
| 1437 | |||
| 1438 | if (!empty($date_session_start)) { |
||
| 1439 | if ($is_coach_course) { |
||
| 1440 | $allowed_time = api_strtotime($coachAccessStartDate); |
||
| 1441 | } else { |
||
| 1442 | $allowed_time = api_strtotime($date_session_start); |
||
| 1443 | } |
||
| 1444 | |||
| 1445 | $endSessionToTms = null; |
||
| 1446 | if (!isset($_GET['history'])) { |
||
| 1447 | if (!empty($date_session_end)) { |
||
| 1448 | if ($is_coach_course) { |
||
| 1449 | // if coach end date is empty we use the default end date |
||
| 1450 | if (empty($coachAccessEndDate)) { |
||
| 1451 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 1452 | if ($session_now > $endSessionToTms) { |
||
| 1453 | $allowedEndTime = false; |
||
| 1454 | } |
||
| 1455 | } else { |
||
| 1456 | $endSessionToTms = api_strtotime($coachAccessEndDate); |
||
| 1457 | if ($session_now > $endSessionToTms) { |
||
| 1458 | $allowedEndTime = false; |
||
| 1459 | } |
||
| 1460 | } |
||
| 1461 | } else { |
||
| 1462 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 1463 | if ($session_now > $endSessionToTms) { |
||
| 1464 | $allowedEndTime = false; |
||
| 1465 | } |
||
| 1466 | } |
||
| 1467 | } |
||
| 1468 | } |
||
| 1469 | } |
||
| 1470 | |||
| 1471 | if ($showAllSessions) { |
||
| 1472 | if ($allowed_time < $session_now && false === $allowedEndTime) { |
||
| 1473 | $markAsOld = true; |
||
| 1474 | } |
||
| 1475 | if ($allowed_time > $session_now && $endSessionToTms > $session_now) { |
||
| 1476 | $markAsFuture = true; |
||
| 1477 | } |
||
| 1478 | $allowedEndTime = true; |
||
| 1479 | $allowed_time = 0; |
||
| 1480 | } |
||
| 1481 | |||
| 1482 | if ($session_now >= $allowed_time && $allowedEndTime) { |
||
| 1483 | // Read only and accessible. |
||
| 1484 | $atLeastOneCourseIsVisible = true; |
||
| 1485 | if ('false' === api_get_setting('hide_courses_in_sessions')) { |
||
| 1486 | $courseUserHtml = CourseManager::get_logged_user_course_html( |
||
| 1487 | $course, |
||
| 1488 | $session_id, |
||
| 1489 | 'session_course_item', |
||
| 1490 | true, |
||
| 1491 | $this->load_directories_preview |
||
| 1492 | ); |
||
| 1493 | if (isset($courseUserHtml[1])) { |
||
| 1494 | $course_session = $courseUserHtml[1]; |
||
| 1495 | $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : ''; |
||
| 1496 | |||
| 1497 | // Course option (show student progress) |
||
| 1498 | // This code will add new variables (Progress, Score, Certificate) |
||
| 1499 | if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) { |
||
| 1500 | if ($studentInfoProgress) { |
||
| 1501 | $progress = Tracking::get_avg_student_progress( |
||
| 1502 | $user_id, |
||
| 1503 | $course['course_code'], |
||
| 1504 | [], |
||
| 1505 | $session_id |
||
| 1506 | ); |
||
| 1507 | $course_session['student_info']['progress'] = false === $progress ? null : $progress; |
||
| 1508 | } |
||
| 1509 | |||
| 1510 | if ($studentInfoScore) { |
||
| 1511 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1512 | $user_id, |
||
| 1513 | $course['course_code'], |
||
| 1514 | [], |
||
| 1515 | $session_id |
||
| 1516 | ); |
||
| 1517 | $course_session['student_info']['score'] = $percentage_score; |
||
| 1518 | } |
||
| 1519 | |||
| 1520 | if ($studentInfoCertificate) { |
||
| 1521 | $category = Category::load( |
||
| 1522 | null, |
||
| 1523 | null, |
||
| 1524 | $course['course_code'], |
||
| 1525 | null, |
||
| 1526 | null, |
||
| 1527 | $session_id |
||
| 1528 | ); |
||
| 1529 | $course_session['student_info']['certificate'] = null; |
||
| 1530 | if (isset($category[0])) { |
||
| 1531 | if ($category[0]->is_certificate_available($user_id)) { |
||
| 1532 | $course_session['student_info']['certificate'] = Display::label( |
||
| 1533 | get_lang('Yes'), |
||
| 1534 | 'success' |
||
| 1535 | ); |
||
| 1536 | } else { |
||
| 1537 | $course_session['student_info']['certificate'] = Display::label( |
||
| 1538 | get_lang('No') |
||
| 1539 | ); |
||
| 1540 | } |
||
| 1541 | } |
||
| 1542 | } |
||
| 1543 | } |
||
| 1544 | $html_courses_session[] = $course_session; |
||
| 1545 | } |
||
| 1546 | } |
||
| 1547 | $count_courses_session++; |
||
| 1548 | } |
||
| 1549 | } |
||
| 1550 | |||
| 1551 | // No courses to show. |
||
| 1552 | if (false === $atLeastOneCourseIsVisible) { |
||
| 1553 | if (empty($html_courses_session)) { |
||
| 1554 | continue; |
||
| 1555 | } |
||
| 1556 | } |
||
| 1557 | |||
| 1558 | if ($count_courses_session > 0) { |
||
| 1559 | $params = [ |
||
| 1560 | 'id' => $session_id, |
||
| 1561 | ]; |
||
| 1562 | $session_box = Display::getSessionTitleBox($session_id); |
||
| 1563 | $coachId = $session_box['id_coach']; |
||
| 1564 | $imageField = $extraFieldValue->get_values_by_handler_and_field_variable( |
||
| 1565 | $session_id, |
||
| 1566 | 'image' |
||
| 1567 | ); |
||
| 1568 | |||
| 1569 | $params['category_id'] = $session_box['category_id']; |
||
| 1570 | $params['title'] = $session_box['title']; |
||
| 1571 | $params['id_coach'] = $coachId; |
||
| 1572 | $params['coach_url'] = api_get_path(WEB_AJAX_PATH). |
||
| 1573 | 'user_manager.ajax.php?a=get_user_popup&user_id='.$coachId; |
||
| 1574 | $params['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null; |
||
| 1575 | $params['coach_avatar'] = UserManager::getUserPicture( |
||
| 1576 | $coachId, |
||
| 1577 | USER_IMAGE_SIZE_SMALL |
||
| 1578 | ); |
||
| 1579 | $params['date'] = $session_box['dates']; |
||
| 1580 | $params['image'] = isset($imageField['value']) ? $imageField['value'] : null; |
||
| 1581 | $params['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null; |
||
| 1582 | $params['show_actions'] = SessionManager::cantEditSession($session_id); |
||
| 1583 | |||
| 1584 | if ($collapsable) { |
||
| 1585 | $collapsableData = SessionManager::getCollapsableData( |
||
| 1586 | $user_id, |
||
| 1587 | $session_id, |
||
| 1588 | $extraFieldValue, |
||
| 1589 | $collapsableLink |
||
| 1590 | ); |
||
| 1591 | $params['collapsed'] = $collapsableData['collapsed']; |
||
| 1592 | $params['collapsable_link'] = $collapsableData['collapsable_link']; |
||
| 1593 | } |
||
| 1594 | |||
| 1595 | $params['show_description'] = 1 == $session_box['show_description'] && $portalShowDescription; |
||
| 1596 | $params['description'] = $session_box['description']; |
||
| 1597 | $params['visibility'] = $session_box['visibility']; |
||
| 1598 | $params['show_simple_session_info'] = $showSimpleSessionInfo; |
||
| 1599 | $params['course_list_session_style'] = $coursesListSessionStyle; |
||
| 1600 | $params['num_users'] = $session_box['num_users']; |
||
| 1601 | $params['num_courses'] = $session_box['num_courses']; |
||
| 1602 | $params['course_categories'] = CourseManager::getCourseCategoriesFromCourseList( |
||
| 1603 | $html_courses_session |
||
| 1604 | ); |
||
| 1605 | $params['courses'] = $html_courses_session; |
||
| 1606 | $params['is_old'] = $markAsOld; |
||
| 1607 | $params['is_future'] = $markAsFuture; |
||
| 1608 | |||
| 1609 | if ($showSimpleSessionInfo) { |
||
| 1610 | $params['subtitle'] = self::getSimpleSessionDetails( |
||
| 1611 | $session_box['coach'], |
||
| 1612 | $session_box['dates'], |
||
| 1613 | isset($session_box['duration']) ? $session_box['duration'] : null |
||
| 1614 | ); |
||
| 1615 | } |
||
| 1616 | |||
| 1617 | if ($gameModeIsActive) { |
||
| 1618 | $params['stars'] = GamificationUtils::getSessionStars( |
||
| 1619 | $params['id'], |
||
| 1620 | $this->user_id |
||
| 1621 | ); |
||
| 1622 | $params['progress'] = GamificationUtils::getSessionProgress( |
||
| 1623 | $params['id'], |
||
| 1624 | $this->user_id |
||
| 1625 | ); |
||
| 1626 | $params['points'] = GamificationUtils::getSessionPoints( |
||
| 1627 | $params['id'], |
||
| 1628 | $this->user_id |
||
| 1629 | ); |
||
| 1630 | } |
||
| 1631 | $listSession[] = $params; |
||
| 1632 | $sessionCount++; |
||
| 1633 | } |
||
| 1634 | } |
||
| 1635 | } else { |
||
| 1636 | // All sessions included in |
||
| 1637 | $count_courses_session = 0; |
||
| 1638 | $html_sessions = ''; |
||
| 1639 | if (isset($session_category['sessions'])) { |
||
| 1640 | foreach ($session_category['sessions'] as $session) { |
||
| 1641 | $session_id = $session['session_id']; |
||
| 1642 | |||
| 1643 | // Don't show empty sessions. |
||
| 1644 | if (count($session['courses']) < 1) { |
||
| 1645 | continue; |
||
| 1646 | } |
||
| 1647 | |||
| 1648 | $date_session_start = $session['access_start_date']; |
||
| 1649 | $date_session_end = $session['access_end_date']; |
||
| 1650 | $coachAccessStartDate = $session['coach_access_start_date']; |
||
| 1651 | $coachAccessEndDate = $session['coach_access_end_date']; |
||
| 1652 | $html_courses_session = []; |
||
| 1653 | $count = 0; |
||
| 1654 | $markAsOld = false; |
||
| 1655 | $markAsFuture = false; |
||
| 1656 | |||
| 1657 | foreach ($session['courses'] as $course) { |
||
| 1658 | $is_coach_course = api_is_coach($session_id, $course['real_id']); |
||
| 1659 | $allowed_time = 0; |
||
| 1660 | $allowedEndTime = true; |
||
| 1661 | |||
| 1662 | if (!empty($date_session_start)) { |
||
| 1663 | if ($is_coach_course) { |
||
| 1664 | $allowed_time = api_strtotime($coachAccessStartDate); |
||
| 1665 | } else { |
||
| 1666 | $allowed_time = api_strtotime($date_session_start); |
||
| 1667 | } |
||
| 1668 | |||
| 1669 | if (!isset($_GET['history'])) { |
||
| 1670 | if (!empty($date_session_end)) { |
||
| 1671 | if ($is_coach_course) { |
||
| 1672 | // if coach end date is empty we use the default end date |
||
| 1673 | if (empty($coachAccessEndDate)) { |
||
| 1674 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 1675 | if ($session_now > $endSessionToTms) { |
||
| 1676 | $allowedEndTime = false; |
||
| 1677 | } |
||
| 1678 | } else { |
||
| 1679 | $endSessionToTms = api_strtotime($coachAccessEndDate); |
||
| 1680 | if ($session_now > $endSessionToTms) { |
||
| 1681 | $allowedEndTime = false; |
||
| 1682 | } |
||
| 1683 | } |
||
| 1684 | } else { |
||
| 1685 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 1686 | if ($session_now > $endSessionToTms) { |
||
| 1687 | $allowedEndTime = false; |
||
| 1688 | } |
||
| 1689 | } |
||
| 1690 | } |
||
| 1691 | } |
||
| 1692 | } |
||
| 1693 | |||
| 1694 | if ($showAllSessions) { |
||
| 1695 | if ($allowed_time < $session_now && false == $allowedEndTime) { |
||
| 1696 | $markAsOld = true; |
||
| 1697 | } |
||
| 1698 | if ($allowed_time > $session_now && $endSessionToTms > $session_now) { |
||
| 1699 | $markAsFuture = true; |
||
| 1700 | } |
||
| 1701 | $allowedEndTime = true; |
||
| 1702 | $allowed_time = 0; |
||
| 1703 | } |
||
| 1704 | |||
| 1705 | if ($session_now >= $allowed_time && $allowedEndTime) { |
||
| 1706 | if ('false' === api_get_setting('hide_courses_in_sessions')) { |
||
| 1707 | $c = CourseManager::get_logged_user_course_html( |
||
| 1708 | $course, |
||
| 1709 | $session_id, |
||
| 1710 | 'session_course_item' |
||
| 1711 | ); |
||
| 1712 | if (isset($c[1])) { |
||
| 1713 | $html_courses_session[] = $c[1]; |
||
| 1714 | } |
||
| 1715 | } |
||
| 1716 | $count_courses_session++; |
||
| 1717 | $count++; |
||
| 1718 | } |
||
| 1719 | } |
||
| 1720 | |||
| 1721 | $sessionParams = []; |
||
| 1722 | // Category |
||
| 1723 | if ($count > 0) { |
||
| 1724 | $session_box = Display::getSessionTitleBox($session_id); |
||
| 1725 | $sessionParams[0]['id'] = $session_id; |
||
| 1726 | $sessionParams[0]['date'] = $session_box['dates']; |
||
| 1727 | $sessionParams[0]['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null; |
||
| 1728 | $sessionParams[0]['course_list_session_style'] = $coursesListSessionStyle; |
||
| 1729 | $sessionParams[0]['title'] = $session_box['title']; |
||
| 1730 | $sessionParams[0]['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates']; |
||
| 1731 | $sessionParams[0]['show_actions'] = SessionManager::cantEditSession($session_id); |
||
| 1732 | $sessionParams[0]['courses'] = $html_courses_session; |
||
| 1733 | $sessionParams[0]['show_simple_session_info'] = $showSimpleSessionInfo; |
||
| 1734 | $sessionParams[0]['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null; |
||
| 1735 | $sessionParams[0]['is_old'] = $markAsOld; |
||
| 1736 | $sessionParams[0]['is_future'] = $markAsFuture; |
||
| 1737 | |||
| 1738 | if ($collapsable) { |
||
| 1739 | $collapsableData = SessionManager::getCollapsableData( |
||
| 1740 | $user_id, |
||
| 1741 | $session_id, |
||
| 1742 | $extraFieldValue, |
||
| 1743 | $collapsableLink |
||
| 1744 | ); |
||
| 1745 | $sessionParams[0]['collapsable_link'] = $collapsableData['collapsable_link']; |
||
| 1746 | $sessionParams[0]['collapsed'] = $collapsableData['collapsed']; |
||
| 1747 | } |
||
| 1748 | |||
| 1749 | if ($showSimpleSessionInfo) { |
||
| 1750 | $sessionParams[0]['subtitle'] = self::getSimpleSessionDetails( |
||
| 1751 | $session_box['coach'], |
||
| 1752 | $session_box['dates'], |
||
| 1753 | isset($session_box['duration']) ? $session_box['duration'] : null |
||
| 1754 | ); |
||
| 1755 | } |
||
| 1756 | $this->tpl->assign('session', $sessionParams); |
||
| 1757 | $this->tpl->assign('show_tutor', ('true' === api_get_setting('show_session_coach') ? true : false)); |
||
| 1758 | $this->tpl->assign('gamification_mode', $gameModeIsActive); |
||
| 1759 | $this->tpl->assign('remove_session_url', api_get_configuration_value('remove_session_url')); |
||
| 1760 | |||
| 1761 | if ($viewGridCourses) { |
||
| 1762 | $html_sessions .= $this->tpl->fetch( |
||
| 1763 | $this->tpl->get_template('/user_portal/grid_session.tpl') |
||
| 1764 | ); |
||
| 1765 | } else { |
||
| 1766 | $html_sessions .= $this->tpl->fetch( |
||
| 1767 | $this->tpl->get_template('user_portal/classic_session.tpl') |
||
| 1768 | ); |
||
| 1769 | } |
||
| 1770 | $sessionCount++; |
||
| 1771 | } |
||
| 1772 | } |
||
| 1773 | } |
||
| 1774 | |||
| 1775 | if ($count_courses_session > 0) { |
||
| 1776 | $categoryParams = [ |
||
| 1777 | 'id' => $session_category['session_category']['id'], |
||
| 1778 | 'title' => $session_category['session_category']['name'], |
||
| 1779 | 'show_actions' => api_is_platform_admin(), |
||
| 1780 | 'subtitle' => '', |
||
| 1781 | 'sessions' => $html_sessions, |
||
| 1782 | ]; |
||
| 1783 | |||
| 1784 | $session_category_start_date = $session_category['session_category']['date_start']; |
||
| 1785 | $session_category_end_date = $session_category['session_category']['date_end']; |
||
| 1786 | if ('0000-00-00' == $session_category_start_date) { |
||
| 1787 | $session_category_start_date = ''; |
||
| 1788 | } |
||
| 1789 | |||
| 1790 | if ('0000-00-00' == $session_category_end_date) { |
||
| 1791 | $session_category_end_date = ''; |
||
| 1792 | } |
||
| 1793 | |||
| 1794 | if (!empty($session_category_start_date) && |
||
| 1795 | !empty($session_category_end_date) |
||
| 1796 | ) { |
||
| 1797 | $categoryParams['subtitle'] = sprintf( |
||
| 1798 | get_lang('From %s to %s'), |
||
| 1799 | $session_category_start_date, |
||
| 1800 | $session_category_end_date |
||
| 1801 | ); |
||
| 1802 | } else { |
||
| 1803 | if (!empty($session_category_start_date)) { |
||
| 1804 | $categoryParams['subtitle'] = get_lang('From').' '.$session_category_start_date; |
||
| 1805 | } |
||
| 1806 | |||
| 1807 | if (!empty($session_category_end_date)) { |
||
| 1808 | $categoryParams['subtitle'] = get_lang('Until').' '.$session_category_end_date; |
||
| 1809 | } |
||
| 1810 | } |
||
| 1811 | |||
| 1812 | $this->tpl->assign('session_category', $categoryParams); |
||
| 1813 | $sessions_with_category .= $this->tpl->fetch( |
||
| 1814 | $this->tpl->get_template('user_portal/session_category.tpl') |
||
| 1815 | ); |
||
| 1816 | } |
||
| 1817 | } |
||
| 1818 | } |
||
| 1819 | |||
| 1820 | $allCoursesInSessions = []; |
||
| 1821 | foreach ($listSession as $currentSession) { |
||
| 1822 | $coursesInSessions = $currentSession['courses']; |
||
| 1823 | unset($currentSession['courses']); |
||
| 1824 | foreach ($coursesInSessions as $coursesInSession) { |
||
| 1825 | $coursesInSession['session'] = $currentSession; |
||
| 1826 | $allCoursesInSessions[] = $coursesInSession; |
||
| 1827 | } |
||
| 1828 | } |
||
| 1829 | |||
| 1830 | $this->tpl->assign('all_courses', $allCoursesInSessions); |
||
| 1831 | $this->tpl->assign('session', $listSession); |
||
| 1832 | $this->tpl->assign('show_tutor', ('true' === api_get_setting('show_session_coach') ? true : false)); |
||
| 1833 | $this->tpl->assign('gamification_mode', $gameModeIsActive); |
||
| 1834 | $this->tpl->assign('remove_session_url', api_get_configuration_value('remove_session_url')); |
||
| 1835 | |||
| 1836 | if ($viewGridCourses) { |
||
| 1837 | $sessions_with_no_category = $this->tpl->fetch( |
||
| 1838 | $this->tpl->get_template('/user_portal/grid_session.tpl') |
||
| 1839 | ); |
||
| 1840 | } else { |
||
| 1841 | $sessions_with_no_category = $this->tpl->fetch( |
||
| 1842 | $this->tpl->get_template('user_portal/classic_session.tpl') |
||
| 1843 | ); |
||
| 1844 | } |
||
| 1845 | } |
||
| 1846 | } |
||
| 1847 | |||
| 1848 | return [ |
||
| 1849 | 'courses' => $courseCompleteList, |
||
| 1850 | 'sessions' => $session_categories, |
||
| 1851 | 'html' => trim($specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse), |
||
| 1852 | 'session_count' => $sessionCount, |
||
| 1853 | 'course_count' => $courseCount, |
||
| 1854 | ]; |
||
| 2340 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return,dieorexitstatements that have been added for debug purposes.In the above example, the last
return falsewill never be executed, because a return statement has already been met in every possible execution path.