|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00026 defined('MOODLE_INTERNAL') || die(); 00027 00031 class tool_customlang_renderer extends plugin_renderer_base { 00032 00038 protected function render_tool_customlang_menu(tool_customlang_menu $menu) { 00039 $output = ''; 00040 foreach ($menu->get_items() as $item) { 00041 $output .= $this->single_button($item->url, $item->title, $item->method); 00042 } 00043 return $this->box($output, 'menu'); 00044 } 00045 00052 protected function render_tool_customlang_translator(tool_customlang_translator $translator) { 00053 $output = ''; 00054 00055 if (empty($translator->strings)) { 00056 return $this->heading(get_string('nostringsfound', 'tool_customlang'), 3); 00057 } 00058 00059 $table = new html_table(); 00060 $table->id = 'translator'; 00061 $table->head = array( 00062 get_string('headingcomponent', 'tool_customlang'), 00063 get_string('headingstringid', 'tool_customlang'), 00064 get_string('headingstandard', 'tool_customlang'), 00065 get_string('headinglocal', 'tool_customlang'), 00066 ); 00067 00068 foreach ($translator->strings as $string) { 00069 $cells = array(); 00070 // component name 00071 $cells[0] = new html_table_cell($string->component); 00072 $cells[0]->attributes['class'] = 'component'; 00073 // string identification code 00074 $cells[1] = new html_table_cell(html_writer::tag('div', s($string->stringid), array('class' => 'stringid'))); 00075 $cells[1]->attributes['class'] = 'stringid'; 00076 // master translation of the string 00077 $master = html_writer::tag('div', s($string->master), array('class' => 'preformatted')); 00078 $minheight = strlen($string->master) / 200; 00079 if (preg_match('/\{\$a(->.+)?\}/', $string->master)) { 00080 $master .= html_writer::tag('div', $this->help_icon('placeholder', 'tool_customlang', 00081 get_string('placeholderwarning', 'tool_customlang')), array('class' => 'placeholderinfo')); 00082 } 00083 $cells[2] = new html_table_cell($master); 00084 $cells[2]->attributes['class'] = 'standard master'; 00085 // local customization of the string 00086 $textareaattributes = array('name'=>'cust['.$string->id.']', 'cols'=>40, 'rows'=>3); 00087 if ($minheight>1) { 00088 $textareaattributes['style'] = 'min-height:' . (int) 4*$minheight . 'em;'; 00089 } 00090 $textarea = html_writer::tag('textarea', s($string->local), $textareaattributes); 00091 $cells[3] = new html_table_cell($textarea); 00092 if (!is_null($string->local) and $string->outdated) { 00093 $mark = html_writer::empty_tag('input', array('type' => 'checkbox', 'id' => 'update_' . $string->id, 00094 'name' => 'updates[]', 'value' => $string->id)); 00095 $help = $this->help_icon('markinguptodate', 'tool_customlang'); 00096 $mark .= html_writer::tag('label', get_string('markuptodate', 'tool_customlang') . $help, 00097 array('for' => 'update_' . $string->id)); 00098 $mark = html_writer::tag('div', $mark, array('class' => 'uptodatewrapper')); 00099 } else { 00100 $mark = ''; 00101 } 00102 $cells[3] = new html_table_cell($textarea."\n".$mark); 00103 $cells[3]->attributes['class'] = 'local'; 00104 $cells[3]->id = 'id_'.$string->id; 00105 if (!is_null($string->local)) { 00106 $cells[3]->attributes['class'] .= ' customized'; 00107 } 00108 if ($string->outdated) { 00109 $cells[3]->attributes['class'] .= ' outdated'; 00110 } 00111 if ($string->modified) { 00112 $cells[3]->attributes['class'] .= ' modified'; 00113 } 00114 00115 if ($string->original !== $string->master) { 00116 $cells[0]->rowspan = $cells[1]->rowspan = $cells[3]->rowspan = 2; 00117 } 00118 00119 $row = new html_table_row($cells); 00120 $table->data[] = $row; 00121 00122 if ($string->original !== $string->master) { 00123 $cells = array(); 00124 // original of the string 00125 $cells[2] = new html_table_cell(html_writer::tag('div', s($string->original), array('class' => 'preformatted'))); 00126 $cells[2]->attributes['class'] = 'standard original'; 00127 $row = new html_table_row($cells); 00128 $table->data[] = $row; 00129 } 00130 } 00131 00132 $output .= html_writer::start_tag('form', array('method'=>'post', 'action'=>$translator->handler->out())); 00133 $output .= html_writer::start_tag('div'); 00134 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'translatorsubmitted', 'value'=>1)); 00135 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey())); 00136 $save1 = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savecontinue', 'value'=>get_string('savecontinue', 'tool_customlang'))); 00137 $save2 = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savecheckin', 'value'=>get_string('savecheckin', 'tool_customlang'))); 00138 $output .= html_writer::tag('fieldset', $save1.$save2, array('class'=>'buttonsbar')); 00139 $output .= html_writer::table($table); 00140 $output .= html_writer::tag('fieldset', $save1.$save2, array('class'=>'buttonsbar')); 00141 $output .= html_writer::end_tag('div'); 00142 $output .= html_writer::end_tag('form'); 00143 00144 return $output; 00145 } 00146 }