Gitlab CSE Unil

Commit 61e911d3 authored by M. Chardon's avatar M. Chardon
Browse files

- adapation for no-visible document

- adaption for moodle3.5 basic requirements
parent 7af16f9a
......@@ -154,6 +154,29 @@ class assign_feedback_editpdfplus extends assign_feedback_plugin {
$widget = $this->get_widget($userid, $grade, false);
$html = $renderer->render($widget);
$enablewidget = $this->is_enabled_precheck(true);
if ($enablewidget === true) {
// True means 'activate and show'
// We potentially have to re-show the annotation widget.
$html .= '<script>(function($){$(\'button.btn.collapse-none\').click();})(jQuery)</script>';
} else {
// False || 'jsonly' means we want to collapse the annotation widget panel.
$html .= "<script>
(function($) {
$(document).ready(function(){
setTimeout(function(){
$('button.btn.collapse-review-panel').click();
}, 1000);
});
})(jQuery)
</script>";
}
if (!$enablewidget) {
// False means we have to deactivate altogether (i.e. hide by CSS as it's easier) the annotation widget.
$html .= '<style>.assignfeedback_editpdfplus_widget { display: none; }</style>';
}
$mform->addElement('static', 'editpdf', get_string('editpdf', 'assignfeedback_editpdfplus'), $html);
$mform->addHelpButton('editpdf', 'editpdf', 'assignfeedback_editpdfplus');
$mform->addElement('hidden', 'editpdf_source_userid', $userid);
......@@ -293,6 +316,126 @@ class assign_feedback_editpdfplus extends assign_feedback_plugin {
return true;
}
/**
* Pre-check to determine whether we (Unil) thinks we should use annotation
*
* this function is called from $this->get_form_elements_for_user() with $isajax parameter set to true
*
* This function considers all user submitted files for the initial page load, to check whether the annotation
* feature should be enabled at all.
* On subsequent (AJAX) calls, only the currently graded user's submitted files are considered, to show or hide
* the annotation panel.
*
* Then, the following algorithm is used :
* 1. If we're not in the grading process, don't bother changing anything.
* 2. If we're using \assign_submission_mahara, deactivate annotation.
* 3. If we're using \assign_submission_onlinetext and no other plugins, activate annotation.
* 4. If we're using \assign_submission_file, deactivate if any files are not annotable
* for the current user if $isajax is true
* 5. If no annotable files for current/all (depending on $isajax) participants have been found,
* deactivate annotation.
* 6. If the grading area is using rubrics (i.e., an evaluation grid) return 'jsonly', which yields true
* but (in get_form_elements_for_user()) slides the annotation pane off screen.
* 7. Finally, return true.
*
* @param bool $isajax are we loading the page, on a subsequent AJAX request getting the grading elements
* for a particular user
*
* @return bool|string activate or not | special
*/
private function is_enabled_precheck($isajax = false) {
global $PAGE;
if (in_array($PAGE->url->get_param('action'), array('grade', 'grader'))) {
// Step 1.
// Only do this if we're on the grading interface for minimal execution flow disruption.
// Action 'grader' is used for direct HTTP hit, 'grade' apparently used in subsequent AJAX requests.
$plugins = $this->assignment->get_submission_plugins();
// These are all the currently installed submission plugins.
foreach ($plugins as $plugin) {
if (!($plugin->is_enabled() // Is the plugin enabled in this assignment?
&& $plugin->is_visible() // Is the plugin enabled at site level? ("visible" with eye icon)
)) {
continue;
}
if ($plugin instanceof \assign_submission_mahara) {
return false;
// Step 2.
// Never try to annotate in this case
}
if ($plugin instanceof \assign_submission_onlinetext) {
if (count($plugins) == 1) {
break;
// Step 3.
// Always try to annotate if no other plugins are activated
}
}
if ($plugin instanceof \assign_submission_file) {
// Step 4.
$userid = ($PAGE->url->get_param('userid')) ? $PAGE->url->get_param('userid') : (optional_param('userid', 0, PARAM_INT));
if ($isajax && $userid) {
if ($this->assignment->get_instance()->teamsubmission) {
// groups enabled, use group submission
$participants = $this->assignment->get_shared_group_members($this->assignment->get_course_module(), $userid);
} else {
$participants = array($userid);
}
// That's the user we're currently grading, loading the UI via AJAX.
} else {
$participants = array_keys($this->assignment->list_participants(0, true));
// We don't know yet which user we'll be grading (initial full page load of grading interface),
// so we have to take all assignment participants into account.
}
$fs = get_file_storage();
$files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, false, 'timemodified', false);
// We've now got all submission files, let's check them out.
$supported_extensions = array('bmp', 'doc', 'docx', 'eps', 'fodt', 'gif', 'jpeg', 'jpg', 'odt', 'ott', 'pdf', 'png', 'rtf', 'svg', 'tiff');
$nbfiles = 0;
foreach ($files as $file) {
if (!in_array($file->get_userid(), $participants)) {
continue;
// Don't take this file into account as it does not belong to the relevant participant(s).
}
$extension = core_text::strtolower(pathinfo($file->get_filename(), PATHINFO_EXTENSION));
if (in_array($extension, $supported_extensions)) {
$nbfiles++;
} else {
if ($isajax) {
return false;
// Step 4.
// Don't annotate if ANY non annoatable files found for the current user.
}
}
}
if (!$nbfiles) {
return false;
// Step 5.
// Didn't find any files to annotate.
}
}
}
if ($isajax) {
global $DB;
$cm = $this->assignment->get_course_module();
$context = \context_module::instance($cm->id);
$gradingarea = $DB->get_record('grading_areas', array('contextid' => $context->id));
// $gradingdefinition = $DB->get_record('grading_definitions', array('areaid' => $gradingarea->id));
if ($gradingarea && $gradingarea->activemethod == 'rubric') {
// Step 6.
return 'jsonly';
// If we're using a grading grid (rubrics) then click the 'slide pane' button for AJAX only,
// so that the rubrics table can be more prominent.
}
}
}
// Step 7.
return true;
// No reason not to activate the annotation interface.
}
public function is_available() {
return $this->is_enabled();
}
/**
* Automatically enable or disable editpdfplus feedback plugin based on
* whether the ghostscript path is set correctly.
......
Supports Markdown
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