Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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 text's core interaction API.
19
 *
20
 * @package    customcertelement_text
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_text;
26
 
27
/**
28
 * The customcert element text's core interaction API.
29
 *
30
 * @package    customcertelement_text
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
        $mform->addElement('textarea', 'text', get_string('text', 'customcertelement_text'));
43
        $mform->setType('text', PARAM_RAW);
44
        $mform->addHelpButton('text', 'text', 'customcertelement_text');
45
 
46
        parent::render_form_elements($mform);
47
    }
48
 
49
    /**
50
     * This will handle how form data will be saved into the data column in the
51
     * customcert_elements table.
52
     *
53
     * @param \stdClass $data the form data
54
     * @return string the text
55
     */
56
    public function save_unique_data($data) {
57
        return $data->text;
58
    }
59
 
60
    /**
61
     * Handles rendering the element on the pdf.
62
     *
63
     * @param \pdf $pdf the pdf object
64
     * @param bool $preview true if it is a preview, false otherwise
65
     * @param \stdClass $user the user we are rendering this for
66
     */
67
    public function render($pdf, $preview, $user) {
68
        \mod_customcert\element_helper::render_content($pdf, $this, $this->get_text());
69
    }
70
 
71
    /**
72
     * Render the element in html.
73
     *
74
     * This function is used to render the element when we are using the
75
     * drag and drop interface to position it.
76
     *
77
     * @return string the html
78
     */
79
    public function render_html() {
80
        return \mod_customcert\element_helper::render_html_content($this, $this->get_text());
81
    }
82
 
83
    /**
84
     * Sets the data on the form when editing an element.
85
     *
86
     * @param \MoodleQuickForm $mform the edit_form instance
87
     */
88
    public function definition_after_data($mform) {
89
        if (!empty($this->get_data())) {
90
            $element = $mform->getElement('text');
91
            $element->setValue($this->get_data());
92
        }
93
        parent::definition_after_data($mform);
94
    }
95
 
96
    /**
97
     * Helper function that returns the text.
98
     *
99
     * @return string
100
     */
101
    protected function get_text() : string {
102
        $context = \mod_customcert\element_helper::get_context($this->get_id());
103
        return format_text($this->get_data(), FORMAT_HTML, ['context' => $context]);
104
    }
105
}