diff --git a/classes/base_table.php b/classes/base_table.php index 22d6e4b..eaf9973 100644 --- a/classes/base_table.php +++ b/classes/base_table.php @@ -196,7 +196,7 @@ public function col_date_from($values) { return '-'; } - return date(get_config('block_advnotifications', 'dateformat'), $values->date_from); + return userdate($values->date_from, get_string(get_config('block_advnotifications', 'dateformat'), 'langconfig')); } /** @@ -212,7 +212,7 @@ public function col_date_to($values) { return '-'; } - return date(get_config('block_advnotifications', 'dateformat'), $values->date_to); + return userdate($values->date_to, get_string(get_config('block_advnotifications', 'dateformat'), 'langconfig')); } /** @@ -223,4 +223,4 @@ public function print_nothing_to_display() { echo '
' . get_string('advnotifications_table_empty', 'block_advnotifications') . '
'; } -} \ No newline at end of file +} diff --git a/locallib.php b/locallib.php index da33a2a..f7ed196 100644 --- a/locallib.php +++ b/locallib.php @@ -143,15 +143,24 @@ function prep_notifications($instanceid) { * @return array Array of formats as key and today's date in that format as value. */ function get_date_formats() { - $formats = []; + // Hard-code date so users can see the difference between short dates with and without the leading zero. + // Eg. 06/07/18 vs 6/07/18. + $date = 1530849658; // Add supported formats to array. - $formats['d/m/Y'] = date('d/m/Y'); - $formats['j/n/y'] = date('j/n/y'); - $formats['m-d-Y'] = date('m-d-Y'); - $formats['n-j-y'] = date('n-j-y'); - $formats['j M y'] = date('j M y'); - $formats['j F Y'] = date('j F Y'); - - return $formats; -} \ No newline at end of file + $dateformats = []; + + $strdateformats = [ + 'strftimedatetime', + 'strftimedatetimeshort', + 'strftimedaydatetime', + 'strftimerecent', + 'strftimerecentfull', + ]; + + foreach ($strdateformats as $strdateformat) { + $dateformats[$strdateformat] = userdate($date, get_string($strdateformat, 'langconfig')); + } + + return $dateformats; +} diff --git a/pages/process.php b/pages/process.php index 77ee9a1..ffecfff 100644 --- a/pages/process.php +++ b/pages/process.php @@ -64,6 +64,8 @@ $dismissible = optional_param('dismissible', null, PARAM_TEXT); $datefrom = optional_param('date_from', null, PARAM_TEXT); $dateto = optional_param('date_to', null, PARAM_TEXT); +$timefrom = optional_param('time_from', null, PARAM_TEXT); +$timeto = optional_param('time_to', null, PARAM_TEXT); $dismiss = optional_param('dismiss', null, PARAM_TEXT); // User dismissed notification. $purpose = optional_param('purpose', null, PARAM_TEXT); // Purpose of request. @@ -157,6 +159,9 @@ if ($purpose == 'edit') { $enotification = $DB->get_record('block_advnotifications', array('id' => $tableaction)); + $enotification->time_from = date('H:i', $enotification->date_from); + $enotification->time_to = date('H:i', $enotification->date_to); + $enotification->date_from = date('Y-m-d', $enotification->date_from); $enotification->date_to = date('Y-m-d', $enotification->date_to); @@ -250,9 +255,22 @@ $urow->global = $global; $urow->blockid = $blockinstance; $urow->dismissible = $dismissible; - $urow->date_from = $datefrom; - $urow->date_to = $dateto; - $urow->times = $times; + + if (empty($timefrom)) { + $urow->date_from = $datefrom; + } else { + list($hours, $minutes) = explode(':', $timefrom, 2); + $seconds = $minutes * 60 + $hours * 3600; + $urow->date_from = $datefrom + $seconds; + } + + if (empty($timeto)) { + $urow->date_to = $dateto; + } else { + list($hours, $minutes) = explode(':', $timeto, 2); + $seconds = $minutes * 60 + $hours * 3600; + $urow->date_to = $dateto + $seconds; + } $DB->update_record('block_advnotifications', $urow); @@ -315,8 +333,23 @@ $row->global = $global; $row->blockid = $blockinstance; $row->dismissible = $dismissible; - $row->date_from = $datefrom; - $row->date_to = $dateto; + + if (empty($timefrom)) { + $row->date_from = $datefrom; + } else { + list($hours, $minutes) = explode(':', $timefrom, 2); + $seconds = $minutes * 60 + $hours * 3600; + $row->date_from = $datefrom + $seconds; + } + + if (empty($timeto)) { + $row->date_to = $dateto; + } else { + list($hours, $minutes) = explode(':', $timeto, 2); + $seconds = $minutes * 60 + $hours * 3600; + $row->date_to = $dateto + $seconds; + } + $row->times = $times; $row->deleted = 0; $row->deleted_at = 0; diff --git a/renderer.php b/renderer.php index 1647aec..061cf3c 100644 --- a/renderer.php +++ b/renderer.php @@ -197,14 +197,26 @@ class="form-check-input" id="add_notification_date_from" class="form-control" name="date_from" - placeholder="yyyy-mm-dd"/> + placeholder="yyyy-mm-dd" + style="width: 10em;"/> + + placeholder="yyyy-mm-dd" + style="width: 10em;"/> + ' . get_string('advnotifications_date_info', 'block_advnotifications') . '