Gitlab CSE Unil

Commit 1ffa90b3 authored by M. Chardon's avatar M. Chardon
Browse files

noettoyage et optimisation code avec sonarqube

parent a0f7790a
......@@ -33,6 +33,10 @@ require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_sesskey();
const PLUGIN_NAME = "assignfeedback_editpdfplus";
const PERMISSION_ASSIGN_GRADE = "mod/assign:grade";
const PERMISSION_ASSIGN_SUBMIT = "mod/assign:submit";
$action = optional_param('action', '', PARAM_ALPHANUM);
$assignmentid = required_param('assignmentid', PARAM_INT);
$userid = required_param('userid', PARAM_INT);
......@@ -52,11 +56,11 @@ if (!$assignment->can_view_submission($userid)) {
if ($action === 'pollconversions') {
$draft = true;
if (!has_capability('mod/assign:grade', $context)) {
if (!has_capability(PERMISSION_ASSIGN_GRADE, $context)) {
// A student always sees the readonly version.
$readonly = true;
$draft = false;
require_capability('mod/assign:submit', $context);
require_capability(PERMISSION_ASSIGN_SUBMIT, $context);
}
if ($readonly) {
......@@ -96,7 +100,7 @@ if ($action === 'pollconversions') {
$index = count($response->pages);
$page = new stdClass();
//$comments = page_editor::get_comments($grade->id, $index, $draft);
$page->url = moodle_url::make_pluginfile_url($context->id, 'assignfeedback_editpdfplus', $filearea, $grade->id, '/', $pagefile->get_filename())->out();
$page->url = moodle_url::make_pluginfile_url($context->id, PLUGIN_NAME, $filearea, $grade->id, '/', $pagefile->get_filename())->out();
//$page->comments = $comments;
if ($imageinfo = $pagefile->get_imageinfo()) {
$page->width = $imageinfo['width'];
......@@ -109,7 +113,7 @@ if ($action === 'pollconversions') {
$page->annotations = $annotations;
$response->pages[] = $page;
$component = 'assignfeedback_editpdfplus';
$component = PLUGIN_NAME;
$filearea = document_services::PAGE_IMAGE_FILEAREA;
$filepath = '/';
$fs = get_file_storage();
......@@ -128,7 +132,7 @@ if ($action === 'pollconversions') {
echo json_encode($response);
die();
} else if ($action == 'savepage') {
require_capability('mod/assign:grade', $context);
require_capability(PERMISSION_ASSIGN_GRADE, $context);
$response = new stdClass();
$response->errors = array();
......@@ -141,19 +145,18 @@ if ($action === 'pollconversions') {
$added = page_editor::set_annotations($grade->id, $index, $page->annotations);
if ($added != count($page->annotations)) {
array_push($response->errors, get_string('couldnotsavepage', 'assignfeedback_editpdfplus', $index + 1));
array_push($response->errors, get_string('couldnotsavepage', PLUGIN_NAME, $index + 1));
}
echo json_encode($response);
die();
} else if ($action == 'generatepdf') {
$refresh = optional_param('refresh', false, PARAM_BOOL);
if (!$refresh) {
require_capability('mod/assign:grade', $context);
require_capability(PERMISSION_ASSIGN_GRADE, $context);
} else {
require_capability('mod/assign:submit', $context);
require_capability(PERMISSION_ASSIGN_SUBMIT, $context);
}
$response = new stdClass();
$grade = $assignment->get_user_grade($userid, true, $attemptnumber);
......@@ -161,7 +164,7 @@ if ($action === 'pollconversions') {
$response->url = '';
if ($file) {
$url = moodle_url::make_pluginfile_url($assignment->get_context()->id, 'assignfeedback_editpdfplus', document_services::FINAL_PDF_FILEAREA, $grade->id, '/', $file->get_filename(), false);
$url = moodle_url::make_pluginfile_url($assignment->get_context()->id, PLUGIN_NAME, document_services::FINAL_PDF_FILEAREA, $grade->id, '/', $file->get_filename(), false);
$response->url = $url->out(true);
$response->filename = $file->get_filename();
}
......@@ -198,7 +201,7 @@ if ($action === 'pollconversions') {
. "<p>La correction du devoir a été mise à jour. Vous pouvez accéder au document en suivant ce <a href='"
. $response->url
. "'>lien</a></p>"
. "<i>Ceci est un mail automatique.</i>";
. "<i>Ceci est un mail automatique, merci de ne pas y répondre.</i>";
foreach ($teachers as $teacher) {
$res = email_to_user($teacher, $USER, "[Moodle] Mise à jour devoir", $body, $bodyhtml);
}
......@@ -207,7 +210,7 @@ if ($action === 'pollconversions') {
echo json_encode($response);
die();
} else if ($action == 'revertchanges') {
require_capability('mod/assign:grade', $context);
require_capability(PERMISSION_ASSIGN_GRADE, $context);
$grade = $assignment->get_user_grade($userid, true, $attemptnumber);
......@@ -216,7 +219,7 @@ if ($action === 'pollconversions') {
echo json_encode($result);
die();
} else if ($action == 'deletefeedbackdocument') {
require_capability('mod/assign:grade', $context);
require_capability(PERMISSION_ASSIGN_GRADE, $context);
$grade = $assignment->get_user_grade($userid, true, $attemptnumber);
$result = document_services::delete_feedback_document($assignment, $userid, $attemptnumber);
......@@ -225,7 +228,7 @@ if ($action === 'pollconversions') {
echo json_encode($result);
die();
} else if ($action == 'updatestudentview') {
require_capability('mod/assign:submit', $context);
require_capability(PERMISSION_ASSIGN_SUBMIT, $context);
$response = new stdClass();
$response->errors = array();
......@@ -238,7 +241,7 @@ if ($action === 'pollconversions') {
$added = page_editor::update_annotations_status($page->annotations);
if ($added != count($page->annotations)) {
array_push($response->errors, get_string('couldnotsavepage', 'assignfeedback_editpdfplus', $index + 1));
array_push($response->errors, get_string('couldnotsavepage', PLUGIN_NAME, $index + 1));
}
echo json_encode($response);
die();
......
......@@ -35,6 +35,8 @@ defined('MOODLE_INTERNAL') || die();
*/
class backup_assignfeedback_editpdfplus_subplugin extends backup_subplugin {
const GRADEID = 'gradeid';
/**
* Returns the subplugin information to attach to feedback element
* @return backup_subplugin_element
......@@ -44,10 +46,10 @@ class backup_assignfeedback_editpdfplus_subplugin extends backup_subplugin {
// Create XML elements.
$subplugin = $this->get_subplugin_element();
$subpluginwrapper = new backup_nested_element($this->get_recommended_name());
$subpluginelementfiles = new backup_nested_element('feedback_editpdfplus_files', null, array('gradeid'));
$subpluginelementfiles = new backup_nested_element('feedback_editpdfplus_files', null, array(self::GRADEID));
$subpluginelementannotations = new backup_nested_element('feedback_editpdfplus_annotations');
$subpluginelementannotation = new backup_nested_element(
'feedback_editpdfplus_annotation', null, array('gradeid', 'pageno', 'x', 'y', 'endx', 'endy', 'cartridgex', 'cartridgey', 'path', 'toolid', 'textannot', 'colour', 'draft', 'answerrequested', 'studentanswer', 'studentstatus', 'displaylock', 'displayrotation', 'borderstyle', 'parent_annot')
'feedback_editpdfplus_annotation', null, array(self::GRADEID, 'pageno', 'x', 'y', 'endx', 'endy', 'cartridgex', 'cartridgey', 'path', 'toolid', 'textannot', 'colour', 'draft', 'answerrequested', 'studentanswer', 'studentstatus', 'displaylock', 'displayrotation', 'borderstyle', 'parent_annot')
);
// Connect XML elements into the tree.
......@@ -57,12 +59,12 @@ class backup_assignfeedback_editpdfplus_subplugin extends backup_subplugin {
$subpluginwrapper->add_child($subpluginelementannotations);
// Set source to populate the data.
$subpluginelementfiles->set_source_sql('SELECT id AS gradeid from {assign_grades} where id = :gradeid', array('gradeid' => backup::VAR_PARENTID));
$subpluginelementannotation->set_source_table('assignfeedback_editpp_annot', array('gradeid' => backup::VAR_PARENTID));
$subpluginelementfiles->set_source_sql('SELECT id AS gradeid from {assign_grades} where id = :' . self::GRADEID, array(self::GRADEID => backup::VAR_PARENTID));
$subpluginelementannotation->set_source_table('assignfeedback_editpp_annot', array(self::GRADEID => backup::VAR_PARENTID));
// We only need to backup the files in the final pdf area, and the readonly page images - the others can be regenerated.
$subpluginelementfiles->annotate_files('assignfeedback_editpdfplus', \assignfeedback_editpdfplus\document_services::FINAL_PDF_FILEAREA, 'gradeid');
$subpluginelementfiles->annotate_files('assignfeedback_editpdfplus', \assignfeedback_editpdfplus\document_services::PAGE_IMAGE_READONLY_FILEAREA, 'gradeid');
$subpluginelementfiles->annotate_files('assignfeedback_editpdfplus', \assignfeedback_editpdfplus\document_services::FINAL_PDF_FILEAREA, self::GRADEID);
$subpluginelementfiles->annotate_files('assignfeedback_editpdfplus', \assignfeedback_editpdfplus\document_services::PAGE_IMAGE_READONLY_FILEAREA, self::GRADEID);
return $subplugin;
}
}
......@@ -36,6 +36,8 @@ defined('MOODLE_INTERNAL') || die();
*/
class restore_assignfeedback_editpdfplus_subplugin extends restore_subplugin {
const GRADE = 'grade';
/**
* Returns the paths to be handled by the subplugin at assignment level
* @return array
......@@ -66,8 +68,8 @@ class restore_assignfeedback_editpdfplus_subplugin extends restore_subplugin {
$data = (object) $data;
// In this case the id is the old gradeid which will be mapped.
$this->add_related_files('assignfeedback_editpdfplus', \assignfeedback_editpdfplus\document_services::FINAL_PDF_FILEAREA, 'grade', null, $data->gradeid);
$this->add_related_files('assignfeedback_editpdfplus', \assignfeedback_editpdfplus\document_services::PAGE_IMAGE_READONLY_FILEAREA, 'grade', null, $data->gradeid);
$this->add_related_files('assignfeedback_editpdfplus', \assignfeedback_editpdfplus\document_services::FINAL_PDF_FILEAREA, self::GRADE, null, $data->gradeid);
$this->add_related_files('assignfeedback_editpdfplus', \assignfeedback_editpdfplus\document_services::PAGE_IMAGE_READONLY_FILEAREA, self::GRADE, null, $data->gradeid);
}
/**
......@@ -81,7 +83,7 @@ class restore_assignfeedback_editpdfplus_subplugin extends restore_subplugin {
$oldgradeid = $data->gradeid;
// The mapping is set in the restore for the core assign activity
// when a grade node is processed.
$data->gradeid = $this->get_mappingid('grade', $data->gradeid);
$data->gradeid = $this->get_mappingid(self::GRADE, $data->gradeid);
$DB->insert_record('assignfeedback_editpp_annot', $data);
}
......
......@@ -188,7 +188,6 @@ class combined_document {
switch ($status) {
case \core_files\conversion::STATUS_COMPLETE:
continue;
break;
default:
$converter->poll_conversion($conversion);
}
......
This diff is collapsed.
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017100400;
$plugin->version = 2018060100;
$plugin->requires = 2018050800; // Requires this Moodle version.
$plugin->maturity = MATURITY_STABLE;
$plugin->release = "2.0 (Build: 2017100400)";
......
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