Skip to content

Commit

Permalink
{profile_field_...} of type Date/Time now displays date/time instead …
Browse files Browse the repository at this point in the history
…of a number.
  • Loading branch information
michael-milette committed Feb 13, 2021
1 parent be79b30 commit eb3b60e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## [2.1.1] 2021-02-13
### Updated
- {profile_field_...} of type Date/Time now displays date/time instead of a number.
## [2.1.0] 2020-11-23
### Added
- New {ifingroup id|idnumber}{/ifingroup} tags.
Expand Down
15 changes: 11 additions & 4 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Main filter code for FilterCodes.
*
* @package filter_filtercodes
* @copyright 2017-2020 TNG Consulting Inc. - www.tngconsulting.ca
* @copyright 2017-2021 TNG Consulting Inc. - www.tngconsulting.ca
* @author Michael Milette
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand All @@ -32,7 +32,7 @@
/**
* Extends the moodle_text_filter class to provide plain text support for new tags.
*
* @copyright 2017-2020 TNG Consulting Inc. - www.tngconsulting.ca
* @copyright 2017-2021 TNG Consulting Inc. - www.tngconsulting.ca
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_filtercodes extends moodle_text_filter {
Expand Down Expand Up @@ -437,16 +437,23 @@ public function filter($text, array $options = []) {
static $profilefields;
static $profiledata;
if (!isset($profilefields)) {
$profilefields = $DB->get_records('user_info_field', null, '', 'id, shortname, visible');
$profilefields = $DB->get_records('user_info_field', null, '', 'id, datatype, shortname, visible, param3');
if (!empty($profilefields)) {
$profiledata = $DB->get_records_menu('user_info_data', ['userid' => $USER->id], '', 'fieldid, data');
}
}

foreach ($profilefields as $field) {
// If the tag exists and is not set to "Not visible" in the custom profile field's settings.
if (stripos($text, '{profile_field_' . $field->shortname . '}') !== false && $field->visible != '0') {
$data = !empty($profiledata[$field->id]) ? $profiledata[$field->id] : '';
if ($field->datatype == 'datetime') {
if (!empty($field->param3)) { // Include date and time.
$datetimeformat = 'strftimedaydatetime';
} else { // Include just the date.
$datetimeformat = 'strftimedate';
}
$data = empty($data) ? '' : userdate($data, get_string($datetimeformat, 'langconfig'));
}
$replace['/\{profile_field_' . $field->shortname . '\}/i'] = $data;
} else {
$replace['/\{profile_field_' . $field->shortname . '\}/i'] = '';
Expand Down

0 comments on commit eb3b60e

Please sign in to comment.