Skip to content
Open
Show file tree
Hide file tree
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
Expand Up @@ -191,8 +191,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.
Expand Down
7 changes: 5 additions & 2 deletions classes/local/form/form_trigger_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,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.
Expand Down
27 changes: 18 additions & 9 deletions classes/local/manager/lib_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -239,11 +239,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;
}

Expand Down
15 changes: 15 additions & 0 deletions classes/local/manager/trigger_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ public static function get_trigger_types() {
$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;
}

Expand Down
60 changes: 60 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

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

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

// Check for the moodle/site:config permission.
Expand Down Expand Up @@ -89,5 +92,62 @@
get_string('config_forum_desc', 'tool_lifecycle'),
null, PARAM_INT));

$triggers = core_component::get_plugin_list('lifecycletrigger');
if ($triggers) {
$settings->add(new admin_setting_heading('lifecycletriggerheader',
get_string('triggers_installed', 'tool_lifecycle'), ''));
foreach ($triggers as $trigger => $path) {
$triggername = html_writer::span(get_string('pluginname', 'lifecycletrigger_' . $trigger),
"font-weight-bold");
$uninstall = '';
if ($trigger == 'sitecourse' || $trigger == 'delayedcourses') {
$uninstall = html_writer::span(' Depracated. Will be removed with version 5.0.', 'text-danger');
}
if ($trigger == 'customfieldsemester') {
$settings->add(new admin_setting_description('lifecycletriggersetting_'.$trigger,
$triggername,
get_string('customfieldsemesterdescription', 'tool_lifecycle')));
} else {
try {
$plugindescription = get_string('plugindescription', 'lifecycletrigger_' . $trigger);
} catch (Exception $e) {
$plugindescription = "";
}
$settings->add(new admin_setting_description('lifecycletriggersetting_'.$trigger,
$triggername,
$plugindescription.$uninstall));
$lib = lib_manager::get_trigger_lib($trigger);
$lib->get_plugin_settings();
}
}
} else {
$settings->add(new admin_setting_heading('adminsettings_notriggers',
get_string('adminsettings_notriggers', 'tool_lifecycle'), ''));
}

$steps = core_component::get_plugin_list('lifecyclestep');
if ($steps) {
$settings->add(new admin_setting_heading('lifecyclestepheader',
get_string('steps_installed', 'tool_lifecycle'), ''));
foreach ($steps as $step => $path) {
$stepname = html_writer::span(get_string('pluginname', 'lifecyclestep_' . $step),
"font-weight-bold");
try {
$plugindescription = get_string('plugindescription', 'lifecyclestep_' . $step);
} catch (Exception $e) {
$plugindescription = "";
}
$settings->add(new admin_setting_description('lifecyclestepsetting_'.$step,
$stepname,
$plugindescription));
$lib = lib_manager::get_step_lib($step);
$lib->get_plugin_settings();
}
} else {
$settings->add(new admin_setting_heading('adminsettings_nosteps',
get_string('adminsettings_nosteps', 'tool_lifecycle'), ''));
}
$settings->add(new admin_setting_description('spacer', "", " "));

$ADMIN->add('tools', $settings);
}
34 changes: 34 additions & 0 deletions step/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,40 @@ public function get_icon() {
public function is_stoppable() {
return false;
}

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

/**
* 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("plugindescription", "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);
}
}
}

/**
Expand Down
16 changes: 8 additions & 8 deletions subplugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/

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

Expand All @@ -50,17 +52,16 @@
echo html_writer::link('https://github.com/learnweb/moodle-tool_lifecycle/wiki/List-of-Installed-Subplugins',
get_string('documentationlink', 'tool_lifecycle'), ['target' => '_blank']);

$triggers = core_component::get_plugin_list('lifecycletrigger');
$triggers = trigger_manager::get_trigger_types();
if ($triggers) {
echo html_writer::div(get_string('triggers_installed', 'tool_lifecycle'), 'h2 mt-2');
foreach ($triggers as $trigger => $path) {
$lib = lib_manager::get_trigger_lib($trigger);
$triggericon = $lib->get_icon();
echo $OUTPUT->pix_icon($triggericon, $trigger, 'moodle', ['class' => 'mr-1']);
echo html_writer::div(get_string('pluginname', 'lifecycletrigger_' . $trigger),
"font-weight-bold d-inline-block");
echo html_writer::div($lib->get_plugin_name(), "font-weight-bold d-inline-block");
try {
$plugindescription = get_string('plugindescription', 'lifecycletrigger_' . $trigger);
$plugindescription = $lib->get_plugin_description();
} catch (Exception $e) {
$plugindescription = "";
}
Expand All @@ -80,17 +81,16 @@
echo html_writer::div(get_string('adminsettings_notriggers', 'tool_lifecycle'));
}

$steps = core_component::get_plugin_list('lifecyclestep');
$steps = step_manager::get_step_types();
if ($steps) {
echo html_writer::div(get_string('steps_installed', 'tool_lifecycle'), 'h2 mt-2');
foreach ($steps as $step => $path) {
$lib = lib_manager::get_step_lib($step);
$stepicon = $lib->get_icon();
echo $OUTPUT->pix_icon($stepicon, $step, 'moodle', ['class' => 'mr-1']);
echo html_writer::div(get_string('pluginname', 'lifecyclestep_' . $step),
"font-weight-bold d-inline-block");
echo html_writer::div($lib->get_plugin_name(), "font-weight-bold d-inline-block");
try {
$plugindescription = get_string('plugindescription', 'lifecyclestep_' . $step);
$plugindescription = $lib->get_plugin_description();
} catch (Exception $e) {
$plugindescription = "";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

namespace tool_samplestep\lifecycle;

use tool_lifecycle\step\interactionlibbase;

/**
* Sample interaction class for lifecycle step plugin.
*
* @package tool_lifecycle
* @copyright 2026 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class interaction extends interactionlibbase {

/**
* Mock method to get the relevant capability for the interaction.
*/
public function get_relevant_capability() {
}

/**
* Mock method to get the action tools for the interaction.
*
* @param \tool_lifecycle\local\entity\process $process
*/
public function get_action_tools($process) {
}

/**
* Mock method to get the status message for the interaction.
*
* @param \tool_lifecycle\local\entity\process $process
* @return string status message
*/
public function get_status_message($process) {
}

/**
* Mock method to get the action string for the interaction.
*
* @param string $action The action being performed.
* @param string $user html-link with username as text that refers to the user profile.
*/
public function get_action_string($action, $user) {
}

/**
* Mock method to handle the interaction.
*
* @param \tool_lifecycle\local\entity\process $process
* @param \tool_lifecycle\local\entity\step_subplugin $step The lifecycle step object.
* @param string $action The action being performed.
*/
public function handle_interaction($process, $step, $action = 'default') {
}
}
Loading