Commit c5881ea3 authored by Robert Lyon's avatar Robert Lyon

Bug 1409546: Adding in the framework module

Installs the framework plugin and add in a basic .maxtrix file

Change-Id: I059ceb523d88894b0b68e3d54dde91f7c441adcc
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 242dbb39
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="2013010705" COMMENT="XMLDB file for Smart Evidence Framework mahara tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="framework">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="institution" TYPE="char" LENGTH="255" NOTNULL="false" DEFAULT="all" />
<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"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="framework_standard">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="framework" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="description" TYPE="text" NOTNULL="false" />
<FIELD NAME="priority" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="mtime" TYPE="datetime" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="frameworkfk" TYPE="foreign" FIELDS="framework" REFTABLE="framework" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="framework_standard_element">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="standard" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="description" TYPE="text" NOTNULL="false" />
<FIELD NAME="priority" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="parent" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="mtime" TYPE="datetime" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="frameworkstandardfk" TYPE="foreign" FIELDS="standard" REFTABLE="framework_standard" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="framework_evidence">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="annotation" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="framework" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="element" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="state" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="reviewer" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="mtime" TYPE="datetime" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="annotationfk" TYPE="foreign" FIELDS="annotation" REFTABLE="block_instance" REFFIELDS="id" />
<KEY NAME="frameworkfk" TYPE="foreign" FIELDS="framework" REFTABLE="framework" REFFIELDS="id" />
<KEY NAME="elementfk" TYPE="foreign" FIELDS="element" REFTABLE="framework_standard_element" REFFIELDS="id" />
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
<KEY NAME="reviewerfk" TYPE="foreign" FIELDS="reviewer" REFTABLE="usr" REFFIELDS="id" />
<KEY NAME="namepluginuk" TYPE="unique" FIELDS="framework, element, view" />
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
\ No newline at end of file
<?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.
*
*/
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
<?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();
/**
* module plugin class. Used for registering the plugin and functions.
*/
class PluginModuleFramework extends PluginModule {
/**
* Is the plugin activated or not?
*
* @return boolean true, if the plugin is activated, otherwise false
*/
public static function is_active() {
$active = false;
if (get_field('module_installed', 'active', 'name', 'framework')) {
$active = true;
}
return $active;
}
/**
* API-Function get the Plugin ShortName
*
* @return string ShortName of the plugin
*/
public static function get_plugin_name() {
return 'framework';
}
public static function postinst($prevversion) {
if ($prevversion < 2016071400) {
// Add foreign key to the collection.framework table on install
log_debug('Add a fireign key on collection.framework to framework.id');
$table = new XMLDBTable('collection');
$field = new XMLDBField('framework');
if (field_exists($table, $field)) {
$key = new XMLDBKey('frameworkfk');
$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();
}
}
}
}
}
/**
* module class
*/
class Framework {
private $id;
private $name;
private $institution;
private $description;
private $selfassess;
private $standards;
const EVIDENCE_BEGUN = 0;
const EVIDENCE_INCOMPLETE = 1;
const EVIDENCE_PARTIALCOMPLETE = 2;
const EVIDENCE_COMPLETED = 3;
public function __construct($id=0, $data=null) {
if (!empty($id)) {
$tempdata = get_record('framework', 'id', $id);
if (empty($tempdata)) {
throw new FrameworkNotFoundException("Framework with id $id not found");
}
if (!empty($data)) {
$data = array_merge((array)$tempdata, $data);
}
else {
$data = $tempdata; // use what the database has
}
$this->id = $id;
}
if (empty($data)) {
$data = array();
}
foreach ((array)$data as $field => $value) {
if (property_exists($this, $field)) {
if (empty($id) && $field === 'standards') {
$value = array('standards' => $value,
'count' => count($value));
}
if ($field == 'selfassess') {
$value = (int) $value;
}
$this->{$field} = $value;
}
}
}
public function get($field) {
if (!property_exists($this, $field)) {
throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this));
}
if ($field == 'standards') {
return $this->standards(false);
}
if ($field == 'standardsoptions') {
return $this->standards();
}
if ($field == 'collections') {
return $this->collections();
}
return $this->{$field};
}
public function set($field, $value) {
if (property_exists($this, $field)) {
$this->{$field} = $value;
$this->mtime = time();
return true;
}
throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this));
}
/**
* Deletes a Framework
*/
public function delete() {
$standards = get_column('framework_standard', 'id', 'framework', $this->id);
db_begin();
delete_records_sql('DELETE FROM {framework_standard_element} WHERE standard IN (' . join(',', array_map('intval', $standards)) . ')');
delete_records('framework_standard', 'framework', $this->id);
delete_records('framework', 'id', $this->id);
db_commit();
}
/**
* This method updates the contents of the
* - framework table
* - framework_standard table (optional based on $this->standards data)
* - framework_standard_element table (optional based on $this->standards data)
*/
public function commit() {
$fordb = new StdClass;
foreach (get_object_vars($this) as $k => $v) {
$fordb->{$k} = $v;
}
db_begin();
// if id is not empty we are editing an existing framework
if (!empty($this->id)) {
update_record('framework', $fordb, 'id');
}
else {
$id = insert_record('framework', $fordb, 'id', true);
if ($id) {
$this->set('id', $id);
}
}
// update standards
$standardsvars = array('shortname','name','description','priority');
if (isset($this->standards) && is_array($this->standards)) {
foreach ($this->standards['standards'] as $standard) {
$sfordb = new StdClass;
$sfordb->framework = $this->id;
$sfordb->mtime = db_format_timestamp(time());
foreach ($standardsvars as $v) {
$sfordb->{$v} = isset($standard->{$v}) ? $standard->{$v} : null;
}
if (!empty($standard->id)) {
update_record('framework_standard', $sfordb, 'id');
}
else {
$sfordb->ctime = db_format_timestamp(time());
$sid = insert_record('framework_standard', $sfordb, 'id', true);
// From .matrix file reading
if (isset($standard->standardelement) && is_array($standard->standardelement)) {
$standard->options = $standard->standardelement;
}
if ($sid && isset($standard->options) && is_array($standard->options)) {
$prevoption = 0;
foreach ($standard->options as $option) {
$sofordb = new StdClass;
$sofordb->standard = $sid;
$sofordb->mtime = db_format_timestamp(time());
foreach ($standardsvars as $ov) {
$sofordb->{$ov} = isset($option->{$ov}) ? $option->{$ov} : null;
}
if (!empty($option->id)) {
$prevoption = $option->id;
update_record('framework_standard', $sofordb, 'id');
}
else {
$sofordb->ctime = db_format_timestamp(time());
$sofordb->parent = ($option->parent && $prevoption) ? $prevoption : null;
$prevoption = insert_record('framework_standard_element', $sofordb, 'id', true);
}
}
}
}
}
}
db_commit();
}
/**
* Returns array of standards in the current framework
*
* @param boolean $options Set to false if you only want the standards without substandard options
* @return array standards
*/
public function standards($options = true) {
if (!isset($this->standards)) {
$sql = "SELECT id, shortname, name, description, priority, ctime, mtime
FROM {framework_standard}
WHERE framework = ?
ORDER BY priority, shortname, name, ctime";
$result = get_records_sql_assoc($sql, array($this->get('id')));
if (!empty($result)) {
if ($options) {
// get all options relating to the standards
$sql = "SELECT id, standard, shortname, name, description, priority, parent, ctime, mtime
FROM {framework_standard_element}
WHERE standard IN (" . join(',', array_map('intval', array_keys($result))) . ")
ORDER BY priority, shortname, name, ctime";
$optresult = get_records_sql_assoc($sql, array());
if ($optresult) {
foreach ($optresult as $opt) {
if (!isset($result[$opt->standard]->options)) {
$result[$opt->standard]->options = array();
}
$result[$opt->standard]->options[] = $opt;
}
}
}
$standards = array(
'standards' => array_values($result),
'count' => count($result),
);
$this->standards = $standards;
}
else {
$this->standards = array();
}
}
return $this->standards;
}
/**
* Check that the framework is being used by a collection
*
* @return boolean
*/
public function in_collections() {
if (empty($this->collections)) {
return false;
}
return true;
}
/**
* Get collections that use the framework
*
* @return object $collections
*/
public function collections() {
require_once('collection.php');
if (!isset($this->collections)) {
$collections = array();
$ids = get_column('collection', 'id', 'framework', $this->id);
foreach ($ids as $id) {
$collection = new Collection($id);
$collections[] = $collection;
}
$this->collections = $collections;
}
return $this->collections;
}
/**
* Get ids of collections that use the framework
*
* @return array $ids
*/
public function get_collectionids() {
$ids = array();
$data = $this->collections();
if (!empty($data)) {
foreach ($data as $c) {
$ids[] = $c->id;
}
}
return $ids;
}
/**
* Return the current state as part of array of all states
*
* @param string $state Current state
*
* @return array All states with current active
*/
public static function get_state_array($state) {
return array(
'begun' => ((int) $state === Self::EVIDENCE_BEGUN),
'incomplete' => ((int) $state === Self::EVIDENCE_INCOMPLETE),
'partialcomplete' => ((int) $state === Self::EVIDENCE_PARTIALCOMPLETE),
'completed' => ((int) $state === Self::EVIDENCE_COMPLETED),
);
}
/**
* Get the evidence state for the framework
*
* @param int $userid
*
* @return outcomes
*/
public function get_evidence() {
$outcomes = get_records_array('framework_evidence', 'framework', $this->id);
return $outcomes;
}
}
class FrameworkNotFoundException extends NotFoundException {}
{"framework":
{"institution":"all",
"name":"SmartEvidence",
"description":"This is the example SmartEvidence matrix",
"selfassess":true,
"standards":
[
{
"shortname":"Professional knowledge 1.",
"name":"Know the students and how they learn",
"description":"",
"priority":1,
"standardelement":
[
{
"shortname":"1.1",
"name":"one point one",
"description":"This is the first sub standard of standard 1",
"priority":1,
"parent":false
},
{
"shortname":"1.2",
"name":"one point two",
"description":"This is the second sub standard of standard 1",
"priority":2,
"parent":false
},
{
"shortname":"1.2.1",
"name":"one point two point one",
"description":"This is the second sub standard of standard 1 with sub clause one",
"priority":3,
"parent":true
},
{
"shortname":"1.3",
"name":"one point three",
"description":"This is the third sub standard of standard 1",
"priority":4,
"parent":false
}
]
},
{
"shortname":"Professional knowledge 2.",
"name":"Know the content and how to teach it",
"description":"Special descritpion for this one",
"priority":2,
"standardelement":
[
{
"shortname":"2.1",
"name":"two point one",
"description":"This is the first sub standard of standard 2",
"priority":1,
"parent":false
},
{
"shortname":"2.2",
"name":"two point two",
"description":"This is the second sub standard of standard 2",
"priority":2,
"parent":false
},
{
"shortname":"2.3",
"name":"two point three",
"description":"This is the third sub standard of standard 2",
"priority":3,
"parent":false
},
{
"shortname":"2.4",
"name":"two point four",
"description":"This is the fourth sub standard of standard 2",
"priority":4,
"parent":false
},
{
"shortname":"2.5",
"name":"two point five",
"description":"This is the fifth sub standard of standard 2",
"priority":5,
"parent":false
},
{
"shortname":"2.6",
"name":"two point six",
"description":"This is the sixth sub standard of standard 2",
"priority":6,
"parent":false
}
]
},
{
"shortname":"Unused standard 1.",
"name":"Will add standardelements later",
"description":"This is an empty standard",
"priority":3
},
{
"shortname":"Professional practice 1.",
"name":"Plan for and implement effective teaching and learning",
"description":"",
"priority":4,
"standardelement":
[
{
"shortname":"4.1",
"name":"four point one",
"description":"This is the first sub standard of standard 4",
"priority":1,
"parent":false
},
{
"shortname":"4.2",
"name":"four point two",
"description":"This is the second sub standard of standard 4",
"priority":2,
"parent":false
}
]
}
]
}
}
\ No newline at end of file
<?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.
*
*/
define('INTERNAL', 1);
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'framework');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'collection.php');
require_once(get_config('libroot') . 'institution.php');