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,77 @@
<?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_lti\output;
use core_reportbuilder\system_report_factory;
use mod_lti\reportbuilder\local\systemreports\course_external_tools_list;
/**
* The course tools page renderable, containing a page header renderable and a course tools system report.
*
* @package mod_lti
* @copyright 2023 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_tools_page implements \renderable {
/** @var course_external_tools_list the course tools system report instance. */
protected course_external_tools_list $coursetoolsreport;
/** @var course_tools_page_header the page header renderable instance. */
protected course_tools_page_header $coursetoolspageheader;
/**
* Renderable constructor.
*
* @param int $courseid the id of the course.
*/
public function __construct(int $courseid) {
global $DB;
$context = \context_course::instance($courseid);
// Page intro, zero state and 'add new' button.
$canadd = has_capability('mod/lti:addcoursetool', $context);
$sql = 'SELECT COUNT(1)
FROM {lti_types} tt
WHERE tt.course IN(:siteid, :courseid)
AND tt.coursevisible NOT IN(:coursevisible)';
$toolcount = $DB->count_records_sql($sql, ['siteid' => get_site()->id, 'courseid' => $courseid, 'coursevisible' => 0]);
$this->coursetoolspageheader = new course_tools_page_header($courseid, $toolcount, $canadd);
// Course tools report itself.
$this->coursetoolsreport = system_report_factory::create(course_external_tools_list::class, $context);
}
/**
* Get the course tools page header renderable.
*
* @return course_tools_page_header the renderable.
*/
public function get_header(): course_tools_page_header {
return $this->coursetoolspageheader;
}
/**
* Get the course tools list system report.
*
* @return course_external_tools_list the course tools list report.
*/
public function get_table(): course_external_tools_list {
return $this->coursetoolsreport;
}
}
@@ -0,0 +1,62 @@
<?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_lti\output;
use core\output\notification;
use renderer_base;
/**
* Course tools page header renderable, containing the data for the page zero state and 'add tool' button.
*
* @package mod_lti
* @copyright 2023 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_tools_page_header implements \templatable {
/**
* Constructor.
*
* @param int $courseid the course id.
* @param int $toolcount the number of tools available in the course.
* @param bool $canadd whether the user can add tools to the course or not.
*/
public function __construct(protected int $courseid, protected int $toolcount, protected bool $canadd) {
}
/**
* Export the header's data for template use.
*
* @param renderer_base $output
* @return object the data.
*/
public function export_for_template(renderer_base $output): \stdClass {
$context = (object) [];
if ($this->canadd) {
$context->addlink = (new \moodle_url('/mod/lti/coursetooledit.php', ['course' => $this->courseid]))->out();
}
if ($this->toolcount == 0) {
$notification = new notification(get_string('nocourseexternaltoolsnotice', 'mod_lti'), notification::NOTIFY_INFO, true);
$context->notoolsnotice = $notification->export_for_template($output);
}
return $context;
}
}
@@ -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/>.
/**
* Class containing data for external registration return page.
*
* @package mod_lti
* @copyright 2015 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lti\output;
require_once($CFG->dirroot.'/mod/lti/locallib.php');
use renderable;
use templatable;
use renderer_base;
use stdClass;
/**
* Class containing data for tool_configure page
*
* @copyright 2015 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class external_registration_return_page implements renderable, templatable {
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output The renderer
* @return stdClass Data to be used by the template
*/
public function export_for_template(renderer_base $output) {
return new stdClass();
}
}
@@ -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/>.
/**
* Class containing data for rendering LTI upgrade choices page.
*
* @copyright 2021 Cengage
* @package mod_lti
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lti\output;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/mod/lti/locallib.php');
use renderable;
use templatable;
use renderer_base;
use stdClass;
/**
* Class containing data for rendering LTI upgrade choices page.
*
* @copyright 2021 Cengage
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class registration_upgrade_choice_page implements renderable, templatable {
/** @var array array of tools. */
protected array $tools = [];
/** @var string tool URL. */
protected string $startregurl;
/**
* Constructor
*
* @param array $tools array of tools that can be upgraded
* @param string $startregurl tool URL to start the registration process
*/
public function __construct(array $tools, string $startregurl) {
$this->tools = $tools;
$this->startregurl = $startregurl;
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output The renderer
* @return stdClass Data to be used by the template
*/
public function export_for_template(renderer_base $output) {
$renderdata = new stdClass();
$renderdata->startregurlenc = urlencode($this->startregurl);
$renderdata->sesskey = sesskey();
$renderdata->tools = [];
foreach ($this->tools as $tool) {
$renderdata->tools[] = (object)$tool;
}
return $renderdata;
}
}
+103
View File
@@ -0,0 +1,103 @@
<?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 class for template library.
*
* @package mod_lti
* @copyright 2015 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lti\output;
defined('MOODLE_INTERNAL') || die;
use plugin_renderer_base;
/**
* Renderer class for template library.
*
* @package mod_lti
* @copyright 2015 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Defer to template.
*
* @param tool_configure_page $page
*
* @return string html for the page
*/
public function render_tool_configure_page($page) {
$data = $page->export_for_template($this);
return parent::render_from_template('mod_lti/tool_configure', $data);
}
/**
* Render the external registration return page
*
* @param tool_configure_page $page
*
* @return string html for the page
*/
public function render_external_registration_return_page($page) {
$data = $page->export_for_template($this);
return parent::render_from_template('mod_lti/external_registration_return', $data);
}
/**
* Render the external registration return page
*
* @param tool_configure_page $page
*
* @return string html for the page
*/
public function render_registration_upgrade_choice_page($page) {
$data = $page->export_for_template($this);
return parent::render_from_template('mod_lti/registration_upgrade_choice_page', $data);
}
/**
* Render the reposting of the cross site request.
*
* @param repost_crosssite_page $page the page renderable.
*
* @return string rendered html for the page.
*/
public function render_repost_crosssite_page(repost_crosssite_page $page): string {
$data = $page->export_for_template($this);
return parent::render_from_template('mod_lti/repost_crosssite', $data);
}
/**
* Render the course tools page header.
*
* @param course_tools_page $page the page renderable.
* @return string the rendered html for the page.
*/
protected function render_course_tools_page(course_tools_page $page): string {
// Render the table header templatable + the report.
$headerrenderable = $page->get_header();
$table = $page->get_table();
$headercontext = $headerrenderable->export_for_template($this);
$headeroutput = parent::render_from_template('mod_lti/course_tools_page_header', $headercontext);
return $headeroutput . $table->output();
}
}
@@ -0,0 +1,82 @@
<?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/>.
/**
* Render a page containing a simple form which reposts to self via JS.
*
* The purpose of this form is to resend a cross-site request to self, which allows the browsers to include the Moodle
* session cookie alongside the original POST data, allowing LTI flows to function despite browsers blocking
* cross-site cookies.
*
* @copyright 2021 Cengage
* @package mod_lti
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lti\output;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/mod/lti/locallib.php');
use renderable;
use templatable;
use renderer_base;
use stdClass;
/**
* Render a page containing a simple form which reposts to self via JS.
*
* The purpose of this form is to resend a cross-site request to self, which allows the browsers to include the Moodle
* session cookie alongside the original POST data, allowing LTI flows to function despite browsers blocking
* cross-site cookies.
*
* @copyright 2021 Cengage
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repost_crosssite_page implements renderable, templatable {
/** @var array POST params. */
protected $params;
/** @var string URL to repost to. */
protected string $url;
/**
* Constructor
*
* @param string $url moodle URL to repost to
* @param array $post the POST params to be re-posted
*/
public function __construct(string $url, array $post) {
$this->params = array_map(function($k) use ($post) {
return ["key" => $k, "value" => $post[$k]];
}, array_keys($post));
$this->url = $url;
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output The renderer
* @return stdClass Data to be used by the template
*/
public function export_for_template(renderer_base $output) {
$renderdata = new stdClass();
$renderdata->url = $this->url;
$renderdata->params = $this->params;
return $renderdata;
}
}
@@ -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/>.
/**
* Class containing data for tool_configure page
*
* @package mod_lti
* @copyright 2015 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lti\output;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/mod/lti/locallib.php');
use moodle_url;
use renderable;
use templatable;
use renderer_base;
use stdClass;
use help_icon;
/**
* Class containing data for tool_configure page
*
* @copyright 2015 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_configure_page implements renderable, templatable {
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output The renderer
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
$data = new stdClass();
$keyhelp = new help_icon('resourcekey', 'mod_lti');
$secrethelp = new help_icon('password', 'mod_lti');
$url = new moodle_url('/mod/lti/typessettings.php', array('sesskey' => sesskey(), 'returnto' => 'toolconfigure'));
$data->configuremanualurl = $url->out();
$url = new moodle_url('/admin/settings.php?section=modsettinglti');
$data->managetoolsurl = $url->out();
$url = new moodle_url('/mod/lti/toolproxies.php');
$data->managetoolproxiesurl = $url->out();
$data->keyhelp = $keyhelp->export_for_template($output);
$data->secrethelp = $secrethelp->export_for_template($output);
return $data;
}
}