Skip to content

add time fields and display format #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions classes/base_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -223,4 +223,4 @@ public function print_nothing_to_display() {

echo '<p class="notifications--empty">' . get_string('advnotifications_table_empty', 'block_advnotifications') . '</p>';
}
}
}
29 changes: 19 additions & 10 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
$dateformats = [];

$strdateformats = [
'strftimedatetime',
'strftimedatetimeshort',
'strftimedaydatetime',
'strftimerecent',
'strftimerecentfull',
];

foreach ($strdateformats as $strdateformat) {
$dateformats[$strdateformat] = userdate($date, get_string($strdateformat, 'langconfig'));
}

return $dateformats;
}
43 changes: 38 additions & 5 deletions pages/process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 14 additions & 2 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;"/>
<input type="time"
id="add_notification_time_from"
class="form-control"
name="time_from"
style="width: 10em;"/>
<label for="add_notification_date_to" class="form-text">' .
get_string('advnotifications_date_to', 'block_advnotifications') . '</label>
<input type="date"
id="add_notification_date_to"
class="form-control"
name="date_to"
placeholder="yyyy-mm-dd"/>
placeholder="yyyy-mm-dd"
style="width: 10em;"/>
<input type="time"
id="add_notification_time_to"
class="form-control"
name="time_to"
style="width: 10em;"/>
<small class="form-text text-muted">' .
get_string('advnotifications_date_info', 'block_advnotifications') . '</small>
</div>
Expand Down