From 2dc05b8b813e6197a7d885c20c0812f52a46f33c Mon Sep 17 00:00:00 2001 From: Sergey Evstegneiev Date: Mon, 24 Feb 2020 12:23:49 +0100 Subject: [PATCH] Adding enrollment start & end date options (#328) --- element/date/classes/element.php | 33 +++++++++++++++++++ .../date/lang/en/customcertelement_date.php | 2 ++ element/date/version.php | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/element/date/classes/element.php b/element/date/classes/element.php index 7a95412..b67b1c0 100644 --- a/element/date/classes/element.php +++ b/element/date/classes/element.php @@ -56,6 +56,16 @@ define('CUSTOMCERT_DATE_COURSE_END', '-4'); */ define('CUSTOMCERT_DATE_CURRENT_DATE', '-5'); +/** + * Date - Enrollment start + */ +define('CUSTOMCERT_DATE_ENROLLMENT_START', '-6'); + +/** + * Date - Entrollment end + */ +define('CUSTOMCERT_DATE_ENROLLMENT_END', '-7'); + require_once($CFG->dirroot . '/lib/grade/constants.php'); /** @@ -83,6 +93,9 @@ class element extends \mod_customcert\element { if ($completionenabled) { $dateoptions[CUSTOMCERT_DATE_COMPLETION] = get_string('completiondate', 'customcertelement_date'); } + $dateoptions[CUSTOMCERT_DATE_ENROLLMENT_START] = get_string('enrollmentstartdate', 'customcertelement_date'); + $dateoptions[CUSTOMCERT_DATE_ENROLLMENT_END] = get_string('enrollmentenddate', 'customcertelement_date'); + $dateoptions[CUSTOMCERT_DATE_COURSE_START] = get_string('coursestartdate', 'customcertelement_date'); $dateoptions[CUSTOMCERT_DATE_COURSE_END] = get_string('courseenddate', 'customcertelement_date'); $dateoptions[CUSTOMCERT_DATE_COURSE_GRADE] = get_string('coursegradedate', 'customcertelement_date'); @@ -164,6 +177,26 @@ class element extends \mod_customcert\element { $date = $timecompleted->timecompleted; } } + } else if ($dateitem == CUSTOMCERT_DATE_ENROLLMENT_START) { + // Get the enrollment start date + $sql = "SELECT ue.timestart FROM {enrol} e JOIN {user_enrolments} ue ON ue.enrolid = e.id + WHERE e.courseid = :courseid + AND ue.userid = :userid"; + if ($timestart = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $courseid))) { + if (!empty($timestart->timestart)) { + $date = $timestart->timestart; + } + } + } else if ($dateitem == CUSTOMCERT_DATE_ENROLLMENT_END) { + // Get the enrollment end date + $sql = "SELECT ue.timeend FROM {enrol} e JOIN {user_enrolments} ue ON ue.enrolid = e.id + WHERE e.courseid = :courseid + AND ue.userid = :userid"; + if ($timeend = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $courseid))) { + if (!empty($timeend->timeend)) { + $date = $timeend->timeend; + } + } } else if ($dateitem == CUSTOMCERT_DATE_COURSE_START) { $date = $DB->get_field('course', 'startdate', array('id' => $courseid)); } else if ($dateitem == CUSTOMCERT_DATE_COURSE_END) { diff --git a/element/date/lang/en/customcertelement_date.php b/element/date/lang/en/customcertelement_date.php index 65471fa..ece67de 100644 --- a/element/date/lang/en/customcertelement_date.php +++ b/element/date/lang/en/customcertelement_date.php @@ -26,6 +26,8 @@ $string['completiondate'] = 'Completion date'; $string['courseenddate'] = 'Course end date'; $string['coursegradedate'] = 'Course grade date'; $string['coursestartdate'] = 'Course start date'; +$string['enrollmentstartdate'] = 'Enrollment start date'; +$string['enrollmentenddate'] = 'Enrollment end date'; $string['currentdate'] = 'Current date'; $string['dateformat'] = 'Date format'; $string['dateformat_help'] = 'This is the format of the date that will be displayed'; diff --git a/element/date/version.php b/element/date/version.php index 14282c2..5af80de 100644 --- a/element/date/version.php +++ b/element/date/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2019111800; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2019111801; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2019111800; // Requires this Moodle version (3.8). $plugin->component = 'customcertelement_date';