Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

issue#178 refactor subplugins calls #189

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions classes/local/form/form_step_instance.php
Original file line number Diff line number Diff line change
@@ -161,8 +161,11 @@ public function definition_after_data() {
$mform->setDefault('id', '');
$subpluginname = $this->subpluginname;
}
$mform->setDefault('subpluginnamestatic',
get_string('pluginname', 'lifecyclestep_' . $subpluginname));

if (isset($this->lib)) {
$mform->setDefault('subpluginnamestatic', $this->lib->get_plugin_description());
}

$mform->setDefault('subpluginname', $subpluginname);

// Setting the default values for the local step settings.
7 changes: 5 additions & 2 deletions classes/local/form/form_trigger_instance.php
Original file line number Diff line number Diff line change
@@ -162,8 +162,11 @@ public function definition_after_data() {
$mform->setDefault('id', $this->trigger->id);
$mform->setDefault('instancename', $this->trigger->instancename);
}
$mform->setDefault('subpluginnamestatic',
get_string('pluginname', 'lifecycletrigger_' . $this->subpluginname));

if (isset($this->lib)) {
$mform->setDefault('subpluginnamestatic', $this->lib->get_plugin_description());
}

$mform->setDefault('subpluginname', $this->subpluginname);

// Setting the default values for the local trigger settings.
27 changes: 18 additions & 9 deletions classes/local/manager/lib_manager.php
Original file line number Diff line number Diff line change
@@ -102,18 +102,27 @@ public static function get_step_interactionlib($subpluginname) {
* @return null|base|libbase
*/
private static function get_lib($subpluginname, $subplugintype, $libsubtype = '') {
// Plugins defined in subplugins.json file.
$triggerlist = \core_component::get_plugin_list('lifecycle' . $subplugintype);
if (!array_key_exists($subpluginname, $triggerlist)) {
return null;
}
$filename = $triggerlist[$subpluginname].'/'.$libsubtype.'lib.php';
if (file_exists($filename)) {
require_once($filename);
$extendedclass = "tool_lifecycle\\$subplugintype\\$libsubtype$subpluginname";
if (class_exists($extendedclass)) {
return new $extendedclass();
if (array_key_exists($subpluginname, $triggerlist)) {
$filename = $triggerlist[$subpluginname].'/'.$libsubtype.'lib.php';
if (file_exists($filename)) {
require_once($filename);
$extendedclass = "tool_lifecycle\\$subplugintype\\$libsubtype$subpluginname";
if (class_exists($extendedclass)) {
return new $extendedclass();
}
}
}

// Plugins defined under "lifecycle" name space.
// The base class has already been checked by get_trigger_types or get_steps_types.
$classname = !$libsubtype ? $subplugintype : $libsubtype;
$classname = "$subpluginname\\lifecycle\\$classname";
if (class_exists($classname)) {
return new $classname();
}

return null;
}
}
16 changes: 16 additions & 0 deletions classes/local/manager/step_manager.php
Original file line number Diff line number Diff line change
@@ -228,11 +228,27 @@ public static function get_step_instances_by_subpluginname($subpluginname) {
* @throws \coding_exception
*/
public static function get_step_types() {
// Sub plugins in 'step' folder.
$subplugins = \core_component::get_plugin_list('lifecyclestep');
$result = [];
foreach (array_keys($subplugins) as $plugin) {
$result[$plugin] = get_string('pluginname', 'lifecyclestep_' . $plugin);
}

// Additional sub plugins defined under "lifecycle" name space, ie "local_newstep\lifecycle".
// The class name must be step (step.php) and placed under "classes/lifecycle" folder.
// The name space must be "local_newstep\lifecycle"
// The "local_newstep\lifecycle\step" class must extend the step base classes.
foreach (array_keys(\core_component::get_plugin_types()) as $plugintype) {
$potentialsteps = \core_component::get_plugin_list_with_class($plugintype, 'lifecycle\\step');
foreach ($potentialsteps as $plugin => $potentialstep) {
// Check if it implements the step base class.
if (is_a($potentialstep, \tool_lifecycle\step\libbase::class, true)) {
$result[$plugin] = get_string('pluginname', $plugin);
}
}
}

return $result;
}

15 changes: 15 additions & 0 deletions classes/local/manager/trigger_manager.php
Original file line number Diff line number Diff line change
@@ -241,6 +241,21 @@ public static function get_trigger_types() {
foreach (array_keys($subplugins) as $plugin) {
$result[$plugin] = get_string('pluginname', 'lifecycletrigger_' . $plugin);
}

// Additional sub plugins defined under "lifecycle" name space, ie "local_newtrigger\lifecycle".
// The class name must be trigger (trigger.php) and placed under "classes/lifecycle" folder.
// The name space must be "local_newtrigger\lifecycle"
// The "local_newtrigger\lifecycle\trigger" class must extend the trigger base classes (base_automatic or base_manual).
foreach (array_keys(\core_component::get_plugin_types()) as $plugintype) {
$potentialtriggers = \core_component::get_plugin_list_with_class($plugintype, 'lifecycle\\trigger');
foreach ($potentialtriggers as $plugin => $potentialtrigger) {
// Check if it implements the trigger base class.
if (is_a($potentialtrigger, \tool_lifecycle\trigger\base::class, true)) {
$result[$plugin] = get_string('pluginname', $plugin);
}
}
}

return $result;
}

26 changes: 13 additions & 13 deletions settings.php
Original file line number Diff line number Diff line change
@@ -21,6 +21,11 @@
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use tool_lifecycle\local\manager\lib_manager;
use tool_lifecycle\local\manager\step_manager;
use tool_lifecycle\local\manager\trigger_manager;

defined('MOODLE_INTERNAL') || die;

if ($hassiteconfig) {
@@ -68,21 +73,16 @@
new moodle_url('/admin/tool/lifecycle/errors.php')));

if ($ADMIN->fulltree) {
$triggers = core_component::get_plugin_list('lifecycletrigger');
foreach ($triggers as $trigger => $path) {
if (file_exists($settingsfile = $path . '/settings.php')) {
$settings->add(new admin_setting_heading('lifecycletriggersetting'.$trigger,
get_string('trigger', 'tool_lifecycle') .
' - ' . get_string('pluginname', 'lifecycletrigger_' . $trigger), ''));
include($settingsfile);
}
$triggers = trigger_manager::get_trigger_types();
foreach ($triggers as $id => $trigger) {
$lib = lib_manager::get_trigger_lib($id);
$lib->get_plugin_settings();
}
}

$steps = core_component::get_plugin_list('lifecyclestep');
foreach ($steps as $step => $path) {
if (file_exists($settingsfile = $path . '/settings.php')) {
include($settingsfile);
}
$steps = step_manager::get_step_types();
foreach ($steps as $id => $step) {
$lib = lib_manager::get_step_lib($id);
$lib->get_plugin_settings();
}
}
24 changes: 23 additions & 1 deletion step/lib.php
Original file line number Diff line number Diff line change
@@ -142,6 +142,29 @@ public function extend_add_instance_form_definition_after_data($mform, $settings
public function abort_course($process) {
}

/**
* Define description of the step.
* Allow subplugins to have custom description.
*
* @return string description of the trigger.
*/
public function get_plugin_description() {
return get_string("pluginname", "lifecyclestep_" . $this->get_subpluginname());
}

/**
* Returns the settings of the step.
*
* @return void
*/
public function get_plugin_settings() {
$step = $this->get_subpluginname();
$file = __DIR__ . "/$step/settings.php";

if (file_exists($file)) {
include($file);
}
}

/**
* Ensure validity of settings upon backup restoration.
@@ -151,7 +174,6 @@ public function abort_course($process) {
public function ensure_validity(array $settings): array {
return [];
}

}

/**
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace tool_samplestep\lifecycle;

global $CFG;
require_once($CFG->dirroot . '/admin/tool/lifecycle/step/interactionlib.php');

use tool_lifecycle\step\interactionlibbase;

defined('MOODLE_INTERNAL') || die();

class interaction extends interactionlibbase {

public function get_relevant_capability()
{
}

public function get_action_tools($process)
{
}

public function get_status_message($process)
{
}

public function get_action_string($action, $user)
{
}

public function handle_interaction($process, $step, $action = 'default')
{
}
}
27 changes: 27 additions & 0 deletions tests/fixtures/fakeplugins/samplestep/classes/lifecycle/step.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace tool_samplestep\lifecycle;

global $CFG;
require_once($CFG->dirroot . '/admin/tool/lifecycle/step/lib.php');

use tool_lifecycle\step\libbase;

defined('MOODLE_INTERNAL') || die();

class step extends libbase {
public function get_subpluginname()
{
return 'sample step';
}

public function get_plugin_description() {
return "Sample step plugin";
}

public function process_course($processid, $instanceid, $course)
{
return null;
}

}
38 changes: 38 additions & 0 deletions tests/fixtures/fakeplugins/samplestep/classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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 tool_samplestep\privacy;

use core_privacy\local\metadata\null_provider;

/**
* Privacy subsystem implementation for tool_samplestep.
*
* @package tool_samplestep
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string the reason
*/
public static function get_reason() : string {
return 'privacy:metadata';
}
}
18 changes: 18 additions & 0 deletions tests/fixtures/fakeplugins/samplestep/lang/en/tool_samplestep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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/>.

$string['pluginname'] = 'Sample step';
$string['privacy:metadata'] = 'The plugin does not store any personal data.';
28 changes: 28 additions & 0 deletions tests/fixtures/fakeplugins/samplestep/version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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/>.

/**
* Fake component for testing
*
* @package core
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023100400;
$plugin->requires = 2022041200;
$plugin->component = 'tool_samplestep';
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace tool_sampletrigger\lifecycle;

global $CFG;
require_once($CFG->dirroot . '/admin/tool/lifecycle/trigger/lib.php');

use tool_lifecycle\trigger\base_automatic;

defined('MOODLE_INTERNAL') || die();

class trigger extends base_automatic {

public function get_subpluginname()
{
return 'sample trigger';
}

public function get_plugin_description() {
return "Sample trigger";
}

public function check_course($course, $triggerid)
{
return null;
}

}
Loading