Commit d0b237b3 authored by Mihail Geshoski's avatar Mihail Geshoski
Browse files

MDL-64438 block_recentlyaccessedcourses: Optionally show course category

AMOS BEGIN
CPY [displaycategories,block_myoverview],[displaycategories,block_recentlyaccessedcourses]
AMOS END
parent 93ad530e
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -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"]',
......@@ -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);
});
......
......@@ -67,4 +67,13 @@ class block_recentlyaccessedcourses extends block_base {
public function applicable_formats() {
return array('my' => true);
}
/**
* Allow the block to have a configuration page
*
* @return boolean
*/
public function has_config() {
return true;
}
}
......@@ -46,6 +46,7 @@ class main implements renderable, templatable {
global $USER;
$nocoursesurl = $output->image_url('courses', 'block_recentlyaccessedcourses')->out(false);
$config = get_config('block_recentlyaccessedcourses');
return [
'userid' => $USER->id,
......@@ -53,7 +54,8 @@ class main implements renderable, templatable {
'pagingbar' => [
'next' => true,
'previous' => true
]
],
'displaycategories' => !empty($config->displaycategories)
];
}
}
......@@ -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';
\ No newline at end of file
$string['nocourses'] = 'No recent courses';
<?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));
}
......@@ -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 }}
......@@ -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>
......
......@@ -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 |
......@@ -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"
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.
\ No newline at end of file
......@@ -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).
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment