Skip to content

Commit

Permalink
Improvement: Add a direct 'view course' link on the course management…
Browse files Browse the repository at this point in the history
… pages, solves #129.
  • Loading branch information
abias committed Nov 4, 2023
1 parent 3b188ee commit def1dda
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes

### Unreleased

* 2023-10-09 - Improvement: Add a direct 'view course' icon on the course management pages, solves #129.
* 2023-10-05 - Improvement: Allow the admin to set the background-position of the background and login background images, solves #111.
* 2023-11-03 - Bugfix: Add missing cachedef strings to the language pack, solves #441.

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,16 @@ With this setting a hint will appear in the course header when a user is accessi

With this setting a hint will appear in the course header if the course is visible and an enrolment without enrolment key is currently possible.

#### Tab "Administration"

In this tab there are the following settings:

##### Course management

###### Show view course icon

By default, on the course management page, Moodle requires you to either open the course details or to pass through the course settings before you can click an additional UI element to view the course. By enabling this setting, you can add a 'View course' icon directly to the category listing on the course management page.

### Settings page "Flavours"

Boost Union's flavours offer a possibility to override particular Moodle look & feel settings in particular contexts. On this page, you can create and manage flavours.
Expand Down
143 changes: 143 additions & 0 deletions classes/output/core_course/management/renderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?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/>.

/**
* Theme Boost Union - Course management renderer
*
* @package theme_boost_union
* @copyright 2023 Alexander Bias <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace theme_boost_union\output\core_course\management;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot.'/course/classes/management_renderer.php');

use core_course_category;
use core_course_list_element;
use html_writer;
use moodle_url;
use pix_icon;

/**
* Extending the core_course_management_renderer.
*
* @package theme_boost_union
* @copyright 2023 Alexander Bias <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends \core_course_management_renderer {
/**
* Renderers actions for individual course actions.
*
* This renderer function is copied and modified from /course/classes/management_renderer.php.
*
* @param core_course_category $category The currently selected category.
* @param core_course_list_element $course The course to renderer actions for.
* @return string
*/
public function course_listitem_actions(core_course_category $category, core_course_list_element $course) {
$actions = \core_course\management\helper::get_course_listitem_actions($category, $course);

// If the admin decided to add a 'view course' icon.
if (get_config('theme_boost_union', 'showviewcourseiconincoursemgnt') == THEME_BOOST_UNION_SETTING_SELECT_YES) {
// If the user can access the course.
if ($course->can_access()) {
// Prepend the 'view course' icon.
$viewaction = [
'url' => new \moodle_url('/course/view.php', ['id' => $course->id]),
'icon' => new \pix_icon('i/course', \get_string('view')),
'attributes' => ['class' => 'action-view'],
];
array_unshift($actions, $viewaction);
}
}

$actionshtml = [];
foreach ($actions as $action) {
$action['attributes']['role'] = 'button';
$actionshtml[] = $this->output->action_icon($action['url'], $action['icon'], null, $action['attributes']);
}
return html_writer::span(join('', $actionshtml), 'course-item-actions item-actions mr-0');
}

/**
* Renderers actions for individual course actions.
*
* This renderer function is copied and modified from /course/classes/management_renderer.php.
*
* @param core_course_list_element $course The course to renderer actions for.
* @return string
*/
public function search_listitem_actions(core_course_list_element $course) {
$baseurl = new moodle_url(
'/course/managementsearch.php',
['courseid' => $course->id, 'categoryid' => $course->category, 'sesskey' => sesskey()]
);
$actions = [];
if ($course->can_access()) {
// If the admin decided to add a 'view course' icon.
if (get_config('theme_boost_union', 'showviewcourseiconincoursemgnt') == THEME_BOOST_UNION_SETTING_SELECT_YES) {
// View.
$actions[] = $this->output->action_icon(
new moodle_url('/course/view.php', ['id' => $course->id]),
new pix_icon('i/course', \get_string('view')),
null,
['class' => 'action-view']
);
}
// Edit.
if ($course->can_edit()) {
$actions[] = $this->output->action_icon(
new moodle_url('/course/edit.php', ['id' => $course->id]),
new pix_icon('t/edit', get_string('edit')),
null,
['class' => 'action-edit']
);
}
// Delete.
if ($course->can_delete()) {
$actions[] = $this->output->action_icon(
new moodle_url('/course/delete.php', ['id' => $course->id]),
new pix_icon('t/delete', get_string('delete')),
null,
['class' => 'action-delete']
);
}
// Show/Hide.
if ($course->can_change_visibility()) {
$actions[] = $this->output->action_icon(
new moodle_url($baseurl, ['action' => 'hidecourse']),
new pix_icon('t/hide', get_string('hide')),
null,
['data-action' => 'hide', 'class' => 'action-hide']
);
$actions[] = $this->output->action_icon(
new moodle_url($baseurl, ['action' => 'showcourse']),
new pix_icon('t/show', get_string('show')),
null,
['data-action' => 'show', 'class' => 'action-show']
);
}
}
if (empty($actions)) {
return '';
}
return html_writer::span(join('', $actions), 'course-item-actions item-actions');
}
}
8 changes: 8 additions & 0 deletions lang/en/theme_boost_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,14 @@
$string['showhintcourseselfenrolsinceuntil'] = 'The <strong>{$a->name}</strong> enrolment instance allows unrestricted self enrolment until {$a->until}.';
$string['showhintcourseselfenrolinstancecallforaction'] = 'If you don\'t want any Moodle user to have access to this course freely, please restrict the self enrolment settings.';

// Settings: Administration tab.
$string['administrationtab'] = 'Administration';
// ... Section: Course management.
$string['coursemanagementheading'] = 'Course management';
// ... ... Setting: Show view course icon in course management.
$string['showviewcourseiconincoursemgntsetting'] = 'Show view course icon';
$string['showviewcourseiconincoursemgntsesetting_desc'] = 'By default, on the <a href="{$a}">course management page</a>, Moodle requires you to either open the course details or to pass through the course settings before you can click an additional UI element to view the course. By enabling this setting, you can add a \'View course\' icon directly to the category listing on the course management page.';

// Settings: Flavours page.
$string['configtitleflavours'] = 'Flavours';
$string['flavoursappliesto'] = 'Applies to';
Expand Down
25 changes: 25 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,31 @@
$page->add($tab);


// Create administration tab.
$tab = new admin_settingpage('theme_boost_union_functionality_administration',
get_string('administrationtab', 'theme_boost_union', null, true));

// Create course management heading.
$name = 'theme_boost_union/coursemanagementheading';
$title = get_string('coursemanagementheading', 'theme_boost_union', null, true);
$setting = new admin_setting_heading($name, $title, null);
$tab->add($setting);

// Prepare course management page URL.
$coursemgnturl = new moodle_url('/course/management.php');

// Setting: Show view course icon in course management.
$name = 'theme_boost_union/showviewcourseiconincoursemgnt';
$title = get_string('showviewcourseiconincoursemgntsetting', 'theme_boost_union', null, true);
$description = get_string('showviewcourseiconincoursemgntsesetting_desc', 'theme_boost_union',
$coursemgnturl->out(), true);
$setting = new admin_setting_configselect($name, $title, $description, THEME_BOOST_UNION_SETTING_SELECT_NO, $yesnooption);
$tab->add($setting);

// Add tab to settings page.
$page->add($tab);


// Add settings page to the admin settings category.
$ADMIN->add('theme_boost_union', $page);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@theme @theme_boost_union @theme_boost_union_functionalitysettings @theme_boost_union_functionalitysettings_administration
Feature: Configuring the theme_boost_union plugin for the "Administration" tab on the "Functionality" page
In order to use the features
As admin
I need to be able to configure the theme Boost Union plugin

Background:
Given the following "categories" exist:
| name | category | idnumber |
| Category C | 0 | C |
And the following "courses" exist:
| fullname | shortname | category |
| Course C1 | C1 | C |

@javascript @testme
Scenario Outline: Setting: Show view course icon - Disable and enable the setting
Given the following config values are set as admin:
| config | value | plugin |
| showviewcourseiconincoursemgnt | <value> | theme_boost_union |
When I log in as "admin"
And I navigate to "Courses > Manage courses and categories" in site administration
And I click on "Category C" "link" in the "#category-listing" "css_element"
Then I should see "Course C1" in the "#course-listing" "css_element"
And "#course-listing .course-item-actions a.action-view" "css_element" <shouldexist>
And I set the field "Search courses" to "Course C1"
And I click on ".simplesearchform .search-icon" "css_element"
And I should see "Search results"
Then I should see "Course C1" in the "#course-listing" "css_element"
And "#course-listing .course-item-actions a.action-view" "css_element" <shouldexist>

Examples:
| value | shouldexist |
| yes | should exist |
| no | should not exist |
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'theme_boost_union';
$plugin->version = 2023102001;
$plugin->version = 2023102002;
$plugin->release = 'v4.3-r1';
$plugin->requires = 2023100900;
$plugin->supported = [403, 403];
Expand Down

0 comments on commit def1dda

Please sign in to comment.