Gitlab CSE Unil

Commit cd172d5f authored by M. Chardon's avatar M. Chardon
Browse files

- display pdf inline/footnote au choix du correcteur

- lien dans le fichier pdf entre annotation et texte
parent 303964cb
......@@ -90,6 +90,9 @@ class annotation {
/** @var string studentanswer */
public $studentanswer = "";
/** @var string pdfdisplay */
public $pdfdisplay = "footnote";
/**
* Convert a compatible stdClass into an instance of this class.
* @param stdClass $record
......
......@@ -730,7 +730,7 @@ EOD;
//add feedback by annotation
$pdf->SetAutoPageBreak(true);
$pdf->AddPage();
$pdf->AddPage('P', 'A4');
$pdf->SetTextColor(0, 0, 0);
$pdf->Write(10, "", '', false, 'L', true);
$pdf->SetFontSize(14);
......@@ -750,7 +750,16 @@ EOD;
if (!$annot->hasReadableComment()) {
continue;
}
$pdf->Write(5, $index, '', false, 'L', false);
//set link target to annotation's text
$pdf->SetLink($pdf->arrayLinks[$index], -1);
//create link source for annotation's display
$pdf->SetTextColor(0, 0, 255);
$pdf->SetFont('', 'U');
$pdf->Write(5, $index, $pdf->arrayLinksOrigi[$index], false, 'L', false);
$pdf->SetFont('', '');
$pdf->SetTextColor(0, 0, 0);
if ($annot->studentstatus === "2") {
$pdf->SetTextColor(255, 0, 0);
$pdf->Write(5, '*', '', false, 'L', false);
......
......@@ -50,6 +50,8 @@ class pdf extends Fpdi {
/** @var string the path to the PDF currently being processed */
protected $filename = null;
public $arrayLinks = array();
public $arrayLinksOrigi = array();
/** No errors */
const GSPATH_OK = 'ok';
......@@ -256,7 +258,7 @@ class pdf extends Fpdi {
if (!$this->filename) {
return false;
}
//check tcpdf cache directory, needed for image transformation
if (!file_exists(K_PATH_CACHE)) {
//try to create the directory
......@@ -478,10 +480,32 @@ class pdf extends Fpdi {
if ($type == 'commentplus' || $type == 'stampcomment' || ($type == 'frame' && !$annotation->parent_annot) || $type == 'verticalline' || $type == 'highlightplus') {
$cartouche = $toolObject->cartridge;
if ($annotation->textannot) {
$cartouche .= ' [' . $annotation_index . ']';
if ($annotation->pdfdisplay === "inline") {
$cartouche .= ' | ' . $annotation->textannot;
}
$this->Write(5, $cartouche . ' [');
//create link source for annotation's text
$link = $this->addLink();
$this->SetTextColor(0, 0, 255);
$this->SetFont('', 'U');
$this->Write(5, $annotation_index, $link);
$this->SetTextColorArray($colourcartridgearray);
$this->SetFont('', '');
$this->arrayLinks[$annotation_index] = $link;
$this->Write(5, ']');
//create link target to go back to the annotation display
$linkorigi = $this->addLink();
$this->setLink($linkorigi, -1);
$this->arrayLinksOrigi[$annotation_index] = $linkorigi;
//$this->Annotation($sx + 50, $sy, 30, 30, $annotation->textannot, array('Subtype' => 'Text', 'Name' => 'Comment', 'T' => $toolObject->label, 'Subj' => 'example', 'C' => $colourarray));
}
$this->Write(5, $cartouche);
//$html = '&nbsp;<a href="#annot' . $annotation_index . '" style="color:red;">' . '[#annot' . $annotation_index . ']' . '</a>';
//$this->writeHTML($html);
}
$this->SetDrawColor(0, 0, 0);
......
......@@ -27,6 +27,7 @@
<FIELD NAME="displayrotation" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="borderstyle" TYPE="char" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="parent_annot" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="pdfdisplay" TYPE="char" LENGTH="20" NOTNULL="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
......
......@@ -333,5 +333,18 @@ function xmldb_assignfeedback_editpdfplus_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2019052400, 'assignfeedback', 'editpdfplus');
}
if ($oldversion < 2019053100) {
/* annotation table */
$table = new xmldb_table('assignfeedback_editpp_annot');
$field = new xmldb_field('pdfdisplay', XMLDB_TYPE_CHAR, '20', null,
XMLDB_NOTNULL, null, 'footnote', 'parent_annot');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Editpdfplus savepoint reached.
upgrade_plugin_savepoint(true, 2019053100, 'assignfeedback', 'editpdfplus');
}
return true;
}
......@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2019052400;
$plugin->version = 2019053100;
$plugin->requires = 2019051100; // Moodle 3.7
$plugin->maturity = MATURITY_STABLE;
$plugin->release = "2.3.0 (Build: 2019052400)";
......
......@@ -751,6 +751,13 @@ Y.extend(ANNOTATION, Y.Base, {
* @public
*/
studentanswer: "",
/**
* pdf display for this annotation
* @property pdfdisplay
* @type String
* @public
*/
pdfdisplay: "footnote",
/**
* Initialise the annotation.
*
......@@ -799,6 +806,7 @@ Y.extend(ANNOTATION, Y.Base, {
this.path = config.path || '';
this.toolid = config.toolid || this.editor.get_dialogue_element(TOOLTYPE.RECTANGLE);
this.drawable = false;
this.pdfdisplay = config.pdfdisplay;
this.tooltypefamille = this.editor.typetools[this.tooltype.type];
},
/**
......@@ -827,7 +835,8 @@ Y.extend(ANNOTATION, Y.Base, {
borderstyle: this.borderstyle,
parent_annot: parseInt(this.parent_annot, 10),
divcartridge: this.divcartridge,
parent_annot_div: this.parent_annot_element.divcartridge
parent_annot_div: this.parent_annot_element.divcartridge,
pdfdisplay: this.pdfdisplay
};
}
return {
......@@ -850,7 +859,8 @@ Y.extend(ANNOTATION, Y.Base, {
divcartridge: this.divcartridge,
parent_annot_div: '',
answerrequested: parseInt(this.answerrequested, 10),
studentstatus: parseInt(this.studentstatus, 10)
studentstatus: parseInt(this.studentstatus, 10),
pdfdisplay: this.pdfdisplay
};
},
/**
......@@ -1141,6 +1151,7 @@ Y.extend(ANNOTATION, Y.Base, {
divconteneurdisplay.append(divinputdisplay);
divconteneurdisplay.append(inputonof);
divconteneurdisplay.append(this.get_input_question());
divconteneurdisplay.append(this.get_input_pdfdisplay());
return divconteneurdisplay;
},
......@@ -1161,6 +1172,7 @@ Y.extend(ANNOTATION, Y.Base, {
if (this.tooltype.reply === 1) {
divtoolbardisplay.append(this.get_button_question());
}
divtoolbardisplay.append(this.get_button_pdfdisplay());
divtoolbardisplay.append(this.get_button_remove());
} else {
divtoolbardisplay.append(this.get_button_student_status());
......@@ -1287,6 +1299,21 @@ Y.extend(ANNOTATION, Y.Base, {
buttontrashdisplay.on('click', this.remove_by_trash, this);
return buttontrashdisplay;
},
/**
* get the html node for the button to change display on pdf for the annotation
* @return node
*/
get_button_pdfdisplay: function () {
var buttontrash = "<button id='"
+ this.divcartridge
+ "_buttonpdfdisplay' style='display:none;margin-left:10px;' class='btn btn-sm btn-outline-dark' type='button'>"
+ "<i class='fa fa-file-pdf-o' aria-hidden='true'></i>&nbsp;"
+ "<i class='fa fa-arrow-circle-o-down' aria-hidden='true'></i>"
+ "</button>";
var buttontrashdisplay = Y.Node.create(buttontrash);
buttontrashdisplay.on('click', this.change_pdf_display, this);
return buttontrashdisplay;
},
/**
* get the html node for the hidden input to keep information about question state
* @return node
......@@ -1298,6 +1325,13 @@ Y.extend(ANNOTATION, Y.Base, {
}
return Y.Node.create("<input type='hidden' id='" + this.divcartridge + "_question' value='" + qst + "'/>");
},
/**
* get the html node for the hidden input to keep information about question state
* @return node
*/
get_input_pdfdisplay: function () {
return Y.Node.create("<input type='hidden' id='" + this.divcartridge + "_pdfdisplay' value='" + this.pdfdisplay + "'/>");
},
/**
* get the final reference text value
* @return node
......@@ -1361,6 +1395,7 @@ Y.extend(ANNOTATION, Y.Base, {
buttonstatus.hide();
}
this.apply_question_status();
this.apply_pdfdisplay();
},
/**
* get the html node for the text to display for the annotation, according to parameters
......@@ -1403,6 +1438,22 @@ Y.extend(ANNOTATION, Y.Base, {
this.apply_visibility_annot();
this.editor.save_current_page();
},
/**
* change question status of the annotation (with or not)
*/
change_pdf_display: function () {
var pdfdisplayvalue = this.editor.get_dialogue_element('#' + this.divcartridge + "_pdfdisplay");
var value = pdfdisplayvalue.get('value');
if (value === "footnote") {
pdfdisplayvalue.set('value', "inline");
this.pdfdisplay = "inline";
} else {
pdfdisplayvalue.set('value', "footnote");
this.pdfdisplay = "footnote";
}
this.apply_pdfdisplay();
this.editor.save_current_page();
},
/**
* change question status of the annotation (with or not)
*/
......@@ -1463,6 +1514,25 @@ Y.extend(ANNOTATION, Y.Base, {
}
return;
},
/**
* change pdf display mode set of the annotation
* @return null
*/
apply_pdfdisplay: function () {
var buttonpdf = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonpdfdisplay");
var pdfdisplayvalue = this.editor.get_dialogue_element('#' + this.divcartridge + "_pdfdisplay");
var value = pdfdisplayvalue.get('value');
if (buttonpdf) {
if (value === 'footnote') {
buttonpdf.setHTML("<i class='fa fa-file-pdf-o' aria-hidden='true'></i>&nbsp;"
+ "<i class='fa fa-arrow-circle-o-down' aria-hidden='true'></i>");
} else {
buttonpdf.setHTML("<i class='fa fa-file-pdf-o' aria-hidden='true'></i>&nbsp;"
+ "<i class='fa fa-arrow-circle-o-right' aria-hidden='true'></i>");
}
}
return;
},
/**
* drag-and-drop start
* @param {type} e
......@@ -1515,7 +1585,7 @@ Y.extend(ANNOTATION, Y.Base, {
var divcartridge = this.editor.get_dialogue_element('#' + this.divcartridge);
divcartridge.setX(offsetcanvas[0] + this.x + this.cartridgex);
divcartridge.setY(offsetcanvas[1] + this.y + this.cartridgey);
window.console.log('move_cartridge_stop');
//window.console.log('move_cartridge_stop');
this.editor.save_current_page();
},
/**
......@@ -1583,6 +1653,7 @@ Y.extend(ANNOTATION, Y.Base, {
var buttoncancel = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttoncancel");
var buttonquestion = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonquestion");
var buttonrotation = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonrotation");
var buttonpdfdisplay = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonpdfdisplay");
var buttonremove = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonremove");
var input = this.editor.get_dialogue_element('#' + this.divcartridge + "_editinput");
divdisplay.hide();
......@@ -1601,6 +1672,7 @@ Y.extend(ANNOTATION, Y.Base, {
if (buttonquestion) {
buttonquestion.show();
}
buttonpdfdisplay.show();
buttonremove.show();
divprincipale.setStyle('z-index', 1000);
if (input) {
......@@ -1640,7 +1712,6 @@ Y.extend(ANNOTATION, Y.Base, {
}
}
this.textannot = result;
window.console.log('save_annot');
this.editor.save_current_page();
if (result.length === 0) {
result = "&nbsp;&nbsp;";
......@@ -1696,6 +1767,7 @@ Y.extend(ANNOTATION, Y.Base, {
var buttoncancel = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttoncancel");
var buttonquestion = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonquestion");
var buttonrotation = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonrotation");
var buttonpdfdisplay = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonpdfdisplay");
var buttonremove = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonremove");
var buttonstatus = this.editor.get_dialogue_element('#' + this.divcartridge + "_radioContainer");
if (divdisplay) {
......@@ -1716,6 +1788,9 @@ Y.extend(ANNOTATION, Y.Base, {
if (buttonquestion) {
buttonquestion.hide();
}
if (buttonpdfdisplay) {
buttonpdfdisplay.hide();
}
if (buttonremove) {
buttonremove.hide();
}
......
......@@ -751,6 +751,13 @@ Y.extend(ANNOTATION, Y.Base, {
* @public
*/
studentanswer: "",
/**
* pdf display for this annotation
* @property pdfdisplay
* @type String
* @public
*/
pdfdisplay: "footnote",
/**
* Initialise the annotation.
*
......@@ -799,6 +806,7 @@ Y.extend(ANNOTATION, Y.Base, {
this.path = config.path || '';
this.toolid = config.toolid || this.editor.get_dialogue_element(TOOLTYPE.RECTANGLE);
this.drawable = false;
this.pdfdisplay = config.pdfdisplay;
this.tooltypefamille = this.editor.typetools[this.tooltype.type];
},
/**
......@@ -827,7 +835,8 @@ Y.extend(ANNOTATION, Y.Base, {
borderstyle: this.borderstyle,
parent_annot: parseInt(this.parent_annot, 10),
divcartridge: this.divcartridge,
parent_annot_div: this.parent_annot_element.divcartridge
parent_annot_div: this.parent_annot_element.divcartridge,
pdfdisplay: this.pdfdisplay
};
}
return {
......@@ -850,7 +859,8 @@ Y.extend(ANNOTATION, Y.Base, {
divcartridge: this.divcartridge,
parent_annot_div: '',
answerrequested: parseInt(this.answerrequested, 10),
studentstatus: parseInt(this.studentstatus, 10)
studentstatus: parseInt(this.studentstatus, 10),
pdfdisplay: this.pdfdisplay
};
},
/**
......@@ -1141,6 +1151,7 @@ Y.extend(ANNOTATION, Y.Base, {
divconteneurdisplay.append(divinputdisplay);
divconteneurdisplay.append(inputonof);
divconteneurdisplay.append(this.get_input_question());
divconteneurdisplay.append(this.get_input_pdfdisplay());
return divconteneurdisplay;
},
......@@ -1161,6 +1172,7 @@ Y.extend(ANNOTATION, Y.Base, {
if (this.tooltype.reply === 1) {
divtoolbardisplay.append(this.get_button_question());
}
divtoolbardisplay.append(this.get_button_pdfdisplay());
divtoolbardisplay.append(this.get_button_remove());
} else {
divtoolbardisplay.append(this.get_button_student_status());
......@@ -1287,6 +1299,21 @@ Y.extend(ANNOTATION, Y.Base, {
buttontrashdisplay.on('click', this.remove_by_trash, this);
return buttontrashdisplay;
},
/**
* get the html node for the button to change display on pdf for the annotation
* @return node
*/
get_button_pdfdisplay: function () {
var buttontrash = "<button id='"
+ this.divcartridge
+ "_buttonpdfdisplay' style='display:none;margin-left:10px;' class='btn btn-sm btn-outline-dark' type='button'>"
+ "<i class='fa fa-file-pdf-o' aria-hidden='true'></i>&nbsp;"
+ "<i class='fa fa-arrow-circle-o-down' aria-hidden='true'></i>"
+ "</button>";
var buttontrashdisplay = Y.Node.create(buttontrash);
buttontrashdisplay.on('click', this.change_pdf_display, this);
return buttontrashdisplay;
},
/**
* get the html node for the hidden input to keep information about question state
* @return node
......@@ -1298,6 +1325,13 @@ Y.extend(ANNOTATION, Y.Base, {
}
return Y.Node.create("<input type='hidden' id='" + this.divcartridge + "_question' value='" + qst + "'/>");
},
/**
* get the html node for the hidden input to keep information about question state
* @return node
*/
get_input_pdfdisplay: function () {
return Y.Node.create("<input type='hidden' id='" + this.divcartridge + "_pdfdisplay' value='" + this.pdfdisplay + "'/>");
},
/**
* get the final reference text value
* @return node
......@@ -1361,6 +1395,7 @@ Y.extend(ANNOTATION, Y.Base, {
buttonstatus.hide();
}
this.apply_question_status();
this.apply_pdfdisplay();
},
/**
* get the html node for the text to display for the annotation, according to parameters
......@@ -1403,6 +1438,22 @@ Y.extend(ANNOTATION, Y.Base, {
this.apply_visibility_annot();
this.editor.save_current_page();
},
/**
* change question status of the annotation (with or not)
*/
change_pdf_display: function () {
var pdfdisplayvalue = this.editor.get_dialogue_element('#' + this.divcartridge + "_pdfdisplay");
var value = pdfdisplayvalue.get('value');
if (value === "footnote") {
pdfdisplayvalue.set('value', "inline");
this.pdfdisplay = "inline";
} else {
pdfdisplayvalue.set('value', "footnote");
this.pdfdisplay = "footnote";
}
this.apply_pdfdisplay();
this.editor.save_current_page();
},
/**
* change question status of the annotation (with or not)
*/
......@@ -1463,6 +1514,25 @@ Y.extend(ANNOTATION, Y.Base, {
}
return;
},
/**
* change pdf display mode set of the annotation
* @return null
*/
apply_pdfdisplay: function () {
var buttonpdf = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonpdfdisplay");
var pdfdisplayvalue = this.editor.get_dialogue_element('#' + this.divcartridge + "_pdfdisplay");
var value = pdfdisplayvalue.get('value');
if (buttonpdf) {
if (value === 'footnote') {
buttonpdf.setHTML("<i class='fa fa-file-pdf-o' aria-hidden='true'></i>&nbsp;"
+ "<i class='fa fa-arrow-circle-o-down' aria-hidden='true'></i>");
} else {
buttonpdf.setHTML("<i class='fa fa-file-pdf-o' aria-hidden='true'></i>&nbsp;"
+ "<i class='fa fa-arrow-circle-o-right' aria-hidden='true'></i>");
}
}
return;
},
/**
* drag-and-drop start
* @param {type} e
......@@ -1515,7 +1585,7 @@ Y.extend(ANNOTATION, Y.Base, {
var divcartridge = this.editor.get_dialogue_element('#' + this.divcartridge);
divcartridge.setX(offsetcanvas[0] + this.x + this.cartridgex);
divcartridge.setY(offsetcanvas[1] + this.y + this.cartridgey);
window.console.log('move_cartridge_stop');
//window.console.log('move_cartridge_stop');
this.editor.save_current_page();
},
/**
......@@ -1583,6 +1653,7 @@ Y.extend(ANNOTATION, Y.Base, {
var buttoncancel = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttoncancel");
var buttonquestion = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonquestion");
var buttonrotation = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonrotation");
var buttonpdfdisplay = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonpdfdisplay");
var buttonremove = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonremove");
var input = this.editor.get_dialogue_element('#' + this.divcartridge + "_editinput");
divdisplay.hide();
......@@ -1601,6 +1672,7 @@ Y.extend(ANNOTATION, Y.Base, {
if (buttonquestion) {
buttonquestion.show();
}
buttonpdfdisplay.show();
buttonremove.show();
divprincipale.setStyle('z-index', 1000);
if (input) {
......@@ -1640,7 +1712,6 @@ Y.extend(ANNOTATION, Y.Base, {
}
}
this.textannot = result;
window.console.log('save_annot');
this.editor.save_current_page();
if (result.length === 0) {
result = "&nbsp;&nbsp;";
......@@ -1696,6 +1767,7 @@ Y.extend(ANNOTATION, Y.Base, {
var buttoncancel = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttoncancel");
var buttonquestion = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonquestion");
var buttonrotation = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonrotation");
var buttonpdfdisplay = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonpdfdisplay");
var buttonremove = this.editor.get_dialogue_element('#' + this.divcartridge + "_buttonremove");
var buttonstatus = this.editor.get_dialogue_element('#' + this.divcartridge + "_radioContainer");
if (divdisplay) {
......@@ -1716,6 +1788,9 @@ Y.extend(ANNOTATION, Y.Base, {
if (buttonquestion) {
buttonquestion.hide();
}
if (buttonpdfdisplay) {
buttonpdfdisplay.hide();
}
if (buttonremove) {
buttonremove.hide();
}
......
......@@ -222,6 +222,13 @@ Y.extend(ANNOTATION, Y.Base, {
* @public
*/
studentanswer: "",
/**
* pdf display for this annotation
* @property pdfdisplay
* @type String
* @public
*/
pdfdisplay: "footnote",
/**
* Initialise the annotation.
*
......@@ -270,6 +277,7 @@ Y.extend(ANNOTATION, Y.Base, {
this.path = config.path || '';
this.toolid = config.toolid || this.editor.get_dialogue_element(TOOLTYPE.RECTANGLE);
this.drawable = false;
this.pdfdisplay = config.pdfdisplay;
this.tooltypefamille = this.editor.typetools[this.tooltype.type];
},
/**
......@@ -298,7 +306,8 @@ Y.extend(ANNOTATION, Y.Base, {
borderstyle: this.borderstyle,
parent_annot: parseInt(this.parent_annot, 10),
divcartridge: this.divcartridge,
parent_annot_div: this.parent_annot_element.divcartridge
parent_annot_div: this.parent_annot_element.divcartridge,
pdfdisplay: this.pdfdisplay
};
}
return {
......@@ -321,7 +330,8 @@ Y.extend(ANNOTATION, Y.Base, {
divcartridge: this.divcartridge,
parent_annot_div: '',
answerrequested: parseInt(this.answerrequested, 10),
studentstatus: parseInt(this.studentstatus, 10)
studentstatus: parseInt(this.studentstatus, 10),
pdfdisplay: this.pdfdisplay
};
},
/**
......@@ -612,6 +622,7 @@ Y.extend(ANNOTATION, Y.Base, {
divconteneurdisplay.append(divinputdisplay);
divconteneurdisplay.append(inputonof);
divconteneurdisplay.append(this.get_input_question());
divconteneurdisplay.append(this.get_input_pdfdisplay());
return divconteneurdisplay;
},
......@@ -632,6 +643,7 @@ Y.extend(ANNOTATION, Y.Base, {
if (this.tooltype.reply === 1) {
divtoolbardisplay.append(this.get_button_question());
}
divtoolbardisplay.append(this.get_button_pdfdisplay());