Skip to content

Commit

Permalink
Merge pull request #9 from Lesterhuis-Training-en-Consultancy/86by49k…
Browse files Browse the repository at this point in the history
…22-upgrade-moodle45

86by49k22 upgrade moodle45
  • Loading branch information
luukverhoeven authored Dec 17, 2024
2 parents 125f68a + 9e8f960 commit f734d2d
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 160 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Types of changes
* **Fixed** for any bug fixes.
* **Security** in case of vulnerabilities.

## Version (4.5.0) - 2024-09-13
- Tested for Moodle 4.5 and PHP 8.1

## Version (4.4.0) - 2024-04-05
- Tested for Moodle 4.4 and PHP 8.1
- Show link when no icon is used in floating menu
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## a Moodle block for better course navigation

In brief, the MFreak block `fastnav` gives users the ability to navigate more easily inside a course.

Special thanks to Gemma Lesterhuis ([Lesterhuis Training & Consultancy](https://ltnc.nl/)) for develop & design, useful input, bug reports and beta testing

![Ldesign.nl](https://ldesign.nl/logo_small.png)
Expand All @@ -10,7 +10,7 @@ Special thanks to Gemma Lesterhuis ([Lesterhuis Training & Consultancy](https://
* Author: Luuk Verhoeven, [MFreak.nl](https://MFreak.nl/)
* Author: Gemma Lesterhuis, [Lesterhuis Training & Consultancy](https://ltnc.nl/)
* Min. required: Moodle 3.9.
* Max: 4.4
* Max: 4.5
* Supports PHP: 7.2, 7.3, 7.4, 8.0, 8.1

![Moodle39](https://img.shields.io/badge/moodle-3.9-brightgreen.svg)
Expand All @@ -19,6 +19,7 @@ Special thanks to Gemma Lesterhuis ([Lesterhuis Training & Consultancy](https://
![Moodle42](https://img.shields.io/badge/moodle-4.2-brightgreen.svg)
![Moodle43](https://img.shields.io/badge/moodle-4.3-brightgreen.svg)
![Moodle44](https://img.shields.io/badge/moodle-4.4-brightgreen.svg)
![Moodle45](https://img.shields.io/badge/moodle-4.5-brightgreen.svg)

![PHP7.4](https://img.shields.io/badge/PHP-7.4-blue.svg)
![PHP8.0](https://img.shields.io/badge/PHP-8.0-blue.svg)
Expand Down
13 changes: 11 additions & 2 deletions amd/build/sidebar.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 amd/build/sidebar.min.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions amd/src/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package block_fastnav
* @copyright 17/07/2020 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
* @author Luuk Verhoeven
**/
define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates', 'core/config'],
function($, Ajax, Log, Notification, Templates) {
define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates', 'core/config', 'core_user/repository'],
function($, Ajax, Log, Notification, Templates, setUserPreference, UserRepository) {
'use strict';

var sidebar = {
Expand Down Expand Up @@ -162,7 +161,8 @@ define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates'
* @param {string} status
*/
updateOpenPreference: function(status) {
M.util.set_user_preference('block_fastnav_open', status);
return UserRepository.setUserPreference(`block_fastnav_open`, status)
.catch(Notification.exception);
}
};

Expand All @@ -177,4 +177,4 @@ define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates'
sidebar.start();
}
};
});
});
26 changes: 10 additions & 16 deletions block_fastnav.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ class block_fastnav extends block_base {
/**
* Init
*
* @throws coding_exception
*/
public function init(): void {
$this->title = get_string('pluginname', 'block_fastnav');
$this->title = get_string(identifier: 'pluginname', component: 'block_fastnav');
}

/**
Expand Down Expand Up @@ -73,16 +72,15 @@ public function applicable_formats(): array {
/**
* Specialization
*
* @throws coding_exception
*/
public function specialization(): void {
if (isset($this->config->title)) {
$this->title = format_string($this->config->title, true, ['context' => $this->context]);
$this->title = format_string(string: $this->config->title, options: ['context' => $this->context]);

return;
}

$this->title = get_string('pluginname', 'block_fastnav');
$this->title = get_string(identifier: 'pluginname', component: 'block_fastnav');
}

/**
Expand All @@ -91,8 +89,6 @@ public function specialization(): void {
* the content object.
*
* @return object
* @throws coding_exception
* @throws moodle_exception
*/
public function get_content(): object {
global $CFG, $USER;
Expand All @@ -106,12 +102,12 @@ public function get_content(): object {
$this->content->text = '';
$this->content->footer = '';

$renderer = $this->page->get_renderer('block_fastnav');
$renderer = $this->page->get_renderer(component: 'block_fastnav');

// Allow ajax call.
$USER->ajax_updatable_user_prefs['block_fastnav_open'] = true;

if (has_capability('block/fastnav:management', $this->context)
if (has_capability(capability: 'block/fastnav:management', context: $this->context)
&& $this->page->user_is_editing()) {
$this->content->text .= $renderer->get_management_buttons($this);
}
Expand All @@ -127,10 +123,10 @@ public function get_content(): object {
}

if ($this->can_display_sidebar()) {
$this->page->requires->js_call_amd('block_fastnav/sidebar', 'init', [
$this->page->requires->js_call_amd(fullmodule: 'block_fastnav/sidebar', func: 'init', params: [
[
'instanceid' => $this->context->instanceid,
'open' => get_user_preferences('block_fastnav_open'),
'open' => get_user_preferences(name: 'block_fastnav_open'),
],
]);
}
Expand All @@ -142,14 +138,13 @@ public function get_content(): object {
* Instance delete
*
* @return bool
* @throws dml_exception
*/
public function instance_delete(): bool {
global $DB;

$fs = get_file_storage();
$fs->delete_area_files($this->context->id, 'block_fastnav');
$DB->delete_records('block_fastnav', ['contextid' => $this->context->id]);
$fs->delete_area_files(contextid: $this->context->id, component: 'block_fastnav');
$DB->delete_records(table: 'block_fastnav', conditions: ['contextid' => $this->context->id]);

return true;
}
Expand All @@ -158,14 +153,13 @@ public function instance_delete(): bool {
* Do any additional initialization you may need at the time a new block instance is created
*
* @return boolean
* @throws dml_exception
*/
public function instance_create(): bool {
global $DB, $COURSE;

if (!empty($COURSE->id) && $COURSE->id > 1) {
// Update default to course-*.
$DB->update_record('block_instances', (object) [
$DB->update_record(table: 'block_instances', dataobject: (object) [
'id' => $this->instance->id,
'pagetypepattern' => '*', // Any page.
'showinsubcontexts' => 1,
Expand Down
17 changes: 7 additions & 10 deletions classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ class external extends external_api {
* @param int $instanceid
*
* @return array
* @throws \coding_exception
* @throws \dml_exception
* @throws \invalid_parameter_exception
*/
public static function get_items(int $instanceid): array {
$warnings = [];
Expand All @@ -68,7 +65,7 @@ public static function get_items(int $instanceid): array {
]);

return [
'open' => get_user_preferences('block_fastnav_open', false),
'open' => get_user_preferences(name: 'block_fastnav_open', default: false),
'items' => array_map(static function($item) {
return [
'id' => $item->get_id(),
Expand All @@ -89,7 +86,7 @@ public static function get_items(int $instanceid): array {
public static function get_items_parameters(): external_function_parameters {
return new external_function_parameters(
[
'instanceid' => new external_value(PARAM_INT, 'Block instance id'),
'instanceid' => new external_value(type: PARAM_INT, desc: 'Block instance id'),
]
);
}
Expand All @@ -102,14 +99,14 @@ public static function get_items_parameters(): external_function_parameters {
public static function get_items_returns(): external_single_structure {
return new external_single_structure(
[
'open' => new external_value(PARAM_BOOL, 'Check if fastnav is locked (open) state'),
'open' => new external_value(type: PARAM_BOOL, desc: 'Check if fastnav is locked (open) state'),
'items' => new external_multiple_structure(
new external_single_structure(
[
'id' => new external_value(PARAM_INT, 'The item ID.'),
'icon' => new external_value(PARAM_RAW, 'The item icon.'),
'name' => new external_value(PARAM_TEXT, 'The item name'),
'link' => new external_value(PARAM_URL, 'The item link'),
'id' => new external_value(type: PARAM_INT, desc: 'The item ID.'),
'icon' => new external_value(type: PARAM_RAW, desc: 'The item icon.'),
'name' => new external_value(type: PARAM_TEXT, desc: 'The item name'),
'link' => new external_value(type: PARAM_URL, desc: 'The item link'),
]
)
),
Expand Down
40 changes: 21 additions & 19 deletions classes/form/form_edit_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
global $CFG;

use block_fastnav\helper;
use core_privacy\local\metadata\types\type;

require_once($CFG->libdir . '/formslib.php');

Expand Down Expand Up @@ -82,27 +83,28 @@ public function __construct($action = null, $customdata = null) {

/**
* Form definition
*
* @throws \coding_exception
*/
protected function definition() : void {
$mform = &$this->_form;

$mform->addElement('text', 'name', get_string('form:name', 'block_fastnav'), []);
$mform->setType('name', PARAM_TEXT);
$mform->addElement('text', 'name', get_string(identifier: 'form:name', component: 'block_fastnav'), []);
$mform->setType(elementname: 'name', paramtype: PARAM_TEXT);

$mform->addElement('text', 'link', get_string('form:link', 'block_fastnav'), []);
$mform->setType('link', PARAM_URL);
$mform->addElement('text', 'link', get_string(identifier: 'form:link', component: 'block_fastnav'), []);
$mform->setType(elementname: 'link', paramtype: PARAM_URL);

$mform->addElement('filepicker', 'link_icon',
get_string('form:link_icon', 'block_fastnav'), null, helper::get_file_options());
get_string(identifier: 'form:link_icon', component: 'block_fastnav'), null, helper::get_file_options());

// Rules.
$mform->addRule('name', get_string('required'), 'required', 255, 'client');
$mform->addRule('link', get_string('required'), 'required', 255, 'client');
$mform->addRule('link', get_string('required'), 'required', 255, 'client');

$this->add_action_buttons(false, get_string('btn:update', 'block_fastnav'));
$mform->addRule(element: 'name', message: get_string(identifier: 'required'), type: 'required', format: 255,
validation: 'client');
$mform->addRule(element: 'link', message: get_string(identifier: 'required'), type: 'required', format: 255,
validation: 'client');
$mform->addRule(element: 'link', message: get_string(identifier: 'required'), type: 'required', format: 255,
validation: 'client');

$this->add_action_buttons(cancel: false, submitlabel: get_string(identifier: 'btn:update', component: 'block_fastnav'));
}

/**
Expand All @@ -112,14 +114,14 @@ protected function definition() : void {
*/
public function definition_after_data() : void {

$draftitemid = file_get_submitted_draft_itemid('link_icon');
$draftitemid = file_get_submitted_draft_itemid(elname: 'link_icon');
file_prepare_draft_area(
$draftitemid,
$this->blockcontext->id,
'block_fastnav',
'link_icon',
$this->item->get_id(),
helper::get_file_options()
draftitemid: $draftitemid,
contextid: $this->blockcontext->id,
component: 'block_fastnav',
filearea: 'link_icon',
itemid: $this->item->get_id(),
options: helper::get_file_options()
);

// Set data.
Expand Down
Loading

0 comments on commit f734d2d

Please sign in to comment.