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
+93
View File
@@ -0,0 +1,93 @@
<?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/>.
/**
* Group details page.
*
* @package core_group
* @copyright 2017 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_group\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use renderer_base;
use stdClass;
use templatable;
use context_course;
use moodle_url;
/**
* Group details page class.
*
* @package core_group
* @copyright 2017 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_details implements renderable, templatable {
/** @var stdClass $group An object with the group information. */
protected $group;
/**
* group_details constructor.
*
* @param int $groupid Group ID to show details of.
*/
public function __construct($groupid) {
$this->group = groups_get_group($groupid, '*', MUST_EXIST);
}
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
if (!empty($this->group->description) || (!empty($this->group->picture))) {
$context = context_course::instance($this->group->courseid);
$description = file_rewrite_pluginfile_urls($this->group->description,
'pluginfile.php',
$context->id,
'group',
'description',
$this->group->id);
$descriptionformat = $this->group->descriptionformat ?? FORMAT_MOODLE;
$options = [
'overflowdiv' => true,
'context' => $context
];
$data = new stdClass();
$data->name = format_string($this->group->name, true, ['context' => $context]);
$data->pictureurl = get_group_picture_url($this->group, $this->group->courseid, true);
$data->description = format_text($description, $descriptionformat, $options);
if (has_capability('moodle/course:managegroups', $context)) {
$url = new moodle_url('/group/group.php', ['id' => $this->group->id, 'courseid' => $this->group->courseid]);
$data->editurl = $url->out(false);
}
return $data;
} else {
return;
}
}
}
+117
View File
@@ -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/>.
/**
* Group index page.
*
* @package core_group
* @copyright 2017 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_group\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use renderer_base;
use stdClass;
use templatable;
/**
* Group index page class.
*
* @package core_group
* @copyright 2017 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class index_page implements renderable, templatable {
/** @var int $courseid The course ID. */
public $courseid;
/** @var array The array of groups to be rendered. */
public $groups;
/** @var string The name of the currently selected group. */
public $selectedgroupname;
/** @var array The array of group members to be rendered, if a group is selected. */
public $selectedgroupmembers;
/** @var bool Whether to disable the add members/edit group buttons. */
public $disableaddedit;
/** @var bool Whether to disable the delete group button. */
public $disabledelete;
/** @var array Groups that can't be deleted by the user. */
public $undeletablegroups;
/** @var bool Whether to show/hide the messaging setting buttons. */
public $messagingsettingsvisible;
/**
* index_page constructor.
*
* @param int $courseid The course ID.
* @param array $groups The array of groups to be rendered.
* @param string $selectedgroupname The name of the currently selected group.
* @param array $selectedgroupmembers The array of group members to be rendered, if a group is selected.
* @param bool $disableaddedit Whether to disable the add members/edit group buttons.
* @param bool $disabledelete Whether to disable the delete group button.
* @param array $undeletablegroups Groups that can't be deleted by the user.
* @param bool $messagingsettingsvisible If the messaging settings buttons should be visible.
*/
public function __construct($courseid, $groups, $selectedgroupname, $selectedgroupmembers, $disableaddedit, $disabledelete,
$undeletablegroups, $messagingsettingsvisible) {
$this->courseid = $courseid;
$this->groups = $groups;
$this->selectedgroupname = $selectedgroupname;
$this->selectedgroupmembers = $selectedgroupmembers;
$this->disableaddedit = $disableaddedit;
$this->disabledelete = $disabledelete;
$this->undeletablegroups = $undeletablegroups;
$this->messagingsettingsvisible = $messagingsettingsvisible;
}
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $CFG;
$data = new stdClass();
// Variables that will be passed to the JS helper.
$data->courseid = $this->courseid;
$data->wwwroot = $CFG->wwwroot;
// To be passed to the JS init script in the template. Encode as a JSON string.
$data->undeletablegroups = json_encode($this->undeletablegroups);
// Some buttons are enabled if single group selected.
$data->addmembersdisabled = $this->disableaddedit;
$data->editgroupsettingsdisabled = $this->disableaddedit;
$data->deletegroupdisabled = $this->disabledelete;
$data->groups = $this->groups;
$data->members = $this->selectedgroupmembers;
$data->selectedgroup = $this->selectedgroupname;
$data->messagingsettingsvisible = $this->messagingsettingsvisible;
return $data;
}
}
+61
View File
@@ -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/>.
/**
* Renderers.
*
* @package core_group
* @copyright 2017 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_group\output;
defined('MOODLE_INTERNAL') || die();
use plugin_renderer_base;
/**
* Renderer class.
*
* @package core_group
* @copyright 2017 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Defer to template.
*
* @param index_page $page
* @return string
*/
public function render_index_page(index_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('core_group/index', $data);
}
/**
* Defer to template.
*
* @param group_details $page Group details page object.
* @return string HTML to render the group details.
*/
public function group_details(group_details $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('core_group/group_details', $data);
}
}
@@ -0,0 +1,180 @@
<?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 core_group\output\user_groups_editable
*
* @package core_group
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_group\output;
use context_course;
use core_user;
use core_external;
use coding_exception;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/group/lib.php');
/**
* Class to display list of user groups.
*
* @package core_group
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_groups_editable extends \core\output\inplace_editable {
/** @var $coursegroups */
private $coursegroups = null;
/** @var $context */
private $context = null;
/**
* Constructor.
*
* @param \stdClass $course The current course
* @param \context $context The course context
* @param \stdClass $user The current user
* @param \stdClass[] $coursegroups The list of course groups from groups_get_all_groups with membership.
* @param array $value Array of groupids.
*/
public function __construct($course, $context, $user, $coursegroups, $value) {
// Check capabilities to get editable value.
$editable = has_capability('moodle/course:managegroups', $context) && !empty($coursegroups);
// Invent an itemid.
$itemid = $course->id . ':' . $user->id;
$value = json_encode($value);
// Remember these for the display value.
$this->coursegroups = $coursegroups;
$this->context = $context;
parent::__construct('core_group', 'user_groups', $itemid, $editable, $value, $value);
// Assignable groups.
$options = [];
foreach ($coursegroups as $group) {
$options[$group->id] = format_string($group->name, true, ['context' => $this->context]);
}
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->context));
$fullname = htmlspecialchars($fullname, ENT_QUOTES, 'utf-8');
$this->edithint = get_string('editusersgroupsa', 'group', $fullname);
$this->editlabel = get_string('editusersgroupsa', 'group', $fullname);
$attributes = ['multiple' => true];
$this->set_type_autocomplete($options, $attributes);
}
/**
* 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) {
$listofgroups = [];
$groupids = json_decode($this->value);
foreach ($groupids as $id) {
$listofgroups[] = format_string($this->coursegroups[$id]->name, true, ['context' => $this->context]);
}
if (!empty($listofgroups)) {
$this->displayvalue = implode(', ', $listofgroups);
} else {
$this->displayvalue = get_string('groupsnone');
}
return parent::export_for_template($output);
}
/**
* Updates the value in database and returns itself, called from inplace_editable callback
*
* @param int $itemid
* @param mixed $newvalue
* @return \self
*/
public static function update($itemid, $newvalue) {
// Check caps.
// Do the thing.
// Return one of me.
// Validate the inputs.
list($courseid, $userid) = explode(':', $itemid, 2);
$courseid = clean_param($courseid, PARAM_INT);
$userid = clean_param($userid, PARAM_INT);
$groupids = json_decode($newvalue);
foreach ($groupids as $index => $groupid) {
$groupids[$index] = clean_param($groupid, PARAM_INT);
}
// Check user is enrolled in the course.
$context = context_course::instance($courseid);
core_external::validate_context($context);
if (!is_enrolled($context, $userid)) {
throw new coding_exception('User does not belong to the course');
}
// Check that all the groups belong to the course.
$coursegroups = groups_get_all_groups($courseid, 0, 0, 'g.*', true);
$byid = [];
foreach ($groupids as $groupid) {
if (!isset($coursegroups[$groupid])) {
throw new coding_exception('Group does not belong to the course');
}
$byid[$groupid] = $groupid;
}
$groupids = $byid;
// Check permissions.
require_capability('moodle/course:managegroups', $context);
// Process adds.
foreach ($groupids as $groupid) {
if (!isset($coursegroups[$groupid]->members[$userid])) {
// Add them.
groups_add_member($groupid, $userid);
// Keep this variable in sync.
$coursegroups[$groupid]->members[$userid] = $userid;
}
}
// Process removals.
foreach ($coursegroups as $groupid => $group) {
if (isset($group->members[$userid]) && !isset($groupids[$groupid])) {
if (groups_remove_member_allowed($groupid, $userid)) {
groups_remove_member($groupid, $userid);
unset($coursegroups[$groupid]->members[$userid]);
} else {
$groupids[$groupid] = $groupid;
}
}
}
$course = get_course($courseid);
$user = core_user::get_user($userid);
return new self($course, $context, $user, $coursegroups, array_values($groupids));
}
}