From 5e1b790eaa96b17e190164c0e5f59319c30ce4f8 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Mon, 27 Apr 2015 09:36:57 -0500 Subject: [PATCH] Fix date visualization and add Roman letters for quarters in cron script to create quarterly sessions - refs BT#9435 --- main/cron/create_course_sessions.php | 29 ++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/main/cron/create_course_sessions.php b/main/cron/create_course_sessions.php index 83e65c9b3d..0a1c1200ca 100644 --- a/main/cron/create_course_sessions.php +++ b/main/cron/create_course_sessions.php @@ -113,6 +113,25 @@ function getQuarterFirstMonth($quarter) return false; } +/** + * Get the quarter in Roman letters + * @param int Quarter + * @return string Roman letters + */ +function getQuarterRoman($quarter) +{ + switch ($quarter) { + case 1: + return 'I'; + case 2: + return 'II'; + case 3: + return 'III'; + case 4: + return 'IV'; + } +} + /** * Creates one session per course with $administratorId as the creator and * adds it to the session starting on $startDate and finishing on $endDate @@ -133,10 +152,11 @@ function createCourseSessions($courses, $administratorId, $startDate, $endDate) foreach ($courses as $course) { //$period = date("m/Y", api_strtotime($startDate)); $month = date("m", api_strtotime($startDate)); - $year = date("y", api_strtotime($startDate)); + $year = date("Y", api_strtotime($startDate)); $quarter = getQuarter($month); - $period = $year . ' - ' . $quarter; - $sessionName = $course['title'] . " (" . $period . ")"; + $quarter = getQuarterRoman($quarter); + $period = $year . '-' . $quarter; + $sessionName = '[' . $period . '] ' . $course['title']; $sessionId = SessionManager::create_session( $sessionName, $startDate, @@ -174,7 +194,8 @@ $courses = CourseManager::getCoursesWithoutSession($dates['startDate'], $dates[' createCourseSessions($courses, $administratorId, $dates['startDate'], $dates['endDate']); // Creates course sessions for the following month -if (date("Y-m-d") >= date("Y-m-".OFFSET)) { +$offsetDay = intval(substr($dates['endDate'], 8, 2)) - OFFSET; +if (date("Y-m-d") >= date(substr($dates['endDate'], 0, 8) . $offsetDay)) { $dates = getQuarterFirstAndLastDates(date("Y-m-d", api_strtotime(date("Y-m-01")." + 3 month"))); // Get courses that don't have any session the next month $courses = CourseManager::getCoursesWithoutSession($dates['startDate'], $dates['endDate']);