public static function instance_config_form(BlockInstance $instance) { global $USER; $instance->set('artefactplugin', 'annotation'); // Get the saved configs in the artefact $configdata = $instance->get('configdata'); if (!($height = get_config('blockeditorheight'))) { $cfheight = param_integer('cfheight', 0); $height = $cfheight ? $cfheight * 0.7 : 150; } // Default annotation text. $text = ''; $tags = ''; $artefactid = ''; $readonly = false; $textreadonly = false; $view = $instance->get_view(); if (!empty($configdata['artefactid'])) { $artefactid = $configdata['artefactid']; try { $artefact = $instance->get_artefact_instance($artefactid); // Get the annotation record -> to get the artefact it's linked to. $annotation = new ArtefactTypeAnnotation($artefactid); // Get the total annotation feedback inserted so far by anyone. $totalannotationfeedback = ArtefactTypeAnnotationfeedback::count_annotation_feedback($artefactid, array($view->get('id')), array($annotation->get('artefact'))); $readonly = $artefact->get('owner') !== $view->get('owner') || $artefact->get('group') !== $view->get('group') || $artefact->get('institution') !== $view->get('institution') || $artefact->get('locked') || !$USER->can_edit_artefact($artefact); if (isset($totalannotationfeedback[$view->get('id')])) { $textreadonly = $totalannotationfeedback[$view->get('id')]->total > 0; } $text = $artefact->get('description'); $tags = $artefact->get('tags'); } catch (ArtefactNotFoundException $e) { unset($artefactid); } } $elements = array('text' => array('type' => $textreadonly ? 'html' : 'wysiwyg', 'class' => '', 'title' => get_string('Annotation', 'artefact.annotation'), 'width' => '100%', 'height' => $height . 'px', 'defaultvalue' => $text, 'rules' => array('maxlength' => 65536)), 'annotationreadonlymsg' => array('type' => 'html', 'class' => 'message info' . ($textreadonly ? '' : ' hidden'), 'value' => get_string('annotationreadonlymessage', 'blocktype.annotation/annotation'), 'help' => true), 'allowfeedback' => array('type' => 'switchbox', 'title' => get_string('allowannotationfeedback', 'artefact.annotation'), 'defaultvalue' => !empty($artefact) ? $artefact->get('allowcomments') : 1), 'tags' => array('type' => 'tags', 'class' => $readonly ? 'hidden' : '', 'width' => '100%', 'title' => get_string('tags'), 'description' => get_string('tagsdescprofile'), 'defaultvalue' => $tags), 'tagsreadonly' => array('type' => 'html', 'class' => $readonly ? '' : 'hidden', 'width' => '100%', 'title' => get_string('tags'), 'value' => '<div id="instconf_tagsreadonly_display">' . (is_array($tags) ? hsc(join(', ', $tags)) : '') . '</div>')); if ($textreadonly) { // The annotation is displayed as html, need to populate its value. $elements['text']['value'] = $text; } return $elements; }