MDL-32533 tool_customlang: don't use h3 for notification
[moodle.git] / admin / tool / customlang / renderer.php
CommitLineData
03ff3b4f 1<?php
03ff3b4f
DM
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/**
b703861f 18 * Output rendering of Language customization admin tool
03ff3b4f 19 *
b703861f 20 * @package tool
03ff3b4f
DM
21 * @subpackage customlang
22 * @copyright 2010 David Mudrak <david@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28/**
b703861f 29 * Rendering methods for the tool widgets
03ff3b4f 30 */
b703861f 31class tool_customlang_renderer extends plugin_renderer_base {
03ff3b4f
DM
32
33 /**
b703861f 34 * Renders customlang tool menu
03ff3b4f
DM
35 *
36 * @return string HTML
37 */
b703861f 38 protected function render_tool_customlang_menu(tool_customlang_menu $menu) {
03ff3b4f
DM
39 $output = '';
40 foreach ($menu->get_items() as $item) {
41 $output .= $this->single_button($item->url, $item->title, $item->method);
42 }
43 return $this->box($output, 'menu');
44 }
45
46 /**
47 * Renders customlang translation table
48 *
b703861f 49 * @param tool_customlang_translator $translator
03ff3b4f
DM
50 * @return string HTML
51 */
b703861f 52 protected function render_tool_customlang_translator(tool_customlang_translator $translator) {
03ff3b4f
DM
53 $output = '';
54
55 if (empty($translator->strings)) {
53717b21 56 return $this->notification(get_string('nostringsfound', 'tool_customlang'));
03ff3b4f
DM
57 }
58
59 $table = new html_table();
60 $table->id = 'translator';
61 $table->head = array(
b703861f
PS
62 get_string('headingcomponent', 'tool_customlang'),
63 get_string('headingstringid', 'tool_customlang'),
64 get_string('headingstandard', 'tool_customlang'),
65 get_string('headinglocal', 'tool_customlang'),
03ff3b4f
DM
66 );
67
68 foreach ($translator->strings as $string) {
69 $cells = array();
70 // component name
71 $cells[0] = new html_table_cell($string->component);
72 $cells[0]->attributes['class'] = 'component';
73 // string identification code
74 $cells[1] = new html_table_cell(html_writer::tag('div', s($string->stringid), array('class' => 'stringid')));
75 $cells[1]->attributes['class'] = 'stringid';
76 // master translation of the string
1828f3d5 77 $master = html_writer::tag('div', s($string->master), array('class' => 'preformatted'));
fda6946e 78 $minheight = strlen($string->master) / 200;
1828f3d5 79 if (preg_match('/\{\$a(->.+)?\}/', $string->master)) {
b703861f
PS
80 $master .= html_writer::tag('div', $this->help_icon('placeholder', 'tool_customlang',
81 get_string('placeholderwarning', 'tool_customlang')), array('class' => 'placeholderinfo'));
1828f3d5
DM
82 }
83 $cells[2] = new html_table_cell($master);
03ff3b4f
DM
84 $cells[2]->attributes['class'] = 'standard master';
85 // local customization of the string
fda6946e
DM
86 $textareaattributes = array('name'=>'cust['.$string->id.']', 'cols'=>40, 'rows'=>3);
87 if ($minheight>1) {
88 $textareaattributes['style'] = 'min-height:' . (int) 4*$minheight . 'em;';
89 }
90 $textarea = html_writer::tag('textarea', s($string->local), $textareaattributes);
03ff3b4f
DM
91 $cells[3] = new html_table_cell($textarea);
92 if (!is_null($string->local) and $string->outdated) {
93 $mark = html_writer::empty_tag('input', array('type' => 'checkbox', 'id' => 'update_' . $string->id,
94 'name' => 'updates[]', 'value' => $string->id));
b703861f
PS
95 $help = $this->help_icon('markinguptodate', 'tool_customlang');
96 $mark .= html_writer::tag('label', get_string('markuptodate', 'tool_customlang') . $help,
03ff3b4f
DM
97 array('for' => 'update_' . $string->id));
98 $mark = html_writer::tag('div', $mark, array('class' => 'uptodatewrapper'));
99 } else {
100 $mark = '';
101 }
102 $cells[3] = new html_table_cell($textarea."\n".$mark);
103 $cells[3]->attributes['class'] = 'local';
104 $cells[3]->id = 'id_'.$string->id;
105 if (!is_null($string->local)) {
106 $cells[3]->attributes['class'] .= ' customized';
107 }
108 if ($string->outdated) {
109 $cells[3]->attributes['class'] .= ' outdated';
110 }
111 if ($string->modified) {
112 $cells[3]->attributes['class'] .= ' modified';
113 }
114
115 if ($string->original !== $string->master) {
116 $cells[0]->rowspan = $cells[1]->rowspan = $cells[3]->rowspan = 2;
117 }
118
119 $row = new html_table_row($cells);
120 $table->data[] = $row;
121
122 if ($string->original !== $string->master) {
123 $cells = array();
124 // original of the string
125 $cells[2] = new html_table_cell(html_writer::tag('div', s($string->original), array('class' => 'preformatted')));
126 $cells[2]->attributes['class'] = 'standard original';
127 $row = new html_table_row($cells);
128 $table->data[] = $row;
129 }
130 }
131
132 $output .= html_writer::start_tag('form', array('method'=>'post', 'action'=>$translator->handler->out()));
133 $output .= html_writer::start_tag('div');
134 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'translatorsubmitted', 'value'=>1));
135 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
b703861f
PS
136 $save1 = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savecontinue', 'value'=>get_string('savecontinue', 'tool_customlang')));
137 $save2 = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savecheckin', 'value'=>get_string('savecheckin', 'tool_customlang')));
03ff3b4f
DM
138 $output .= html_writer::tag('fieldset', $save1.$save2, array('class'=>'buttonsbar'));
139 $output .= html_writer::table($table);
140 $output .= html_writer::tag('fieldset', $save1.$save2, array('class'=>'buttonsbar'));
141 $output .= html_writer::end_tag('div');
142 $output .= html_writer::end_tag('form');
143
144 return $output;
145 }
146}