Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: fda6946eb2
Fetching contributors…

Cannot retrieve contributors at this time

file 147 lines (133 sloc) 6.793 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Output rendering of Language customization admin report
*
* @package report
* @subpackage customlang
* @copyright 2010 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Rendering methods for the report widgets
*/
class report_customlang_renderer extends plugin_renderer_base {

    /**
* Renders customlang report menu
*
* @return string HTML
*/
    protected function render_report_customlang_menu(report_customlang_menu $menu) {
        $output = '';
        foreach ($menu->get_items() as $item) {
            $output .= $this->single_button($item->url, $item->title, $item->method);
        }
        return $this->box($output, 'menu');
    }

    /**
* Renders customlang translation table
*
* @param report_customlang_translator $translator
* @return string HTML
*/
    protected function render_report_customlang_translator(report_customlang_translator $translator) {
        $output = '';

        if (empty($translator->strings)) {
            return $this->heading(get_string('nostringsfound', 'report_customlang'), 3);
        }

        $table = new html_table();
        $table->id = 'translator';
        $table->head = array(
            get_string('headingcomponent', 'report_customlang'),
            get_string('headingstringid', 'report_customlang'),
            get_string('headingstandard', 'report_customlang'),
            get_string('headinglocal', 'report_customlang'),
        );

        foreach ($translator->strings as $string) {
            $cells = array();
            // component name
            $cells[0] = new html_table_cell($string->component);
            $cells[0]->attributes['class'] = 'component';
            // string identification code
            $cells[1] = new html_table_cell(html_writer::tag('div', s($string->stringid), array('class' => 'stringid')));
            $cells[1]->attributes['class'] = 'stringid';
            // master translation of the string
            $master = html_writer::tag('div', s($string->master), array('class' => 'preformatted'));
            $minheight = strlen($string->master) / 200;
            if (preg_match('/\{\$a(->.+)?\}/', $string->master)) {
                $master .= html_writer::tag('div', $this->help_icon('placeholder', 'report_customlang',
                        get_string('placeholderwarning', 'report_customlang')), array('class' => 'placeholderinfo'));
            }
            $cells[2] = new html_table_cell($master);
            $cells[2]->attributes['class'] = 'standard master';
            // local customization of the string
            $textareaattributes = array('name'=>'cust['.$string->id.']', 'cols'=>40, 'rows'=>3);
            if ($minheight>1) {
               $textareaattributes['style'] = 'min-height:' . (int) 4*$minheight . 'em;';
            }
            $textarea = html_writer::tag('textarea', s($string->local), $textareaattributes);
            $cells[3] = new html_table_cell($textarea);
            if (!is_null($string->local) and $string->outdated) {
                $mark = html_writer::empty_tag('input', array('type' => 'checkbox', 'id' => 'update_' . $string->id,
                                                               'name' => 'updates[]', 'value' => $string->id));
                $help = $this->help_icon('markinguptodate', 'report_customlang');
                $mark .= html_writer::tag('label', get_string('markuptodate', 'report_customlang') . $help,
                                          array('for' => 'update_' . $string->id));
                $mark = html_writer::tag('div', $mark, array('class' => 'uptodatewrapper'));
            } else {
                $mark = '';
            }
            $cells[3] = new html_table_cell($textarea."\n".$mark);
            $cells[3]->attributes['class'] = 'local';
            $cells[3]->id = 'id_'.$string->id;
            if (!is_null($string->local)) {
                $cells[3]->attributes['class'] .= ' customized';
            }
            if ($string->outdated) {
                $cells[3]->attributes['class'] .= ' outdated';
            }
            if ($string->modified) {
                $cells[3]->attributes['class'] .= ' modified';
            }

            if ($string->original !== $string->master) {
                $cells[0]->rowspan = $cells[1]->rowspan = $cells[3]->rowspan = 2;
            }

            $row = new html_table_row($cells);
            $table->data[] = $row;

            if ($string->original !== $string->master) {
                $cells = array();
                // original of the string
                $cells[2] = new html_table_cell(html_writer::tag('div', s($string->original), array('class' => 'preformatted')));
                $cells[2]->attributes['class'] = 'standard original';
                $row = new html_table_row($cells);
                $table->data[] = $row;
            }
        }

        $output .= html_writer::start_tag('form', array('method'=>'post', 'action'=>$translator->handler->out()));
        $output .= html_writer::start_tag('div');
        $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'translatorsubmitted', 'value'=>1));
        $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
        $save1 = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savecontinue', 'value'=>get_string('savecontinue', 'report_customlang')));
        $save2 = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savecheckin', 'value'=>get_string('savecheckin', 'report_customlang')));
        $output .= html_writer::tag('fieldset', $save1.$save2, array('class'=>'buttonsbar'));
        $output .= html_writer::table($table);
        $output .= html_writer::tag('fieldset', $save1.$save2, array('class'=>'buttonsbar'));
        $output .= html_writer::end_tag('div');
        $output .= html_writer::end_tag('form');

        return $output;
    }
}
Something went wrong with that request. Please try again.