Gitlab CSE Unil

Commit 86f640c4 authored by M. Chardon's avatar M. Chardon
Browse files

optimisation classes php

parent fffb987f
......@@ -25,7 +25,8 @@
namespace assignfeedback_editpdfplus;
use assignfeedback_editpdfplus\axis;
use assignfeedback_editpdfplus\bdd\axis;
use assignfeedback_editpdfplus\bdd\type_tool;
/**
* This class performs crud operations on comments and annotations from a page of a response.
......@@ -88,7 +89,7 @@ class admin_editor {
* @global type $DB
* @param object $data object with contains tool' info
* @param Integer $contextid context's id
* @return \assignfeedback_editpdfplus\tool created tool
* @return \assignfeedback_editpdfplus\bdd\tool created tool
*/
public static function add_tool($data, $contextid) {
global $DB;
......@@ -232,7 +233,7 @@ class admin_editor {
/**
* Delete a tool
* @global type $DB
* @param \assignfeedback_editpdfplus\tool $tool
* @param \assignfeedback_editpdfplus\bdd\tool $tool
* @return Boolean true if the remove is ok
*/
public static function del_tool($tool) {
......@@ -244,7 +245,7 @@ class admin_editor {
* Get all tools by an axis' id
* @global type $DB
* @param Integer $axisid axis' id
* @return array<\assignfeedback_editpdfplus\tool> the toolbar, order by order_tool
* @return array<\assignfeedback_editpdfplus\bdd\tool> the toolbar, order by order_tool
*/
public static function get_tools_by_axis($axisid) {
global $DB;
......@@ -267,7 +268,7 @@ class admin_editor {
/**
* Get all different contexts id
* @global type $DB
* @return array<\assignfeedback_editpdfplus\axis> the axis with just their contextid
* @return array<\assignfeedback_editpdfplus\bdd\axis> the axis with just their contextid
*/
public static function get_all_different_contexts() {
global $DB;
......@@ -279,7 +280,7 @@ class admin_editor {
* Update a tool
* @global type $DB
* @param object $toolJson object contains tool's values to update
* @return \assignfeedback_editpdfplus\tool
* @return \assignfeedback_editpdfplus\bdd\tool
*/
public static function edit_tool($toolJson) {
global $DB;
......@@ -315,7 +316,7 @@ class admin_editor {
/**
* Get all the type tools which are configurabled.
* @return array<\assignfeedback_editpdfplus\type_tool> array of type tools
* @return array<\assignfeedback_editpdfplus\bdd\type_tool> array of type tools
*/
public static function get_typetools() {
global $DB;
......@@ -334,7 +335,7 @@ class admin_editor {
* Get axis by its id
* @global type $DB
* @param Integer $axeid axis' id
* @return \assignfeedback_editpdfplus\axis the axis
* @return \assignfeedback_editpdfplus\bdd\axis the axis
*/
public static function getAxisById($axeid) {
global $DB;
......@@ -345,7 +346,7 @@ class admin_editor {
/**
* Clone an axis to the context given in parameter
* @global type $DB
* @param \assignfeedback_editpdfplus\axis $axisOrigin
* @param \assignfeedback_editpdfplus\bdd\axis $axisOrigin
* @param Integer $context context's id
* @return Integer id of the imported axis
*/
......@@ -369,8 +370,8 @@ class admin_editor {
/**
* Clone a tool to a new axis
* @global type $DB
* @param \assignfeedback_editpdfplus\tool $toolToImport tool to duplicate
* @param \assignfeedback_editpdfplus\axis $axeNew axis to attached new tool
* @param \assignfeedback_editpdfplus\bdd\tool $toolToImport tool to duplicate
* @param \assignfeedback_editpdfplus\bdd\axis $axeNew axis to attached new tool
* @param Integer $context context's id
* @return Integer id of tool's created
*/
......
......@@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignfeedback_editpdfplus;
namespace assignfeedback_editpdfplus\bdd;
/**
* This class adds and removes annotations from a page of a response.
......
......@@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignfeedback_editpdfplus;
namespace assignfeedback_editpdfplus\bdd;
/**
* Description of axis
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......@@ -23,7 +24,7 @@
* @deprecated since version 2017051600
*/
namespace assignfeedback_editpdfplus;
namespace assignfeedback_editpdfplus\bdd;
/**
* This class represents a comment box on a page of feedback.
......@@ -75,4 +76,5 @@ class comment {
}
}
}
}
......@@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignfeedback_editpdfplus;
namespace assignfeedback_editpdfplus\bdd;
/**
* Description of tool
......@@ -44,6 +44,9 @@ class tool {
/** @var int type */
public $type = null;
/** @var strClass type */
public $typeObject = null;
/** @var string colors used */
public $colors = '';
......@@ -80,6 +83,9 @@ class tool {
/** @var string, html style which will a graphic representation */
public $style = "";
/** @var string, html class which will a graphic representation */
public $displayClass = "";
/**
* Convert a compatible stdClass into an instance of this class.
* @param stdClass $record
......@@ -144,21 +150,52 @@ class tool {
}
public function setDesign() {
if ($this->enabled == "1") {
//$this->button = "";
$this->style = "";
} else {
//$this->button = "";
$this->style = "background-image:none;background-color:#CCCCCC;";
}
$this->label = $this->getButtonLabel();
$this->style = $this->getStyleButton();
}
private function getButtonLabel() {
if ($this->type == "4") {
$this->label = '| ' . $this->label . ' |';
} elseif ($this->type == "5") {
$this->label = '| ' . $this->label;
return '| ' . $this->label . ' |';
}
if ($this->type == "5") {
return '| ' . $this->label;
}
return $this->label;
}
private function getStyleButton() {
$style = "";
if ($this->enabled == "0") {
$style .= "background-image:none;background-color:#CCCCCC;";
}
if ($this->type == "4" || $this->type == "1") {
$this->style .= "text-decoration: underline;";
$style .= "text-decoration: underline;";
}
return $style;
}
public function getRendererBoutonHTMLDisplay($disabled = false) {
$iconhtml = $this->getButtonLabel();
if (!$this->typeObject) {
return array(
'content' => $iconhtml,
'parameters' => null
);
}
$datatool = $this->typeObject->label;
$iconparams = array('data-tool' => $datatool,
'class' => $this->typeObject->label . ' costumtoolbarbutton btn btn-secondary',
'id' => 'ctbutton' . $this->id,
'type' => 'button',
'style' => $this->getStyleButton());
if ($disabled) {
$iconparams['disabled'] = 'true';
}
return array(
'content' => $iconhtml,
'parameters' => $iconparams
);
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the annotation class for the assignfeedback_editpdfplus plugin
*
* @package assignfeedback_editpdfplus
* @copyright 2016 Université de Lausanne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignfeedback_editpdfplus\bdd;
/**
* Description of tool
*
* @author kury
*/
class tool_generic extends tool {
const DISPLAY_CLASS_BUTTON = array(
"highlight" => "fa fa-paint-brush",
"line" => "fa fa-minus",
"oval" => "fa fa-circle-o",
"pen" => "fa fa-pencil",
"rectangle" => "fa fa-square-o",
"drag" => "fa fa-hand-paper-o",
"select" => "fa fa-mouse-pointer",
"annotationcolour" => "fa fa-tint"
);
public function getRendererBoutonHTMLDisplay($disabled = false) {
$iconhtml = \html_writer::tag("i", "", array('class' => self::DISPLAY_CLASS_BUTTON[$this->label], 'aria-hidden' => 'true'));
$iconparams = array('data-tool' => $this->label, 'class' => $this->label . 'button generictoolbarbutton btn btn-secondary', 'type' => 'button');
if ($disabled) {
$iconparams['disabled'] = 'true';
}
return array(
'content' => $iconhtml,
'parameters' => $iconparams
);
}
}
......@@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignfeedback_editpdfplus;
namespace assignfeedback_editpdfplus\bdd;
/**
* Description of type_tool
......
......@@ -265,7 +265,6 @@ EOD;
* @return combined_document
*/
public static function get_combined_document_for_attempt($assignment, $userid, $attemptnumber) {
global $USER, $DB;
$assignment = self::get_assignment_from_param($assignment);
......
......@@ -25,7 +25,11 @@
namespace assignfeedback_editpdfplus;
use assignfeedback_editpdfplus\tool;
use assignfeedback_editpdfplus\bdd\type_tool;
use assignfeedback_editpdfplus\bdd\tool;
use assignfeedback_editpdfplus\bdd\tool_generic;
use assignfeedback_editpdfplus\bdd\axis;
use assignfeedback_editpdfplus\bdd\annotation;
/**
* This class performs crud operations on comments and annotations from a page of a response.
......@@ -54,6 +58,12 @@ class page_editor {
public static function get_tools($contextidlist) {
global $DB;
$typeToolsRaw = self::get_typetools(null);
$typeTools = array();
foreach ($typeToolsRaw as $typeTool) {
$typeTools[$typeTool->id] = $typeTool;
}
$tools = array();
if ($contextidlist) {
$records = $DB->get_records_list(self::BDDTABLEOOL, self::CONTEXTID, $contextidlist);
......@@ -61,9 +71,14 @@ class page_editor {
$records = $DB->get_records(self::BDDTABLEOOL);
}
foreach ($records as $record) {
//if ($record->enabled == 1) {
array_push($tools, new tool($record));
//}
$tooltmp = null;
if (7 < $record->type && $record->type < 13) {
$tooltmp = new tool_generic($record);
} else {
$tooltmp = new tool($record);
}
$tooltmp->typeObject = $typeTools[$tooltmp->type];
array_push($tools, $tooltmp);
}
usort($tools, function($a, $b) {
$al = $a->order_tool;
......@@ -85,7 +100,10 @@ class page_editor {
global $DB;
$record = $DB->get_record(self::BDDTABLEOOL, array('id' => $toolid), '*', IGNORE_MISSING);
if ($record) {
return new tool($record);
$tool = new tool($record);
$typetool = self::get_type_tool($tool->type);
$tool->typeObject = $typetool;
return $tool;
}
return false;
}
......@@ -157,7 +175,7 @@ class page_editor {
* @param int $gradeid
* @param int $pageno
* @param bool $draft
* @return annotation[]
* @return bdd\annotation[]
*/
public static function get_annotations($gradeid, $pageno, $draft) {
global $DB;
......
......@@ -229,13 +229,13 @@ class pdf extends \FPDI {
/**
* Add an annotation to the current page
*
* @param \assignfeedback_editpdfplus\annotation $annotation
* @param \assignfeedback_editpdfplus\bdd\annotation $annotation
* @param int[]|string $path optional for 'pen' annotations this is an array of x and y coordinates for
* the line, for 'stamp' annotations it is the name of the stamp file (without the path)
* @param type $annotation_index
* @return bool true if successful (always)
*/
public function add_annotation(annotation $annotation, $path, $annotation_index) {
public function add_annotation(bdd\annotation $annotation, $path, $annotation_index) {
if (!$this->filename) {
return false;
}
......@@ -253,7 +253,7 @@ class pdf extends \FPDI {
//$type = 'line';
$toolid = $annotation->toolid;
$toolObject = page_editor::get_tool($toolid);
$typetool = page_editor::get_type_tool($toolObject->type);
$typetool = $toolObject->typeObject;
$type = $typetool->label;
$colourcartridge = $toolObject->cartridge_color;
if (!$colourcartridge) {
......
......@@ -24,6 +24,8 @@
*/
defined('MOODLE_INTERNAL') || die();
use \assignfeedback_editpdfplus\bdd\tool_generic;
/**
* A custom renderer class that extends the plugin_renderer_base and is used by the editpdf feedback plugin.
*
......@@ -33,32 +35,11 @@ defined('MOODLE_INTERNAL') || die();
*/
class assignfeedback_editpdfplus_renderer extends plugin_renderer_base {
/**
* Return the PDF button shortcut.
*
* @param string $name the name of a specific button.
* @return string the specific shortcut.
*/
private function get_shortcut($name) {
$shortcuts = array('navigate-previous-button' => 'j',
'navigate-page-select' => 'k',
'navigate-next-button' => 'l',
'select' => 'c',
'drag' => 'd',
'pen' => 'y',
'line' => 'u',
'rectangle' => 'i',
'oval' => 'o',
'highlight' => 'p',
'annotationcolour' => 'r',
'stamp' => 'n',
'currentstamp' => 'm');
// Return the shortcut.
return $shortcuts[$name];
}
const TOOL_NAVPAGESELECT = "navigate-page-select";
const TOOL_NAVPAGENEXT = "navigate-next-button";
const TOOL_SELECT = "select";
const TOOL_DRAG = "drag";
const TOOL_ANNOTATIONCOLOR = "annotationcolour";
/**
* Render a single colour button.
......@@ -68,110 +49,12 @@ class assignfeedback_editpdfplus_renderer extends plugin_renderer_base {
* @param bool $disabled Optional - Is this button disabled.
* @return string
*/
private function render_toolbar_button($tool, assignfeedback_editpdfplus\tool $fulltool = null, $accesskey = null, $disabled = false) {
if (!$fulltool) {
// Build button alt text.
$alttext = new stdClass();
$alttext->tool = $tool;
if (!empty($accesskey)) {
$alttext->shortcut = '(Alt/Shift-Alt/Ctrl-Option + ' . $accesskey . ')';
} else {
$alttext->shortcut = '';
}
$iconalt = get_string('toolbarbutton', 'assignfeedback_editpdfplus', $alttext);
$class = "";
switch ($tool) {
case "drag":
$class = "fa-hand-paper-o";
break;
case "select":
$class = "fa-mouse-pointer";
break;
case "pen":
$class = "fa-pencil";
break;
case "line":
$class = "fa-minus";
break;
case "rectangle":
$class = "fa-square-o";
break;
case "oval":
$class = "fa-circle-o";
break;
case "highlight":
$class = "fa-paint-brush";
break;
case "annotationcolour":
$class = "fa-tint"; //,'style'=>'color:red;'
break;
default:
break;
}
$iconhtml = html_writer::tag("i", "", array('class' => 'fa ' . $class,
'aria-hidden' => 'true'));
$iconparams = array('data-tool' => $tool, 'class' => $tool . 'button btn btn-secondary', 'type' => 'button');
if ($disabled) {
$iconparams['disabled'] = 'true';
}
} else {
$iconalt = $fulltool->label;
$iconhtml = $fulltool->label;
if ($fulltool->type == 4) {
$iconhtml = '| ' . $fulltool->label . ' |';
}
if ($fulltool->type == 5) {
$iconhtml = '| ' . $fulltool->label;
}
$datatool = '';
$class = '';
switch ($fulltool->type) {
case 1:
$datatool = 'highlightplus';
$class = 'highlightplus';
break;
case 2:
$datatool = 'lineplus';
$class = 'lineplus';
break;
case 3:
$datatool = 'stampplus';
$class = 'stampplus';
break;
case 4:
$datatool = 'frame';
$class = 'frame';
break;
case 5:
$datatool = 'verticalline';
$class = 'verticalline';
break;
case 6:
$datatool = 'stampcomment';
$class = 'stampcomment';
break;
case 7:
$datatool = 'commentplus';
$class = 'commentplus';
break;
default:
break;
}
$iconparams = array('data-tool' => $datatool,
'class' => $class . 'btn costumtoolbarbutton btn btn-secondary',
'id' => 'ctbutton' . $fulltool->id,
'type' => 'button');
}
if (!empty($accesskey)) {
$iconparams['accesskey'] = $accesskey;
}
return html_writer::tag('button', $iconhtml, $iconparams);
private function render_toolbar_button(assignfeedback_editpdfplus\bdd\tool $fulltool = null, $disabled = false) {
$displayArray = $fulltool->getRendererBoutonHTMLDisplay($disabled);
return html_writer::tag('button', $displayArray["content"], $displayArray["parameters"]);
}
private function render_toolbar_axis(assignfeedback_editpdfplus\axis $axis) {
private function render_toolbar_axis(assignfeedback_editpdfplus\bdd\axis $axis) {
$iconhtml = $axis->label;
$iconparams = array('type' => 'checkbox', 'class' => 'axis', 'id' => 'ctaxis' . $axis->id, 'value' => $axis->id);
$inputhtml = html_writer::tag('input', "", $iconparams);
......@@ -207,11 +90,11 @@ class assignfeedback_editpdfplus_renderer extends plugin_renderer_base {
$body = '';
$tooglenavigation = html_writer::tag("button", '<span class="navbar-toggler-icon"></span>', array('class' => 'navbar-toggler',
'type' => 'button',
'data-toggle' => "collapse",
'data-target' => "#navbarSupportedContent",
'aria-expanded' => "Toggle navigation"));
/* $tooglenavigation = html_writer::tag("button", '<span class="navbar-toggler-icon"></span>', array('class' => 'navbar-toggler',
'type' => 'button',
'data-toggle' => "collapse",
'data-target' => "#navbarSupportedContent",
'aria-expanded' => "Toggle navigation")); */
// Create the page navigation.
$navigation = '';
......@@ -230,14 +113,14 @@ class assignfeedback_editpdfplus_renderer extends plugin_renderer_base {
'type' => 'button',
'accesskey' => $this->get_shortcut('navigate-previous-button')));
$navigation .= html_writer::tag('select', null, array('disabled' => 'true',
'aria-label' => get_string('gotopage', 'assignfeedback_editpdfplus'), 'class' => 'navigate-page-select',
'accesskey' => $this->get_shortcut('navigate-page-select')));
'aria-label' => get_string('gotopage', 'assignfeedback_editpdfplus'), 'class' => self::TOOL_NAVPAGESELECT,
'accesskey' => $this->get_shortcut(self::TOOL_NAVPAGESELECT)));
$iconhtmlN = html_writer::tag("i", "", array('class' => 'fa fa-caret-right fa-2x',
'aria-hidden' => 'true'));
$navigation .= html_writer::tag('button', $iconhtmlN, array('disabled' => 'true',
'class' => 'btn btn-secondary navigate-next-button',
'class' => 'btn btn-secondary ' . self::TOOL_NAVPAGENEXT,
'type' => 'button',
'accesskey' => $this->get_shortcut('navigate-next-button')));
'accesskey' => $this->get_shortcut(self::TOOL_NAVPAGENEXT)));
$navigationBlock = html_writer::div($navigation, "btn-group btn-group-sm mr-auto", array('role' => 'group'));
......@@ -250,29 +133,32 @@ class assignfeedback_editpdfplus_renderer extends plugin_renderer_base {
if (!$widget->readonly) {
/** Toolbar n°0 : basic tools * */
// Select Tool.
$toolbarBase = $this->render_toolbar_button('drag', null, $this->get_shortcut('drag'));
$toolbarBase .= $this->render_toolbar_button('select', null, $this->get_shortcut('select'));
$dragTool = new tool_generic();
$dragTool->label = self::TOOL_DRAG;
$toolbarBase = $this->render_toolbar_button($dragTool);
$selectTool = new tool_generic();
$selectTool->label = self::TOOL_SELECT;
$toolbarBase .= $this->render_toolbar_button($selectTool);
$toolbarBaseBlock = html_writer::div($toolbarBase, "btn-group btn-group-sm mr-3", array('role' => 'group'));
// Other Tools.
$toolbarDraw = $this->render_toolbar_button('pen', null, $this->get_shortcut('pen'));
$toolbarDraw .= $this->render_toolbar_button('line', null, $this->get_shortcut('line'));
$toolbarDraw .= $this->render_toolbar_button('rectangle', null, $this->get_shortcut('rectangle'));
$toolbarDraw .= $this->render_toolbar_button('oval', null, $this->get_shortcut('oval'));
$toolbarDraw .= $this->render_toolbar_button('highlight', null, $this->get_shortcut('highlight'));
$toolbarDraw .= $this->render_toolbar_button('annotationcolour', null, $this->get_shortcut('annotationcolour'));
// Generic Tools.
$toolbarDraw = '';
foreach ($widget->genericToolbar as $tool) {
$toolbarDraw .= $this->render_toolbar_button($tool);
}
$colorTool = new tool_generic();
$colorTool->label = self::TOOL_ANNOTATIONCOLOR;
$toolbarDraw .= $this->render_toolbar_button($colorTool);
$toolbarDrawBlock = html_writer::div($toolbarDraw, "btn-group btn-group-sm", array('role' => 'group'));
/** Costum toolbars * */
$toolbarCostum = array();
$axis = array();
foreach ($widget->toolbars as $toolbar) {
foreach ($widget->customToolbars as $toolbar) {
$axis[$toolbar['axeid']] = $toolbar['label'];