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 categoryname's core interaction API.
|
|
|
19 |
*
|
|
|
20 |
* @package customcertelement_categoryname
|
|
|
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_categoryname;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* The customcert element categoryname's core interaction API.
|
|
|
29 |
*
|
|
|
30 |
* @package customcertelement_categoryname
|
|
|
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 |
\mod_customcert\element_helper::render_content($pdf, $this, $this->get_category_name());
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Render the element in html.
|
|
|
49 |
*
|
|
|
50 |
* This function is used to render the element when we are using the
|
|
|
51 |
* drag and drop interface to position it.
|
|
|
52 |
*
|
|
|
53 |
* @return string the html
|
|
|
54 |
*/
|
|
|
55 |
public function render_html() {
|
|
|
56 |
return \mod_customcert\element_helper::render_html_content($this, $this->get_category_name());
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Helper function that returns the category name.
|
|
|
61 |
*
|
|
|
62 |
* @return string
|
|
|
63 |
*/
|
|
|
64 |
protected function get_category_name() : string {
|
|
|
65 |
global $DB, $SITE;
|
|
|
66 |
|
|
|
67 |
$courseid = \mod_customcert\element_helper::get_courseid($this->get_id());
|
|
|
68 |
$course = get_course($courseid);
|
|
|
69 |
$context = \mod_customcert\element_helper::get_context($this->get_id());
|
|
|
70 |
|
|
|
71 |
// Check that there is a course category available.
|
|
|
72 |
if (!empty($course->category)) {
|
|
|
73 |
$categoryname = $DB->get_field('course_categories', 'name', ['id' => $course->category], MUST_EXIST);
|
|
|
74 |
} else { // Must be in a site template.
|
|
|
75 |
$categoryname = $SITE->fullname;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
return format_string($categoryname, true, ['context' => $context]);
|
|
|
79 |
}
|
|
|
80 |
}
|