Skip to content

Commit

Permalink
Added new {firstaccessdate} tag.
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Milette <[email protected]>
  • Loading branch information
petermAprende and michael-milette committed Nov 8, 2020
1 parent 0d2973a commit 832c453
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
Binary file added .filter.php.swp
Binary file not shown.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
- New {timezone} tag.
- New {preferredlanguage} tag.
- New {coursesummary} tag.
- New {firstaccessdate} tag/
### Updated
- {courseprogress} and {courseprogressbar} now show zero progress if progress is 0.
- {alert} to allow for optional contextual class stying.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ FilterCodes are meant to be entered as regular text in the Moodle WYSIWYG editor
* {userpictureimg X} : Generates an <img> html tag containing the user's profile picture. X indicates the size and can be **sm** (small), **md** (medium) or **lg** (large). If the user does not have profile picture or is logged out, the default faceless profile photo will be used instead.
* {profile_field_shortname} : Display's custom profile field. Replace "shortname" with the shortname of a custom profile field all in lowercase. NOTE: Will not display if custom profile field's settings are set to **Not Visible**.
* {profilefullname}: Similar to {fullname} except that it displays a profile owner's name when placed on the Profile page.
* {firstaccessdate} : Date that the user first accessd the site.

### System Information

Expand Down Expand Up @@ -567,10 +568,11 @@ Create a Page on your Moodle site, preferably in a course, so that those tags wo
* Total number of active users [{usersactive}]: {usersactive}
* Total number of online users [{usersonline}]: {usersonline}
* Current 4-digit year [{siteyear}]: {siteyear}
* You first accessed the site on [{firstaccessdate}] : {firstaccessdate}
* Course or Site full name [{coursename}]: {coursename}
* Course or Site short name [{courseshortname}]: {courseshortname}
* Course start date [{coursestartdate}]: {coursestartdate}
* Course start date [{courseenddate}]: {courseenddate}
* Course end date [{courseenddate}]: {courseenddate}
* Completion date [{coursecompletiondate}]: {coursecompletiondate}
* Course progress (ALPHA) [{courseprogress}]: {courseprogress}
* Course progress bar (ALPHA) [{courseprogressbar}]: {courseprogressbar}
Expand Down
55 changes: 38 additions & 17 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,18 @@ public function filter($text, array $options = []) {
$replace['/\{idnumber\}/i'] = isloggedin() && !isguestuser() ? $USER->idnumber : '';
}

// Tag: {firstaccessdate}. User first access date.
if (stripos($text, '{firstaccessdate}') !== false) {
if (isloggedin() && !isguestuser() && !empty($USER->firstaccess)) {
// Replace {firstaccessdate} tag with formatted date.
if (stripos($text, '{firstaccessdate}') !== false) {
$replace['/\{firstaccessdate\}/i'] = userdate($USER->firstaccess, get_string('strftimedatefullshort'));
}
} else {
$replace['/\{firstaccessdate\}/i'] = get_string('never');
}
}

if (get_config('filter_filtercodes', 'enable_scrape')) { // Must be enabled in FilterCodes settings.
// Tag: {scrape url="" tag="" class="" id="" code=""}.
if (stripos($text, '{scrape ') !== false) {
Expand Down Expand Up @@ -847,44 +859,53 @@ function ($matches) {
}

// Tag: {coursestartdate}. The course start date.
if (stripos($text, '{coursestartdate}') !== false) {
if (stripos($text, '{coursestartdate') !== false) {
if (empty($PAGE->course->startdate)) {
$PAGE->course->startdate = $DB->get_field_select('course', 'startdate', 'id = :id', ['id' => $course->id]);
$PAGE->course->startdate = $DB->get_field_select('course', 'startdate', 'id = :id', ['id' => $PAGE->course->id]);
}
if ($PAGE->course->startdate > 0) {
$replace['/\{coursestartdate\}/i'] = userdate($PAGE->course->startdate, get_string('strftimedatefullshort'));
if (!empty($PAGE->course->startdate)) {
// Replace {coursestartdate} tag with formatted date.
if (stripos($text, '{coursestartdate}') !== false) {
$replace['/\{coursestartdate\}/i'] = userdate($PAGE->course->startdate, get_string('strftimedatefullshort'));
}
} else {
$replace['/\{coursestartdate\}/i'] = get_string('none');
$replace['/\{coursestartdate\}/i'] = get_string('notyetstarted', 'completion');
}
}

// Tag: {courseenddate}. The course end date.
if (stripos($text, '{courseenddate}') !== false) {
if (stripos($text, '{courseenddate') !== false) {
if (empty($PAGE->course->enddate)) {
$PAGE->course->enddate = $DB->get_field_select('course', 'enddate', 'id = :id', ['id' => $course->id]);
$PAGE->course->enddate = $DB->get_field_select('course', 'enddate', 'id = :id', ['id' => $PAGE->course->id]);
}
if ($PAGE->course->enddate > 0) {
$replace['/\{courseenddate\}/i'] = userdate($PAGE->course->enddate, get_string('strftimedatefullshort'));
} else {
if (!empty($PAGE->course->enddate)) {
// Replace {courseenddate} tag with formatted date.
if (stripos($text, '{courseenddate}') !== false) {
$replace['/\{courseenddate\}/i'] = userdate($PAGE->course->enddate, get_string('strftimedatefullshort'));
}
} else { // No end date has been set.
$replace['/\{courseenddate\}/i'] = get_string('none');
}
}

// Tag: {coursecompletiondate}. The course completion date.
if (stripos($text, '{coursecompletiondate}') !== false) {
if (stripos($text, '{coursecompletiondate') !== false) {
if ($PAGE->course
&& isset($CFG->enablecompletion)
&& $CFG->enablecompletion == COMPLETION_ENABLED
&& $PAGE->course->enablecompletion) {
$ccompletion = new completion_completion(['userid' => $USER->id, 'course' => $PAGE->course->id]);
if ($ccompletion->timecompleted) {
$replace['/\{coursecompletiondate\}/i'] = userdate($ccompletion->timecompleted,
get_string('strftimedatefullshort'));
} else {
$replace['/\{coursecompletiondate\}/i'] = get_string('notcompleted', 'completion');
$incomplete = get_string('notcompleted', 'completion');
} else { // Completion not enabled.
$incomplete = get_string('completionnotenabled', 'completion');
}
if (!empty($ccompletion->timecompleted)) {
// Replace {coursecompletiondate} tag with formatted date.
if (stripos($text, '{coursecompletiondate}') !== false) {
$replace['/\{coursecompletiondate\}/i'] = userdate($ccompletion->timecompleted, get_string('strftimedatefullshort'));
}
} else {
$replace['/\{coursecompletiondate\}/i'] = get_string('completionnotenabled', 'completion');
$replace['/\{coursecompletiondate\}/i'] = $incomplete;
}
}

Expand Down

0 comments on commit 832c453

Please sign in to comment.