Skip to content

Commit

Permalink
DASH-5 add sort order field to layouts, add strings for timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
moodledev committed Dec 23, 2020
1 parent 46019a4 commit 53554eb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,40 @@ If your site is not loading properly you may wish to temporarily disable Dash fr
1. Go to *Site administration / Plugins / Blocks / Dash*. Enable **Disable all Dash output** OR
2. Edit your `config.php` and add `$CFG->block_dash_disableall = true;`

## Timeline

### Core and custom event strings

Standard Moodle event descriptions are vague and ugly. Dash allows strings to be used instead. Here's an example for the `\core\event\course_completed` event:

lang/en/block_dash.php
```php
$string['event_desc_core_event_user_enrolment_created'] = '{$a->relateduserfullname} was enrolled in <a href="{$a->eventurl}" title="View {$a->contextname}">{$a->contextname}</a>';
```

The string identifier is simply `event_desc_` combined with the event class name, with backslashes `\\` replaced with underscores `_`

The variables available in the string are:

```
userid: 123
userfullname: John Doe
relateduserid: 456
relateduserfullname: Mr. Affected User
eventname: Course completed
eventurl: https://example.com/course/view.php?id=100
contextname: Course: Test course
action: created
```

By adding this string, it will be used for all events of type `\core\event\course_completed` in the timeline data source.

Helpful command to load new strings:

```
$ php /path/to/moodle/admin/cli/purge_caches.php --lang
```

# Development

### Key terms
Expand Down
14 changes: 11 additions & 3 deletions classes/local/data_source/abstract_data_source.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ public final function get_filter_collection() {

if ($this->get_preferences('filters')) {
foreach ($this->get_preferences('filters') as $filtername => $filterpreferences) {
if ($this->filtercollection->has_filter($filtername)) {
$this->filtercollection->get_filter($filtername)->set_preferences($filterpreferences);
if (is_array($filterpreferences) || is_object($filterpreferences)) {
if ($this->filtercollection->has_filter($filtername)) {
$this->filtercollection->get_filter($filtername)->set_preferences($filterpreferences);
}
}
}
}
Expand Down Expand Up @@ -426,6 +428,12 @@ public function build_preferences_form(\moodleform $form, \MoodleQuickForm $mfor
$sortablefields);
$mform->setType('config_preferences[default_sort]', PARAM_TEXT);
$mform->addHelpButton('config_preferences[default_sort]', 'defaultsortfield', 'block_dash');

$mform->addElement('select', 'config_preferences[default_sort_direction]', get_string('defaultsortdirection', 'block_dash'), [
'asc' => 'ASC',
'desc' => 'DESC'
]);
$mform->setType('config_preferences[default_sort_direction]', PARAM_TEXT);
}
}

Expand Down Expand Up @@ -591,7 +599,7 @@ public function get_sorting() {
}

if ($defaultsort = $this->get_preferences('default_sort')) {
return [$defaultsort => 'asc'];
return [$defaultsort => $this->get_preferences('default_sort_direction') ?? 'asc'];
}

return [];
Expand Down
10 changes: 10 additions & 0 deletions lang/en/block_dash.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
$string['datecompleted'] = 'Date completed';
$string['daysuntilend'] = 'Days until end date';
$string['daysuntilstart'] = 'Days until start date';
$string['defaultsortdirection'] = 'Sort direction';
$string['defaultsortfield'] = 'Sort by';
$string['defaultsortfield_help'] = 'Sort database results by this field. If layout supports user sorting, this will be the default.';
$string['delete'] = 'Delete';
Expand Down Expand Up @@ -125,10 +126,17 @@
$string['enrollmentstatus'] = 'Enrollment status';
$string['enrollmenttimeend'] = 'Enrollment end date';
$string['enrollmenttimestart'] = 'Enrollment start date';
$string['event_desc_core_event_user_enrolment_created'] = '{$a->relateduserfullname} was enrolled in <a href="{$a->eventurl}" title="View {$a->contextname}">{$a->contextname}</a>';
$string['event_desc_generic'] = '{$a->userfullname} {$a->action} <a href="{$a->eventurl}" title="View {$a->contextname}">{$a->contextname}</a>';
$string['eventbutton'] = 'Event button';
$string['eventclass'] = 'Event class';
$string['eventcolor'] = 'Event color';
$string['eventdescription'] = 'Event description';
$string['eventicon'] = 'Event icon';
$string['eventlink'] = 'Event link';
$string['events'] = 'Events';
$string['eventtime'] = 'Event time';
$string['eventurl'] = 'Event URL';
$string['extracontent'] = 'Extra content';
$string['fieldname'] = 'Field name';
$string['fieldnotfound'] = 'Field not found.';
Expand All @@ -139,12 +147,14 @@
$string['footerfield'] = 'Footer field';
$string['footerrightfield'] = 'Footer field (right)';
$string['fullnamelinked'] = 'Full name (linked to profile)';
$string['gotoevent'] = 'Go to event';
$string['groupby'] = 'Group by';
$string['grouplabel'] = 'Group label';
$string['headercontent'] = 'Header content';
$string['headercontent_help'] = 'Content displayed in the block header.';
$string['headingfield'] = 'Heading field';
$string['hidewhenempty'] = 'Hide when empty';
$string['iconfield'] = 'Icon field';
$string['imageoverlayfield'] = 'Image overlay field';
$string['imageoverlayfield_help'] = 'Content to display over image with solid background.';
$string['imageurlfield'] = 'Image URL field';
Expand Down

0 comments on commit 53554eb

Please sign in to comment.