Skip to content
Snippets Groups Projects
Unverified Commit e36edb86 authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Introduced step instance settings

parent 84a61263
No related branches found
No related tags found
No related merge requests found
...@@ -105,6 +105,20 @@ class step_manager extends subplugin_manager { ...@@ -105,6 +105,20 @@ class step_manager extends subplugin_manager {
return $steps; return $steps;
} }
/**
* Gets a specific step instance.
* @param int $instanceid id of the instance
* @return step_subplugin step instance.
*/
public function get_step_instance($instanceid) {
global $DB;
$record = $DB->get_record('tool_cleanupcourses_step', array('id' => $instanceid));
if ($record) {
return step_subplugin::from_record($record);
}
return null;
}
/** /**
* Gets the list of step subplugins. * Gets the list of step subplugins.
* @return array of step subplugins. * @return array of step subplugins.
......
...@@ -37,5 +37,17 @@ ...@@ -37,5 +37,17 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS> </KEYS>
</TABLE> </TABLE>
<TABLE NAME="tool_cleanupcourses_settings" COMMENT="Settings for step instances">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="instanceid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="id of the step instance"/>
<FIELD NAME="name" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" COMMENT="name of the settings field"/>
<FIELD NAME="value" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="value of the setting"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="instanceid_fk" TYPE="foreign" FIELDS="instanceid" REFTABLE="tool_cleanupcourses_step" REFFIELDS="id" COMMENT="Foreignkey for step instance"/>
</KEYS>
</TABLE>
</TABLES> </TABLES>
</XMLDB> </XMLDB>
\ No newline at end of file
...@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die(); ...@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/../lib.php');
class dummy implements base { class dummy extends base {
/** /**
...@@ -47,4 +47,7 @@ class dummy implements base { ...@@ -47,4 +47,7 @@ class dummy implements base {
} }
public function get_subpluginname() {
return 'dummy';
}
} }
...@@ -25,11 +25,12 @@ ...@@ -25,11 +25,12 @@
*/ */
namespace tool_cleanupcourses\step; namespace tool_cleanupcourses\step;
use tool_cleanupcourses\manager\step_manager;
use tool_cleanupcourses\response\step_response; use tool_cleanupcourses\response\step_response;
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
interface base { abstract class base {
/** /**
...@@ -41,6 +42,50 @@ interface base { ...@@ -41,6 +42,50 @@ interface base {
* @param $course object to be processed. * @param $course object to be processed.
* @return step_response * @return step_response
*/ */
public function process_course($course); public abstract function process_course($course);
public abstract function get_subpluginname();
/**
* @return instance_setting[] containing settings keys and PARAM_TYPES
*/
public function instance_settings() {
return array();
}
public function get_settings($instanceid) {
global $DB;
$manager = new step_manager();
$stepinstance = $manager->get_step_instance($instanceid);
if (!$stepinstance || $stepinstance->name !== $this->get_subpluginname()) {
return null;
}
$settingsvalues = array();
foreach ($this->instance_settings() as $setting) {
$record = $DB->get_record('tool_cleanupcourses_settings',
array('instanceid' => $instanceid,
'name' => $setting->name));
if ($record) {
$value = clean_param($record->value, $setting->paramtype);
$settingsvalues[$setting->name] = $value;
}
}
return $settingsvalues;
}
}
class instance_setting {
public $name;
public $paramtype;
public function __construct($name, $paramtype) {
$this->name = $name;
$this->paramtype = $paramtype;
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment