Skip to content

Commit

Permalink
Add exclusion of hidden or closed courses in getCoursesWithoutSession…
Browse files Browse the repository at this point in the history
…() and fix dates issue in cron to create sessions every month for existing courses - refs BT#9437
  • Loading branch information
ywarnier committed Mar 9, 2015
1 parent f65d7a2 commit ee38e65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions main/cron/create_course_sessions.php
Expand Up @@ -80,9 +80,9 @@ function createCourseSessions($courses, $administratorId, $startDate, $endDate)
$administratorId = intval($administrators[$lastingAdministrators - 1]['user_id']);

// Creates course sessions for the current month
$dates = getMonthFirstAndLastDates();
$dates = getMonthFirstAndLastDates(date('Y-m-').'01');
// 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']);

// Creates course sessions for the following month
Expand Down
9 changes: 7 additions & 2 deletions main/inc/lib/course.lib.php
Expand Up @@ -5578,15 +5578,20 @@ public static function get_course_by_category($category_id)
* This function gets all the courses that are not in a session
* @param date Start date
* @param date End date
* @param bool $includeClosed Whether to include closed and hidden 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) ?
" WHERE id_session IN (SELECT id FROM " . Database::get_main_table(TABLE_MAIN_SESSION) .
" WHERE date_start = '$startDate' AND date_end = '$endDate')" :
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 . ")
ORDER BY id";

Expand Down

0 comments on commit ee38e65

Please sign in to comment.