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,101 @@
<?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 mod_feedback\output;
use context_module;
use renderable;
use renderer_base;
use templatable;
/**
* Class base_action_bar
*
* Base class to be inherited by any other feedback action bar
*
* @package mod_feedback
* @copyright 2021 onwards Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class base_action_bar implements renderable, templatable {
/** @var int $cmid The module id */
protected $cmid;
/** @var object $context The context we are in */
protected $context;
/** @var object $course The course we are in */
protected $course;
/** @var array $urlparams The default params to be used when creating urls */
protected $urlparams;
/** @var object $feedback The activity record that is being viewed */
protected $feedback;
/**
* base_action_bar constructor.
*
* @param int $cmid
*/
public function __construct(int $cmid) {
global $PAGE;
$this->cmid = $cmid;
$this->context = context_module::instance($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid);
$this->course = $course;
$this->urlparams = [
'id' => $cmid
];
$this->feedback = $PAGE->activityrecord;
}
/**
* Recursively iterates through to array of renderables and exports
*
* @param array $items Collection of renderables
* @param renderer_base $output
* @return array $items Data to be used in the mustache template
*/
private function export_items_for_template(array $items, renderer_base $output): array {
$items = array_map(function($item) use ($output) {
if (is_array($item)) {
return $this->export_items_for_template($item, $output);
}
if (is_object($item) && method_exists($item, 'export_for_template')) {
return $item->export_for_template($output);
}
return $item;
}, $items);
return $items;
}
/**
* Export the data so it can be used as the context for a mustache template.
*
* @param renderer_base $output
* @return array
*/
public function export_for_template(renderer_base $output): array {
$items = $this->export_items_for_template($this->get_items(), $output);
return $items;
}
/**
* Function to generate a list of renderables to be displayed
* @return array
*/
abstract protected function get_items(): array;
}
@@ -0,0 +1,100 @@
<?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 mod_feedback\output;
use moodle_url;
use action_link;
use single_select;
use url_select;
/**
* Class actionbar - Display the action bar
*
* @package mod_feedback
* @copyright 2021 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_action_bar extends base_action_bar {
/** @var moodle_url $currenturl The current page url */
private $currenturl;
/** @var int|null $lastposition The index of the last question type in the feedback module */
private $lastposition;
/**
* edit_action_bar constructor.
*
* @param int $cmid The course module id
* @param moodle_url $pageurl The current page url
* @param int|null $lastposition Index of the last question in the feedback
*/
public function __construct(int $cmid, moodle_url $pageurl, ?int $lastposition = null) {
parent::__construct($cmid);
$this->currenturl = $pageurl;
$this->lastposition = $lastposition;
}
/**
* Return the items to be used for the tertiary nav
*
* @return array
*/
public function get_items(): array {
global $DB;
$url = new moodle_url('/mod/feedback/view.php', ['id' => $this->cmid]);
$items['left'][]['actionlink'] = new action_link($url, get_string('back'), null, ['class' => 'btn btn-secondary']);
if (has_capability('mod/feedback:edititems', $this->context)) {
$editurl = new moodle_url('/mod/feedback/edit.php', $this->urlparams);
$templateurl = new moodle_url('/mod/feedback/manage_templates.php', $this->urlparams);
$importurl = new moodle_url('/mod/feedback/import.php', $this->urlparams);
$options = [
$editurl->out(false) => get_string('add_item', 'feedback'),
$templateurl->out(false) => get_string('using_templates', 'feedback'),
$importurl->out(false) => get_string('import_questions', 'feedback')
];
$selected = $this->currenturl;
// Template pages can have sub pages, so match these.
if ($this->currenturl->compare(new moodle_url('/mod/feedback/use_templ.php'), URL_MATCH_BASE)) {
$selected = $templateurl;
}
$items['left'][]['urlselect'] = new url_select($options, $selected->out(false), null);
$viewquestions = $editurl->compare($this->currenturl);
if ($viewquestions) {
$select = new single_select(new moodle_url('/mod/feedback/edit_item.php',
['cmid' => $this->cmid, 'position' => $this->lastposition, 'sesskey' => sesskey()]),
'typ', feedback_load_feedback_items_options());
$items['left'][]['singleselect'] = $select;
if ($DB->record_exists('feedback_item', ['feedback' => $this->feedback->id])) {
$items['export'] = new action_link(
new moodle_url('/mod/feedback/export.php', $this->urlparams + ['action' => 'exportfile']),
get_string('export_questions', 'feedback'),
null,
['class' => 'btn btn-secondary'],
);
}
}
}
return $items;
}
}
@@ -0,0 +1,86 @@
<?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 mod_feedback\output;
use confirm_action;
use context_system;
use moodle_url;
use action_link;
/**
* Class actionbar - Display the action bar
*
* @package mod_feedback
* @copyright 2021 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_template_action_bar extends base_action_bar {
/** @var int $templateid The template that is being edited/used */
private $templateid;
/** @var string $mode The type of view we are dealing with */
private $mode;
/**
* edit_template_action_bar constructor.
* @param int $cmid
* @param int $templateid
* @param string $mode
*/
public function __construct(int $cmid, int $templateid, string $mode) {
parent::__construct($cmid);
$this->templateid = $templateid;
$this->mode = $mode;
}
/**
* Return the items to be used in the tertiary nav
*
* @return array
*/
public function get_items(): array {
global $DB;
$additionalparams = ($this->mode ? ['mode' => $this->mode] : []);
$templateurl = new moodle_url('/mod/feedback/manage_templates.php', $this->urlparams + $additionalparams);
$items['left'][]['actionlink'] = new action_link($templateurl, get_string('back'), null, ['class' => 'btn btn-secondary']);
if (has_capability('mod/feedback:edititems', $this->context)) {
$items['usetemplate'] = $this->urlparams + [
'templateid' => $this->templateid
];
}
$template = $DB->get_record('feedback_template', array('id' => $this->templateid), '*', MUST_EXIST);
$systemcontext = context_system::instance();
$showdelete = has_capability('mod/feedback:deletetemplate', $this->context);
if ($template->ispublic) {
$showdelete = has_capability('mod/feedback:createpublictemplate', $systemcontext) &&
has_capability('mod/feedback:deletetemplate', $systemcontext);
}
if ($showdelete) {
$params = $this->urlparams + $additionalparams + [
'deletetemplate' => $this->templateid,
'sesskey' => sesskey()
];
$deleteurl = new moodle_url('/mod/feedback/manage_templates.php', $params);
$deleteaction = new confirm_action(get_string('confirmdeletetemplate', 'feedback'));
$items['export'] = new action_link($deleteurl, get_string('delete'), $deleteaction, ['class' => 'btn btn-secondary']);
}
return $items;
}
}
+50
View File
@@ -0,0 +1,50 @@
<?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 mod_feedback\output;
use plugin_renderer_base;
/**
* Class renderer
*
* @package mod_feedback
* @copyright 2021 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Generate the tertiary nav
*
* @param base_action_bar $actionmenu
* @return bool|string
*/
public function main_action_bar(base_action_bar $actionmenu) {
$context = $actionmenu->export_for_template($this);
return $this->render_from_template('mod_feedback/main_action_menu', $context);
}
/**
* Render the create template form
*
* @param int $id
* @return bool|string
*/
public function create_template_form(int $id) {
return $this->render_from_template('mod_feedback/create_template', ['id' => $id]);
}
}
@@ -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 mod_feedback\output;
use moodle_url;
use url_select;
/**
* Class responses_action_bar. The tertiary nav for the responses page
*
* @copyright 2021 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package mod_feedback
*/
class responses_action_bar extends base_action_bar {
/** @var moodle_url $currenturl The current page url */
private $currenturl;
/**
* responses_action_bar constructor.
*
* @param int $cmid The cmid for the module we are operating on
* @param moodle_url $pageurl The current page url
*/
public function __construct(int $cmid, moodle_url $pageurl) {
parent::__construct($cmid);
$this->currenturl = $pageurl;
$this->urlparams['courseid'] = $this->course->id;
}
/**
* Return the items to be used in the tertiary nav
*
* @return array
*/
public function get_items(): array {
$items = [];
if (has_capability('mod/feedback:viewreports', $this->context)) {
$reporturl = new moodle_url('/mod/feedback/show_entries.php', $this->urlparams);
$options[$reporturl->out(false)] = get_string('show_entries', 'feedback');
$selected = $this->currenturl->compare($reporturl, URL_MATCH_BASE) ? $reporturl : $this->currenturl;
if ($this->feedback->anonymous == FEEDBACK_ANONYMOUS_NO && $this->course->id != SITEID) {
$nonrespondenturl = new moodle_url('/mod/feedback/show_nonrespondents.php', $this->urlparams);
$options[$nonrespondenturl->out(false)] = get_string('show_nonrespondents', 'feedback');
$selected = $this->currenturl->compare($nonrespondenturl, URL_MATCH_BASE) ? $nonrespondenturl : $this->currenturl;;
}
// Don't show the dropdown if it's only a single item.
if (count($options) != 1) {
$items['left'][]['urlselect'] = new url_select($options,
$selected->out(false),
null);
}
}
return $items;
}
}
@@ -0,0 +1,100 @@
<?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 mod_feedback\output;
use action_link;
use moodle_url;
/**
* Class standard_action_bar
*
* The default tertiary nav on the module landing page
*
* @copyright 2021 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package mod_feedback
*/
class standard_action_bar extends base_action_bar {
/** @var int $startpage The page to resume with. */
private $startpage;
/** @var int $viewcompletion Whether or not the user can finish the feedback */
private $viewcompletion;
/**
* standard_action_bar constructor.
*
* @param int $cmid
* @param bool $viewcompletion Whether or not the user can finish the feedback
* @param int|null $startpage The page to resume with.
* @param int|null $courseid The course that the feedback is being accessed from. If null, courseid will be
* set via the $cmid relationship
*/
public function __construct(int $cmid, bool $viewcompletion, ?int $startpage = null, ?int $courseid = null) {
parent::__construct($cmid);
$this->startpage = $startpage;
$this->viewcompletion = $viewcompletion;
if ($courseid && $courseid != $this->course->id) {
$this->course = get_course($courseid);
}
$this->urlparams['courseid'] = $this->course->id;
}
/**
* Return the items to be used in the tertiary nav
*
* @return array
*/
public function get_items(): array {
$items = [];
if (has_capability('mod/feedback:edititems', $this->context)) {
$editurl = new moodle_url('/mod/feedback/edit.php', $this->urlparams);
$items['left'][]['actionlink'] = new action_link($editurl, get_string('edit_items', 'feedback'),
null, ['class' => 'btn btn-secondary']);
}
// The preview icon should be displayed only to users with capability to edit or view reports (to include
// non-editing teachers too).
$capabilities = [
'mod/feedback:edititems',
'mod/feedback:viewreports',
];
if (has_any_capability($capabilities, $this->context)) {
$previewlnk = new moodle_url('/mod/feedback/print.php', array('id' => $this->cmid));
if ($this->course->id) {
$previewlnk->param('courseid', $this->course->id);
}
$items['left'][]['actionlink'] = new action_link($previewlnk, get_string('previewquestions', 'feedback'),
null, ['class' => 'btn btn-secondary']);
}
if ($this->viewcompletion) {
// Display a link to complete feedback or resume.
$completeurl = new moodle_url('/mod/feedback/complete.php',
['id' => $this->cmid, 'courseid' => $this->course->id]);
if ($this->startpage) {
$completeurl->param('gopage', $this->startpage);
$label = get_string('continue_the_form', 'feedback');
} else {
$label = get_string('complete_the_form', 'feedback');
}
$items['left'][]['actionlink'] = new action_link($completeurl, $label, null, ['class' => 'btn btn-primary']);
}
return $items;
}
}
+73
View File
@@ -0,0 +1,73 @@
<?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 class mod_feedback\output\summary
*
* @package mod_feedback
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_feedback\output;
use renderable;
use templatable;
use renderer_base;
use stdClass;
use moodle_url;
use mod_feedback_structure;
/**
* Class to help display feedback summary
*
* @package mod_feedback
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class summary implements renderable, templatable {
/** @var mod_feedback_structure */
protected $feedbackstructure;
/** @var int */
protected $mygroupid;
/**
* Constructor.
*
* @param mod_feedback_structure $feedbackstructure
* @param int $mygroupid currently selected group
*/
public function __construct($feedbackstructure, $mygroupid = false) {
$this->feedbackstructure = $feedbackstructure;
$this->mygroupid = $mygroupid;
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
$r = new stdClass();
$r->completedcount = $this->feedbackstructure->count_completed_responses($this->mygroupid);
$r->itemscount = count($this->feedbackstructure->get_items(true));
return $r;
}
}