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,117 @@
<?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/>.
namespace format_topics\courseformat;
use core_courseformat\stateupdates;
use core_courseformat\stateactions as stateactions_base;
use core\event\course_module_updated;
use cm_info;
use section_info;
use stdClass;
use course_modinfo;
use moodle_exception;
use context_module;
use context_course;
/**
* Contains the core course state actions specific to topics format.
*
* @package format_topics
* @copyright 2022 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class stateactions extends stateactions_base {
/**
* Highlight course section.
*
* @param stateupdates $updates the affected course elements track
* @param stdClass $course the course object
* @param int[] $ids section ids (only ther first one will be highlighted)
* @param int $targetsectionid not used
* @param int $targetcmid not used
*/
public function section_highlight(
stateupdates $updates,
stdClass $course,
array $ids = [],
?int $targetsectionid = null,
?int $targetcmid = null
): void {
global $DB;
$this->validate_sections($course, $ids, __FUNCTION__);
$coursecontext = context_course::instance($course->id);
require_capability('moodle/course:setcurrentsection', $coursecontext);
// Get the previous marked section.
$modinfo = get_fast_modinfo($course);
$previousmarker = $DB->get_field("course", "marker", ['id' => $course->id]);
$section = $modinfo->get_section_info_by_id(reset($ids), MUST_EXIST);
if ($section->section == $previousmarker) {
return;
}
// Mark the new one.
course_set_marker($course->id, $section->section);
$updates->add_section_put($section->id);
if ($previousmarker) {
$section = $modinfo->get_section_info($previousmarker);
$updates->add_section_put($section->id);
}
}
/**
* Remove highlight from a course sections.
*
* @param stateupdates $updates the affected course elements track
* @param stdClass $course the course object
* @param int[] $ids optional extra section ids to refresh
* @param int $targetsectionid not used
* @param int $targetcmid not used
*/
public function section_unhighlight(
stateupdates $updates,
stdClass $course,
array $ids = [],
?int $targetsectionid = null,
?int $targetcmid = null
): void {
global $DB;
$this->validate_sections($course, $ids, __FUNCTION__);
$coursecontext = context_course::instance($course->id);
require_capability('moodle/course:setcurrentsection', $coursecontext);
$affectedsections = [];
// Get the previous marked section and unmark it.
$modinfo = get_fast_modinfo($course);
$previousmarker = $DB->get_field("course", "marker", ['id' => $course->id]);
course_set_marker($course->id, 0);
$section = $modinfo->get_section_info($previousmarker, MUST_EXIST);
$updates->add_section_put($section->id);
foreach ($ids as $sectionid) {
$section = $modinfo->get_section_info_by_id($sectionid, MUST_EXIST);
if ($section->section != $previousmarker) {
$updates->add_section_put($section->id);
}
}
}
}
@@ -0,0 +1,57 @@
<?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/>.
/**
* Contains the default content output class.
*
* @package format_topics
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace format_topics\output\courseformat;
use core_courseformat\output\local\content as content_base;
use renderer_base;
/**
* Base class to render a course content.
*
* @package format_topics
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class content extends content_base {
/**
* @var bool Topic format has also add section after each topic.
*/
protected $hasaddsection = true;
/**
* Export this data so it can be used as the context for a mustache template (core/inplace_editable).
*
* @param renderer_base $output typically, the renderer that's calling this function
* @return stdClass data context for a mustache template
*/
public function export_for_template(renderer_base $output) {
global $PAGE;
$PAGE->requires->js_call_amd('format_topics/mutations', 'init');
$PAGE->requires->js_call_amd('format_topics/section', 'init');
return parent::export_for_template($output);
}
}
@@ -0,0 +1,57 @@
<?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/>.
/**
* Contains the default section controls output class.
*
* @package format_topics
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace format_topics\output\courseformat\content;
use core_courseformat\base as course_format;
use core_courseformat\output\local\content\section as section_base;
use stdClass;
/**
* Base class to render a course section.
*
* @package format_topics
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class section extends section_base {
/** @var course_format the course format */
protected $format;
public function export_for_template(\renderer_base $output): stdClass {
$format = $this->format;
$data = parent::export_for_template($output);
if (!$this->format->get_sectionnum()) {
$addsectionclass = $format->get_output_classname('content\\addsection');
$addsection = new $addsectionclass($format);
$data->numsections = $addsection->export_for_template($output);
$data->insertafter = true;
}
return $data;
}
}
@@ -0,0 +1,162 @@
<?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/>.
/**
* Contains the default section controls output class.
*
* @package format_topics
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace format_topics\output\courseformat\content\section;
use core_courseformat\output\local\content\section\controlmenu as controlmenu_base;
use moodle_url;
/**
* Base class to render a course section menu.
*
* @package format_topics
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class controlmenu extends controlmenu_base {
/** @var \core_courseformat\base the course format class */
protected $format;
/** @var \section_info the course section class */
protected $section;
/**
* Generate the edit control items of a section.
*
* This method must remain public until the final deprecation of section_edit_control_items.
*
* @return array of edit control items
*/
public function section_control_items() {
$format = $this->format;
$section = $this->section;
$coursecontext = $format->get_context();
$controls = [];
if ($section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) {
$controls['highlight'] = $this->get_highlight_control();
}
$parentcontrols = parent::section_control_items();
// If the edit key exists, we are going to insert our controls after it.
if (array_key_exists("edit", $parentcontrols)) {
$merged = [];
// We can't use splice because we are using associative arrays.
// Step through the array and merge the arrays.
foreach ($parentcontrols as $key => $action) {
$merged[$key] = $action;
if ($key == "edit") {
// If we have come to the edit key, merge these controls here.
$merged = array_merge($merged, $controls);
}
}
return $merged;
} else {
return array_merge($controls, $parentcontrols);
}
}
/**
* Return the course url.
*
* @return moodle_url
*/
protected function get_course_url(): moodle_url {
$format = $this->format;
$section = $this->section;
$course = $format->get_course();
$sectionreturn = $format->get_sectionnum();
if ($sectionreturn) {
$url = course_get_url($course, $section->section);
} else {
$url = course_get_url($course);
}
$url->param('sesskey', sesskey());
return $url;
}
/**
* Return the specific section highlight action.
*
* @return array the action element.
*/
protected function get_highlight_control(): array {
$format = $this->format;
$section = $this->section;
$course = $format->get_course();
$sectionreturn = $format->get_sectionnum();
$url = $this->get_course_url();
if (!is_null($sectionreturn)) {
$url->param('sectionid', $format->get_sectionid());
}
$highlightoff = get_string('highlightoff');
$highlightofficon = 'i/marked';
$highlighton = get_string('highlight');
$highlightonicon = 'i/marker';
if ($course->marker == $section->section) { // Show the "light globe" on/off.
$url->param('marker', 0);
$result = [
'url' => $url,
'icon' => $highlightofficon,
'name' => $highlightoff,
'pixattr' => ['class' => ''],
'attr' => [
'class' => 'editing_highlight',
'data-action' => 'sectionUnhighlight',
'data-sectionreturn' => $sectionreturn,
'data-id' => $section->id,
'data-icon' => $highlightofficon,
'data-swapname' => $highlighton,
'data-swapicon' => $highlightonicon,
],
];
} else {
$url->param('marker', $section->section);
$result = [
'url' => $url,
'icon' => $highlightonicon,
'name' => $highlighton,
'pixattr' => ['class' => ''],
'attr' => [
'class' => 'editing_highlight',
'data-action' => 'sectionHighlight',
'data-sectionreturn' => $sectionreturn,
'data-id' => $section->id,
'data-icon' => $highlightonicon,
'data-swapname' => $highlightoff,
'data-swapicon' => $highlightofficon,
],
];
}
return $result;
}
}
@@ -0,0 +1,66 @@
<?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/>.
namespace format_topics\output;
use core_courseformat\output\section_renderer;
use moodle_page;
/**
* Basic renderer for topics format.
*
* @copyright 2012 Dan Poltawski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends section_renderer {
/**
* Constructor method, calls the parent constructor.
*
* @param moodle_page $page
* @param string $target one of rendering target constants
*/
public function __construct(moodle_page $page, $target) {
parent::__construct($page, $target);
// Since format_topics_renderer::section_edit_control_items() only displays the 'Highlight' control
// when editing mode is on we need to be sure that the link 'Turn editing mode on' is available for a user
// who does not have any other managing capability.
$page->set_other_editing_capability('moodle/course:setcurrentsection');
}
/**
* Generate the section title, wraps it in a link to the section page if page is to be displayed on a separate page.
*
* @param section_info|stdClass $section The course_section entry from DB
* @param stdClass $course The course entry from DB
* @return string HTML to output.
*/
public function section_title($section, $course) {
return $this->render(course_get_format($course)->inplace_editable_render_section_name($section));
}
/**
* Generate the section title to be displayed on the section page, without a link.
*
* @param section_info|stdClass $section The course_section entry from DB
* @param int|stdClass $course The course entry from DB
* @return string HTML to output.
*/
public function section_title_without_link($section, $course) {
return $this->render(course_get_format($course)->inplace_editable_render_section_name($section, false));
}
}
@@ -0,0 +1,48 @@
<?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 Topics course format.
*
* @package format_topics
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace format_topics\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\metadata\null_provider;
/**
* Privacy Subsystem for Topics course format implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements 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';
}
}