From 36d178bda36b5582fb2f0a709aad2c53579acbe2 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 17 Jun 2019 13:33:16 +0800 Subject: [PATCH] Add ability to specify the current date for date related elements (#289) --- element/date/classes/element.php | 8 ++++++++ element/date/lang/en/customcertelement_date.php | 1 + element/daterange/classes/element.php | 10 ++++++++++ .../daterange/lang/en/customcertelement_daterange.php | 1 + 4 files changed, 20 insertions(+) diff --git a/element/date/classes/element.php b/element/date/classes/element.php index d3693e7..c148059 100644 --- a/element/date/classes/element.php +++ b/element/date/classes/element.php @@ -51,6 +51,11 @@ define('CUSTOMCERT_DATE_COURSE_START', '-3'); */ define('CUSTOMCERT_DATE_COURSE_END', '-4'); +/** + * Date - Current date + */ +define('CUSTOMCERT_DATE_CURRENT_DATE', '-5'); + require_once($CFG->dirroot . '/lib/grade/constants.php'); /** @@ -73,6 +78,7 @@ class element extends \mod_customcert\element { // Get the possible date options. $dateoptions = array(); $dateoptions[CUSTOMCERT_DATE_ISSUE] = get_string('issueddate', 'customcertelement_date'); + $dateoptions[CUSTOMCERT_DATE_CURRENT_DATE] = get_string('currentdate', 'customcertelement_date'); $completionenabled = $CFG->enablecompletion && ($COURSE->id == SITEID || $COURSE->enablecompletion); if ($completionenabled) { $dateoptions[CUSTOMCERT_DATE_COMPLETION] = get_string('completiondate', 'customcertelement_date'); @@ -145,6 +151,8 @@ class element extends \mod_customcert\element { if ($dateitem == CUSTOMCERT_DATE_ISSUE) { $date = $issue->timecreated; + } else if ($dateitem == CUSTOMCERT_DATE_CURRENT_DATE) { + $date = time(); } else if ($dateitem == CUSTOMCERT_DATE_COMPLETION) { // Get the last completion date. $sql = "SELECT MAX(c.timecompleted) as timecompleted diff --git a/element/date/lang/en/customcertelement_date.php b/element/date/lang/en/customcertelement_date.php index 366ac6e..65471fa 100644 --- a/element/date/lang/en/customcertelement_date.php +++ b/element/date/lang/en/customcertelement_date.php @@ -26,6 +26,7 @@ $string['completiondate'] = 'Completion date'; $string['courseenddate'] = 'Course end date'; $string['coursegradedate'] = 'Course grade date'; $string['coursestartdate'] = 'Course start date'; +$string['currentdate'] = 'Current date'; $string['dateformat'] = 'Date format'; $string['dateformat_help'] = 'This is the format of the date that will be displayed'; $string['dateitem'] = 'Date item'; diff --git a/element/daterange/classes/element.php b/element/daterange/classes/element.php index fdfdef8..0e45ca4 100644 --- a/element/daterange/classes/element.php +++ b/element/daterange/classes/element.php @@ -99,6 +99,11 @@ class element extends \mod_customcert\element { */ const DATE_COURSE_GRADE = -5; + /** + * Date - Course current date + */ + const DATE_CURRENT_DATE = -6; + /** * This function renders the form elements when adding a customcert element. * @@ -110,6 +115,7 @@ class element extends \mod_customcert\element { // Get the possible date options. $dateoptions = array(); $dateoptions[self::DATE_ISSUE] = get_string('issueddate', 'customcertelement_daterange'); + $dateoptions[self::DATE_CURRENT_DATE] = get_string('currentdate', 'customcertelement_daterange'); $dateoptions[self::DATE_COMPLETION] = get_string('completiondate', 'customcertelement_daterange'); $dateoptions[self::DATE_COURSE_START] = get_string('coursestartdate', 'customcertelement_daterange'); $dateoptions[self::DATE_COURSE_END] = get_string('courseenddate', 'customcertelement_daterange'); @@ -346,6 +352,10 @@ class element extends \mod_customcert\element { $date = $issue->timecreated; break; + case self::DATE_CURRENT_DATE: + $date = time(); + break; + case self::DATE_COMPLETION: // Get the last completion date. $sql = "SELECT MAX(c.timecompleted) as timecompleted diff --git a/element/daterange/lang/en/customcertelement_daterange.php b/element/daterange/lang/en/customcertelement_daterange.php index 08ce9f6..551ee31 100644 --- a/element/daterange/lang/en/customcertelement_daterange.php +++ b/element/daterange/lang/en/customcertelement_daterange.php @@ -29,6 +29,7 @@ $string['completiondate'] = 'Completion date'; $string['courseenddate'] = 'Course end date'; $string['coursegradedate'] = 'Course grade date'; $string['coursestartdate'] = 'Course start date'; +$string['currentdate'] = 'Current date'; $string['dateitem'] = 'Date item'; $string['dateitem_help'] = 'This will be the date that is printed on the certificate'; $string['dateranges'] = 'Date ranges';