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,51 @@
<?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 message_notification_list class for displaying on message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\output\preferences;
defined('MOODLE_INTERNAL') || die();
/**
* Class to create context for the list of notifications on the message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_notification_list extends notification_list {
/**
* Create the list component output object.
*
* @param string $component
* @param array $readyprocessors
* @param array $providers
* @param \stdClass $preferences
* @param \stdClass $user
* @return message_notification_list_component
*/
protected function create_list_component($component, $readyprocessors, $providers, $preferences, $user) {
return new message_notification_list_component($component, $readyprocessors, $providers, $preferences, $user);
}
}
@@ -0,0 +1,52 @@
<?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 notification_list_component class for displaying on message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\output\preferences;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/message/lib.php');
use renderable;
use templatable;
/**
* Class to create context for a notification component on the message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_notification_list_component extends notification_list_component {
/**
* Determine if the preference should be displayed.
*
* @param string $preferencekey
* @return bool
*/
protected function should_show_preference_key($preferencekey) {
return $preferencekey === 'message_provider_moodle_instantmessage';
}
}
@@ -0,0 +1,167 @@
<?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 notification_list class for displaying on message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\output\preferences;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use context_user;
/**
* Class to create context for the list of notifications on the message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class notification_list implements templatable, renderable {
/**
* @var array A list of message processors.
*/
protected $processors;
/**
* @var array A list of message providers.
*/
protected $providers;
/**
* @var array A list of message preferences.
*/
protected $preferences;
/**
* @var \stdClass A user.
*/
protected $user;
/**
* Constructor.
*
* @param array $processors
* @param array $providers
* @param \stdClass $preferences
* @param \stdClass $user
*/
public function __construct($processors, $providers, $preferences, $user) {
$this->processors = $processors;
$this->providers = $providers;
$this->preferences = $preferences;
$this->user = $user;
}
/**
* Create the list component output object.
*
* @param string $component
* @param array $readyprocessors
* @param array $providers
* @param \stdClass $preferences
* @param \stdClass $user
* @return notification_list_component
*/
protected function create_list_component($component, $readyprocessors, $providers, $preferences, $user) {
return new notification_list_component($component, $readyprocessors, $providers, $preferences, $user);
}
public function export_for_template(\renderer_base $output) {
$processors = $this->processors;
$providers = $this->providers;
$preferences = $this->preferences;
$user = $this->user;
$usercontext = context_user::instance($user->id);
$activitycomponents = [];
$othercomponents = [];
// Order the components so that the activities appear first, followed
// by the system and then anything else.
foreach ($providers as $provider) {
if ($provider->component != 'moodle') {
if (substr($provider->component, 0, 4) == 'mod_') {
// Activities.
$activitycomponents[] = $provider->component;
} else {
// Other stuff.
$othercomponents[] = $provider->component;
}
}
}
$activitycomponents = array_unique($activitycomponents);
asort($activitycomponents);
$othercomponents = array_unique($othercomponents);
asort($othercomponents);
$components = array_merge($activitycomponents, ['moodle'], $othercomponents);
asort($providers);
$context = [
'userid' => $user->id,
'disableall' => $user->emailstop,
'processors' => [],
];
$readyprocessors = [];
// Make the unconfigured processors appear last in the array.
uasort($processors, function($a, $b) {
$aconf = $a->object->is_user_configured();
$bconf = $b->object->is_user_configured();
if ($aconf == $bconf) {
return 0;
}
return ($aconf < $bconf) ? 1 : -1;
});
foreach ($processors as $processor) {
if (!$processor->enabled || !$processor->configured) {
// If the processor isn't enabled and configured at the site
// level then we should ignore it.
continue;
}
$context['processors'][] = [
'displayname' => get_string('pluginname', 'message_'.$processor->name),
'name' => $processor->name,
'hassettings' => !empty($processor->object->config_form($preferences)),
'contextid' => $usercontext->id,
'userconfigured' => $processor->object->is_user_configured(),
];
$readyprocessors[] = $processor;
}
foreach ($components as $component) {
$notificationcomponent = $this->create_list_component($component, $readyprocessors,
$providers, $preferences, $user);
$context['components'][] = $notificationcomponent->export_for_template($output);
}
return $context;
}
}
@@ -0,0 +1,168 @@
<?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 notification_list_component class for displaying on message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\output\preferences;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/message/lib.php');
use renderable;
use templatable;
/**
* Class to create context for a notification component on the message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class notification_list_component implements templatable, renderable {
/**
* @var array A list of message processors.
*/
protected $processors;
/**
* @var array A list of message providers.
*/
protected $providers;
/**
* @var array A list of message preferences.
*/
protected $preferences;
/**
* @var string The component name.
*/
protected $component;
/**
* @var \stdClass A user.
*/
protected $user;
/**
* Constructor.
*
* @param string $component
* @param array $processors
* @param array $providers
* @param \stdClass $preferences
* @param \stdClass $user
*/
public function __construct($component, $processors, $providers, $preferences, $user) {
$this->processors = $processors;
$this->providers = $providers;
$this->preferences = $preferences;
$this->component = $component;
$this->user = $user;
}
/**
* Get the base key prefix for the given provider.
*
* @param \stdClass $provider The message provider
* @return string
*/
private function get_preference_base($provider) {
return $provider->component.'_'.$provider->name;
}
/**
* Get the display name for the given provider.
*
* @param \stdClass $provider The message provider
* @return string
*/
private function get_provider_display_name($provider) {
return get_string('messageprovider:'.$provider->name, $provider->component);
}
/**
* Determine if the preference should be displayed.
*
* @param string $preferencekey
* @return bool
*/
protected function should_show_preference_key($preferencekey) {
return $preferencekey !== 'message_provider_moodle_instantmessage';
}
public function export_for_template(\renderer_base $output) {
$processors = $this->processors;
$providers = $this->providers;
$preferences = $this->preferences;
$component = $this->component;
$defaultpreferences = get_message_output_default_preferences();
if ($component != 'moodle') {
$componentname = get_string('pluginname', $component);
} else {
$componentname = get_string('coresystem');
}
$context = [
'displayname' => $componentname,
'colspan' => count($processors) + 1,
'notifications' => [],
];
foreach ($providers as $provider) {
$preferencebase = $this->get_preference_base($provider);
$preferencekey = 'message_provider_'.$preferencebase;
// Hack to stop this one specific preference from showing up in the
// notification list because it belongs to the message preferences page.
if (!$this->should_show_preference_key($preferencekey)) {
continue;
}
// If provider component is not same or provider disabled then don't show.
if (($provider->component != $component) ||
(!empty($defaultpreferences->{$preferencebase.'_disable'}))) {
continue;
}
$notificationcontext = [
'displayname' => $this->get_provider_display_name($provider),
'preferencekey' => $preferencekey,
'processors' => [],
];
foreach ($processors as $processor) {
$notificationprocessor = new notification_list_processor($processor, $provider, $preferences);
$notificationcontext['processors'][] = $notificationprocessor->export_for_template($output);
}
$context['notifications'][] = $notificationcontext;
}
$context['hasnotifications'] = (count($context['notifications']) > 0);
return $context;
}
}
@@ -0,0 +1,170 @@
<?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 notification_list_processor class for displaying on message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\output\preferences;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/message/lib.php');
use renderable;
use templatable;
/**
* Class to create context for a notification component on the message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class notification_list_processor implements templatable, renderable {
/**
* @var \stdClass A notification processor.
*/
protected $processor;
/**
* @var \stdClass A notification provider.
*/
protected $provider;
/**
* @var \stdClass A list of message preferences.
*/
protected $preferences;
/**
* Constructor.
*
* @param \stdClass $processor
* @param \stdClass $provider
* @param \stdClass $preferences
*/
public function __construct($processor, $provider, $preferences) {
$this->processor = $processor;
$this->provider = $provider;
$this->preferences = $preferences;
}
/**
* Get the base key prefix for the given provider.
*
* @return string
*/
private function get_preference_base() {
return $this->provider->component . '_' . $this->provider->name;
}
/**
* Check if the given preference is enabled or not.
*
* @param string $name preference name
* @param string $locked Wether the preference is locked by admin.
* @return bool
*/
private function is_preference_enabled($name, $locked) {
$processor = $this->processor;
$preferences = $this->preferences;
$defaultpreferences = get_message_output_default_preferences();
$checked = false;
// See if user has touched this preference.
if (!$locked && isset($preferences->{$name})) {
// User has some preferences for this state in the database.
$checked = isset($preferences->{$name}[$processor->name]);
} else {
// User has not set this preference yet, using site default preferences set by admin.
$defaultpreference = 'message_provider_'.$name;
if (isset($defaultpreferences->{$defaultpreference})) {
$checked = (int)in_array($processor->name, explode(',', $defaultpreferences->{$defaultpreference}));
}
}
return $checked;
}
/**
* Export this data so it can be used as the context for a mustache template.
* @todo Remove loggedin and loggedoff from context on MDL-73284.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(\renderer_base $output) {
$processor = $this->processor;
$preferencebase = $this->get_preference_base();
$defaultpreferences = get_message_output_default_preferences();
$defaultpreference = $processor->name.'_provider_'.$preferencebase.'_locked';
$providername = get_string('messageprovider:'.$this->provider->name, $this->provider->component);
$processorname = get_string('pluginname', 'message_'.$processor->name);
$labelparams = [
'provider' => $providername,
'processor' => $processorname,
];
$context = [
'displayname' => $processorname,
'name' => $processor->name,
'locked' => false,
'userconfigured' => $processor->object->is_user_configured(),
// Backward compatibility, deprecated attribute.
'loggedin' => [
'name' => 'loggedin',
'displayname' => 'loggedin',
'checked' => false,
],
// Backward compatibility, deprecated attribute.
'loggedoff' => [
'name' => 'loggedoff',
'displayname' => 'loggedoff',
'checked' => false,
],
'enabled' => false,
'enabledlabel' => get_string('sendingviaenabled', 'message', $labelparams),
];
// Determine the default setting.
if (isset($defaultpreferences->{$defaultpreference})) {
$context['locked'] = $defaultpreferences->{$defaultpreference};
}
$context['enabled'] = $this->is_preference_enabled($preferencebase.'_enabled', $context['locked']);
$context['loggedoff']['checked'] = $context['enabled']; // Backward compatibility, deprecated attribute.
$context['loggedin']['checked'] = $context['enabled']; // Backward compatibility, deprecated attribute.
// If settings are disallowed or forced, just display the corresponding message, if not use user settings.
if ($context['locked']) {
if ($context['enabled']) {
$context['lockedmessage'] = get_string('forcedmessage', 'message');
$context['lockedlabel'] = get_string('providerprocesorislocked', 'message', $labelparams);
} else {
$context['lockedmessage'] = get_string('disallowed', 'message');
$context['lockedlabel'] = get_string('providerprocesorisdisallowed', 'message', $labelparams);
}
}
return $context;
}
}
@@ -0,0 +1,84 @@
<?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 processor class for displaying on message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\output\preferences;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
/**
* Class to create context for one of the message processors settings on the message preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class processor implements templatable, renderable {
/**
* @var \stdClass The message processor.
*/
protected $processor;
/**
* @var \stdClass list of message preferences.
*/
protected $preferences;
/**
* @var \stdClass A user.
*/
protected $user;
/**
* @var string The processor type.
*/
protected $type;
/**
* Constructor.
*
* @param \stdClass $processor
* @param \stdClass $preferences
* @param \stdClass $user
* @param string $type
*/
public function __construct($processor, $preferences, $user, $type) {
$this->processor = $processor;
$this->preferences = $preferences;
$this->user = $user;
$this->type = $type;
}
public function export_for_template(\renderer_base $output) {
return [
'userid' => $this->user->id,
'displayname' => get_string('pluginname', 'message_'.$this->type),
'name' => $this->type,
'formhtml' => $this->processor->config_form($this->preferences),
];
}
}
+75
View File
@@ -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/>.
/**
* Contains class used to prepare a message processor for display.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\output;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/message/lib.php');
use renderable;
use templatable;
/**
* Class to prepare a message processor for display.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class processor implements templatable, renderable {
/**
* @var \stdClass The message processor
*/
protected $processor;
/**
* @var \stdClass The user
*/
protected $user;
/**
* Constructor.
*
* @param \stdClass $processor
* @param \stdClass $user
*/
public function __construct($processor, $user) {
$this->processor = $processor;
$this->user = $user;
}
public function export_for_template(\renderer_base $output) {
$processor = $this->processor;
$user = $this->user;
$context = [
'systemconfigured' => $processor->is_system_configured(),
'userconfigured' => $processor->is_user_configured($user),
];
return $context;
}
}