1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of the customcert module for Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* This file contains the customcert element border's core interaction API.
|
|
|
19 |
*
|
|
|
20 |
* @package customcertelement_border
|
|
|
21 |
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace customcertelement_border;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* The customcert element border's core interaction API.
|
|
|
29 |
*
|
|
|
30 |
* @package customcertelement_border
|
|
|
31 |
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class element extends \mod_customcert\element {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* This function renders the form elements when adding a customcert element.
|
|
|
38 |
*
|
|
|
39 |
* @param \MoodleQuickForm $mform the edit_form instance
|
|
|
40 |
*/
|
|
|
41 |
public function render_form_elements($mform) {
|
|
|
42 |
// We want to define the width of the border.
|
|
|
43 |
\mod_customcert\element_helper::render_form_element_width($mform);
|
|
|
44 |
|
|
|
45 |
// The only other thing to define is the colour we want the border to be.
|
|
|
46 |
\mod_customcert\element_helper::render_form_element_colour($mform);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Handles rendering the element on the pdf.
|
|
|
51 |
*
|
|
|
52 |
* @param \pdf $pdf the pdf object
|
|
|
53 |
* @param bool $preview true if it is a preview, false otherwise
|
|
|
54 |
* @param \stdClass $user the user we are rendering this for
|
|
|
55 |
*/
|
|
|
56 |
public function render($pdf, $preview, $user) {
|
|
|
57 |
$colour = \TCPDF_COLORS::convertHTMLColorToDec($this->get_colour(), $colour);
|
|
|
58 |
$pdf->SetLineStyle(['width' => $this->get_data(), 'color' => $colour]);
|
|
|
59 |
$pdf->Line(0, 0, $pdf->getPageWidth(), 0);
|
|
|
60 |
$pdf->Line($pdf->getPageWidth(), 0, $pdf->getPageWidth(), $pdf->getPageHeight());
|
|
|
61 |
$pdf->Line(0, $pdf->getPageHeight(), $pdf->getPageWidth(), $pdf->getPageHeight());
|
|
|
62 |
$pdf->Line(0, 0, 0, $pdf->getPageHeight());
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Render the element in html.
|
|
|
67 |
*
|
|
|
68 |
* This function is used to render the element when we are using the
|
|
|
69 |
* drag and drop interface to position it.
|
|
|
70 |
*
|
|
|
71 |
* @return string the html
|
|
|
72 |
*/
|
|
|
73 |
public function render_html() {
|
|
|
74 |
return '';
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Performs validation on the element values.
|
|
|
79 |
*
|
|
|
80 |
* @param array $data the submitted data
|
|
|
81 |
* @param array $files the submitted files
|
|
|
82 |
* @return array the validation errors
|
|
|
83 |
*/
|
|
|
84 |
public function validate_form_elements($data, $files) {
|
|
|
85 |
// Array to return the errors.
|
|
|
86 |
$errors = [];
|
|
|
87 |
|
|
|
88 |
// Validate the width.
|
|
|
89 |
$errors += \mod_customcert\element_helper::validate_form_element_width($data, false);
|
|
|
90 |
|
|
|
91 |
// Validate the colour.
|
|
|
92 |
$errors += \mod_customcert\element_helper::validate_form_element_colour($data);
|
|
|
93 |
|
|
|
94 |
return $errors;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
* Sets the data on the form when editing an element.
|
|
|
99 |
*
|
|
|
100 |
* @param \MoodleQuickForm $mform the edit_form instance
|
|
|
101 |
*/
|
|
|
102 |
public function definition_after_data($mform) {
|
|
|
103 |
if (!empty($this->get_data())) {
|
|
|
104 |
$element = $mform->getElement('width');
|
|
|
105 |
$element->setValue($this->get_data());
|
|
|
106 |
}
|
|
|
107 |
parent::definition_after_data($mform);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* This will handle how form data will be saved into the data column in the
|
|
|
112 |
* customcert_elements table.
|
|
|
113 |
*
|
|
|
114 |
* @param \stdClass $data the form data
|
|
|
115 |
* @return string the json encoded array
|
|
|
116 |
*/
|
|
|
117 |
public function save_unique_data($data) {
|
|
|
118 |
return $data->width;
|
|
|
119 |
}
|
|
|
120 |
}
|