Commit 9ac1591c authored by Robert Lyon's avatar Robert Lyon

Bug 1409546: Plugin config option to install a .maxtrix file

After the plugin is installed

Change-Id: Id936e7a45ec4766220d34456d4c63a5b9ad1d57d
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent c5881ea3
......@@ -13,4 +13,7 @@ defined('INTERNAL') || die();
$string['accessdeniedsmartevidencenotallowed'] = 'SmartEvidence needs to be enabled for the institution "%s".';
$string['taskscompleted'] = 'Tasks completed';
$string['addpages'] = 'Add more pages to this collection if you want them to show up here in the SmartEvidence map.';
\ No newline at end of file
$string['addpages'] = 'Add more pages to this collection if you want them to show up here in the SmartEvidence map.';
$string['matrixname'] = 'Name of matrix file';
$string['matrixnamedesc'] = 'The name of the matrix file that you have added to the "module/framework/matrices/" directory';
$string['errorbadmatrixname'] = 'Unable to find the matrix file';
\ No newline at end of file
......@@ -48,24 +48,67 @@ class PluginModuleFramework extends PluginModule {
$key->setAttributes(XMLDB_KEY_FOREIGN, array('framework'), 'framework', array('id'));
add_key($table, $key);
}
// Add in any smart evidence framework data to the framework tables
// based on any existing .matrix files in the matricies directory
$files = glob(get_config('docroot') . 'module/framework/matrices/*.matrix');
foreach ($files as $file) {
$matrix = file_get_contents($file);
$content = json_decode($matrix);
if (!$content || empty($content->framework) || empty($content->framework->name)) {
log_debug($file . ' is not a valid JSON file');
}
else {
safe_require('module', 'framework');
$framework = new Framework(null, $content->framework);
$framework->commit();
}
self::add_matrix_to_db($file);
}
}
}
private function add_matrix_to_db($filename) {
if (substr_count($filename, '/') == 0) {
$filename = get_config('docroot') . 'module/framework/matrices/' . $filename;
}
$matrix = file_get_contents($filename);
$content = json_decode($matrix);
if (!$content || empty($content->framework) || empty($content->framework->name)) {
log_warn($file . ' is not a valid JSON file');
return false;
}
else {
safe_require('module', 'framework');
$framework = new Framework(null, $content->framework);
$framework->commit();
}
}
public static function has_config() {
return true;
}
public static function get_config_options() {
$elements = array(
'matrix' => array(
'type' => 'text',
'size' => 50,
'title' => get_string('matrixname', 'module.framework'),
'rules' => array(
'required' => true,
),
'description' => get_string('matrixnamedesc', 'module.framework'),
)
);
return array(
'elements' => $elements,
);
}
public static function validate_config_options(Pieform $form, $values) {
if (empty($values['matrix']) ||
preg_match("/\.matrix$/", $values['matrix']) === 0 ||
!file_exists(get_config('docroot') . 'module/framework/matrices/' . $values['matrix'])
) {
$form->set_error('matrix', get_string('errorbadmatrixname', 'module.framework'));
}
}
public static function save_config_options(Pieform $form, $values) {
self::add_matrix_to_db($values['matrix']);
}
}
/**
......
......@@ -11,3 +11,8 @@ Scenario: Installing framework module
Then I should see "Hide" in the "form#activate_module_framework" "css_element"
# Also make sure the annotation blocktype plugin is active
And I press "Show" in the "form#activate_blocktype_annotation" "css_element"
# Make sure we have a matrix config form
And I scroll to the base of id "module.framework"
And I follow "Configuration for module framework"
Then I should see "Name of matrix file"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment