Commit | Line | Data |
---|---|---|
03ff3b4f DM |
1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * Output rendering of Language customization admin report | |
20 | * | |
21 | * @package report | |
22 | * @subpackage customlang | |
23 | * @copyright 2010 David Mudrak <david@moodle.com> | |
24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
25 | */ | |
26 | ||
27 | defined('MOODLE_INTERNAL') || die(); | |
28 | ||
29 | /** | |
30 | * Rendering methods for the report widgets | |
31 | */ | |
32 | class report_customlang_renderer extends plugin_renderer_base { | |
33 | ||
34 | /** | |
35 | * Renders customlang report menu | |
36 | * | |
37 | * @return string HTML | |
38 | */ | |
39 | protected function render_report_customlang_menu(report_customlang_menu $menu) { | |
40 | $output = ''; | |
41 | foreach ($menu->get_items() as $item) { | |
42 | $output .= $this->single_button($item->url, $item->title, $item->method); | |
43 | } | |
44 | return $this->box($output, 'menu'); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Renders customlang translation table | |
49 | * | |
50 | * @param report_customlang_translator $translator | |
51 | * @return string HTML | |
52 | */ | |
53 | protected function render_report_customlang_translator(report_customlang_translator $translator) { | |
54 | $output = ''; | |
55 | ||
56 | if (empty($translator->strings)) { | |
57 | return $this->heading(get_string('nostringsfound', 'report_customlang'), 3); | |
58 | } | |
59 | ||
60 | $table = new html_table(); | |
61 | $table->id = 'translator'; | |
62 | $table->head = array( | |
63 | get_string('headingcomponent', 'report_customlang'), | |
64 | get_string('headingstringid', 'report_customlang'), | |
65 | get_string('headingstandard', 'report_customlang'), | |
66 | get_string('headinglocal', 'report_customlang'), | |
67 | ); | |
68 | ||
69 | foreach ($translator->strings as $string) { | |
70 | $cells = array(); | |
71 | // component name | |
72 | $cells[0] = new html_table_cell($string->component); | |
73 | $cells[0]->attributes['class'] = 'component'; | |
74 | // string identification code | |
75 | $cells[1] = new html_table_cell(html_writer::tag('div', s($string->stringid), array('class' => 'stringid'))); | |
76 | $cells[1]->attributes['class'] = 'stringid'; | |
77 | // master translation of the string | |
1828f3d5 DM |
78 | $master = html_writer::tag('div', s($string->master), array('class' => 'preformatted')); |
79 | if (preg_match('/\{\$a(->.+)?\}/', $string->master)) { | |
80 | $master .= html_writer::tag('div', $this->help_icon('placeholder', 'report_customlang', | |
81 | get_string('placeholderwarning', 'report_customlang')), array('class' => 'placeholderinfo')); | |
82 | } | |
83 | $cells[2] = new html_table_cell($master); | |
03ff3b4f DM |
84 | $cells[2]->attributes['class'] = 'standard master'; |
85 | // local customization of the string | |
86 | $textarea = html_writer::tag('textarea', s($string->local), array('name'=>'cust['.$string->id.']')); | |
87 | $cells[3] = new html_table_cell($textarea); | |
88 | if (!is_null($string->local) and $string->outdated) { | |
89 | $mark = html_writer::empty_tag('input', array('type' => 'checkbox', 'id' => 'update_' . $string->id, | |
90 | 'name' => 'updates[]', 'value' => $string->id)); | |
91 | $help = $this->help_icon('markinguptodate', 'report_customlang'); | |
92 | $mark .= html_writer::tag('label', get_string('markuptodate', 'report_customlang') . $help, | |
93 | array('for' => 'update_' . $string->id)); | |
94 | $mark = html_writer::tag('div', $mark, array('class' => 'uptodatewrapper')); | |
95 | } else { | |
96 | $mark = ''; | |
97 | } | |
98 | $cells[3] = new html_table_cell($textarea."\n".$mark); | |
99 | $cells[3]->attributes['class'] = 'local'; | |
100 | $cells[3]->id = 'id_'.$string->id; | |
101 | if (!is_null($string->local)) { | |
102 | $cells[3]->attributes['class'] .= ' customized'; | |
103 | } | |
104 | if ($string->outdated) { | |
105 | $cells[3]->attributes['class'] .= ' outdated'; | |
106 | } | |
107 | if ($string->modified) { | |
108 | $cells[3]->attributes['class'] .= ' modified'; | |
109 | } | |
110 | ||
111 | if ($string->original !== $string->master) { | |
112 | $cells[0]->rowspan = $cells[1]->rowspan = $cells[3]->rowspan = 2; | |
113 | } | |
114 | ||
115 | $row = new html_table_row($cells); | |
116 | $table->data[] = $row; | |
117 | ||
118 | if ($string->original !== $string->master) { | |
119 | $cells = array(); | |
120 | // original of the string | |
121 | $cells[2] = new html_table_cell(html_writer::tag('div', s($string->original), array('class' => 'preformatted'))); | |
122 | $cells[2]->attributes['class'] = 'standard original'; | |
123 | $row = new html_table_row($cells); | |
124 | $table->data[] = $row; | |
125 | } | |
126 | } | |
127 | ||
128 | $output .= html_writer::start_tag('form', array('method'=>'post', 'action'=>$translator->handler->out())); | |
129 | $output .= html_writer::start_tag('div'); | |
130 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'translatorsubmitted', 'value'=>1)); | |
131 | $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey())); | |
132 | $save1 = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savecontinue', 'value'=>get_string('savecontinue', 'report_customlang'))); | |
133 | $save2 = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savecheckin', 'value'=>get_string('savecheckin', 'report_customlang'))); | |
134 | $output .= html_writer::tag('fieldset', $save1.$save2, array('class'=>'buttonsbar')); | |
135 | $output .= html_writer::table($table); | |
136 | $output .= html_writer::tag('fieldset', $save1.$save2, array('class'=>'buttonsbar')); | |
137 | $output .= html_writer::end_tag('div'); | |
138 | $output .= html_writer::end_tag('form'); | |
139 | ||
140 | return $output; | |
141 | } | |
142 | } |