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 code's core interaction API.
19
 *
20
 * @package    customcertelement_code
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_code;
26
 
27
/**
28
 * The customcert element code's core interaction API.
29
 *
30
 * @package    customcertelement_code
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
     * Handles rendering the element on the pdf.
38
     *
39
     * @param \pdf $pdf the pdf object
40
     * @param bool $preview true if it is a preview, false otherwise
41
     * @param \stdClass $user the user we are rendering this for
42
     */
43
    public function render($pdf, $preview, $user) {
44
        global $DB;
45
 
46
        if ($preview) {
47
            $code = \mod_customcert\certificate::generate_code();
48
        } else {
49
            // Get the page.
50
            $page = $DB->get_record('customcert_pages', ['id' => $this->get_pageid()], '*', MUST_EXIST);
51
            // Get the customcert this page belongs to.
52
            $customcert = $DB->get_record('customcert', ['templateid' => $page->templateid], '*', MUST_EXIST);
53
            // Now we can get the issue for this user.
54
            $issue = $DB->get_record('customcert_issues', ['userid' => $user->id, 'customcertid' => $customcert->id],
55
                '*', IGNORE_MULTIPLE);
56
            $code = $issue->code;
57
        }
58
 
59
        \mod_customcert\element_helper::render_content($pdf, $this, $code);
60
    }
61
 
62
    /**
63
     * Render the element in html.
64
     *
65
     * This function is used to render the element when we are using the
66
     * drag and drop interface to position it.
67
     *
68
     * @return string the html
69
     */
70
    public function render_html() {
71
        $code = \mod_customcert\certificate::generate_code();
72
 
73
        return \mod_customcert\element_helper::render_html_content($this, $code);
74
    }
75
}