1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of 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 |
namespace core\output;
|
|
|
18 |
|
|
|
19 |
use moodle_url;
|
|
|
20 |
use stdClass;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Data structure representing a help icon.
|
|
|
24 |
*
|
|
|
25 |
* @copyright 2010 Petr Skoda (info@skodak.org)
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
* @since Moodle 2.0
|
|
|
28 |
* @package core
|
|
|
29 |
* @category output
|
|
|
30 |
*/
|
|
|
31 |
class help_icon implements renderable, templatable {
|
|
|
32 |
/**
|
|
|
33 |
* @var string lang pack identifier (without the "_help" suffix),
|
|
|
34 |
* both get_string($identifier, $component) and get_string($identifier.'_help', $component)
|
|
|
35 |
* must exist.
|
|
|
36 |
*/
|
|
|
37 |
public $identifier;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* @var string Component name, the same as in get_string()
|
|
|
41 |
*/
|
|
|
42 |
public $component;
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* @var string Extra descriptive text next to the icon
|
|
|
46 |
*/
|
|
|
47 |
public $linktext = null;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* @var mixed An object, string or number that can be used within translation strings
|
|
|
51 |
*/
|
|
|
52 |
public $a = null;
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Constructor
|
|
|
56 |
*
|
|
|
57 |
* @param string $identifier string for help page title,
|
|
|
58 |
* string with _help suffix is used for the actual help text.
|
|
|
59 |
* string with _link suffix is used to create a link to further info (if it exists)
|
|
|
60 |
* @param string $component
|
|
|
61 |
* @param string|object|array|int $a An object, string or number that can be used
|
|
|
62 |
* within translation strings
|
|
|
63 |
*/
|
|
|
64 |
public function __construct($identifier, $component, $a = null) {
|
|
|
65 |
$this->identifier = $identifier;
|
|
|
66 |
$this->component = $component;
|
|
|
67 |
$this->a = $a;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Verifies that both help strings exists, shows debug warnings if not
|
|
|
72 |
*/
|
|
|
73 |
public function diag_strings() {
|
|
|
74 |
$sm = get_string_manager();
|
|
|
75 |
if (!$sm->string_exists($this->identifier, $this->component)) {
|
|
|
76 |
debugging("Help title string does not exist: [$this->identifier, $this->component]");
|
|
|
77 |
}
|
|
|
78 |
if (!$sm->string_exists($this->identifier . '_help', $this->component)) {
|
|
|
79 |
debugging("Help contents string does not exist: [{$this->identifier}_help, $this->component]");
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Export this data so it can be used as the context for a mustache template.
|
|
|
85 |
*
|
|
|
86 |
* @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
|
|
|
87 |
* @return stdClass
|
|
|
88 |
*/
|
|
|
89 |
public function export_for_template(renderer_base $output) {
|
|
|
90 |
global $CFG;
|
|
|
91 |
|
|
|
92 |
$title = get_string($this->identifier, $this->component, $this->a);
|
|
|
93 |
|
|
|
94 |
if (empty($this->linktext)) {
|
|
|
95 |
$alt = get_string('helpprefix2', '', trim($title, ". \t"));
|
|
|
96 |
} else {
|
|
|
97 |
$alt = get_string('helpwiththis');
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
$data = get_formatted_help_string($this->identifier, $this->component, false, $this->a);
|
|
|
101 |
|
|
|
102 |
$data->alt = $alt;
|
|
|
103 |
$data->icon = (new pix_icon('help', $alt, 'core'))->export_for_template($output);
|
|
|
104 |
$data->linktext = $this->linktext;
|
|
|
105 |
$data->title = get_string('helpprefix2', '', trim($title, ". \t"));
|
|
|
106 |
|
|
|
107 |
$options = [
|
|
|
108 |
'component' => $this->component,
|
|
|
109 |
'identifier' => $this->identifier,
|
|
|
110 |
'lang' => current_language(),
|
|
|
111 |
];
|
|
|
112 |
|
|
|
113 |
// Debugging feature lets you display string identifier and component.
|
|
|
114 |
if (isset($CFG->debugstringids) && $CFG->debugstringids && optional_param('strings', 0, PARAM_INT)) {
|
|
|
115 |
$options['strings'] = 1;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
$data->url = (new moodle_url('/help.php', $options))->out(false);
|
|
|
119 |
$data->ltr = !right_to_left();
|
|
|
120 |
return $data;
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
// Alias this class to the old name.
|
|
|
125 |
// This file will be autoloaded by the legacyclasses autoload system.
|
|
|
126 |
// In future all uses of this class will be corrected and the legacy references will be removed.
|
|
|
127 |
class_alias(help_icon::class, \help_icon::class);
|