Commit e171a342 authored by Robert Lyon's avatar Robert Lyon

Bug 1409546: Fixes for issues found in the earlier patches

Should be code changes only

behatnotneeded

Change-Id: Ie0a35a8cf54d3f19b6875022a3f6a9f30de1cbd3
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 956625b9
......@@ -47,8 +47,8 @@ foreach (array_keys($plugins) as $plugin) {
$plugins[$plugin]['installed'][$key] = array(
'active' => $i->active,
'disableable' => call_static_method($classname, 'can_be_disabled'),
'deprecated' => method_exists($classname, 'is_deprecated') ? call_static_method($classname, 'is_deprecated') : 0,
'name' => method_exists($classname, 'get_plugin_name') ? call_static_method($classname, 'get_plugin_name') : null,
'deprecated' => call_static_method($classname, 'is_deprecated'),
'name' => call_static_method($classname, 'get_plugin_display_name'),
);
if ($plugins[$plugin]['installed'][$key]['disableable'] || !$i->active) {
$plugins[$plugin]['installed'][$key]['activateform'] = activate_plugin_form($plugin, $i);
......@@ -102,10 +102,8 @@ foreach (array_keys($plugins) as $plugin) {
validate_plugin($plugin, $dir);
$classname = generate_class_name($plugin, $dir);
$classname::sanity_check();
if (method_exists($classname, 'get_plugin_name')) {
$name = call_static_method($classname, 'get_plugin_name');
$plugins[$plugin]['notinstalled'][$dir]['name'] = $name;
}
$name = call_static_method($classname, 'get_plugin_display_name');
$plugins[$plugin]['notinstalled'][$dir]['name'] = $name;
}
catch (InstallationException $e) {
$plugins[$plugin]['notinstalled'][$dir]['notinstallable'] = $e->GetMessage();
......
......@@ -262,7 +262,6 @@ if ($institution || $add) {
$sitename = get_config('sitename');
safe_require('artefact', 'internal');
safe_require('module', 'framework');
$elements = array(
'add' => array(
'type' => 'hidden',
......@@ -529,8 +528,8 @@ if ($institution || $add) {
'type' => 'switchbox',
'title' => get_string('allowinstitutionsmartevidence', 'admin'),
'description' => get_string('allowinstitutionsmartevidencedescription','admin'),
'defaultvalue' => PluginModuleFramework::is_active() && $data->allowinstitutionsmartevidence,
'disabled' => PluginModuleFramework::is_active() == false,
'defaultvalue' => is_plugin_active('framework', 'module') && $data->allowinstitutionsmartevidence,
'disabled' => is_plugin_active('framework', 'module') == false,
'help' => true,
);
$elements['lockedfields'] = array(
......@@ -706,8 +705,7 @@ function institution_validate(Pieform $form, $values) {
if (!empty($values['lang']) && $values['lang'] != 'sitedefault' && !array_key_exists($values['lang'], get_languages())) {
$form->set_error('lang', get_string('institutionlanginvalid', 'admin'));
}
safe_require('module', 'framework');
if (!PluginModuleFramework::is_active() && (!empty($values['allowinstitutionsmartevidence']))) {
if (!is_plugin_active('framework', 'module') && (!empty($values['allowinstitutionsmartevidence']))) {
$form->set_error('allowinstitutionsmartevidence', get_string('institutionsmartevidencenotallowed', 'admin'));
}
......
......@@ -236,7 +236,7 @@ class PluginBlocktypeAnnotation extends MaharaCoreBlocktype {
$elements['text']['value'] = $text;
}
$collection = $view->get('collection');
if (is_object($collection) && $collection->get('framework')) {
if (is_object($collection) && $collection->has_framework()) {
safe_require('module', 'framework');
$framework = new Framework($collection->get('framework'));
$standards = $framework->standards();
......@@ -393,6 +393,17 @@ class PluginBlocktypeAnnotation extends MaharaCoreBlocktype {
return 'full';
}
public static function has_feedback_allowed($id) {
return (bool) get_field_sql("
SELECT a.allowcomments FROM {artefact} a
JOIN {view_artefact} va ON va.artefact = a.id
JOIN {view} v ON v.id = va.view
JOIN {block_instance} bi ON bi.id = va.block
WHERE a.artefacttype = 'annotation'
AND bi.blocktype = 'annotation'
AND bi.id = ?", array($id));
}
public static function get_instance_javascript(BlockInstance $bi) {
return array(
array(
......
......@@ -962,7 +962,7 @@ class ArtefactTypeAnnotationfeedback extends ArtefactType {
$smarty->assign('annotationfeedback', $annotationfeedback);
if ($annotationartefact->get('allowcomments')) {
$form = ArtefactTypeAnnotationfeedback::add_annotation_feedback_form(false, $annotationartefact->get('approvecomments'), $annotationartefact, $view, null, $blockid);
$form = ArtefactTypeAnnotationfeedback::add_annotation_feedback_form($annotationartefact, $view, null, $blockid, false, $annotationartefact->get('approvecomments'));
// Replace the submit/cancel with just a submit button
$submit = array(
'type' => 'submit',
......@@ -1036,6 +1036,8 @@ class ArtefactTypeAnnotationfeedback extends ArtefactType {
$annotationfeedback->commit();
db_commit();
if (isset($data->requestpublic) && $data->requestpublic === 'author' && $data->owner) {
$arg = $author ? display_name($USER, null, true) : $data->authorname;
$moderatemsg = (object) array(
......@@ -1074,8 +1076,6 @@ class ArtefactTypeAnnotationfeedback extends ArtefactType {
activity_occurred('maharamessage', $moderatemsg);
}
db_commit();
list($count, $newlist) = self::get_annotation_feedback_for_matrix($annotationartefact, $view, $blockid, true);
return $newlist->tablerows;
}
......@@ -1111,7 +1111,7 @@ class ArtefactTypeAnnotationfeedback extends ArtefactType {
// Return the rendered form.
$smarty = smarty_core();
if ($annotationartefact->get('allowcomments') && !$editing) {
$addannotationfeedbackform = pieform(ArtefactTypeAnnotationfeedback::add_annotation_feedback_form(false, $annotationartefact->get('approvecomments'), $annotationartefact, $view, null, $blockid));
$addannotationfeedbackform = pieform(ArtefactTypeAnnotationfeedback::add_annotation_feedback_form($annotationartefact, $view, null, $blockid, false, $annotationartefact->get('approvecomments')));
$smarty->assign('addannotationfeedbackform', $addannotationfeedbackform);
}
else {
......@@ -1203,14 +1203,15 @@ class ArtefactTypeAnnotationfeedback extends ArtefactType {
/**
* Create a form so the user can enter feedback for an annotation that is linked to
* a view or an artefact.
* @param boolean $defaultprivate set the private setting. Default is false.
* @param boolean $moderate if moderating feedback. Default is false.
* @param object $annotation the annotation artefact object.
* @param object $view the view object that the annotation is linked to.
* @param object $artefact the artefact object that the annotation is linked to.
* @param string $blockid the id of the block instance
* @param boolean $defaultprivate set the private setting. Default is false.
* @param boolean $moderate if moderating feedback. Default is false.
* @return multitype:string multitype:NULL string
*/
public static function add_annotation_feedback_form($defaultprivate=false, $moderate=false, $annotation, $view, $artefact, $blockid) {
public static function add_annotation_feedback_form($annotation, $view, $artefact, $blockid, $defaultprivate=false, $moderate=false) {
global $USER;
$form = array(
'name' => 'add_annotation_feedback_form_' . $blockid,
......@@ -1247,37 +1248,38 @@ class ArtefactTypeAnnotationfeedback extends ArtefactType {
'cols' => 80,
'rules' => array('maxlength' => 8192),
);
if (isset($view)) {
$collection = $view->get('collection');
if (is_object($collection) && $collection->get('framework')) {
foreach ($view->get_artefact_metadata() as $metadata) {
if ($metadata->id === $annotation->get('id')) {
safe_require('module', 'framework');
$evidence = get_record('framework_evidence', 'annotation', $metadata->block);
$defaultval = $evidence->state;
if ($options = Framework::allow_assessment($view->get('owner'), true, $evidence->framework)) {
if (!array_key_exists($defaultval, $options)) {
$defaultval = null;
}
$form['elements']['assessment'] = array(
'type' => 'select',
'title' => get_string('assessment', 'module.framework'),
'options' => $options,
'defaultvalue' => $defaultval,
'width' => '280px',
);
$form['elements']['evidence'] = array(
'type' => 'hidden',
'value' => $evidence->id,
);
$collection = $view->get('collection');
if (is_object($collection) && $collection->has_framework()) {
$view->get_artefact_instances(); // populate the artefact_metadata
foreach ($view->get('artefact_metadata') as $metadata) {
if ($metadata->id === $annotation->get('id')) {
safe_require('module', 'framework');
$evidence = get_record('framework_evidence', 'annotation', $metadata->block);
$defaultval = $evidence->state;
if ($options = Framework::get_my_assessment_options_for_user($view->get('owner'), $evidence->framework)) {
if (!array_key_exists($defaultval, $options)) {
$defaultval = null;
}
$form['elements']['assessment'] = array(
'type' => 'select',
'title' => get_string('assessment', 'module.framework'),
'options' => $options,
'defaultvalue' => $defaultval,
'width' => '280px',
);
$form['elements']['evidence'] = array(
'type' => 'hidden',
'value' => $evidence->id,
);
}
}
}
}
$form['elements']['ispublic'] = array(
'type' => 'switchbox',
'title' => get_string('makepublic', 'artefact.annotation'),
......
......@@ -109,8 +109,8 @@ $form = pieform(array(
'name' => 'edit',
'plugintype' => 'core',
'pluginname' => 'collection',
'validatecallback' => 'validate',
'successcallback' => 'submit',
'validatecallback' => 'collectionedit_validate',
'successcallback' => 'collectionedit_submit',
'elements' => $elements,
));
......@@ -122,15 +122,15 @@ $smarty->assign('headingclass', 'page-header');
$smarty->assign_by_ref('form', $form);
$smarty->display('collection/edit.tpl');
function validate(Pieform $form, $values) {
$rendered = $form->get_property('elements');
if (isset($rendered['framework'])) {
if (!empty($rendered['framework']['defaultvalue']) && $rendered['framework']['defaultvalue'] != $values['framework']) {
function collectionedit_validate(Pieform $form, $values) {
if (!empty($values['id'])) {
$collection = new Collection($values['id']);
if ($collection->has_framework() && $collection->get('framework') != $values['framework']) {
// Make sure that if the user is changing the framework that there isn't annotations paired to the old framework
$views = get_records_sql_array("SELECT v.id, v.title FROM {view} v
JOIN {collection_view} cv ON cv.view = v.id
JOIN {framework_evidence} fe ON fe.view = cv.view
WHERE cv.collection = ?", array($rendered['id']['value']));
WHERE cv.collection = ?", array($values['id']));
if (!empty($views)) {
$errorstr = get_string('changeframeworkproblems', 'module.framework');
foreach ($views as $view) {
......@@ -142,7 +142,7 @@ function validate(Pieform $form, $values) {
}
}
function submit(Pieform $form, $values) {
function collectionedit_submit(Pieform $form, $values) {
global $SESSION, $new, $copy, $urlparams;
$values['navigation'] = (int) $values['navigation'];
if (empty($values['framework'])) {
......
......@@ -68,8 +68,7 @@ foreach ($data->data as $value) {
if (!empty($views)) {
$value->views = $views['views'];
}
safe_require('module', 'framework');
if (PluginModuleFramework::is_active() && $collection->get('framework')) {
if (is_plugin_active('framework', 'module') && $collection->has_framework()) {
$framework = new Framework($collection->get('framework'));
$value->frameworkname = $framework->get('name');
}
......
......@@ -96,8 +96,7 @@ foreach ($data->data as $value) {
if (!empty($views)) {
$value->views = $views['views'];
}
safe_require('module', 'framework');
if (PluginModuleFramework::is_active() && $collection->get('framework')) {
if (is_plugin_active('framework', 'module') && $collection->has_framework()) {
$framework = new Framework($collection->get('framework'));
$value->frameworkname = $framework->get('name');
}
......
......@@ -382,7 +382,7 @@ class Collection {
}
self::add_submission_info($data);
self::framework_url($data);
self::add_framework_urls($data);
$result = (object) array(
'count' => $count,
......@@ -477,7 +477,7 @@ class Collection {
'defaultvalue' => 1,
),
);
if ($frameworks = $this->can_have_framework()) {
if ($frameworks = $this->get_available_frameworks()) {
$options = array('' => get_string('noframeworkselected', 'module.framework'));
foreach ($frameworks as $framework) {
$options[$framework->id] = $framework->name;
......@@ -578,15 +578,14 @@ class Collection {
* - The institution has 'SmartEvidence' turned on
* - There frameworks available for the institution
*
* @return mixed array of available frameworks or false
* @return bool
*/
public function can_have_framework() {
if (!empty($this->group)) {
return false;
}
safe_require('module', 'framework');
if (!PluginModuleFramework::is_active()) {
if (!is_plugin_active('framework', 'module')) {
return false;
}
......@@ -604,16 +603,45 @@ class Collection {
if (!$institution->allowinstitutionsmartevidence) {
return false;
}
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 true;
}
/**
* Get available frameworks
*
* @return array Available frameworks
*/
public function get_available_frameworks() {
if (!$this->can_have_framework()) {
return array();
}
if ($this->institution) {
$institution = $this->institution;
}
else {
$user = new User();
$user->find_by_id($this->owner);
$institutions = array_keys($user->get('institutions'));
$institution = (!empty($institutions)) ? $institutions[0] : 'mahara';
}
$institution = new Institution($institution);
// Check that smart evidence is enabled for the institution
if (!$institution->allowinstitutionsmartevidence) {
return false;
}
if ($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;
}
return $frameworks;
return array();
}
/**
......@@ -634,7 +662,7 @@ class Collection {
if (!$this->views()) {
return false;
}
if (!PluginModuleFramework::is_active()) {
if (!is_plugin_active('framework', 'module')) {
return false;
}
return true;
......@@ -649,32 +677,44 @@ class Collection {
$option = new StdClass;
$option->framework = $this->framework;
$option->id = $this->id;
$option->title = get_string('smartevidence', 'collection');
$option->title = get_field('framework', 'name', 'id', $this->framework);
$option->framework = true;
self::framework_url($option);
$option->fullurl = self::get_framework_url($option);
return $option;
}
/**
* Making the framework url
* Adding the framework frameworkurl / fullurl to collections
*
* @param mixed $data Object / array of objects
* @param array $data Array of objects
*
* @return $data or $url
* @return $data
*/
public static function framework_url(&$data) {
public static function add_framework_urls(&$data) {
if (is_array($data)) {
foreach ($data as $k => $r) {
$r->frameworkurl = 'module/framework/matrix.php?id=' . $r->id;
$r->fullurl = get_config('wwwroot') . $r->frameworkurl;
$r->frameworkurl = self::get_framework_url($r, false);
$r->fullurl = self::get_framework_url($r, true);
}
}
else if (is_object($data)) {
$data->frameworkurl = 'module/framework/matrix.php?id=' . $data->id;
$data->fullurl = get_config('wwwroot') . $data->frameworkurl;
}
/**
* Making the framework url
*
* @param object $data Either a collection or standard object
* @param bool $fullurl Return full url rather than relative one
*
* @return $url
*/
public static function get_framework_url($data, $fullurl = true) {
$url = 'module/framework/matrix.php?id=' . $data->id;
if ($fullurl) {
return get_config('wwwroot') . $url;
}
return $url;
}
/**
......@@ -901,7 +941,12 @@ class Collection {
$views = $this->views();
if (!empty($views)) {
if ($this->framework) {
$this->framework_url($this);
if ($full) {
$this->fullurl = Collection::get_framework_url($this);
}
else {
$this->frameworkurl = Collection::get_framework_url($this, false);
}
return $this->frameworkurl;
}
......
......@@ -1616,6 +1616,7 @@ function plugin_types() {
static $pluginstocheck;
if (empty($pluginstocheck)) {
// ORDER MATTERS! artefact has to be before blocktype
// And so does module because module.framework has blocks as foreign keys in DB
$pluginstocheck = array('artefact', 'auth', 'notification', 'search', 'module', 'blocktype', 'interaction', 'grouptype', 'import', 'export');
}
return $pluginstocheck;
......@@ -2355,6 +2356,22 @@ abstract class Plugin implements IPlugin {
public static function accountprefs_submit(Pieform $form, $values) {
return;
}
/**
* Is plugin deprecated - going to be obsolete / removed
* @return bool
*/
public static function is_deprecated() {
return false;
}
/**
* Fetch plugin's display name rather than plugin name that is based on dir name.
* @return $tring or null
*/
public static function get_plugin_display_name() {
return null;
}
}
/**
......@@ -4731,6 +4748,8 @@ function pieform($data) {
/**
* Wrapper for setting up Pieform headdata.
* When there is no pieforms on the page but pieforms are called via ajax
* HACK: The ideal would be to refactor Pieforms so that Javascript dependencies can be loaded
* dynamically when we load up a form via AJAX
*
* @param array $elements A Piefrom element array if one needs to set element specific headdata js files
*/
......
......@@ -238,7 +238,7 @@ function check_upgrades($name=null) {
$classname = generate_class_name($plugintype, $pluginname);
safe_require($plugintype, $pluginname);
// Check if there is a displayname
$plugininfo->displayname = method_exists($classname, 'get_plugin_name') ? call_static_method($classname, 'get_plugin_name') : null;
$plugininfo->displayname = call_static_method($classname, 'get_plugin_display_name');
try {
$classname::sanity_check();
......@@ -284,7 +284,7 @@ function check_upgrades($name=null) {
$classname = generate_class_name($plugintype, $pluginname);
safe_require($plugintype, $pluginname);
// Check if there is a displayname
$plugininfo->displayname = method_exists($classname, 'get_plugin_name') ? call_static_method($classname, 'get_plugin_name') : null;
$plugininfo->displayname = call_static_method($classname, 'get_plugin_display_name');
try {
$classname::sanity_check();
}
......@@ -1418,7 +1418,7 @@ function set_antispam_defaults() {
function activate_plugin_form($plugintype, $plugin) {
// Check if there is a displayname
$classname = generate_class_name($plugintype, $plugin->name);
$plugin->displayname = method_exists($classname, 'get_plugin_name') ? call_static_method($classname, 'get_plugin_name') : null;
$plugin->displayname = call_static_method($classname, 'get_plugin_display_name');
return pieform(array(
'name' => 'activate_' . $plugintype . '_' . $plugin->name,
......
......@@ -5984,7 +5984,10 @@ class View {
$collections[$cid]['ownerurl'] = $v['ownerurl'];
}
if (!empty($r['framework'])) {
$collections[$cid]['url'] = get_config('wwwroot') . 'module/framework/matrix.php?id=' . $cid;
require_once('collection.php');
$coll = new StdClass();
$coll->id = $cid;
$collections[$cid]['url'] = Collection::get_framework_url($coll);
}
}
$collections[$cid]['views'][$vid] = $v;
......
......@@ -324,7 +324,7 @@ tinyMCE.init({
});
ed.on('LoadContent', function(e) {
// Hide all the 2nd/3rd row menu buttons
jQuery('.mce-toolbar.mce-first').siblings().toggleClass('hidden');
jQuery('.mce-toolbar.mce-first').siblings().addClass('hidden');
// The tinymce fullscreen mode does not work properly in a transformed container div
// such as div.vertcentre
// and IE doesn't like a preset z-index
......
......@@ -72,11 +72,11 @@
<KEY NAME="namepluginuk" TYPE="unique" FIELDS="framework, element, view" />
</KEYS>
</TABLE>
<TABLE NAME="framework_choices">
<TABLE NAME="framework_evidence_statuses">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="framework" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="choice" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="type" TYPE="int" LENGTH="1" NOTNULL="true" />
</FIELDS>
<KEYS>
......
......@@ -22,11 +22,11 @@ function xmldb_module_framework_upgrade($oldversion=0) {
}
if ($oldversion < 2016082200) {
log_debug('Adding "framework_choices" table');
$table = new XMLDBTable('framework_choices');
log_debug('Adding "framework_evidence_statuses" table');
$table = new XMLDBTable('framework_evidence_statuses');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('framework', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('choice', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('type', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
create_table($table);
......
......@@ -20,13 +20,94 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('Framework', 'module.framework'));
safe_require('module', 'framework');
$frameworks = Framework::list_frameworks();
$frameworks = Framework::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,
)
),
)
);
}
}
}
function framework_update_submit(Pieform $form, $values) {
global $SESSION;
// Should not normall get here as the form has no submit button and is updated via ajax/frameworks.json.php