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,157 @@
<?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 core_course\output;
use cm_info;
use core_availability\info;
use core_completion\cm_completion_details;
use core_user;
use core_user\fields;
use renderable;
use renderer_base;
use stdClass;
use templatable;
/**
* The activity completion renderable class.
*
* @package core_course
* @copyright 2023 Mikel Martín <mikel@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity_completion implements renderable, templatable {
/**
* Constructor.
*
* @param cm_info $cminfo The course module information.
* @param cm_completion_details $cmcompletion The course module information.
*/
public function __construct(
protected cm_info $cminfo,
protected cm_completion_details $cmcompletion
) {
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output Renderer base.
* @return stdClass
*/
public function export_for_template(renderer_base $output): stdClass {
global $CFG;
$overallcompletion = $this->cmcompletion->get_overall_completion();
$isoverallcomplete = $this->cmcompletion->is_overall_complete();
$overrideby = $this->get_overrideby();
$course = $this->cminfo->get_course();
// Whether the completion of this activity controls the availability of other activities/sections in the course.
// An activity with manual completion tracking which is used to enable access to other activities/sections in
// the course needs to refresh the page after having its completion state toggled. This withavailability flag will enable
// this functionality on the course homepage. Otherwise, the completion toggling will just happen normally via ajax.
if ($this->cmcompletion->has_completion() && $this->cmcompletion->is_manual()) {
$withavailability = !empty($CFG->enableavailability) && info::completion_value_used($course, $this->cminfo->id);
}
return (object) [
'cmid' => $this->cminfo->id,
'activityname' => $this->cminfo->get_formatted_name(),
'uservisible' => $this->cminfo->uservisible,
'hascompletion' => $this->cmcompletion->has_completion(),
'isautomatic' => $this->cmcompletion->is_automatic(),
'ismanual' => $this->cmcompletion->is_manual(),
'showmanualcompletion' => $this->cmcompletion->show_manual_completion(),
'istrackeduser' => $this->cmcompletion->is_tracked_user(),
'overallcomplete' => $isoverallcomplete,
'overallincomplete' => !$isoverallcomplete,
'withavailability' => $withavailability ?? false,
'overrideby' => $overrideby,
'completiondetails' => $this->get_completion_details($overrideby),
'accessibledescription' => $this->get_accessible_description($overrideby, $overallcompletion),
];
}
/**
* Returns the name of the user overriding the completion condition, if available.
*
* @return string
*/
private function get_overrideby(): string {
$overrideby = $this->cmcompletion->overridden_by();
if (!empty($overrideby)) {
$userfields = fields::for_name();
$overridebyrecord = core_user::get_user($overrideby, 'id ' . $userfields->get_sql()->selects, MUST_EXIST);
return fullname($overridebyrecord);
}
return '';
}
/**
* Returns automatic completion details
*
* @param string $overrideby The name of the user overriding the completion condition, if available.
* @return array
*/
private function get_completion_details($overrideby): array {
$details = [];
foreach ($this->cmcompletion->get_details() as $key => $detail) {
$detail->key = $key;
$detail->statuscomplete = in_array($detail->status, [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS]);
$detail->statuscompletefail = $detail->status == COMPLETION_COMPLETE_FAIL;
// This is not used by core themes but may be needed in custom themes.
$detail->statuscompletepass = $detail->status == COMPLETION_COMPLETE_PASS;
$detail->statusincomplete = $detail->status == COMPLETION_INCOMPLETE;
// Add an accessible description to be used for title and aria-label attributes for overridden completion details.
if ($overrideby) {
$setbydata = (object)[
'condition' => $detail->description,
'setby' => $overrideby,
];
$overridestatus = $detail->statuscomplete ? 'done' : 'todo';
$detail->accessibledescription = get_string('completion_setby:auto:' . $overridestatus, 'course', $setbydata);
}
unset($detail->status);
$details[] = $detail;
}
return $details;
}
/**
* Returns the accessible description for manual completions with overridden completion state.
*
* @param string $overrideby The name of the user overriding the completion condition, if available.
* @param int $overallcompletion The overall completion state of the activity.
* @return string
*/
private function get_accessible_description($overrideby, $overallcompletion): string {
if ($this->cmcompletion->is_manual() && $overrideby) {
$setbydata = (object)[
'activityname' => $this->cminfo->get_formatted_name(),
'setby' => $overrideby,
];
$isoverallcompleted = $overallcompletion == COMPLETION_COMPLETE;
$setbylangkey = $isoverallcompleted ? 'completion_setby:manual:done' : 'completion_setby:manual:markdone';
return get_string($setbylangkey, 'course', $setbydata);
}
return '';
}
}
+72
View File
@@ -0,0 +1,72 @@
<?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 core_course\output;
use renderable;
use renderer_base;
use stdClass;
use templatable;
/**
* The activity dates renderable class.
*
* @package core_course
* @copyright 2023 Mikel Martín <mikel@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity_dates implements renderable, templatable {
/**
* Constructor.
*
* @param array $activitydates The activity dates.
*/
public function __construct(
protected array $activitydates
) {
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output Renderer base.
* @return stdClass
*/
public function export_for_template(renderer_base $output): stdClass {
$activitydates = [];
foreach ($this->activitydates as $date) {
if (empty($date['relativeto'])) {
$date['datestring'] = userdate($date['timestamp'], get_string('strftimedaydatetime', 'core_langconfig'));
} else {
$diffstr = get_time_interval_string($date['timestamp'], $date['relativeto']);
if ($date['timestamp'] >= $date['relativeto']) {
$date['datestring'] = get_string('relativedatessubmissionduedateafter', 'core_course',
['datediffstr' => $diffstr]);
} else {
$date['datestring'] = get_string('relativedatessubmissionduedatebefore', 'core_course',
['datediffstr' => $diffstr]);
}
}
$activitydates[] = $date;
}
return (object) [
'hasdates' => !empty($this->activitydates),
'activitydates' => $activitydates,
];
}
}
@@ -0,0 +1,209 @@
<?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/>.
/**
* File containing the class activity information renderable.
*
* @package core_course
* @copyright 2021 Jun Pataleta <jun@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\output;
defined('MOODLE_INTERNAL') || die();
use cm_info;
use completion_info;
use context;
use core\activity_dates;
use core_availability\info;
use core_completion\cm_completion_details;
use core_user;
use core_user\fields;
use renderable;
use renderer_base;
use stdClass;
use templatable;
/**
* The activity information renderable class.
*
* @deprecated since Moodle 4.3 MDL-78744
* @todo MDL-78926 This class will be deleted in Moodle 4.7
*
* @package core_course
* @copyright 2021 Jun Pataleta <jun@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity_information implements renderable, templatable {
/** @var cm_info The course module information. */
protected $cminfo = null;
/** @var array The array of relevant dates for this activity. */
protected $activitydates = [];
/** @var cm_completion_details The user's completion details for this activity. */
protected $cmcompletion = null;
/**
* Constructor.
*
* @deprecated since Moodle 4.3
*
* @param cm_info $cminfo The course module information.
* @param cm_completion_details $cmcompletion The course module information.
* @param array $activitydates The activity dates.
*/
public function __construct(cm_info $cminfo, cm_completion_details $cmcompletion, array $activitydates) {
debugging('activity_information class is deprecated. Use activity_completion and activity_dates instead.', DEBUG_DEVELOPER);
$this->cminfo = $cminfo;
$this->cmcompletion = $cmcompletion;
$this->activitydates = $activitydates;
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @deprecated since Moodle 4.3
*
* @param renderer_base $output Renderer base.
* @return stdClass
*/
public function export_for_template(renderer_base $output): stdClass {
debugging('activity_information class is deprecated. Use activity_completion and activity_dates instead.', DEBUG_DEVELOPER);
$data = $this->build_completion_data();
$data->cmid = $this->cminfo->id;
$data->activityname = $this->cminfo->get_formatted_name();
$this->build_dates_data($data);
$data->hasdates = !empty($this->activitydates);
return $data;
}
/**
* Builds the dates data for export.
*
* @param stdClass $data
*/
protected function build_dates_data(stdClass $data): void {
foreach ($this->activitydates as $date) {
if (empty($date['relativeto'])) {
$date['datestring'] = userdate($date['timestamp'], get_string('strftimedaydatetime', 'core_langconfig'));
} else {
$diffstr = get_time_interval_string($date['timestamp'], $date['relativeto']);
if ($date['timestamp'] >= $date['relativeto']) {
$date['datestring'] = get_string('relativedatessubmissionduedateafter', 'core_course',
['datediffstr' => $diffstr]);
} else {
$date['datestring'] = get_string('relativedatessubmissionduedatebefore', 'core_course',
['datediffstr' => $diffstr]);
}
}
$data->activitydates[] = $date;
}
}
/**
* Builds the completion data for export.
*
* @return stdClass
*/
protected function build_completion_data(): stdClass {
global $CFG;
$data = new stdClass();
$data->hascompletion = $this->cmcompletion->has_completion();
$data->isautomatic = $this->cmcompletion->is_automatic();
$data->ismanual = $this->cmcompletion->is_manual();
$data->showmanualcompletion = $this->cmcompletion->show_manual_completion();
// Get the name of the user overriding the completion condition, if available.
$data->overrideby = null;
$overrideby = $this->cmcompletion->overridden_by();
$overridebyname = null;
if (!empty($overrideby)) {
$userfields = fields::for_name();
$overridebyrecord = core_user::get_user($overrideby, 'id ' . $userfields->get_sql()->selects, MUST_EXIST);
$data->overrideby = fullname($overridebyrecord);
}
// We'll show only the completion conditions and not the completion status if we're not tracking completion for this user
// (e.g. a teacher, admin).
$data->istrackeduser = $this->cmcompletion->is_tracked_user();
// Overall completion states.
$overallcompletion = $this->cmcompletion->get_overall_completion();
$data->overallcomplete = $overallcompletion == COMPLETION_COMPLETE;
$data->overallincomplete = $overallcompletion == COMPLETION_INCOMPLETE;
// Set an accessible description for manual completions with overridden completion state.
if (!$data->isautomatic && $data->overrideby) {
$setbydata = (object)[
'activityname' => $this->cminfo->get_formatted_name(),
'setby' => $data->overrideby,
];
$setbylangkey = $data->overallcomplete ? 'completion_setby:manual:done' : 'completion_setby:manual:markdone';
$data->accessibledescription = get_string($setbylangkey, 'course', $setbydata);
}
// Whether the completion of this activity controls the availability of other activities/sections in the course.
$data->withavailability = false;
$course = $this->cminfo->get_course();
// An activity with manual completion tracking which is used to enable access to other activities/sections in
// the course needs to refresh the page after having its completion state toggled. This withavailability flag will enable
// this functionality on the course homepage. Otherwise, the completion toggling will just happen normally via ajax.
if ($this->cmcompletion->has_completion() && !$this->cmcompletion->is_automatic()) {
$data->withavailability = !empty($CFG->enableavailability) && info::completion_value_used($course, $this->cminfo->id);
}
// Whether this activity is visible to the user. If not, completion information will not be shown.
$data->uservisible = $this->cminfo->uservisible;
// Build automatic completion details.
$details = [];
foreach ($this->cmcompletion->get_details() as $key => $detail) {
// Set additional attributes for the template.
$detail->key = $key;
$detail->statuscomplete = in_array($detail->status, [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS]);
$detail->statuscompletefail = $detail->status == COMPLETION_COMPLETE_FAIL;
// This is not used by core themes but may be needed in custom themes.
$detail->statuscompletepass = $detail->status == COMPLETION_COMPLETE_PASS;
$detail->statusincomplete = $detail->status == COMPLETION_INCOMPLETE;
// Add an accessible description to be used for title and aria-label attributes for overridden completion details.
if ($data->overrideby) {
$setbydata = (object)[
'condition' => $detail->description,
'setby' => $data->overrideby,
];
$overridestatus = $detail->statuscomplete ? 'done' : 'todo';
$detail->accessibledescription = get_string('completion_setby:auto:' . $overridestatus, 'course', $setbydata);
}
// We don't need the status in the template.
unset($detail->status);
$details[] = $detail;
}
$data->completiondetails = $details;
return $data;
}
}
@@ -0,0 +1,127 @@
<?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/>.
/**
* File containing the class activity navigation renderable.
*
* @package core_course
* @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use url_select;
/**
* The class activity navigation renderable.
*
* @package core_course
* @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity_navigation implements renderable, templatable {
/**
* @var \action_link The action link object for the prev link.
*/
public $prevlink = null;
/**
* @var \action_link The action link object for the next link.
*/
public $nextlink = null;
/**
* @var url_select The url select object for the activity selector menu.
*/
public $activitylist = null;
/**
* Constructor.
*
* @param \cm_info|null $prevmod The previous module to display, null if none.
* @param \cm_info|null $nextmod The next module to display, null if none.
* @param array $activitylist The list of activity URLs (as key) and names (as value) for the activity dropdown menu.
*/
public function __construct($prevmod, $nextmod, $activitylist = array()) {
global $OUTPUT;
// Check if there is a previous module to display.
if ($prevmod) {
$linkurl = new \moodle_url($prevmod->url, array('forceview' => 1));
$linkname = $prevmod->get_formatted_name();
if (!$prevmod->visible) {
$linkname .= ' ' . get_string('hiddenwithbrackets');
}
$attributes = [
'class' => 'btn btn-link',
'id' => 'prev-activity-link',
];
$this->prevlink = new \action_link($linkurl, $OUTPUT->larrow() . ' ' . $linkname, null, $attributes);
}
// Check if there is a next module to display.
if ($nextmod) {
$linkurl = new \moodle_url($nextmod->url, array('forceview' => 1));
$linkname = $nextmod->get_formatted_name();
if (!$nextmod->visible) {
$linkname .= ' ' . get_string('hiddenwithbrackets');
}
$attributes = [
'class' => 'btn btn-link',
'id' => 'next-activity-link',
];
$this->nextlink = new \action_link($linkurl, $linkname . ' ' . $OUTPUT->rarrow(), null, $attributes);
}
// Render the activity list dropdown menu if available.
if (!empty($activitylist)) {
$select = new url_select($activitylist, '', array('' => get_string('jumpto')));
$select->set_label(get_string('jumpto'), array('class' => 'sr-only'));
$select->attributes = array('id' => 'jump-to-activity');
$this->activitylist = $select;
}
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param \renderer_base $output Renderer base.
* @return \stdClass
*/
public function export_for_template(\renderer_base $output) {
$data = new \stdClass();
if ($this->prevlink) {
$data->prevlink = $this->prevlink->export_for_template($output);
}
if ($this->nextlink) {
$data->nextlink = $this->nextlink->export_for_template($output);
}
if ($this->activitylist) {
$data->activitylist = $this->activitylist->export_for_template($output);
}
return $data;
}
}
@@ -0,0 +1,154 @@
<?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/>.
use core_completion\manager;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/course/renderer.php');
/**
* Main renderer for the bulk activity completion stuff.
*
* @package core_course
* @copyright 2017 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_course_bulk_activity_completion_renderer extends plugin_renderer_base {
/**
* @deprecated since Moodle 4.0
*/
public function navigation() {
throw new coding_exception(__FUNCTION__ . '() has been removed.');
}
/**
* Render the bulk completion tab.
*
* @param Array|stdClass $data the context data to pass to the template.
* @return bool|string
*/
public function bulkcompletion($data) {
return parent::render_from_template('core_course/bulkactivitycompletion', $data);
}
/**
* Render the default completion tab.
*
* @param array|stdClass $data the context data to pass to the template.
* @param array $modules The modules that have been sent through the form.
* @param moodleform $form The current form that has been sent.
* @return bool|string
*/
public function defaultcompletion($data, $modules, $form) {
$course = get_course($data->courseid);
foreach ($data->modules as $module) {
// If the user can manage this module, then the activity completion form needs to be returned too, without the
// cancel button (so only "Save changes" button is displayed).
if ($module->canmanage) {
// Only create the form if it's different from the one that has been sent.
$modform = $form;
if (empty($form) || !in_array($module->id, array_keys($modules))) {
$modform = new \core_completion_defaultedit_form(
null,
[
'course' => $course,
'modules' => [
$module->id => $module,
],
'displaycancel' => false,
'forceuniqueid' => true,
],
);
$module->modulecollapsed = true;
}
$moduleform = manager::get_module_form($module->name, $course);
if ($moduleform) {
$module->formhtml = $modform->render();
} else {
// If the module form is not available, then display a message.
$module->formhtml = $this->output->notification(
get_string('incompatibleplugin', 'completion'),
\core\output\notification::NOTIFY_INFO,
false
);
}
}
}
$data->issite = $course->id == SITEID;
return parent::render_from_template('core_course/defaultactivitycompletion', $data);
}
/**
* Renders the form for bulk editing activities completion
*
* @param moodleform $form
* @param array $activities
* @return string
*/
public function edit_bulk_completion($form, $activities) {
ob_start();
$form->display();
$formhtml = ob_get_contents();
ob_end_clean();
$data = (object)[
'form' => $formhtml,
'activities' => array_values($activities),
'activitiescount' => count($activities),
];
return parent::render_from_template('core_course/editbulkactivitycompletion', $data);
}
/**
* Renders the form for editing default completion
*
* @param moodleform $form
* @param array $modules
* @return string
* @deprecated since Moodle 4.3 MDL-78528
* @todo MDL-78711 This will be deleted in Moodle 4.7
*/
public function edit_default_completion($form, $modules) {
debugging('edit_default_completion() is deprecated and will be removed.', DEBUG_DEVELOPER);
ob_start();
$form->display();
$formhtml = ob_get_contents();
ob_end_clean();
$data = (object)[
'form' => $formhtml,
'modules' => array_values($modules),
'modulescount' => count($modules),
];
return parent::render_from_template('core_course/editdefaultcompletion', $data);
}
/**
* Renders the course completion action bar.
*
* @param \core_course\output\completion_action_bar $actionbar
* @return string The HTML output
*/
public function render_course_completion_action_bar(\core_course\output\completion_action_bar $actionbar): string {
$data = $actionbar->export_for_template($this->output);
return $this->output->render_from_template('core_course/completion_action_bar', $data);
}
}
@@ -0,0 +1,171 @@
<?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 core_course\output;
use context_coursecat;
use core_course_category;
use course_request;
use moodle_page;
use moodle_url;
/**
* Class responsible for generating the action bar (tertiary nav) elements in an individual category page
*
* @package core
* @copyright 2021 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class category_action_bar extends manage_categories_action_bar {
/**
* @var object The current category we are referring to.
*/
protected $category;
/**
* Constructor category_action_bar
*
* @param moodle_page $page The page object
* @param object $category
* @param object|null $course The course that we are generating the nav for
* @param string|null $searchvalue
*/
public function __construct(moodle_page $page, object $category, ?object $course = null, ?string $searchvalue = null) {
$this->category = $category;
parent::__construct($page, 'courses', $course, $searchvalue);
}
/**
* Gets the url_select to be displayed in the participants page if available.
*
* @param \renderer_base $output
* @return object|null The content required to render the url_select
*/
protected function get_category_select(\renderer_base $output): ?object {
if (!$this->searchvalue && !core_course_category::is_simple_site()) {
$categories = core_course_category::make_categories_list();
if (count($categories) > 1) {
foreach ($categories as $id => $cat) {
$url = new moodle_url($this->page->url, ['categoryid' => $id]);
$options[$url->out()] = $cat;
}
$currenturl = new moodle_url($this->page->url, ['categoryid' => $this->category->id]);
$select = new \url_select($options, $currenturl, null);
$select->set_label(get_string('categories'), ['class' => 'sr-only']);
$select->class .= ' text-truncate w-100';
return $select->export_for_template($output);
}
}
return null;
}
/**
* Gets the additional options to be displayed within a 'More' dropdown in the tertiary navigation.
* The predefined order defined by UX is:
* - Add a course
* - Add a sub cat
* - Manage course
* - Request a course
* - Course pending approval
*
* @return array
*/
protected function get_additional_category_options(): array {
global $CFG, $DB;
if ($this->category->is_uservisible()) {
$context = get_category_or_system_context($this->category->id);
if (has_capability('moodle/course:create', $context)) {
$params = [
'category' => $this->category->id ?: $CFG->defaultrequestcategory,
'returnto' => $this->category->id ? 'category' : 'topcat'
];
$options[0] = [
'url' => new moodle_url('/course/edit.php', $params),
'string' => get_string('addnewcourse')
];
}
if (!empty($CFG->enablecourserequests)) {
// Display an option to request a new course.
if (course_request::can_request($context)) {
$params = [];
if ($context instanceof context_coursecat) {
$params['category'] = $context->instanceid;
}
$options[3] = [
'url' => new moodle_url('/course/request.php', $params),
'string' => get_string('requestcourse')
];
}
// Display the manage pending requests option.
if (has_capability('moodle/site:approvecourse', $context)) {
$disabled = !$DB->record_exists('course_request', array());
if (!$disabled) {
$options[4] = [
'url' => new moodle_url('/course/pending.php'),
'string' => get_string('coursespending')
];
}
}
}
}
if ($this->category->can_create_course() || $this->category->has_manage_capability()) {
// Add 'Manage' button if user has permissions to edit this category.
$options[2] = [
'url' => new moodle_url('/course/management.php', ['categoryid' => $this->category->id]),
'string' => get_string('managecourses')
];
if ($this->category->has_manage_capability()) {
$addsubcaturl = new moodle_url('/course/editcategory.php', array('parent' => $this->category->id));
$options[1] = [
'url' => $addsubcaturl,
'string' => get_string('addsubcategory')
];
}
}
// We have stored the options in a predefined order. Sort it based on index and return.
if (isset($options)) {
sort($options);
return ['options' => $options];
}
return [];
}
/**
* Export the content to be displayed on the category page.
*
* @param \renderer_base $output
* @return array Consists of the following:
* - categoryselect A list of available categories to be fed into a urlselect
* - search The course search form
* - additionaloptions Additional actions that can be performed in a category
*/
public function export_for_template(\renderer_base $output): array {
return [
'categoryselect' => $this->get_category_select($output),
'search' => $this->get_search_form(),
'additionaloptions' => $this->get_additional_category_options()
];
}
}
@@ -0,0 +1,75 @@
<?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 core_course\output;
use core\output\select_menu;
use core_completion\manager;
use moodle_url;
use renderable;
use renderer_base;
use templatable;
use url_select;
/**
* Renderable class for the action bar elements in the course completion pages.
*
* @package core_course
* @copyright 2022 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_action_bar implements templatable, renderable {
/** @var int $courseid The course id. */
private $courseid;
/** @var moodle_url $currenturl The URL of the current page. */
private $currenturl;
/**
* The class constructor.
*
* @param int $courseid The course id.
* @param moodle_url $pageurl The URL of the current page.
*/
public function __construct(int $courseid, moodle_url $pageurl) {
$this->courseid = $courseid;
$this->currenturl = $pageurl;
}
/**
* Export the data for the mustache template.
*
* @param renderer_base $output renderer to be used to render the action bar elements.
* @return array The array which contains the data required to output the tertiary navigation selector for the course
* completion pages.
*/
public function export_for_template(renderer_base $output): array {
$selectmenu = new select_menu(
'coursecompletionnavigation',
manager::get_available_completion_options($this->courseid),
$this->currenturl->out(false)
);
$selectmenu->set_label(
get_string('coursecompletionnavigation', 'completion'),
['class' => 'sr-only']
);
return [
'navigation' => $selectmenu->export_for_template($output),
];
}
}
@@ -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/>.
/**
* Prepares content for buttons/links to course content export/download.
*
* @package core_course
* @copyright 2020 Michael Hawkins <michaelh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\output;
/**
* Prepares content for buttons/links to course content export/download.
*
* @package core_course
* @copyright 2020 Michael Hawkins <michaelh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class content_export_link {
/**
* Prepare and return the various attributes required for a link/button to populate/trigger the download course content modal.
*
* @param \context $context The context of the content being exported.
* @return \stdClass
*/
public static function get_attributes(\context $context): \stdClass {
global $CFG;
$downloadattr = new \stdClass();
$downloadattr->url = new \moodle_url('/course/downloadcontent.php', ['contextid' => $context->id]);
$downloadattr->displaystring = get_string('downloadcoursecontent', 'course');
$maxfilesize = display_size($CFG->maxsizeperdownloadcoursefile);
$downloadlink = new \moodle_url('/course/downloadcontent.php', ['contextid' => $context->id, 'download' => 1]);
$downloadattr->elementattributes = [
'data-downloadcourse' => 1,
'data-download-body' => get_string('downloadcourseconfirmation', 'course', $maxfilesize),
'data-download-button-text' => get_string('download'),
'data-download-link' => $downloadlink->out(false),
'data-download-title' => get_string('downloadcoursecontent', 'course'),
'data-overrides-tree-activation-key-handler' => 1,
];
return $downloadattr;
}
}
@@ -0,0 +1,164 @@
<?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 core_course\output;
use moodle_page;
use moodle_url;
/**
* Class responsible for generating the action bar (tertiary nav) elements in the category management page
*
* @package core
* @copyright 2021 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manage_categories_action_bar implements \renderable {
/** @var object $course The course we are dealing with. */
protected $course;
/** @var moodle_page $page The current page. */
protected $page;
/** @var string|null $viewmode The viewmode of the underlying page - Course and categories, categories or courses */
protected $viewmode;
/** @var string|null $heading The heading to display */
protected $heading;
/** @var string|null $searchvalue The search value if any */
protected $searchvalue;
/**
* Constructor for the manage_categories_action_bar
*
* @param moodle_page $page The page object
* @param string $viewmode The type of page we are viewing.
* @param object|null $course The course that we are generating the nav for
* @param string|null $searchvalue The search value if applicable
*/
public function __construct(moodle_page $page, string $viewmode, ?object $course, ?string $searchvalue) {
$this->course = $course;
$this->page = $page;
$this->viewmode = $viewmode;
$this->searchvalue = $searchvalue;
if ($searchvalue) {
$this->heading = get_string('searchresults');
}
}
/**
* Gets the url_select to be displayed in the participants page if available.
*
* @param \renderer_base $output
* @return object|null The content required to render the url_select
*/
protected function get_dropdown(\renderer_base $output): ?object {
// If a search is being performed then no need to display the dropdown.
if ($this->searchvalue) {
return null;
}
$modes = \core_course\management\helper::get_management_viewmodes();
$activeurl = null;
$content = [];
foreach ($modes as $mode => $description) {
$url = new moodle_url($this->page->url, ['view' => $mode]);
$content[$url->out()] = $description;
if ($this->viewmode == $mode) {
$activeurl = $url->out();
$this->heading = get_string("manage$mode");
}
}
// Default to the first option if asking for default. This is combined.
if (!$activeurl && $this->viewmode === 'default') {
$activeurl = array_key_first($content);
$this->heading = get_string("managecombined");
}
if ($content) {
$urlselect = new \url_select($content, $activeurl, null);
$urlselect->set_label(get_string('viewing'), ['class' => 'sr-only']);
return $urlselect->export_for_template($output);
}
return null;
}
/**
* Gets the url_select to be displayed in the participants page if available.
*
* @param \renderer_base $output
* @return object|null The content required to render the url_select
*/
protected function get_category_select(\renderer_base $output): ?object {
if (!$this->searchvalue && $this->viewmode === 'courses') {
$categories = \core_course_category::make_categories_list(array('moodle/category:manage', 'moodle/course:create'));
if (!$categories) {
return null;
}
$currentcat = $this->page->url->param('categoryid');
foreach ($categories as $id => $cat) {
$url = new moodle_url($this->page->url, ['categoryid' => $id]);
if ($id == $currentcat) {
$currenturl = $url->out();
}
$options[$url->out()] = $cat;
}
$select = new \url_select($options, $currenturl);
$select->set_label(get_string('category'), ['class' => 'sr-only']);
$select->class .= ' text-truncate w-100';
return $select->export_for_template($output);
}
return null;
}
/**
* Get the search box
*
* @return array
*/
protected function get_search_form(): array {
$searchform = [
'btnclass' => 'btn-primary',
'inputname' => 'search',
'searchstring' => get_string('searchcourses'),
'query' => $this->searchvalue
];
if (\core_course_category::has_capability_on_any(['moodle/category:manage', 'moodle/course:create'])) {
$searchform['action'] = new moodle_url('/course/management.php');
} else {
$searchform['action'] = new moodle_url('/course/search.php');
}
return $searchform;
}
/**
* Export the content to be displayed on the participants page.
*
* @param \renderer_base $output
* @return array Consists of the following:
* - urlselect A stdclass representing the standard navigation options to be fed into a urlselect
* - renderedcontent Rendered content to be displayed in line with the tertiary nav
*/
public function export_for_template(\renderer_base $output): array {
return [
'urlselect' => $this->get_dropdown($output),
'categoryselect' => $this->get_category_select($output),
'search' => $this->get_search_form(),
'heading' => $this->heading,
];
}
}
@@ -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/>.
/**
* Contains activity_list renderable used for the recommended activities page.
*
* @package core_course
* @copyright 2020 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\output\recommendations;
/**
* Activity list renderable.
*
* @package core_course
* @copyright 2020 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity_list implements \renderable, \templatable {
/** @var array $modules activities to display in the recommendations page. */
protected $modules;
/** @var string $searchquery The search query. */
protected $searchquery;
/**
* Constructor method.
*
* @param array $modules Activities to display
* @param string $searchquery The search query if present
*/
public function __construct(array $modules, string $searchquery) {
$this->modules = $modules;
$this->searchquery = $searchquery;
}
/**
* Export method to configure information into something the template can use.
*
* @param \renderer_base $output Not actually used.
* @return array Template context information.
*/
public function export_for_template(\renderer_base $output): array {
$info = array_map(function($module) {
return [
'id' => $module->id ?? '',
'name' => $module->title,
'componentname' => $module->componentname,
'icon' => $module->icon,
'recommended' => $module->recommended ?? ''
];
}, $this->modules);
return [
'categories' => [
[
'categoryname' => get_string('activities'),
'hascategorydata' => !empty($info),
'categorydata' => $info
]
],
'search' => [
'query' => $this->searchquery,
'searchresultsnumber' => count($this->modules)
]
];
}
}
@@ -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/>.
/**
* Contains renderers for the recommendations page.
*
* @package core_course
* @copyright 2020 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\output\recommendations;
/**
* Main renderer for the recommendations page.
*
* @package core_course
* @copyright 2020 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends \plugin_renderer_base {
/**
* Render a list of activities to recommend.
*
* @param \core_course\output\recommendations\activity_list $page activity list renderable
* @return string html for displaying.
*/
public function render_activity_list(\core_course\output\recommendations\activity_list $page): string {
$data = $page->export_for_template($this);
return parent::render_from_template('core_course/activity_list', $data);
}
}