Commit d68b1537 authored by Robert Lyon's avatar Robert Lyon

Bug 1625861: Moving the upload form off the plugin config system

And moving it to the Admin -> Exntension -> SmartEvidence page

Change-Id: I897d45398e34b456640001392ce143d8c6865c58
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
(cherry picked from commit 805752b5)
parent d355e86d
......@@ -20,6 +20,19 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('Framework', 'module.framework'));
safe_require('module', 'framework');
$upload = param_boolean('upload');
if ($upload) {
define('SUBSECTIONHEADING', get_string('upload'));
$form = upload_matrix_form();
$smarty = smarty();
setpageicon($smarty, 'icon-th');
$smarty->assign('wwwroot', get_config('wwwroot'));
$smarty->assign('form', $form);
$smarty->display('module:framework:uploadframework.tpl');
exit;
}
$frameworks = Framework::get_frameworks('any');
if ($frameworks) {
foreach ($frameworks as $framework) {
......
......@@ -43,3 +43,5 @@ $string['partialcomplete'] = 'Partially meets the standard';
$string['completed'] = 'Meets the standard';
$string['usedincollections'] = 'Used in collections';
$string['selfassess'] = 'Self-assess';
$string['uploadframeworkdesc'] = 'Upload a JSON encoded .matrix file. See <a href="https://git.mahara.org/mahara/mahara/blob/master/test/behat/upload_files/example.matrix">Mahara git repository</a> for an example of the markup.';
$string['savematrix'] = 'Upload matrix';
......@@ -107,7 +107,7 @@ class PluginModuleFramework extends PluginModule {
return $ok;
}
private function add_matrix_to_db($filename) {
public function add_matrix_to_db($filename) {
if (substr_count($filename, '/') == 0) {
$filename = get_config('docroot') . 'module/framework/matrices/' . $filename;
}
......@@ -122,47 +122,7 @@ class PluginModuleFramework extends PluginModule {
}
public static function has_config() {
return true;
}
public static function get_config_options() {
$elements = array(
'matrix' => array(
'type' => 'file',
'title' => get_string('matrixfile', 'module.framework'),
'description' => get_string('matrixfiledesc', 'module.framework'),
'accept' => '.matrix',
'rules' => array(
'required' => true
)
),
);
return array(
'elements' => $elements,
);
}
public static function validate_config_options(Pieform $form, $values) {
require_once('uploadmanager.php');
$um = new upload_manager('matrix');
if ($error = $um->preprocess_file()) {
$form->set_error('matrix', $error);
}
$reqext = ".matrix";
$fileext = substr($values['matrix']['name'], (-1 * strlen($reqext)));
if ($fileext !== $reqext) {
$form->set_error('matrix', get_string('notvalidmatrixfile', 'module.framework'));
}
$matrixfile = self::matrix_is_valid_json($um->file['tmp_name']);
if ($matrixfile['error']) {
$form->set_error('matrix', $matrixfile['message']);
}
}
public static function save_config_options(Pieform $form, $values) {
self::add_matrix_to_db($values['matrix']['tmp_name']);
return false;
}
public static function admin_menu_items() {
......@@ -1008,3 +968,61 @@ class Framework {
}
class FrameworkNotFoundException extends NotFoundException {}
/**
* The functions for verifying/saving the matrix upload
*/
function upload_matrix_form() {
$elements = array(
'matrix' => array(
'type' => 'file',
'title' => get_string('matrixfile', 'module.framework'),
'description' => get_string('matrixfiledesc', 'module.framework'),
'accept' => '.matrix',
'rules' => array(
'required' => true
)
),
'submit' => array(
'type' => 'submitcancel',
'class' => 'btn-primary',
'value' => array(get_string('savematrix','module.framework'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'module/framework/frameworks.php',
)
);
$form = array(
'name' => 'matrixupload',
'plugintype' => 'module',
'pluginname' => 'framework',
'validatecallback' => 'validate_matrixupload',
'successcallback' => 'matrixupload_submit',
'elements' => $elements,
);
return pieform($form);
}
function validate_matrixupload(Pieform $form, $values) {
require_once('uploadmanager.php');
$um = new upload_manager('matrix');
if ($error = $um->preprocess_file()) {
$form->set_error('matrix', $error);
}
$reqext = ".matrix";
$fileext = substr($values['matrix']['name'], (-strlen($reqext)));
if ($fileext !== $reqext) {
$form->set_error('matrix', get_string('notvalidmatrixfile', 'module.framework'));
}
$matrixfile = PluginModuleFramework::matrix_is_valid_json($um->file['tmp_name']);
if ($matrixfile['error']) {
$form->set_error('matrix', $matrixfile['message']);
}
}
function matrixupload_submit(Pieform $form, $values) {
PluginModuleFramework::add_matrix_to_db($values['matrix']['tmp_name']);
redirect(get_config('wwwroot') . 'module/framework/frameworks.php');
}
{include file="header.tpl"}
<div class="btn-group btn-group-top only-button">
<a class="btn btn-default btn-group-item pull-left" href="{$wwwroot}admin/extensions/pluginconfig.php?plugintype=module&pluginname=framework">
<a class="btn btn-default btn-group-item pull-left" href="{$wwwroot}module/framework/frameworks.php?upload=1">
<span class="icon icon-plus icon-lg left" role="presentation" aria-hidden="true"></span>
<span class="btn-title">{str tag="addframework" section="module.framework"}</span>
</a>
......
{include file="header.tpl"}
<p>{str tag="uploadframeworkdesc" section="module.framework"}</p>
{$form|safe}
{include file="footer.tpl"}
......@@ -40,14 +40,12 @@ Scenario: Installing framework module and activating for an institution
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 smartevidence"
And I choose "SmartEvidence" in "Extensions"
And I follow "Add framework"
And I attach the file "example.matrix" to "Matrix file"
And I press "Save"
Then I should see "Settings saved"
And I press "Upload matrix"
# Check that we have new framework
And I choose "SmartEvidence" in "Extensions"
Then I should see "Title of your framework"
# Activate smartevidence in an institution
......
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