Add exclusion of hidden or closed courses in getCoursesWithoutSession() and fix dates issue in cron to create sessions every month for existing courses - refs BT#9437

1.10.x
Yannick Warnier 11 years ago
parent f65d7a2b70
commit ee38e659eb
  1. 4
      main/cron/create_course_sessions.php
  2. 9
      main/inc/lib/course.lib.php

@ -80,9 +80,9 @@ if (!$lastingAdministrators) {
$administratorId = intval($administrators[$lastingAdministrators - 1]['user_id']); $administratorId = intval($administrators[$lastingAdministrators - 1]['user_id']);
// Creates course sessions for the current month // Creates course sessions for the current month
$dates = getMonthFirstAndLastDates(); $dates = getMonthFirstAndLastDates(date('Y-m-').'01');
// Get courses that don't have any session // Get courses that don't have any session
$courses = CourseManager::getCoursesWithoutSession(); $courses = CourseManager::getCoursesWithoutSession($dates['startDate'], $dates['endDate']);
createCourseSessions($courses, $administratorId, $dates['startDate'], $dates['endDate']); createCourseSessions($courses, $administratorId, $dates['startDate'], $dates['endDate']);
// Creates course sessions for the following month // Creates course sessions for the following month

@ -5578,15 +5578,20 @@ class CourseManager
* This function gets all the courses that are not in a session * This function gets all the courses that are not in a session
* @param date Start date * @param date Start date
* @param date End date * @param date End date
* @param bool $includeClosed Whether to include closed and hidden courses
* @return array Not-in-session courses * @return array Not-in-session courses
*/ */
public static function getCoursesWithoutSession($startDate = null, $endDate = null) public static function getCoursesWithoutSession($startDate = null, $endDate = null, $includeClosed = false)
{ {
$dateConditional = ($startDate && $endDate) ? $dateConditional = ($startDate && $endDate) ?
" WHERE id_session IN (SELECT id FROM " . Database::get_main_table(TABLE_MAIN_SESSION) . " WHERE id_session IN (SELECT id FROM " . Database::get_main_table(TABLE_MAIN_SESSION) .
" WHERE date_start = '$startDate' AND date_end = '$endDate')" : " WHERE date_start = '$startDate' AND date_end = '$endDate')" :
null; null;
$query = "SELECT id, code, title FROM " . Database::get_main_table(TABLE_MAIN_COURSE) . " WHERE CODE NOT IN $visibility = ($includeClosed ? '' : 'visibility NOT IN (0, 4) AND ');
$query = "SELECT id, code, title FROM " . Database::get_main_table(TABLE_MAIN_COURSE)
. " WHERE $visibility
code NOT IN
(SELECT DISTINCT course_code FROM " . Database::get_main_table(TABLE_MAIN_SESSION_COURSE) . $dateConditional . ") (SELECT DISTINCT course_code FROM " . Database::get_main_table(TABLE_MAIN_SESSION_COURSE) . $dateConditional . ")
ORDER BY id"; ORDER BY id";

Loading…
Cancel
Save