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
+145
View File
@@ -0,0 +1,145 @@
<?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/>.
/**
* Starred courses block external API
*
* @package block_starredcourses
* @category external
* @copyright 2018 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/course/externallib.php');
use core_course\external\course_summary_exporter;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_value;
/**
* Starred courses block external functions.
*
* @copyright 2018 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_starredcourses_external extends core_course_external {
/**
* Returns description of method parameters
*
* @return external_function_parameters
* @since Moodle 3.6
*/
public static function get_starred_courses_parameters() {
return new external_function_parameters([
'limit' => new external_value(PARAM_INT, 'Limit', VALUE_DEFAULT, 0),
'offset' => new external_value(PARAM_INT, 'Offset', VALUE_DEFAULT, 0)
]);
}
/**
* Get users starred courses.
*
* @param int $limit Limit
* @param int $offset Offset
*
* @return array list of courses and warnings
*/
public static function get_starred_courses($limit, $offset) {
global $USER, $PAGE;
$params = self::validate_parameters(self::get_starred_courses_parameters(), [
'limit' => $limit,
'offset' => $offset
]);
$limit = $params['limit'];
$offset = $params['offset'];
$usercontext = context_user::instance($USER->id);
self::validate_context($usercontext);
$PAGE->set_context($usercontext);
$renderer = $PAGE->get_renderer('core');
// Get the user favourites service, scoped to a single user (their favourites only).
$userservice = \core_favourites\service_factory::get_service_for_user_context($usercontext);
// Get the favourites, by type, for the user.
$favourites = $userservice->find_favourites_by_type('core_course', 'courses', $offset, $limit);
$favouritecourseids = [];
if ($favourites) {
$favouritecourseids = array_map(
function($favourite) {
return $favourite->itemid;
}, $favourites);
}
// Get all courses that the current user is enroled in, restricted down to favourites.
$filteredcourses = [];
if ($favouritecourseids) {
$courses = course_get_enrolled_courses_for_logged_in_user(0, 0, null, null,
COURSE_DB_QUERY_LIMIT, $favouritecourseids);
list($filteredcourses, $processedcount) = course_filter_courses_by_favourites(
$courses,
$favouritecourseids,
0
);
}
// Grab the course ids.
$filteredcourseids = array_column($filteredcourses, 'id');
// Filter out any favourites that are not in the list of enroled courses.
$filteredfavourites = array_filter($favourites, function($favourite) use ($filteredcourseids) {
return in_array($favourite->itemid, $filteredcourseids);
});
// Sort the favourites getting last added first.
usort($filteredfavourites, function($a, $b) {
if ($a->timemodified == $b->timemodified) return 0;
return ($a->timemodified > $b->timemodified) ? -1 : 1;
});
$formattedcourses = array();
foreach ($filteredfavourites as $favourite) {
$course = get_course($favourite->itemid);
$context = \context_course::instance($favourite->itemid);
$canviewhiddencourses = has_capability('moodle/course:viewhiddencourses', $context);
if ($course->visible || $canviewhiddencourses) {
$exporter = new course_summary_exporter($course, ['context' => $context, 'isfavourite' => true]);
$formattedcourse = $exporter->export($renderer);
$formattedcourses[] = $formattedcourse;
}
}
return $formattedcourses;
}
/**
* Returns description of method result value
*
* @return \core_external\external_description
* @since Moodle 3.6
*/
public static function get_starred_courses_returns() {
return new external_multiple_structure(course_summary_exporter::get_read_structure());
}
}
@@ -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/>.
/**
* Class containing data for starred courses block.
*
* @package block_starredcourses
* @copyright 2018 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_starredcourses\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use renderer_base;
use templatable;
use core_course\external\course_summary_exporter;
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->libdir . '/completionlib.php');
/**
* Class containing data for starred courses block.
*
* @copyright 2018 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class main implements renderable, templatable {
/**
* Export this 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) {
global $USER;
$nocoursesurl = $output->image_url('courses', 'block_starredcourses')->out();
$config = get_config('block_starredcourses');
return [
'userid' => $USER->id,
'nocoursesimg' => $nocoursesurl,
'displaycategories' => !empty($config->displaycategories)
];
}
}
@@ -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/>.
/**
* Starred courses block renderer.
*
* @package block_starredcourses
* @copyright 2018 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_starredcourses\output;
defined('MOODLE_INTERNAL') || die;
use plugin_renderer_base;
/**
* Starred courses block renderer.
*
* @package block_starredcourses
* @copyright 2018 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Return the main content for the block.
*
* @param main $main The main renderable
* @return string HTML string
*/
public function render_main(main $main) {
return $this->render_from_template('block_starredcourses/main',
$main->export_for_template($this));
}
}
@@ -0,0 +1,45 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for block_starredcourses.
*
* @package block_starredcourses
* @copyright 2018 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_starredcourses\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for block_starredcourses.
*
* @copyright 2018 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}