mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
Merge branch 'MDL-77357-master' of https://github.com/safatshahin/moodle
This commit is contained in:
commit
74813d9f37
12
communication/amd/build/providerchooser.min.js
vendored
Normal file
12
communication/amd/build/providerchooser.min.js
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
define("core_communication/providerchooser",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0;
|
||||
/**
|
||||
* Communication provider selection handler.
|
||||
*
|
||||
* @module core_communication/communicationchooser
|
||||
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 4.2
|
||||
*/
|
||||
const Selectors_fields={selector:'[data-communicationchooser-field="selector"]',updateButton:'[data-communicationchooser-field="updateButton"]'};_exports.init=()=>{document.querySelector(Selectors_fields.selector).addEventListener("change",(e=>{const form=e.target.closest("form"),updateButton=form.querySelector(Selectors_fields.updateButton),fieldset=updateButton.closest("fieldset"),url=new URL(form.action);url.hash=fieldset.id,form.action=url.toString(),updateButton.click()}))}}));
|
||||
|
||||
//# sourceMappingURL=providerchooser.min.js.map
|
1
communication/amd/build/providerchooser.min.js.map
Normal file
1
communication/amd/build/providerchooser.min.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"providerchooser.min.js","sources":["../src/providerchooser.js"],"sourcesContent":["\n// This file is part of Moodle - http://moodle.org/ //\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Communication provider selection handler.\n *\n * @module core_communication/communicationchooser\n * @copyright 2023 Safat Shahin <safat.shahin@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 4.2\n */\n\nconst Selectors = {\n fields: {\n selector: '[data-communicationchooser-field=\"selector\"]',\n updateButton: '[data-communicationchooser-field=\"updateButton\"]',\n },\n};\n\n/**\n * Initialise the format chooser.\n */\nexport const init = () => {\n document.querySelector(Selectors.fields.selector).addEventListener('change', e => {\n const form = e.target.closest('form');\n const updateButton = form.querySelector(Selectors.fields.updateButton);\n const fieldset = updateButton.closest('fieldset');\n\n const url = new URL(form.action);\n url.hash = fieldset.id;\n\n form.action = url.toString();\n updateButton.click();\n });\n};\n"],"names":["Selectors","selector","updateButton","document","querySelector","addEventListener","e","form","target","closest","fieldset","url","URL","action","hash","id","toString","click"],"mappings":";;;;;;;;;MAwBMA,iBACM,CACJC,SAAU,+CACVC,aAAc,kEAOF,KAChBC,SAASC,cAAcJ,iBAAiBC,UAAUI,iBAAiB,UAAUC,UACnEC,KAAOD,EAAEE,OAAOC,QAAQ,QACxBP,aAAeK,KAAKH,cAAcJ,iBAAiBE,cACnDQ,SAAWR,aAAaO,QAAQ,YAEhCE,IAAM,IAAIC,IAAIL,KAAKM,QACzBF,IAAIG,KAAOJ,SAASK,GAEpBR,KAAKM,OAASF,IAAIK,WAClBd,aAAae"}
|
47
communication/amd/src/providerchooser.js
Normal file
47
communication/amd/src/providerchooser.js
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
// 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/>.
|
||||
|
||||
/**
|
||||
* Communication provider selection handler.
|
||||
*
|
||||
* @module core_communication/communicationchooser
|
||||
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 4.2
|
||||
*/
|
||||
|
||||
const Selectors = {
|
||||
fields: {
|
||||
selector: '[data-communicationchooser-field="selector"]',
|
||||
updateButton: '[data-communicationchooser-field="updateButton"]',
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise the format chooser.
|
||||
*/
|
||||
export const init = () => {
|
||||
document.querySelector(Selectors.fields.selector).addEventListener('change', e => {
|
||||
const form = e.target.closest('form');
|
||||
const updateButton = form.querySelector(Selectors.fields.updateButton);
|
||||
const fieldset = updateButton.closest('fieldset');
|
||||
|
||||
const url = new URL(form.action);
|
||||
url.hash = fieldset.id;
|
||||
|
||||
form.action = url.toString();
|
||||
updateButton.click();
|
||||
});
|
||||
};
|
@ -122,6 +122,9 @@ class api {
|
||||
* @param \MoodleQuickForm $mform The form element
|
||||
*/
|
||||
public function form_definition(\MoodleQuickForm $mform): void {
|
||||
global $PAGE;
|
||||
$PAGE->requires->js_call_amd('core_communication/providerchooser', 'init');
|
||||
|
||||
$mform->addElement('header', 'communication', get_string('communication', 'communication'));
|
||||
|
||||
// List the communication providers.
|
||||
@ -130,22 +133,47 @@ class api {
|
||||
'select',
|
||||
'selectedcommunication',
|
||||
get_string('seleccommunicationprovider', 'communication'),
|
||||
$communicationproviders);
|
||||
$communicationproviders,
|
||||
['data-communicationchooser-field' => 'selector'],
|
||||
);
|
||||
$mform->addHelpButton('selectedcommunication', 'seleccommunicationprovider', 'communication');
|
||||
$mform->setDefault('selectedcommunication', processor::PROVIDER_NONE);
|
||||
|
||||
// Room name for the communication provider.
|
||||
$mform->addElement('text',
|
||||
'communicationroomname',
|
||||
get_string('communicationroomname', 'communication'),
|
||||
'maxlength="100" size="20"');
|
||||
$mform->addHelpButton('communicationroomname', 'communicationroomname', 'communication');
|
||||
$mform->setType('communicationroomname', PARAM_TEXT);
|
||||
$mform->hideIf(
|
||||
'communicationroomname',
|
||||
'selectedcommunication',
|
||||
'eq',
|
||||
processor::PROVIDER_NONE);
|
||||
$mform->registerNoSubmitButton('updatecommunicationprovider');
|
||||
$mform->addElement('submit',
|
||||
'updatecommunicationprovider',
|
||||
'update communication',
|
||||
['data-communicationchooser-field' => 'updateButton', 'class' => 'd-none',]);
|
||||
|
||||
// Just a placeholder for the communication options.
|
||||
$mform->addElement('hidden', 'addcommunicationoptionshere');
|
||||
$mform->setType('addcommunicationoptionshere', PARAM_BOOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the form definitions for the plugins.
|
||||
*
|
||||
* @param \MoodleQuickForm $mform
|
||||
* @return void
|
||||
*/
|
||||
public function form_definition_for_provider(\MoodleQuickForm $mform): void {
|
||||
$provider = $mform->getElementValue('selectedcommunication');
|
||||
|
||||
if ($provider[0] !== processor::PROVIDER_NONE) {
|
||||
// Room name for the communication provider.
|
||||
$mform->insertElementBefore(
|
||||
$mform->createElement(
|
||||
'text',
|
||||
'communicationroomname',
|
||||
get_string('communicationroomname', 'communication'), 'maxlength="100" size="20"'),
|
||||
'addcommunicationoptionshere'
|
||||
);
|
||||
$mform->addHelpButton('communicationroomname', 'communicationroomname', 'communication');
|
||||
$mform->setType('communicationroomname', PARAM_TEXT);
|
||||
|
||||
processor::set_proider_form_definition($provider[0], $mform);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,6 +251,8 @@ class api {
|
||||
if (!empty($instance->id) && $this->communication) {
|
||||
$instance->selectedcommunication = $this->communication->get_provider();
|
||||
$instance->communicationroomname = $this->communication->get_room_name();
|
||||
|
||||
$this->communication->get_form_provider()->set_form_data($instance);
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,12 +274,14 @@ class api {
|
||||
*
|
||||
* @param string $selectedcommunication The selected communication provider
|
||||
* @param string $communicationroomname The communication room name
|
||||
* @param \stdClass|null $instance The actual instance object
|
||||
* @param string|null $avatarurl The avatar url
|
||||
*/
|
||||
public function create_and_configure_room(
|
||||
string $selectedcommunication,
|
||||
string $communicationroomname,
|
||||
?string $avatarurl = null,
|
||||
?\stdClass $instance = null,
|
||||
): void {
|
||||
|
||||
if ($selectedcommunication !== processor::PROVIDER_NONE && $selectedcommunication !== '') {
|
||||
@ -262,6 +294,11 @@ class api {
|
||||
$communicationroomname,
|
||||
);
|
||||
|
||||
// Update provider record from form data.
|
||||
if ($instance !== null) {
|
||||
$this->communication->get_form_provider()->save_form_data($instance);
|
||||
}
|
||||
|
||||
// Set the avatar.
|
||||
if (!empty($avatarurl)) {
|
||||
$this->set_avatar_from_datauri_or_filepath($avatarurl);
|
||||
@ -280,12 +317,14 @@ class api {
|
||||
*
|
||||
* @param string $selectedprovider The selected communication provider
|
||||
* @param string $communicationroomname The communication room name
|
||||
* @param \stdClass|null $instance The actual instance object
|
||||
* @param string|null $avatarurl The avatar url
|
||||
*/
|
||||
public function update_room(
|
||||
string $selectedprovider,
|
||||
string $communicationroomname,
|
||||
?string $avatarurl = null,
|
||||
?\stdClass $instance = null,
|
||||
): void {
|
||||
|
||||
// Existing object found, let's update the communication record and associated actions.
|
||||
@ -297,6 +336,11 @@ class api {
|
||||
// Update communication record.
|
||||
$this->communication->update_instance($selectedprovider, $communicationroomname);
|
||||
|
||||
// Update provider record from form data.
|
||||
if ($instance !== null) {
|
||||
$this->communication->get_form_provider()->save_form_data($instance);
|
||||
}
|
||||
|
||||
// Update the avatar.
|
||||
$imageupdaterequired = $this->set_avatar_from_datauri_or_filepath($avatarurl);
|
||||
|
||||
@ -306,9 +350,9 @@ class api {
|
||||
}
|
||||
|
||||
// Add ad-hoc task to update the provider room if the room name changed.
|
||||
// TODO add efficiency considering dynamic fields.
|
||||
if (
|
||||
$previousprovider === $selectedprovider &&
|
||||
($previousroomname !== $communicationroomname || $imageupdaterequired)
|
||||
$previousprovider === $selectedprovider
|
||||
) {
|
||||
update_room_task::queue(
|
||||
$this->communication,
|
||||
@ -323,7 +367,7 @@ class api {
|
||||
}
|
||||
} else {
|
||||
// The instance didn't have any communication record, so create one.
|
||||
$this->create_and_configure_room($selectedprovider, $communicationroomname, $avatarurl);
|
||||
$this->create_and_configure_room($selectedprovider, $communicationroomname, $avatarurl, $instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
50
communication/classes/form_provider.php
Normal file
50
communication/classes/form_provider.php
Normal 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 core_communication;
|
||||
|
||||
/**
|
||||
* Interface form_provider to manage communication provider form options from provider plugins.
|
||||
*
|
||||
* Every provider plugin should implement this class to return the implemented form elements for custom data.
|
||||
*
|
||||
* @package core_communication
|
||||
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
interface form_provider {
|
||||
|
||||
/**
|
||||
* Set the form data to the instance if any data is available.
|
||||
*
|
||||
* @param \stdClass $instance The actual instance to set the data
|
||||
*/
|
||||
public function save_form_data(\stdClass $instance): void;
|
||||
|
||||
/**
|
||||
* Set the form data to the instance if any data is available.
|
||||
*
|
||||
* @param \stdClass $instance The actual instance to set the data
|
||||
*/
|
||||
public function set_form_data(\stdClass $instance): void;
|
||||
|
||||
/**
|
||||
* Set the form definitions.
|
||||
*
|
||||
* @param \MoodleQuickForm $mform The form object
|
||||
*/
|
||||
public static function set_form_definition(\MoodleQuickForm $mform): void;
|
||||
}
|
@ -409,7 +409,6 @@ class processor {
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_provider(): ?string {
|
||||
// var_dump($this->instancedata);die;
|
||||
if ((int)$this->instancedata->active === self::PROVIDER_ACTIVE) {
|
||||
return $this->instancedata->provider;
|
||||
}
|
||||
@ -459,6 +458,27 @@ class processor {
|
||||
return $this->provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get communication provider for form feature.
|
||||
*
|
||||
* @param string $provider The provider name
|
||||
* @param \MoodleQuickForm $mform The moodle form
|
||||
*/
|
||||
public static function set_proider_form_definition(string $provider, \MoodleQuickForm $mform): void {
|
||||
$providerclass = "{$provider}\\communication_feature";
|
||||
$providerclass::set_form_definition($mform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get communication instance for form feature.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function get_form_provider(): form_provider {
|
||||
$this->requires_form_features();
|
||||
return $this->provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get communication instance id.
|
||||
*
|
||||
@ -485,6 +505,26 @@ class processor {
|
||||
return ($this->provider instanceof room_user_provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check form feature available.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function requires_form_features(): void {
|
||||
if (!$this->supports_form_features()) {
|
||||
throw new \coding_exception('Form features are not supported by the provider');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check support for form feature.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports_form_features(): bool {
|
||||
return ($this->provider instanceof form_provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get communication instance id.
|
||||
*/
|
||||
|
@ -29,8 +29,8 @@ class communication_feature implements
|
||||
\core_communication\communication_provider,
|
||||
\core_communication\user_provider,
|
||||
\core_communication\room_chat_provider,
|
||||
\core_communication\room_user_provider {
|
||||
|
||||
\core_communication\room_user_provider,
|
||||
\core_communication\form_provider {
|
||||
|
||||
/** @var matrix_events_manager $eventmanager The event manager object to get the endpoints */
|
||||
private matrix_events_manager $eventmanager;
|
||||
@ -234,7 +234,7 @@ class communication_feature implements
|
||||
}
|
||||
|
||||
public function create_chat_room(): bool {
|
||||
if ($this->matrixrooms->room_record_exists()) {
|
||||
if ($this->matrixrooms->room_record_exists() && $this->matrixrooms->get_matrix_room_id()) {
|
||||
return $this->update_chat_room();
|
||||
}
|
||||
// Create a new room.
|
||||
@ -245,12 +245,21 @@ class communication_feature implements
|
||||
'initial_state' => [],
|
||||
];
|
||||
|
||||
// Set the room topic if set.
|
||||
if (!empty($matrixroomtopic = $this->matrixrooms->get_matrix_room_topic())) {
|
||||
$json['topic'] = $matrixroomtopic;
|
||||
}
|
||||
|
||||
$response = $this->eventmanager->request($json)->post($this->eventmanager->get_create_room_endpoint());
|
||||
$response = json_decode($response->getBody(), false, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
// Check if room was created.
|
||||
if (!empty($roomid = $response->room_id)) {
|
||||
$this->matrixrooms->create_matrix_room_record($this->communication->get_id(), $roomid);
|
||||
if ($this->matrixrooms->room_record_exists()) {
|
||||
$this->matrixrooms->update_matrix_room_record($roomid, $matrixroomtopic);
|
||||
} else {
|
||||
$this->matrixrooms->create_matrix_room_record($this->communication->get_id(), $roomid, $matrixroomtopic);
|
||||
}
|
||||
$this->eventmanager->roomid = $roomid;
|
||||
$this->update_room_avatar();
|
||||
return true;
|
||||
@ -274,6 +283,13 @@ class communication_feature implements
|
||||
$this->eventmanager->request($json)->put($this->eventmanager->get_update_room_name_endpoint());
|
||||
}
|
||||
|
||||
// Update the room topic if set.
|
||||
if (!empty($matrixroomtopic = $this->matrixrooms->get_matrix_room_topic())) {
|
||||
$json = ['topic' => $matrixroomtopic];
|
||||
$this->eventmanager->request($json)->put($this->eventmanager->get_update_room_topic_endpoint());
|
||||
$this->matrixrooms->update_matrix_room_record($this->matrixrooms->get_matrix_room_id(), $matrixroomtopic);
|
||||
}
|
||||
|
||||
// Update room avatar.
|
||||
$this->update_room_avatar();
|
||||
|
||||
@ -313,4 +329,33 @@ class communication_feature implements
|
||||
|
||||
return $this->eventmanager->matrixwebclienturl . '#/room/' . $this->matrixrooms->get_matrix_room_id();
|
||||
}
|
||||
|
||||
public function save_form_data(\stdClass $instance): void {
|
||||
$matrixroomtopic = $instance->matrixroomtopic ?? null;
|
||||
if ($this->matrixrooms->room_record_exists()) {
|
||||
$this->matrixrooms->update_matrix_room_record($this->matrixrooms->get_matrix_room_id(), $matrixroomtopic);
|
||||
} else {
|
||||
// Create the record with empty room id as we don't have it yet.
|
||||
$this->matrixrooms->create_matrix_room_record(
|
||||
$this->communication->get_id(),
|
||||
$this->matrixrooms->get_matrix_room_id(),
|
||||
$matrixroomtopic,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function set_form_data(\stdClass $instance): void {
|
||||
if (!empty($instance->id) && !empty($this->communication->get_id())) {
|
||||
$instance->matrixroomtopic = $this->matrixrooms->get_matrix_room_topic();
|
||||
}
|
||||
}
|
||||
|
||||
public static function set_form_definition(\MoodleQuickForm $mform): void {
|
||||
// Room description for the communication provider.
|
||||
$mform->insertElementBefore($mform->createElement('text', 'matrixroomtopic',
|
||||
get_string('matrixroomtopic', 'communication_matrix'),
|
||||
'maxlength="255" size="20"'), 'addcommunicationoptionshere');
|
||||
$mform->addHelpButton('matrixroomtopic', 'matrixroomtopic', 'communication_matrix');
|
||||
$mform->setType('matrixroomtopic', PARAM_TEXT);
|
||||
}
|
||||
}
|
||||
|
@ -56,13 +56,19 @@ class matrix_rooms {
|
||||
* Create matrix room data.
|
||||
*
|
||||
* @param int $commid The id of the communication record
|
||||
* @param string $roomid The id of the room from matrix
|
||||
* @param string|null $roomid The id of the room from matrix
|
||||
* @param string|null $roomtopic The topic of the room for matrix
|
||||
*/
|
||||
public function create_matrix_room_record(int $commid, string $roomid): void {
|
||||
public function create_matrix_room_record(
|
||||
int $commid,
|
||||
?string $roomid,
|
||||
?string $roomtopic
|
||||
): void {
|
||||
global $DB;
|
||||
$roomrecord = new \stdClass();
|
||||
$roomrecord->commid = $commid;
|
||||
$roomrecord->roomid = $roomid;
|
||||
$roomrecord->topic = $roomtopic;
|
||||
$roomrecord->id = $DB->insert_record('matrix_rooms', $roomrecord);
|
||||
$this->matrixroomrecord = $roomrecord;
|
||||
}
|
||||
@ -70,12 +76,14 @@ class matrix_rooms {
|
||||
/**
|
||||
* Update matrix room data.
|
||||
*
|
||||
* @param string $roomid The id of the room from matrix
|
||||
* @param string|null $roomid The id of the room from matrix
|
||||
* @param string|null $roomtopic The topic of the room for matrix
|
||||
*/
|
||||
public function update_matrix_room_record(string $roomid): void {
|
||||
public function update_matrix_room_record(?string $roomid, ?string $roomtopic): void {
|
||||
global $DB;
|
||||
if ($this->room_record_exists()) {
|
||||
$this->matrixroomrecord->roomid = $roomid;
|
||||
$this->matrixroomrecord->topic = $roomtopic;
|
||||
$DB->update_record('matrix_rooms', $this->matrixroomrecord);
|
||||
}
|
||||
}
|
||||
@ -105,6 +113,18 @@ class matrix_rooms {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the matrix room topic.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_matrix_room_topic(): ?string {
|
||||
if ($this->room_record_exists()) {
|
||||
return $this->matrixroomrecord->topic;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if room record exist for matrix.
|
||||
*
|
||||
|
@ -9,6 +9,7 @@
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="commid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the communication record"/>
|
||||
<FIELD NAME="roomid" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="ID of the matrix room instance"/>
|
||||
<FIELD NAME="topic" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Topic of the matrix room instance."/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
|
45
communication/provider/matrix/db/upgrade.php
Normal file
45
communication/provider/matrix/db/upgrade.php
Normal file
@ -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/>.
|
||||
|
||||
/**
|
||||
* Install steps for communication_matrix.
|
||||
*
|
||||
* @package communication_matrix
|
||||
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Upgrade procedures for the matrix plugin.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function xmldb_communication_matrix_upgrade($oldversion) {
|
||||
global $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
if ($oldversion < 2023041100) {
|
||||
$table = new xmldb_table('matrix_rooms');
|
||||
$field = new xmldb_field('topic', XMLDB_TYPE_CHAR, '255', null, false, false, null, 'roomid');
|
||||
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
@ -32,5 +32,7 @@ $string['matrixrefreshtoken'] = 'Refresh token';
|
||||
$string['matrixrefreshtoken_desc'] = 'Admin refresh token to associated with the access token.';
|
||||
$string['matrixelementurl'] = 'Element web URL';
|
||||
$string['matrixelementurl_desc'] = 'The URL to Element Web instance.';
|
||||
$string['matrixroomtopic'] = 'Room topic';
|
||||
$string['matrixroomtopic_help'] = 'A short description of what this room is for.';
|
||||
$string['pluginname'] = 'Matrix';
|
||||
$string['privacy:metadata'] = 'Matrix communication plugin does not store any personal data.';
|
||||
|
@ -0,0 +1,53 @@
|
||||
@communication @communication_matrix @javascript
|
||||
Feature: Communication matrix form field
|
||||
In order to create a new communication room in matrix
|
||||
As a teacher
|
||||
I can update the room the information from course
|
||||
|
||||
Background: Make sure the mock server is initialized and a course is created for teacher
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Test course | Test course | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | Test course | editingteacher |
|
||||
|
||||
Scenario: I can add room name for matrix room
|
||||
Given a Matrix mock server is configured
|
||||
And I log in as "teacher1"
|
||||
And I am on "Test course" course homepage
|
||||
When I navigate to "Settings" in current page administration
|
||||
And I click on "Communication" "link"
|
||||
And I set the field "id_selectedcommunication" to "Matrix"
|
||||
And I wait to be redirected
|
||||
And I should see "Room name"
|
||||
And I set the field "id_communicationroomname" to "Sampleroomname"
|
||||
And I press "Save and display"
|
||||
And I navigate to "Settings" in current page administration
|
||||
And I expand all fieldsets
|
||||
Then the field "id_communicationroomname" matches value "Sampleroomname"
|
||||
|
||||
Scenario: I can add room topic for matrix room
|
||||
Given a Matrix mock server is configured
|
||||
And I log in as "teacher1"
|
||||
And I am on "Test course" course homepage
|
||||
When I navigate to "Settings" in current page administration
|
||||
And I click on "Communication" "link"
|
||||
And I set the field "id_selectedcommunication" to "Matrix"
|
||||
And I wait to be redirected
|
||||
And I should see "Room name"
|
||||
And I should see "Room topic"
|
||||
And I set the field "id_communicationroomname" to "Sampleroomname"
|
||||
And I set the field "id_matrixroomtopic" to "Sampleroomtopic"
|
||||
And I press "Save and display"
|
||||
And I navigate to "Settings" in current page administration
|
||||
And I click on "Communication" "link"
|
||||
Then the field "id_communicationroomname" matches value "Sampleroomname"
|
||||
And I press "Cancel"
|
||||
And I run all adhoc tasks
|
||||
And I navigate to "Settings" in current page administration
|
||||
And I click on "Communication" "link"
|
||||
And the field "id_matrixroomtopic" matches value "Sampleroomtopic"
|
@ -321,4 +321,27 @@ class communication_feature_test extends \advanced_testcase {
|
||||
$this->assertFalse($communicationprocessor->get_room_provider()->check_room_membership($matrixuserid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test save form data options.
|
||||
*
|
||||
* @covers ::save_form_data
|
||||
*/
|
||||
public function test_save_form_data(): void {
|
||||
$this->resetAfterTest();
|
||||
$course = $this->get_course();
|
||||
|
||||
$communicationprocessor = processor::load_by_instance(
|
||||
'core_course',
|
||||
'coursecommunication',
|
||||
$course->id
|
||||
);
|
||||
|
||||
$course->matrixroomtopic = 'Sampletopicupdated';
|
||||
$communicationprocessor->get_form_provider()->save_form_data($course);
|
||||
|
||||
// Test the updated topic.
|
||||
$matrixroomdata = new matrix_rooms($communicationprocessor->get_id());
|
||||
$this->assertEquals('Sampletopicupdated', $matrixroomdata->get_matrix_room_topic());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -916,4 +916,30 @@ class matrix_communication_test extends \advanced_testcase {
|
||||
$notifications = \core\notification::fetch();
|
||||
$this->assertStringContainsString('Your Matrix room is ready!', $notifications[0]->get_message());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test set provider data from handler.
|
||||
*
|
||||
* @covers ::set_data
|
||||
*/
|
||||
public function test_set_provider_data(): void {
|
||||
$this->resetAfterTest();
|
||||
$course = $this->get_course();
|
||||
$communication = \core_communication\api::load_by_instance(
|
||||
'core_course',
|
||||
'coursecommunication',
|
||||
$course->id
|
||||
);
|
||||
|
||||
// Sample data.
|
||||
$roomname = 'Sampleroom';
|
||||
$provider = 'communication_matrix';
|
||||
|
||||
// Set the data.
|
||||
$communication->set_data($course);
|
||||
|
||||
// Test the set data.
|
||||
$this->assertEquals($roomname, $course->communicationroomname);
|
||||
$this->assertEquals($provider, $course->selectedcommunication);
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ class matrix_rooms_test extends \advanced_testcase {
|
||||
$course = $this->get_course();
|
||||
|
||||
$sampleroomid = 'samplematrixroomid';
|
||||
$sampleroomtopic = 'samplematrixroomtopic';
|
||||
|
||||
// Communication internal api call.
|
||||
$communicationprocessor = processor::load_by_instance(
|
||||
@ -64,9 +65,9 @@ class matrix_rooms_test extends \advanced_testcase {
|
||||
|
||||
// Call matrix room object to create the matrix data.
|
||||
$matrixroom = new \communication_matrix\matrix_rooms($communicationprocessor->get_id());
|
||||
$matrixroom->create_matrix_room_record(
|
||||
$communicationprocessor->get_id(),
|
||||
$matrixroom->update_matrix_room_record(
|
||||
$sampleroomid,
|
||||
$sampleroomtopic
|
||||
);
|
||||
|
||||
// Test the object.
|
||||
@ -92,6 +93,7 @@ class matrix_rooms_test extends \advanced_testcase {
|
||||
$course = $this->get_course();
|
||||
|
||||
$sampleroomid = 'samplematrixroomid';
|
||||
$sampleroomtopic = 'samplematrixroomtopic';
|
||||
|
||||
// Communication internal api call.
|
||||
$communicationprocessor = processor::load_by_instance(
|
||||
@ -102,9 +104,9 @@ class matrix_rooms_test extends \advanced_testcase {
|
||||
|
||||
// Call matrix room object to create the matrix data.
|
||||
$matrixroom = new \communication_matrix\matrix_rooms($communicationprocessor->get_id());
|
||||
$matrixroom->create_matrix_room_record(
|
||||
$communicationprocessor->get_id(),
|
||||
$matrixroom->update_matrix_room_record(
|
||||
$sampleroomid,
|
||||
$sampleroomtopic
|
||||
);
|
||||
|
||||
// Get the record from db.
|
||||
@ -118,6 +120,7 @@ class matrix_rooms_test extends \advanced_testcase {
|
||||
|
||||
$matrixroom->update_matrix_room_record(
|
||||
$sampleroomidupdated,
|
||||
$sampleroomtopic
|
||||
);
|
||||
|
||||
// Test the object.
|
||||
@ -144,6 +147,7 @@ class matrix_rooms_test extends \advanced_testcase {
|
||||
$course = $this->get_course();
|
||||
|
||||
$sampleroomid = 'samplematrixroomid';
|
||||
$sampleroomtopic = 'samplematrixroomtopic';
|
||||
|
||||
// Communication internal api call.
|
||||
$communicationprocessor = processor::load_by_instance(
|
||||
@ -154,9 +158,9 @@ class matrix_rooms_test extends \advanced_testcase {
|
||||
|
||||
// Call matrix room object to create the matrix data.
|
||||
$matrixroom = new \communication_matrix\matrix_rooms($communicationprocessor->get_id());
|
||||
$matrixroom->create_matrix_room_record(
|
||||
$communicationprocessor->get_id(),
|
||||
$matrixroom->update_matrix_room_record(
|
||||
$sampleroomid,
|
||||
$sampleroomtopic
|
||||
);
|
||||
|
||||
// Get the record from db.
|
||||
|
@ -25,6 +25,6 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'communication_matrix';
|
||||
$plugin->version = 2023051900;
|
||||
$plugin->version = 2023060100;
|
||||
$plugin->requires = 2023011300;
|
||||
$plugin->maturity = MATURITY_ALPHA;
|
||||
|
@ -482,6 +482,16 @@ class course_edit_form extends moodleform {
|
||||
// Tweak the form with values provided by custom fields in use.
|
||||
$handler = core_course\customfield\course_handler::create();
|
||||
$handler->instance_form_definition_after_data($mform, empty($courseid) ? 0 : $courseid);
|
||||
|
||||
// Add communication plugins to the form.
|
||||
if (core_communication\api::is_available()) {
|
||||
$communication = \core_communication\api::load_by_instance(
|
||||
'core_course',
|
||||
'coursecommunication',
|
||||
empty($course->id) ? 0 : $course->id
|
||||
);
|
||||
$communication->form_definition_for_provider($mform);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2323,7 +2323,7 @@ function create_course($data, $editoroptions = NULL) {
|
||||
|
||||
// Communication api call.
|
||||
$communication = \core_communication\api::load_by_instance('core_course', 'coursecommunication', $course->id);
|
||||
$communication->create_and_configure_room($selectedcommunication, $communicationroomname, $courseimage);
|
||||
$communication->create_and_configure_room($selectedcommunication, $communicationroomname, $courseimage, $data);
|
||||
}
|
||||
|
||||
// Save custom fields if there are any of them in the form.
|
||||
@ -2506,7 +2506,7 @@ function update_course($data, $editoroptions = NULL) {
|
||||
}
|
||||
}
|
||||
|
||||
$communication->update_room($provider, $communicationroomname, $courseimage);
|
||||
$communication->update_room($provider, $communicationroomname, $courseimage, $data);
|
||||
if ($addafterupdate) {
|
||||
$communication->add_members_to_room($enrolledusers, false);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user