Skip to content

Commit

Permalink
MDL-64438 block_recentlyaccessedcourses: Optionally show course category
Browse files Browse the repository at this point in the history
AMOS BEGIN
CPY [displaycategories,block_myoverview],[displaycategories,block_recentlyaccessedcourses]
AMOS END
  • Loading branch information
Mihail Geshoski committed Sep 18, 2019
1 parent 93ad530 commit d0b237b
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 16 deletions.
2 changes: 1 addition & 1 deletion blocks/recentlyaccessedcourses/amd/build/main.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blocks/recentlyaccessedcourses/amd/build/main.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions blocks/recentlyaccessedcourses/amd/src/main.js
Expand Up @@ -47,6 +47,7 @@ define(
// Constants.
var NUM_COURSES_TOTAL = 10;
var SELECTORS = {
BLOCK_CONTAINER: '[data-region="recentlyaccessedcourses"]',
CARD_CONTAINER: '[data-region="card-deck"]',
COURSE_IS_FAVOURITE: '[data-region="is-favourite"]',
CONTENT: '[data-region="view-content"]',
Expand Down Expand Up @@ -145,7 +146,9 @@ define(
* @return {promise} Resolved with list of rendered courses as jQuery objects.
*/
var renderAllCourses = function(courses) {
var showcoursecategory = $(SELECTORS.BLOCK_CONTAINER).data('displaycoursecategory');
var promises = courses.map(function(course) {
course.showcoursecategory = showcoursecategory;
return Templates.render('block_recentlyaccessedcourses/course-card', course);
});

Expand Down
Expand Up @@ -67,4 +67,13 @@ public function get_content() {
public function applicable_formats() {
return array('my' => true);
}

/**
* Allow the block to have a configuration page
*
* @return boolean
*/
public function has_config() {
return true;
}
}
4 changes: 3 additions & 1 deletion blocks/recentlyaccessedcourses/classes/output/main.php
Expand Up @@ -46,14 +46,16 @@ public function export_for_template(renderer_base $output) {
global $USER;

$nocoursesurl = $output->image_url('courses', 'block_recentlyaccessedcourses')->out(false);
$config = get_config('block_recentlyaccessedcourses');

return [
'userid' => $USER->id,
'nocoursesimgurl' => $nocoursesurl,
'pagingbar' => [
'next' => true,
'previous' => true
]
],
'displaycategories' => !empty($config->displaycategories)
];
}
}
Expand Up @@ -20,7 +20,9 @@
* @copyright 2018 Victor Deniz <victor@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['displaycategories'] = 'Display categories';
$string['displaycategories_help'] = 'Display the course category on the recently accessed courses block items.';
$string['pluginname'] = 'Recently accessed courses';
$string['privacy:metadata'] = 'The Recently accessed courses block does not store any personal data.';
$string['recentlyaccessedcourses:myaddinstance'] = 'Add a new recently accessed courses block to Dashboard';
$string['nocourses'] = 'No recent courses';
$string['nocourses'] = 'No recent courses';
34 changes: 34 additions & 0 deletions blocks/recentlyaccessedcourses/settings.php
@@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Settings for the recentlyaccessedcourses block
*
* @package block_recentlyaccessedcourses
* @copyright 2019 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;

if ($ADMIN->fulltree) {
// Display Course Categories on the recently accessed courses block items.
$settings->add(new admin_setting_configcheckbox(
'block_recentlyaccessedcourses/displaycategories',
get_string('displaycategories', 'block_recentlyaccessedcourses'),
get_string('displaycategories_help', 'block_recentlyaccessedcourses'),
1));
}
15 changes: 11 additions & 4 deletions blocks/recentlyaccessedcourses/templates/course-card.mustache
Expand Up @@ -35,10 +35,17 @@

{{< core_course/coursecard }}
{{$coursecategory}}
<span class="sr-only">
{{#str}}aria:coursecategory, core_course{{/str}}
</span>
<span class="text-truncate">{{{coursecategory}}}</span>
{{#showcoursecategory}}
<span class="sr-only">
{{#str}}aria:coursecategory, core_course{{/str}}
</span>
<span class="text-truncate">{{{coursecategory}}}</span>
{{/showcoursecategory}}
{{/coursecategory}}
{{$coursename}} <span class="text-truncate">{{{fullname}}}</span> {{/coursename}}
{{$divider}}
{{#showcoursecategory}}
<div class="pl-1 pr-1">|</div>
{{/showcoursecategory}}
{{/divider}}
{{/ core_course/coursecard }}
2 changes: 1 addition & 1 deletion blocks/recentlyaccessedcourses/templates/main.mustache
Expand Up @@ -27,7 +27,7 @@
}}

<div id="block-recentlyaccessedcourses-{{uniqid}}" class="block-recentlyaccessedcourses block-cards" data-region="recentlyaccessedcourses"
data-userid="{{userid}}">
data-userid="{{userid}}" data-displaycoursecategory="{{displaycategories}}">
<div class="container-fluid p-0">
{{> block_recentlyaccessedcourses/recentlyaccessedcourses-view }}
</div>
Expand Down
Expand Up @@ -8,13 +8,16 @@ Feature: The recently accessed courses block allows users to easily access their
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "categories" exist:
| name | category | idnumber |
| Category 1 | 0 | CAT1 |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
| Course 2 | C2 |
| Course 3 | C3 |
| Course 4 | C4 |
| Course 5 | C5 |
| fullname | shortname | category |
| Course 1 | C1 | 0 |
| Course 2 | C2 | 0 |
| Course 3 | C3 | 0 |
| Course 4 | C4 | CAT1 |
| Course 5 | C5 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
Expand All @@ -40,3 +43,43 @@ Feature: The recently accessed courses block allows users to easily access their
And I should not see "Course 3" in the "Recently accessed courses" "block"
And I should not see "Course 4" in the "Recently accessed courses" "block"
And I should not see "Course 5" in the "Recently accessed courses" "block"

Scenario: Show course category name
Given the following config values are set as admin:
| displaycategories | 1 | block_recentlyaccessedcourses |
And I log in as "student1"
And I am on "Course 1" course homepage
And I am on "Course 4" course homepage
And I follow "Dashboard" in the user menu
And I should see "Miscellaneous" in the "Recently accessed courses" "block"
And I should see "Category 1" in the "Recently accessed courses" "block"

Scenario: Hide course category name
Given the following config values are set as admin:
| displaycategories | 0 | block_recentlyaccessedcourses |
And I log in as "student1"
And I am on "Course 1" course homepage
And I am on "Course 4" course homepage
And I follow "Dashboard" in the user menu
And I should not see "Miscellaneous" in the "Recently accessed courses" "block"
And I should not see "Category 1" in the "Recently accessed courses" "block"

Scenario: Show short course name
Given the following config values are set as admin:
| courselistshortnames | 1 |
And I log in as "student1"
And I am on "Course 1" course homepage
And I am on "Course 4" course homepage
And I follow "Dashboard" in the user menu
And I should see "C1" in the "Recently accessed courses" "block"
And I should see "C4" in the "Recently accessed courses" "block"

Scenario: Hide short course name
Given the following config values are set as admin:
| courselistshortnames | 0 |
And I log in as "student1"
And I am on "Course 1" course homepage
And I am on "Course 4" course homepage
And I follow "Dashboard" in the user menu
And I should not see "C1" in the "Recently accessed courses" "block"
And I should not see "C4" in the "Recently accessed courses" "block"
5 changes: 5 additions & 0 deletions blocks/recentlyaccessedcourses/upgrade.txt
@@ -1,5 +1,10 @@
This file describes API changes in the recentlyaccessedcourses block code.

=== 3.8 ===

* New admin setting block_recentlyaccessedcourses/displaycategories which enables the recently accessed
courses block to display the course category.

=== 3.7 ===

* The 'block/recentlyaccessedcourses:addinstance' capability has been removed. It has never been used in code.
2 changes: 1 addition & 1 deletion blocks/recentlyaccessedcourses/version.php
Expand Up @@ -22,6 +22,6 @@
*/
defined('MOODLE_INTERNAL') || die();

$plugin->version = 2019052000; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2019052001; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2019051100; // Requires this Moodle version.
$plugin->component = 'block_recentlyaccessedcourses'; // Full name of the plugin (used for diagnostics).

0 comments on commit d0b237b

Please sign in to comment.