mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-78823 core: Add new events when enabling and disabling qbank plugins
- Loading branch information
1 parent
a1d5d1b
commit b7b932a
Showing
10 changed files
with
255 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?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\event; | ||
|
||
/** | ||
* Question bank plugin event. | ||
* | ||
* This describes an administrative event relating to a question bank plugin, in the system context. | ||
* The pluginname will be stored in the other property, and userid will be the user who performed the action on the plugin. | ||
* | ||
* @package core | ||
* @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net} | ||
* @author Mark Johnson <mark.johnson@catalyst-eu.net> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
abstract class qbank_plugin_base extends base { | ||
|
||
protected function init() { | ||
$this->data['edulevel'] = self::LEVEL_OTHER; | ||
$this->data['crud'] = 'u'; | ||
$this->context = \context_system::instance(); | ||
} | ||
|
||
protected function validate_data() { | ||
if (!str_starts_with($this->data['other']['pluginname'], 'qbank_')) { | ||
throw new \coding_exception('You must provide the full frankenstyle name of a qbank plugin (e.g. qbank_usage)'); | ||
} | ||
} | ||
|
||
/** | ||
* Return an event instance with $this->other['pluginname'] set to the provided plugin name. | ||
* | ||
* @param string $pluginname | ||
* @return base | ||
* @throws \coding_exception | ||
*/ | ||
public static function create_for_plugin(string $pluginname): base { | ||
return self::create([ | ||
'other' => ['pluginname' => $pluginname], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?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\event; | ||
|
||
/** | ||
* Question bank plugin was disabled | ||
* | ||
* @package core | ||
* @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net} | ||
* @author Mark Johnson <mark.johnson@catalyst-eu.net> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class qbank_plugin_disabled extends qbank_plugin_base { | ||
|
||
public static function get_name() { | ||
return get_string('eventqbankdisabled', 'question'); | ||
} | ||
|
||
public function get_description() { | ||
return 'User ' . $this->data['userid'] . ' disabled question bank plugin ' . $this->data['other']['pluginname']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?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\event; | ||
|
||
/** | ||
* Question bank plugin was enabled | ||
* | ||
* @package core | ||
* @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net} | ||
* @author Mark Johnson <mark.johnson@catalyst-eu.net> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class qbank_plugin_enabled extends qbank_plugin_base { | ||
|
||
public static function get_name() { | ||
return get_string('eventqbankenabled', 'question'); | ||
} | ||
|
||
public function get_description() { | ||
return 'User ' . $this->data['userid'] . ' enabled question bank plugin ' . $this->data['other']['pluginname']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
question/bank/columnsortorder/classes/event/plugin_observer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/>. | ||
|
||
namespace qbank_columnsortorder\event; | ||
|
||
use core\event\qbank_plugin_disabled; | ||
use core\event\qbank_plugin_enabled; | ||
use qbank_columnsortorder\column_manager; | ||
|
||
/** | ||
* Observer for qbank plugin enabled/disabled events | ||
* | ||
* @package qbank_columnsortorder | ||
* @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net} | ||
* @author Mark Johnson <mark.johnson@catalyst-eu.net> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class plugin_observer { | ||
|
||
/** | ||
* When a plugin is enabled, enable its columns. | ||
* | ||
* @param qbank_plugin_enabled $event | ||
* @return void | ||
*/ | ||
public static function plugin_enabled(qbank_plugin_enabled $event): void { | ||
(new column_manager())->enable_columns($event->other['pluginname']); | ||
} | ||
|
||
/** | ||
* When a plugin is disabled, disable its columns. | ||
* | ||
* @param qbank_plugin_disabled $event | ||
* @return void | ||
*/ | ||
public static function plugin_disabled(qbank_plugin_disabled $event): void { | ||
(new column_manager())->disable_columns($event->other['pluginname']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Event observer registration | ||
* | ||
* @package qbank_columnsortorder | ||
* @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net} | ||
* @author Mark Johnson <mark.johnson@catalyst-eu.net> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
$observers = [ | ||
[ | ||
'eventname' => '\core\event\qbank_plugin_enabled', | ||
'callback' => '\qbank_columnsortorder\event\plugin_observer::plugin_enabled', | ||
], | ||
[ | ||
'eventname' => '\core\event\qbank_plugin_disabled', | ||
'callback' => '\qbank_columnsortorder\event\plugin_observer::plugin_disabled', | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters