Commit 32f76d8e authored by Robert Lyon's avatar Robert Lyon

Bug 1409546: Adding an 'active' column to framework db

So we can make a framework inactive if needed.
Active by default

Also can now delete empty framework

Fixed up behat uninstall as well so that it uninstalls module.framework
correctly

Change-Id: I764f43a27c1bf0cbfcf3f3ea22d0dd74f9a1e6be
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent c46b241f
......@@ -12,6 +12,7 @@
defined('INTERNAL') || die();
// General form strings
$string['active'] = 'Active';
$string['add'] = 'Add';
$string['addone'] = 'Add one';
$string['cancel'] = 'Cancel';
......
......@@ -606,7 +606,13 @@ class Collection {
}
safe_require('module','framework');
$frameworks = Framework::get_frameworks($institution->name, true);
// Inactive frameworks are only allowed if they were added to
// collection when they were active.
foreach ($frameworks as $key => $framework) {
if (empty($framework->active) && $framework->id != $this->framework) {
unset ($frameworks[$key]);
}
}
return $frameworks;
}
......
......@@ -11,6 +11,7 @@
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="description" TYPE="text" NOTNULL="false" />
<FIELD NAME="selfassess" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0"/>
<FIELD NAME="active" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
defined('INTERNAL') || die();
function xmldb_module_framework_upgrade($oldversion=0) {
if ($oldversion < 2016081900) {
log_debug('Adding "active" column to "framework" table');
$table = new XMLDBTable('framework');
$field = new XMLDBField('active');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
add_field($table, $field);
}
return true;
}
<?php
/**
*
* @package mahara
* @subpackage module-framework
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('module', 'framework');
global $USER;
if (!is_plugin_active('framework', 'module')) {
json_reply(true, get_string('needtoactivate', 'module.framework'));
}
if (!$USER->get('admin')) {
json_reply(true, get_string('accessdenied'));
}
else {
form_validate(param_variable('sesskey', null));
$id = param_integer('id');
$enabledval = param_alphanum('enabled', false);
$enabled = ($enabledval == 'on' || $enabledval == 1) ? 1 : 0;
// need to update the active status
if (set_field('framework', 'active', $enabled, 'id', $id)) {
json_reply(false, array('data' => array('ok' => true)));
}
}
<?php
/**
*
* @package mahara
* @subpackage module-framework
* @author Catalyst IT Ltd.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configextensions/frameworks');
define('SECTION_PLUGINTYPE', 'module');
define('SECTION_PLUGINNAME', 'framework');
define('SECTION_PAGE', 'frameworks');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('Framework', 'module.framework'));
safe_require('module', 'framework');
$frameworks = Framework::list_frameworks();
function framework_delete_submit(Pieform $form, $values) {
global $SESSION;
$framework = new Framework($values['framework']);
if (!$framework->in_collections()) {
$framework->delete();
$SESSION->add_ok_msg(get_string('itemdeleted'));
}
else {
$SESSION->add_error_msg(get_string('deletefailed', 'admin'));
}
redirect('/module/framework/frameworks.php');
}
$smarty = smarty();
setpageicon($smarty, 'icon-th');
$smarty->assign('frameworks', $frameworks);
$smarty->assign('wwwroot', get_config('wwwroot'));
$smarty->display('module:framework:frameworks.tpl');
......@@ -12,9 +12,13 @@
defined('INTERNAL') || die();
$string['Framework'] = 'SmartEvidence framework';
$string['Frameworks'] = 'SmartEvidence frameworks';
$string['frameworks'] = 'Installed frameworks';
$string['frameworkdesc'] = 'Choose the competency framework that you want to associate with your portfolio.';
$string['frameworksdesc'] = 'List of frameworks that are installed in the system. Inactive frameworks are not able to be chosen for collections unless the collection is already associated with the framework when it was active.';
$string['taskscompleted'] = 'Tasks completed';
$string['addpages'] = 'Add more pages to this collection if you want them to show up here in the SmartEvidence map.';
$string['addframework'] = 'Add framework';
$string['matrixfile'] = 'Matrix file';
$string['matrixfiledesc'] = 'The .matrix file containing the JSON encoded matrix framework';
$string['notvalidmatrixfile'] = 'Not a valid matrix file';
......@@ -36,3 +40,4 @@ $string['begun'] = 'Ready for assessment';
$string['incomplete'] = 'Doesn\'t meet the standard';
$string['partialcomplete'] = 'Partially meets the standard';
$string['completed'] = 'Meets the standard';
$string['usedincollections'] = 'Used in collections';
......@@ -149,6 +149,28 @@ class PluginModuleFramework extends PluginModule {
public static function save_config_options(Pieform $form, $values) {
self::add_matrix_to_db($values['matrix']['tmp_name']);
}
public static function admin_menu_items() {
if (!is_plugin_active('framework', 'module')) {
return array();
}
$map = array(
'configextensions/frameworks' => array(
'path' => 'configextensions/frameworks',
'url' => 'module/framework/frameworks.php',
'title' => get_string('Frameworks', 'module.framework'),
'weight' => 50,
),
);
if (defined('MENUITEM') && isset($map[MENUITEM])) {
$map[MENUITEM]['selected'] = true;
}
return $map;
}
}
/**
......@@ -161,6 +183,7 @@ class Framework {
private $institution;
private $description;
private $selfassess;
private $active = 1; // active by default
private $standards;
const EVIDENCE_BEGUN = 0;
......@@ -193,7 +216,7 @@ class Framework {
$value = array('standards' => $value,
'count' => count($value));
}
if ($field == 'selfassess') {
if ($field == 'selfassess' || $field == 'active') {
$value = (int) $value;
}
$this->{$field} = $value;
......@@ -409,7 +432,7 @@ class Framework {
if (!empty($data)) {
foreach ($data as $c) {
$ids[] = $c->id;
$ids[] = $c->get('id');
}
}
......@@ -810,6 +833,61 @@ class Framework {
Self::EVIDENCE_COMPLETED => get_string('completed','module.framework'),
);
}
public static function list_frameworks() {
$frameworks = Self::get_frameworks('any');
if ($frameworks) {
foreach ($frameworks as $framework) {
$framework->activationswitch = pieform(
array(
'name' => 'framework' . $framework->id,
'successcallback' => 'framework_update_submit',
'renderer' => 'div',
'class' => 'form-inline pull-left framework',
'jsform' => false,
'checkdirtychange' => false,
'elements' => array(
'plugintype' => array('type' => 'hidden', 'value' => 'module'),
'pluginname' => array('type' => 'hidden', 'value' => 'framework'),
'id' => array('type' => 'hidden', 'value' => $framework->id),
'enabled' => array(
'type' => 'switchbox',
'value' => $framework->active,
),
),
)
);
$fk = new Framework($framework->id);
$framework->collections = count($fk->get_collectionids());
$framework->delete = false;
if (empty($framework->collections)) {
$framework->delete = pieform(
array(
'name' => 'framework_delete_' . $framework->id,
'successcallback' => 'framework_delete_submit',
'renderer' => 'div',
'class' => 'form-inline form-as-button pull-right framework',
'elements' => array(
'submit' => array(
'type' => 'button',
'class' => 'btn-default btn-sm',
'usebuttontag' => true,
'value' => '<span class="icon icon-trash icon-lg text-danger" role="presentation" aria-hidden="true"></span><span class="sr-only">'. get_string('delete') . '</span>',
'confirm' => get_string('confirmdeletemenuitem', 'admin'),
),
'framework' => array(
'type' => 'hidden',
'value' => $framework->id,
)
),
)
);
}
}
return $frameworks;
}
return false;
}
}
class FrameworkNotFoundException extends NotFoundException {}
......@@ -12,6 +12,6 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2016071400;
$config->release = '1.0.0';
$config->version = 2016081900;
$config->release = '1.0.1';
......@@ -702,6 +702,11 @@ abstract class TestingUtil {
log_info("Uninstalling $plugintype.$pluginname");
$location = get_config('docroot') . $pluginpath . DIRECTORY_SEPARATOR . 'db';
if (is_readable($location . DIRECTORY_SEPARATOR . 'install.xml')) {
if ($plugintype == 'module' && $pluginname == 'framework') {
// This module has a core collection.framework as a foreign key
execute_sql('UPDATE {collection} SET framework = null');
execute_sql('ALTER TABLE {collection} DROP CONSTRAINT {coll_fra_fk}');
}
uninstall_from_xmldb_file($location . DIRECTORY_SEPARATOR . 'install.xml');
}
}
......
{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">
<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>
</div>
<h4>{str tag="frameworks" section="module.framework"}</h4>
<p class="lead">{str tag="frameworksdesc" section="module.framework"}</p>
<table class="listing table table-striped text-small">
<thead>
<tr>
<th>{str tag="name"}</th>
<th>{str tag="usedincollections" section="module.framework"}</th>
<th>{str tag="active"}</th>
</tr>
</thead>
<tbody>
{foreach from=$frameworks key=k item=item}
<tr>
<td>{$item->name}</td>
<td>{$item->collections}</td>
<td class="buttonscell framework">{$item->activationswitch|safe}
<script type="application/javascript">
jQuery('#framework{$item->id}_enabled').on('change', function() {
// save switch
jQuery.post(config.wwwroot + 'module/framework/frameworks.json.php', jQuery('#framework{$item->id}').serialize())
.done(function(data) {
console.log(data);
});
});
</script>
{$item->delete|safe}</td>
</tr>
{/foreach}
</tbody>
</table>
{include file="footer.tpl"}
......@@ -60,4 +60,12 @@
position: absolute;
}
}
}
.listing {
.buttonscell {
&.framework {
width: 125px;
}
}
}
\ No newline at end of file
......@@ -39,6 +39,10 @@ Scenario: Installing framework module and activating for an institution
And I press "Save"
Then I should see "Settings saved"
# Check that we have new framework
And I choose "SmartEvidence frameworks" in "Extensions"
Then I should see "SmartEvidence example"
# Activate smartevidence in an institution
And I choose "Institutions" in "Institutions"
And I click on "Edit" in "No Institution" row
......
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