first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,183 @@
<?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/>.
/**
* This file contains the main class for the section links block.
*
* @package block_section_links
* @copyright Jason Hardin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Section links block class.
*
* @package block_section_links
* @copyright Jason Hardin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_section_links extends block_base {
/**
* Initialises the block instance.
*/
public function init() {
$this->title = get_string('pluginname', 'block_section_links');
}
/**
* Returns an array of formats for which this block can be used.
*
* @return array
*/
public function applicable_formats() {
return [
'course-view-weeks' => true,
'course-view-topics' => true,
'course-view-section-weeks' => true,
'course-view-section-topics' => true,
];
}
/**
* Generates the content of the block and returns it.
*
* If the content has already been generated then the previously generated content is returned.
*
* @return stdClass
*/
public function get_content() {
// The config should be loaded by now.
// If its empty then we will use the global config for the section links block.
if (isset($this->config)){
$config = $this->config;
} else{
$config = get_config('block_section_links');
}
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
$this->content->footer = '';
$this->content->text = '';
if (empty($this->instance)) {
return $this->content;
}
$course = $this->page->course;
$courseformat = course_get_format($course);
$numsections = $courseformat->get_last_section_number();
$context = context_course::instance($course->id);
// Course format options 'numsections' is required to display the block.
if (empty($numsections)) {
return $this->content;
}
// Prepare the increment value.
if (!empty($config->numsections1) and ($numsections > $config->numsections1)) {
$inc = $config->incby1;
} else if ($numsections > 22) {
$inc = 2;
} else {
$inc = 1;
}
if (!empty($config->numsections2) and ($numsections > $config->numsections2)) {
$inc = $config->incby2;
} else {
if ($numsections > 40) {
$inc = 5;
}
}
// Whether or not section name should be displayed.
$showsectionname = !empty($config->showsectionname) ? true : false;
// Prepare an array of sections to create links for.
$sections = array();
$canviewhidden = has_capability('moodle/course:update', $context);
$coursesections = $courseformat->get_sections();
$coursesectionscount = count($coursesections);
$sectiontojumpto = false;
for ($i = $inc; $i <= $coursesectionscount; $i += $inc) {
if ($i > $numsections || !isset($coursesections[$i])) {
continue;
}
$section = $coursesections[$i];
if ($section->section && ($section->visible || $canviewhidden)) {
$sections[$i] = (object)array(
'section' => $section->section,
'visible' => $section->visible,
'highlight' => false
);
if ($courseformat->is_section_current($section)) {
$sections[$i]->highlight = true;
$sectiontojumpto = $section->section;
}
if ($showsectionname) {
$sections[$i]->name = $courseformat->get_section_name($i);
}
}
}
if (!empty($sections)) {
// Render the sections.
$renderer = $this->page->get_renderer('block_section_links');
$this->content->text = $renderer->render_section_links($this->page->course, $sections,
$sectiontojumpto, $showsectionname);
}
return $this->content;
}
/**
* Returns true if this block has instance config.
*
* @return bool
**/
public function instance_allow_config() {
return true;
}
/**
* Returns true if this block has global config.
*
* @return bool
*/
public function has_config() {
return true;
}
/**
* Return the plugin config settings for external functions.
*
* @return stdClass the configs for both the block instance and plugin
* @since Moodle 3.8
*/
public function get_config_for_external() {
// Return all settings for all users since it is safe (no private keys, etc..).
$instanceconfigs = !empty($this->config) ? $this->config : new stdClass();
$pluginconfigs = get_config('block_section_links');
return (object) [
'instance' => $instanceconfigs,
'plugin' => $pluginconfigs,
];
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for block_section_links.
*
* @package block_section_links
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_section_links\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for block_section_links implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+41
View File
@@ -0,0 +1,41 @@
<?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/>.
/**
* Section links block caps.
*
* @package block_section_links
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/section_links:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
+61
View File
@@ -0,0 +1,61 @@
<?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/>.
/**
* This file keeps track of upgrades to the section links block
*
* Sometimes, changes between versions involve alterations to database structures
* and other major things that may break installations.
*
* The upgrade function in this file will attempt to perform all the necessary
* actions to upgrade your older installation to the current version.
*
* If there's something it cannot do itself, it will tell you what you need to do.
*
* The commands in here will all be database-neutral, using the methods of
* database_manager class
*
* Please do not forget to use upgrade_set_timeout()
* before any action that may take longer time to finish.
*
* @since Moodle 2.5
* @package block_section_links
* @copyright 2013 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Upgrade code for the section links block.
*
* @global moodle_database $DB
* @param int $oldversion
* @param object $block
*/
function xmldb_block_section_links_upgrade($oldversion, $block) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
+89
View File
@@ -0,0 +1,89 @@
<?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/>.
/**
* Instance configuration for the section links block.
*
* @package block_section_links
* @copyright 2013 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Instance configuration form.
*
* @package block_section_links
* @copyright 2013 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_section_links_edit_form extends block_edit_form {
/**
* The definition of the fields to use.
*
* @param MoodleQuickForm $mform
*/
protected function specific_definition($mform) {
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
$numberofsections = array();
for ($i = 1; $i < 53; $i++){
$numberofsections[$i] = $i;
}
$increments = array();
for ($i = 1; $i < 11; $i++){
$increments[$i] = $i;
}
$config = get_config('block_section_links');
$selected = array(
1 => array(22, 2),
2 => array(40, 5),
);
if (!empty($config->numsections1)) {
if (empty($config->incby1)) {
$config->incby1 = $selected[1][1];
}
$selected[1] = array($config->numsections1, $config->incby1);
}
if (!empty($config->numsections2)) {
if (empty($config->incby1)) {
$config->incby1 = $selected[2][1];
}
$selected[2] = array($config->numsections2, $config->incby2);
}
for ($i = 1; $i < 3; $i++) {
$mform->addElement('select', 'config_numsections'.$i, get_string('numsections'.$i, 'block_section_links'), $numberofsections);
$mform->setDefault('config_numsections'.$i, $selected[$i][0]);
$mform->setType('config_numsections'.$i, PARAM_INT);
$mform->addHelpButton('config_numsections'.$i, 'numsections'.$i, 'block_section_links');
$mform->addElement('select', 'config_incby'.$i, get_string('incby'.$i, 'block_section_links'), $increments);
$mform->setDefault('config_incby'.$i, $selected[$i][1]);
$mform->setType('config_incby'.$i, PARAM_INT);
$mform->addHelpButton('config_incby'.$i, 'incby'.$i, 'block_section_links');
}
$mform->addElement('selectyesno', 'config_showsectionname', get_string('showsectionname', 'block_section_links'));
$mform->setDefault('config_showsectionname', !empty($config->showsectionname) ? 1 : 0);
$mform->addHelpButton('config_showsectionname', 'showsectionname', 'block_section_links');
}
}
@@ -0,0 +1,39 @@
<?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/>.
/**
* Strings for component 'block_section_links', language 'en', branch 'MOODLE_20_STABLE'
*
* @package block_section_links
* @copyright Jason Hardin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['incby1'] = 'Increase by';
$string['incby1_help'] = 'This is the value the section is incremented each time a section link is displayed starting at 1.';
$string['incby2'] = 'Alternative increase by';
$string['incby2_help'] = 'This is the value the section is incremented each time a section link is displayed starting at 1.';
$string['jumptocurrenttopic'] = 'Jump to highlighted section';
$string['jumptocurrentweek'] = 'Jump to current week';
$string['numsections1'] = 'Number of sections';
$string['numsections1_help'] = 'Once the number of sections in the course reaches this number then the increment by value is used.';
$string['numsections2'] = 'Alternative number of sections';
$string['numsections2_help'] = 'Once the number of sections in the course reaches this number then the Alternative increment by value is used.';
$string['pluginname'] = 'Section links';
$string['section_links:addinstance'] = 'Add a new section links block';
$string['showsectionname'] = 'Display section name';
$string['showsectionname_help'] = 'Display section name in addition to section number';
$string['privacy:metadata'] = 'The Section links block only shows data stored in other locations.';
+85
View File
@@ -0,0 +1,85 @@
<?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/>.
/**
* Renderer for the section links block.
*
* @since Moodle 2.5
* @package block_section_links
* @copyright 2013 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Renderer for the section links block.
*
* @package block_section_links
* @copyright 2013 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_section_links_renderer extends plugin_renderer_base {
/**
* Render a series of section links.
*
* @param stdClass $course The course we are rendering for.
* @param array $sections An array of section objects to render.
* @param bool|int The section to provide a jump to link for.
* @param bool $showsectionname Whether or not section name should be displayed.
* @return string The HTML to display.
*/
public function render_section_links(stdClass $course, array $sections, $jumptosection = false, $showsectionname = false) {
$olparams = $showsectionname ? ['class' => 'unlist'] : ['class' => 'inline-list'];
$html = html_writer::start_tag('ol', $olparams);
foreach ($sections as $section) {
$attributes = array();
if (!$section->visible) {
$attributes['class'] = 'dimmed';
}
$html .= html_writer::start_tag('li');
$sectiontext = $section->section;
if ($showsectionname) {
$sectiontext .= ': ' . $section->name;
}
if ($section->highlight) {
$sectiontext = html_writer::tag('strong', $sectiontext);
}
$html .= html_writer::link(
course_get_url($course, $section->section, ['navigation' => true]),
$sectiontext,
$attributes
);
$html .= html_writer::end_tag('li').' ';
}
$html .= html_writer::end_tag('ol');
if ($jumptosection && isset($sections[$jumptosection])) {
if ($course->format == 'weeks') {
$linktext = new lang_string('jumptocurrentweek', 'block_section_links');
} else if ($course->format == 'topics') {
$linktext = new lang_string('jumptocurrenttopic', 'block_section_links');
}
$attributes = array();
if (!$sections[$jumptosection]->visible) {
$attributes['class'] = 'dimmed';
}
$html .= html_writer::link(course_get_url($course, $jumptosection, ['navigation' => true]), $linktext, $attributes);
}
return $html;
}
}
+56
View File
@@ -0,0 +1,56 @@
<?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/>.
/**
* Section links block
*
* @package block_section_links
* @copyright Jason Hardin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
$numberofsections = array();
for ($i = 1; $i < 53; $i++){
$numberofsections[$i] = $i;
}
$increments = array();
for ($i = 1; $i < 11; $i++){
$increments[$i] = $i;
}
$selected = array(1 => array(22,2),
2 => array(40,5));
for($i = 1; $i < 3; $i++){
$settings->add(new admin_setting_configselect('block_section_links/numsections'.$i, get_string('numsections'.$i, 'block_section_links'),
get_string('numsections'.$i.'_help', 'block_section_links'),
$selected[$i][0], $numberofsections));
$settings->add(new admin_setting_configselect('block_section_links/incby'.$i, get_string('incby'.$i, 'block_section_links'),
get_string('incby'.$i.'_help', 'block_section_links'),
$selected[$i][1], $increments));
}
$settings->add(new admin_setting_configcheckbox('block_section_links/showsectionname',
get_string('showsectionname', 'block_section_links'),
get_string('showsectionname_help', 'block_section_links'),
0));
}
@@ -0,0 +1,62 @@
@block @block_section_links
Feature: The section links block allows users to quickly navigate around a moodle course
In order to navigate a moodle course
As a teacher
I can use the section links block
Background:
Given the following "courses" exist:
| fullname | shortname | category | numsections | coursedisplay |
| Course 1 | C1 | 0 | 20 | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "activities" exist:
| activity | name | intro | course | section | idnumber | assignsubmission_file_enabled |
| assign | Test assignment 1 | Offline text | C1 | 5 | assign1 | 0 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
Scenario: Add the section links block to a course.
Given the following config values are set as admin:
| unaddableblocks | | theme_boost|
And I add the "Section links" block
And I turn editing mode off
And I should see "5" in the "Section links" "block"
When I follow "5"
Then I should see "Test assignment 1"
Scenario: Add the section links block to a course and limit the sections displayed.
Given the following config values are set as admin:
| unaddableblocks | | theme_boost|
And I add the "Section links" block
And I configure the "Section links" block
And I set the following fields to these values:
| config_numsections1 | 5 |
| config_incby1 | 5 |
| config_numsections2 | 40 |
| config_incby2 | 10 |
And I press "Save changes"
And I turn editing mode off
And I should see "5" in the "Section links" "block"
When I follow "5"
Then I should see "Test assignment 1"
Scenario: Add the section links block to a course and limit the sections displayed using the alternative number of sections.
Given the following config values are set as admin:
| unaddableblocks | | theme_boost|
And I add the "Section links" block
And I configure the "Section links" block
And I set the following fields to these values:
| config_numsections1 | 5 |
| config_incby1 | 1 |
| config_numsections2 | 10 |
| config_incby2 | 5 |
And I press "Save changes"
And I turn editing mode off
And I should see "5" in the "Section links" "block"
When I follow "5"
Then I should see "Test assignment 1"
@@ -0,0 +1,46 @@
@block @block_section_links
Feature: The Section links block can be configured to display section name in addition to section number
Background:
Given the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| category | 0 |
| numsections | 10 |
| coursedisplay | 1 |
| initsections | 1 |
And the following "activities" exist:
| activity | name | course | idnumber | section |
| assign | First assignment | C1 | assign1 | 7 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following config values are set as admin:
| showsectionname | 1 | block_section_links |
| unaddableblocks | | theme_boost|
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| section_links | Course | C1 | course-view-* | side-pre |
Scenario: Student can see section name under the Section links block
When I am on the "Course 1" course page logged in as student1
Then I should see "7: Section 7" in the "Section links" "block"
And I follow "7: Section 7"
And I should see "First assignment"
Scenario: Teacher can configure existing Section links block to display section number or section name
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
When I configure the "Section links" block
And I set the following fields to these values:
| Display section name | No |
And I click on "Save changes" "button"
Then I should not see "7: Section 7" in the "Section links" "block"
And I should see "7" in the "Section links" "block"
And I follow "7"
And I should see "First assignment"
+6
View File
@@ -0,0 +1,6 @@
This file describes API changes in the section_links block code.
=== 3.11 ===
* New optional parameter $showsectionname has been added to render_section_links(). Setting this to true will display
section name in addition to section number.
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* Version details
*
* @package block_section_links
* @copyright Jason Hardin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'block_section_links'; // Full name of the plugin (used for diagnostics)