Example #1
0
 /**
  * Checks the decsep and thousandssep config strings are set correctly
  *
  * @link http://tracker.moodle.org/browse/MDL-31332
  * @return bool check success flag
  */
 protected function check_decsep_thousandssep()
 {
     $details = array();
     $langnames = array();
     $tree = mlang_tools::components_tree(array('component' => 'langconfig'));
     foreach ($tree as $branch => $languages) {
         $version = mlang_version::by_code($branch);
         foreach (array_keys($languages) as $language) {
             $langconfig = mlang_component::from_snapshot('langconfig', $language, $version);
             if ($langname = $langconfig->get_string('thislanguageint')) {
                 $langnames[$language] = $langname->text;
             } else {
                 $langnames[$language] = $language;
             }
             if ($decsep = $langconfig->get_string('decsep')) {
                 $decsep = $decsep->text;
             }
             if ($thousandssep = $langconfig->get_string('thousandssep')) {
                 $thousandssep = $thousandssep->text;
             }
             if (empty($decsep) and empty($thousandssep)) {
                 $details[$language][$version->label] = 1;
             } else {
                 if (empty($decsep) or empty($thousandssep)) {
                     $details[$language][$version->label] = 2;
                 } else {
                     if ($decsep === $thousandssep) {
                         $details[$language][$version->label] = 3;
                     }
                 }
             }
         }
     }
     ksort($details);
     foreach ($details as $language => $branches) {
         $msg = sprintf('Invalid decsep and/or thousandssep in %s {%s} at', $langnames[$language], $language);
         foreach ($branches as $branch => $severity) {
             $msg .= ' ' . $branch . str_repeat('!', $severity);
         }
         $this->output($msg, true);
     }
     if (empty($details)) {
         return 0;
     }
     return 1;
 }
Example #2
0
$PAGE->set_heading('AMOS');
$output = $PAGE->get_renderer('local_amos');
/// Output starts here
echo $output->header();
echo $output->heading(get_string('amos', 'local_amos'), 1);
echo $output->container(get_string('about', 'local_amos'));
echo $output->heading(get_string('privileges', 'local_amos'));
$caps = array();
if (has_capability('local/amos:manage', get_system_context())) {
    $caps[] = get_string('amos:manage', 'local_amos');
}
if (has_capability('local/amos:stage', get_system_context())) {
    $caps[] = get_string('amos:stage', 'local_amos');
}
if (has_capability('local/amos:commit', get_system_context())) {
    $allowed = mlang_tools::list_allowed_languages($USER->id);
    if (empty($allowed)) {
        $allowed = get_string('committablenone', 'local_amos');
    } elseif (!empty($allowed['X'])) {
        $allowed = get_string('committableall', 'local_amos');
    } else {
        $allowed = implode(', ', $allowed);
    }
    $caps[] = get_string('amos:commit', 'local_amos') . ' (' . $allowed . ')';
}
if (empty($caps)) {
    get_string('privilegesnone', 'local_amos');
} else {
    $caps = '<li>' . implode("</li>\n<li>", $caps) . '</li>';
    echo html_writer::tag('ul', $caps);
}
    $gitout = array();
    $gitstatus = 0;
    $gitcmd = AMOS_PATH_GIT . " show {$gitbranch}:install/stringnames.txt";
    exec($gitcmd, $gitout, $gitstatus);
    if ($gitstatus != 0) {
        fputs(STDERR, "ERROR EXECUTING {$gitcmd}\n");
        exit($gitstatus);
    }
    $list = array();
    // [component][stringid] => true
    foreach ($gitout as $string) {
        list($stringid, $component) = array_map('trim', explode(',', $string));
        $list[$component][$stringid] = true;
    }
    unset($gitout);
    $tree = mlang_tools::components_tree(array('branch' => $version->code));
    $langs = array_keys($tree[$version->code]);
    unset($tree);
    $phpdoc = <<<EOF
/**
 * Automatically generated strings for Moodle {$version->label} installer
 *
 * Do not edit this file manually! It contains just a subset of strings
 * needed during the very first steps of installation. This file was
 * generated automatically by export-installer.php (which is part of AMOS
 * {@link http://docs.moodle.org/dev/Languages/AMOS}) using the
 * list of strings defined in /install/stringnames.txt.
 *
 * @package   installer
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
Example #4
0
 function definition()
 {
     global $USER;
     $mform = $this->_form;
     // Commits filter
     $mform->addElement('header', 'logfiltercommits', get_string('logfiltercommits', 'local_amos'));
     // Committed after
     $mform->addElement('date_time_selector', 'committedafter', get_string('logfiltercommittedafter', 'local_amos'), array('optional' => true, 'timezone' => 'UTC', 'applydst' => false));
     $mform->setDefault('committedafter', $USER->lastlogin);
     // Committed before
     $mform->addElement('date_time_selector', 'committedbefore', get_string('logfiltercommittedbefore', 'local_amos'), array('optional' => true, 'timezone' => 'UTC', 'applydst' => false));
     $mform->setAdvanced('committedbefore');
     // Committer
     $committers = get_users_by_capability(get_system_context(), 'local/amos:commit', user_picture::fields('u'), 'lastname, firstname');
     $users = array('' => '');
     foreach ($committers as $committer) {
         $users[$committer->id] = s(fullname($committer) . ' <' . $committer->email . '>');
     }
     $usergrp[] = $mform->createElement('select', 'userid', '', $users);
     $usergrp[] = $mform->createElement('text', 'userinfo', '');
     $mform->setType('userinfo', PARAM_NOTAGS);
     $mform->addGroup($usergrp, 'usergrp', get_string('logfilterusergrp', 'local_amos'), get_string('logfilterusergrpor', 'local_amos'), false);
     $mform->setAdvanced('usergrp');
     // Source
     $sources = array('' => '', 'git' => get_string('logfiltersourcegit', 'local_amos'), 'amos' => get_string('logfiltersourceamos', 'local_amos'), 'revclean' => get_string('logfiltersourcerevclean', 'local_amos'), 'commitscript' => get_string('logfiltersourcecommitscript', 'local_amos'), 'fixdrift' => get_string('logfiltersourcefixdrift', 'local_amos'), 'bot' => get_string('logfiltersourcebot', 'local_amos'));
     $mform->addElement('select', 'source', get_string('logfiltersource', 'local_amos'), $sources);
     $mform->setAdvanced('source');
     // Commit message
     $mform->addElement('text', 'commitmsg', get_string('logfiltercommitmsg', 'local_amos'));
     $mform->setAdvanced('commitmsg');
     // Commit hash
     $mform->addElement('text', 'commithash', get_string('logfiltercommithash', 'local_amos'));
     $mform->setAdvanced('commithash');
     // Strings filter
     $mform->addElement('header', 'logfilterstrings', get_string('logfilterstrings', 'local_amos'));
     // Branch
     $branchgrp = array();
     foreach (mlang_version::list_all() as $version) {
         $branchgrp[] = $mform->createElement('checkbox', $version->code, '', $version->label);
     }
     $mform->addGroup($branchgrp, 'branch', get_string('logfilterbranch', 'local_amos'), ' ');
     foreach (mlang_version::list_all() as $version) {
         if ($version->current) {
             $mform->setDefault('branch[' . $version->code . ']', 1);
         }
     }
     // Lang
     $langgrp = array();
     $langgrp[] = $mform->createElement('checkbox', 'langenabled', '', get_string('enable'));
     $langgrp[] = $mform->createElement('select', 'lang', '', mlang_tools::list_languages(), array('multiple' => 'multiple', 'size' => 5));
     $mform->addGroup($langgrp, 'langgrp', get_string('logfilterlang', 'local_amos'), '<br />', false);
     $mform->setDefault('lang', array('en', current_language()));
     $mform->disabledIf('lang', 'langenabled');
     // does not seem to work for multiple selects :-/
     $mform->setAdvanced('langgrp');
     // Components
     $optionscore = array();
     $optionsstandard = array();
     $optionscontrib = array();
     $standard = array();
     foreach (local_amos_standard_plugins() as $plugins) {
         $standard = array_merge($standard, $plugins);
     }
     foreach (mlang_tools::list_components() as $componentname => $undefined) {
         if (isset($standard[$componentname])) {
             if ($standard[$componentname] === 'core' or substr($standard[$componentname], 0, 5) === 'core_') {
                 $optionscore[$componentname] = $standard[$componentname];
             } else {
                 $optionsstandard[$componentname] = $standard[$componentname];
             }
         } else {
             $optionscontrib[$componentname] = $componentname;
         }
     }
     asort($optionscore);
     asort($optionsstandard);
     asort($optionscontrib);
     $options = array(get_string('pluginclasscore', 'local_amos') => $optionscore, get_string('pluginclassstandard', 'local_amos') => $optionsstandard, get_string('pluginclassnonstandard', 'local_amos') => $optionscontrib);
     $componentgrp = array();
     $componentgrp[] = $mform->createElement('checkbox', 'componentenabled', '', get_string('enable'));
     $componentgrp[] = $mform->createElement('selectgroups', 'component', '', $options, array('multiple' => 'multiple', 'size' => 5));
     $mform->addGroup($componentgrp, 'componentgrp', get_string('logfiltercomponent', 'local_amos'), '<br />', false);
     $mform->disabledIf('component', 'componentenabled');
     // does not seem to work for multiple selects :-/
     $mform->setAdvanced('componentgrp');
     // Stringid
     $mform->addElement('text', 'stringid', get_string('logfilterstringid', 'local_amos'));
     $mform->setType('stringid', PARAM_STRINGID);
     $mform->setAdvanced('stringid');
     // Submit
     $mform->addElement('submit', 'submit', get_string('logfiltershow', 'local_amos'));
     $mform->closeHeaderBefore('submit');
 }
Example #5
0
require_login(SITEID, false);
require_capability('local/amos:execute', get_system_context());
require_capability('local/amos:stage', get_system_context());
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/local/amos/execute.php');
navigation_node::override_active_url(new moodle_url('/local/amos/stage.php'));
$PAGE->set_title('AMOS ' . get_string('scriptexecute', 'local_amos'));
$PAGE->set_heading('AMOS ' . get_string('scriptexecute', 'local_amos'));
$executeform = new local_amos_execute_form(null, local_amos_execute_options());
if ($data = $executeform->get_data()) {
    $version = mlang_version::by_code($data->version);
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $instructions = mlang_tools::extract_script_from_text($data->script);
    if (!empty($instructions)) {
        foreach ($instructions as $instruction) {
            $changes = mlang_tools::execute($instruction, $version);
            if ($changes instanceof mlang_stage) {
                foreach ($changes->get_iterator() as $component) {
                    $stage->add($component, true);
                }
                $changes->clear();
            } elseif ($changes < 0) {
                throw new moodle_exception('error_during_amoscript_execution', 'local_amos', '', null, $changes);
            }
            unset($changes);
        }
    }
    $stage->rebase();
    $stage->store();
    if (!isset($SESSION->local_amos)) {
        $SESSION->local_amos = new stdClass();
Example #6
0
require_login(SITEID, false);
require_capability('local/amos:stage', get_system_context());
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/local/amos/diff.php');
navigation_node::override_active_url(new moodle_url('/local/amos/stage.php'));
$PAGE->set_title('AMOS ' . get_string('diff', 'local_amos'));
$PAGE->set_heading('AMOS ' . get_string('diff', 'local_amos'));
$diffform = new local_amos_diff_form(null, local_amos_diff_options());
if ($data = $diffform->get_data()) {
    if ($data->versiona == $data->versionb) {
        notice(get_string('nodiffs', 'local_amos'), new moodle_url('/local/amos/stage.php'));
    }
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $versiona = mlang_version::by_code($data->versiona);
    $versionb = mlang_version::by_code($data->versionb);
    $tree = mlang_tools::components_tree(array('branch' => $versiona->code, 'lang' => 'en'));
    $componentnames = array_keys($tree[$versiona->code]['en']);
    $total = count($componentnames);
    unset($tree);
    echo $OUTPUT->header();
    $progressbar = new progress_bar();
    $progressbar->create();
    // prints the HTML code of the progress bar
    // we may need a bit of extra execution time and memory here
    @set_time_limit(HOURSECS);
    raise_memory_limit(MEMORY_EXTRA);
    // number of differences
    $num = 0;
    foreach ($componentnames as $i => $componentname) {
        $progressbar->update($i, $total, get_string('diffprogress', 'local_amos'));
        // the most recent snapshots
Example #7
0
 * @package   local_amos
 * @copyright 2010 David Mudrak <*****@*****.**>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('CLI_SCRIPT', true);
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php';
require_once $CFG->dirroot . '/local/amos/cli/config.php';
require_once $CFG->dirroot . '/local/amos/mlanglib.php';
require_once $CFG->dirroot . '/local/amos/renderer.php';
require_once $CFG->libdir . '/clilib.php';
list($options, $unrecognized) = cli_get_params(array('full' => false), array('f' => 'full'));
fputs(STDOUT, "*****************************************\n");
fputs(STDOUT, date('Y-m-d H:i', time()));
fputs(STDOUT, " REVERSE CLEANUP JOB STARTED\n");
$mem = memory_get_usage();
$tree = mlang_tools::components_tree();
foreach ($tree as $vercode => $languages) {
    $version = mlang_version::by_code($vercode);
    foreach ($languages['en'] as $componentname => $unused) {
        if ($componentname == 'langconfig') {
            continue;
        }
        $memprev = $mem;
        $mem = memory_get_usage();
        $memdiff = $memprev < $mem ? '+' : '-';
        $memdiff = $memdiff . abs($mem - $memprev);
        $english = mlang_component::from_snapshot($componentname, 'en', $version, null, true, true);
        foreach ($english->get_iterator() as $string) {
            if (empty($options['full']) and $string->timemodified < time() - DAYSECS) {
                continue;
            }
Example #8
0
/**
 * This is a helper function that just contains a block of code that needs to be
 * executed from two different places in this script. Consider it more as C macro
 * than a real function.
 */
function amos_parse_core_commit()
{
    global $DB;
    global $stage, $realmodified, $timemodified, $commitmsg, $committer, $committeremail, $commithash, $version, $fullcommitmsg, $startatlock, $affected;
    // if there is nothing to do, just store the last hash processed and return
    // this is typical for git commits that do not touch any lang file
    if (!$stage->has_component()) {
        file_put_contents($startatlock, $commithash);
        return;
    }
    if (empty($commithash)) {
        throw new coding_exception('When storing strings from a git commit, the hash must be provided');
    }
    // this is a hacky check to make sure that the git commit has not been processed already
    // this helps to prevent situations when a commit is reverted and AMOS is adding
    // and removing strings in sort of loop
    if ($DB->record_exists('amos_commits', array('source' => 'git', 'commithash' => $commithash))) {
        $stage->clear();
        fputs(STDOUT, "SKIP {$commithash} has already been processed before\n");
        file_put_contents($startatlock, $commithash);
        return;
    }
    // rebase the stage so that it contains just real modifications of strings
    $stage->rebase($timemodified, true, $timemodified);
    // make sure that the strings to be removed are really affected by the commit
    foreach ($stage->get_iterator() as $component) {
        foreach ($component->get_iterator() as $string) {
            if (!isset($affected[$component->name][$string->id])) {
                $component->unlink_string($string->id);
            }
        }
    }
    // rebase again to get rid of eventually empty components that were
    // left after removing unaffected strings
    $stage->rebase($timemodified, false);
    // if there is nothing to do now, just store the last has processed and return.
    // this is typical for git commits that touch some lang file but they do not actually
    // modify any string. Note that we do not execute AMOScript in this situation.
    if (!$stage->has_component()) {
        fputs(STDOUT, "NOOP {$commithash} does not introduce any string change\n");
        file_put_contents($startatlock, $commithash);
        return;
    }
    // ok so it seems we finally have something to do here! let's spam the world first
    amos_core_commit_notify($stage, $commitmsg, $committer, $committeremail, $commithash, $fullcommitmsg);
    // actually commit the changes
    $stage->commit($commitmsg, array('source' => 'git', 'userinfo' => $committer . ' <' . $committeremail . '>', 'commithash' => $commithash), true, $timemodified);
    // execute AMOS script if the commit message contains some
    if ($version->code >= mlang_version::MOODLE_20) {
        $instructions = mlang_tools::extract_script_from_text($fullcommitmsg);
        if (!empty($instructions)) {
            foreach ($instructions as $instruction) {
                fputs(STDOUT, "EXEC {$instruction}\n");
                $changes = mlang_tools::execute($instruction, $version, $timemodified);
                if ($changes instanceof mlang_stage) {
                    $changes->rebase($timemodified);
                    $changes->commit($commitmsg, array('source' => 'commitscript', 'userinfo' => $committer . ' <' . $committeremail . '>', 'commithash' => $commithash), true, $timemodified);
                } elseif ($changes < 0) {
                    fputs(STDERR, "EXEC STATUS {$changes}\n");
                }
                unset($changes);
            }
        }
    }
    // remember the processed commithash
    file_put_contents($startatlock, $commithash);
}
Example #9
0
if (!empty($del)) {
    require_sesskey();
    $lang = required_param('langcode', PARAM_SAFEDIR);
    if (empty($lang)) {
        print_error('err_invalidlangcode', 'local_amos');
    }
    $DB->delete_records('amos_translators', array('userid' => $del, 'lang' => $lang));
    redirect($PAGE->url);
}
$options = array();
foreach ($available as $userid => $user) {
    $options[$userid] = sprintf('%s, %s &lt;%s&gt;', $user->lastname, $user->firstname, $user->email);
}
/// Output starts here
echo $OUTPUT->header();
$languages = array_merge(array('X' => '(All languages)'), mlang_tools::list_languages(true, true, false));
foreach ($languages as $langcode => $langname) {
    $list[$langcode] = (object) array('langname' => $langname, 'translators' => array());
}
$sql = "SELECT at.id AS tid, at.lang, u.id, u.lastname, u.firstname, u.email, u.imagealt, u.picture\n          FROM {amos_translators} at\n          JOIN {user} u ON at.userid=u.id\n      ORDER BY at.lang, u.lastname, u.firstname";
$translators = $DB->get_records_sql($sql);
foreach ($translators as $translator) {
    if (empty($list[$translator->lang])) {
        debugging('Unknown language ' . $translator->lang);
        continue;
    }
    $name = $OUTPUT->user_picture($translator, array('size' => 20)) . fullname($translator) . ' &lt;' . $translator->email . '&gt;';
    $url = new moodle_url($PAGE->url, array('langcode' => $translator->lang, 'del' => $translator->id, 'sesskey' => sesskey()));
    $delicon = $OUTPUT->action_icon($url, new pix_icon('t/delete', 'Revoke'));
    $list[$translator->lang]->translators[$translator->id] = $name . $delicon;
}
Example #10
0
 /**
  * @param stdclass $user the owner of the stage
  */
 public function __construct(stdclass $user)
 {
     global $DB;
     $stringstree = array();
     // tree of strings to simulate ORDER BY component, stringid, lang, branch
     $this->strings = array();
     // final list populated from the stringstree
     $stage = mlang_persistent_stage::instance_for_user($user->id, $user->sesskey);
     $needed = array();
     // describes all strings that we will have to load to displaye the stage
     if (has_capability('local/amos:importfile', get_system_context(), $user)) {
         $this->importform = new local_amos_importfile_form(new moodle_url('/local/amos/importfile.php'), local_amos_importfile_options());
     }
     if (has_capability('local/amos:commit', get_system_context(), $user)) {
         $this->mergeform = new local_amos_merge_form(new moodle_url('/local/amos/merge.php'), local_amos_merge_options());
     }
     if (has_capability('local/amos:stage', get_system_context(), $user)) {
         $this->diffform = new local_amos_diff_form(new moodle_url('/local/amos/diff.php'), local_amos_diff_options());
     }
     if (has_all_capabilities(array('local/amos:execute', 'local/amos:stage'), get_system_context(), $user)) {
         $this->executeform = new local_amos_execute_form(new moodle_url('/local/amos/execute.php'), local_amos_execute_options());
     }
     foreach ($stage->get_iterator() as $component) {
         foreach ($component->get_iterator() as $staged) {
             if (!isset($needed[$component->version->code][$component->lang][$component->name])) {
                 $needed[$component->version->code][$component->lang][$component->name] = array();
             }
             $needed[$component->version->code][$component->lang][$component->name][] = $staged->id;
             $needed[$component->version->code]['en'][$component->name][] = $staged->id;
             $string = new stdclass();
             $string->component = $component->name;
             $string->branch = $component->version->code;
             $string->version = $component->version->label;
             $string->language = $component->lang;
             $string->stringid = $staged->id;
             $string->text = $staged->text;
             $string->timemodified = $staged->timemodified;
             $string->deleted = $staged->deleted;
             $string->original = null;
             // is populated in the next step
             $string->current = null;
             // dtto
             $string->new = $staged->text;
             $string->committable = false;
             $stringstree[$string->component][$string->stringid][$string->language][$string->branch] = $string;
         }
     }
     // order by component
     ksort($stringstree);
     foreach ($stringstree as $subtree) {
         // order by stringid
         ksort($subtree);
         foreach ($subtree as $subsubtree) {
             // order by language
             ksort($subsubtree);
             foreach ($subsubtree as $subsubsubtree) {
                 // order by branch
                 ksort($subsubsubtree);
                 foreach ($subsubsubtree as $string) {
                     $this->strings[] = $string;
                 }
             }
         }
     }
     unset($stringstree);
     $fver = array();
     $flng = array();
     $fcmp = array();
     foreach ($needed as $branch => $languages) {
         $fver[$branch] = true;
         foreach ($languages as $language => $components) {
             $flng[$language] = true;
             foreach ($components as $component => $strings) {
                 $fcmp[$component] = true;
                 $needed[$branch][$language][$component] = mlang_component::from_snapshot($component, $language, mlang_version::by_code($branch), null, false, false, $strings);
             }
         }
     }
     $this->filterfields->fver = array_keys($fver);
     $this->filterfields->flng = array_keys($flng);
     $this->filterfields->fcmp = array_keys($fcmp);
     $allowedlangs = mlang_tools::list_allowed_languages($user->id);
     foreach ($this->strings as $string) {
         if (!empty($allowedlangs['X']) or !empty($allowedlangs[$string->language])) {
             $string->committable = true;
         }
         if (!$needed[$string->branch]['en'][$string->component]->has_string($string->stringid)) {
             $string->original = '*DELETED*';
         } else {
             $string->original = $needed[$string->branch]['en'][$string->component]->get_string($string->stringid)->text;
         }
         if ($needed[$string->branch][$string->language][$string->component] instanceof mlang_component) {
             $string->current = $needed[$string->branch][$string->language][$string->component]->get_string($string->stringid);
             if ($string->current instanceof mlang_string) {
                 $string->current = $string->current->text;
             }
         }
         if (empty(mlang_version::by_code($string->branch)->translatable)) {
             $string->committable = false;
         }
     }
 }
Example #11
0
 public function test_components_tree()
 {
     // prepare a tree
     $stage = new mlang_stage();
     $components = array();
     foreach (array('MOODLE_19_STABLE', 'MOODLE_20_STABLE', 'MOODLE_21_STABLE') as $branch) {
         foreach (array('en', 'cs', 'es') as $language) {
             foreach (array('moodle', 'auth_mnet', 'workshop') as $componentname) {
                 $component = new mlang_component($componentname, $language, mlang_version::by_branch($branch));
                 $component->add_string(new mlang_string('foo', 'Bar'));
                 $stage->add($component);
                 $component->clear();
             }
         }
     }
     $stage->commit('Committing test strings');
     // full tree
     $tree = mlang_tools::components_tree();
     $this->assertIsA($tree, 'array');
     $this->assertEqual(3, count($tree));
     // 3 versions
     $this->assertEqual(3, count($tree[1900]));
     // 3 languages
     $this->assertEqual(3, count($tree[2000]));
     // 3 languages
     $this->assertEqual(3, count($tree[2100]));
     // 3 languages
     $this->assertEqual(3, count($tree[1900]['cs']));
     // 3 components
     $this->assertEqual(3, count($tree[2000]['en']));
     // 3 components
     $this->assertEqual(3, count($tree[2100]['es']));
     // 3 components
     $this->assertEqual(1, $tree[2100]['es']['moodle']);
     // 1 string
     // empty trees
     $tree = mlang_tools::components_tree(array('branch' => 1800));
     $this->assertIsA($tree, 'array');
     $this->assertTrue(empty($tree));
     $tree = mlang_tools::components_tree(array('component' => 'book'));
     $this->assertIsA($tree, 'array');
     $this->assertTrue(empty($tree));
     // single value filter
     $tree = mlang_tools::components_tree(array('branch' => 2000, 'lang' => 'cs'));
     $this->assertIsA($tree, 'array');
     $this->assertEqual(1, count($tree));
     $this->assertEqual(1, count($tree[2000]));
     $this->assertEqual(3, count($tree[2000]['cs']));
     $this->assertEqual(1, $tree[2000]['cs']['workshop']);
     // yet another single value filter
     $tree = mlang_tools::components_tree(array('component' => 'auth_mnet'));
     $this->assertEqual(3, count($tree));
     $this->assertEqual(3, count($tree[1900]));
     $this->assertEqual(3, count($tree[2000]));
     $this->assertEqual(3, count($tree[2100]));
     $this->assertEqual(1, count($tree[1900]['cs']));
     $this->assertEqual(1, count($tree[2000]['en']));
     $this->assertEqual(1, count($tree[2100]['es']));
     $this->assertEqual(1, $tree[2100]['en']['auth_mnet']);
     // multivalues filter
     $tree = mlang_tools::components_tree(array('branch' => array(2000, 2100), 'lang' => array('en'), 'component' => array('moodle', 'workshop')));
     $this->assertEqual(2, count($tree));
     $this->assertEqual(1, count($tree[2000]));
     $this->assertEqual(1, count($tree[2100]));
     $this->assertEqual(2, count($tree[2000]['en']));
     $this->assertEqual(2, count($tree[2100]['en']));
     $this->assertEqual(1, $tree[2000]['en']['moodle']);
     $this->assertEqual(1, $tree[2000]['en']['workshop']);
     $this->assertEqual(1, $tree[2100]['en']['moodle']);
     $this->assertEqual(1, $tree[2100]['en']['workshop']);
 }
Example #12
0
 /**
  * Renders the filter form
  *
  * @todo this code was used as sort of prototype of the HTML produced by the future forms framework, to be replaced by proper forms library
  * @param local_amos_filter $filter
  * @return string
  */
 protected function render_local_amos_filter(local_amos_filter $filter)
 {
     $output = '';
     // version checkboxes
     $output .= html_writer::start_tag('div', array('class' => 'item elementsgroup'));
     $output .= html_writer::start_tag('div', array('class' => 'label first'));
     $output .= html_writer::tag('label', get_string('filterver', 'local_amos'), array('for' => 'amosfilter_fver'));
     $output .= html_writer::tag('div', get_string('filterver_desc', 'local_amos'), array('class' => 'description'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::start_tag('div', array('class' => 'element'));
     $fver = '';
     foreach (mlang_version::list_all() as $version) {
         if ($version->code < 1900) {
             continue;
         }
         $checkbox = html_writer::checkbox('fver[]', $version->code, in_array($version->code, $filter->get_data()->version), $version->label);
         $fver .= html_writer::tag('div', $checkbox, array('class' => 'labelled_checkbox'));
     }
     $output .= html_writer::tag('div', $fver, array('id' => 'amosfilter_fver', 'class' => 'checkboxgroup'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     // language selector
     $output .= html_writer::start_tag('div', array('class' => 'item select'));
     $output .= html_writer::start_tag('div', array('class' => 'label'));
     $output .= html_writer::tag('label', get_string('filterlng', 'local_amos'), array('for' => 'amosfilter_flng'));
     $output .= html_writer::tag('div', get_string('filterlng_desc', 'local_amos'), array('class' => 'description'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::start_tag('div', array('class' => 'element'));
     $options = mlang_tools::list_languages();
     foreach ($options as $langcode => $langname) {
         $options[$langcode] = $langname;
     }
     unset($options['en']);
     // English is not translatable via AMOS
     $output .= html_writer::select($options, 'flng[]', $filter->get_data()->language, '', array('id' => 'amosfilter_flng', 'multiple' => 'multiple', 'size' => 3));
     $output .= html_writer::tag('span', '', array('id' => 'amosfilter_flng_actions', 'class' => 'actions'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     // component selector
     $output .= html_writer::start_tag('div', array('class' => 'item select'));
     $output .= html_writer::start_tag('div', array('class' => 'label'));
     $output .= html_writer::tag('label', get_string('filtercmp', 'local_amos'), array('for' => 'amosfilter_fcmp'));
     $output .= html_writer::tag('div', get_string('filtercmp_desc', 'local_amos'), array('class' => 'description'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::start_tag('div', array('class' => 'element'));
     $optionscore = array();
     $optionsstandard = array();
     $optionscontrib = array();
     $standard = array();
     foreach (local_amos_standard_plugins() as $plugins) {
         $standard = array_merge($standard, $plugins);
     }
     foreach (mlang_tools::list_components() as $componentname => $undefined) {
         if (isset($standard[$componentname])) {
             if ($standard[$componentname] === 'core' or substr($standard[$componentname], 0, 5) === 'core_') {
                 $optionscore[$componentname] = $standard[$componentname];
             } else {
                 $optionsstandard[$componentname] = $standard[$componentname];
             }
         } else {
             $optionscontrib[$componentname] = $componentname;
         }
     }
     asort($optionscore);
     asort($optionsstandard);
     asort($optionscontrib);
     $options = array(array(get_string('typecore', 'local_amos') => $optionscore), array(get_string('typestandard', 'local_amos') => $optionsstandard), array(get_string('typecontrib', 'local_amos') => $optionscontrib));
     $output .= html_writer::select($options, 'fcmp[]', $filter->get_data()->component, '', array('id' => 'amosfilter_fcmp', 'multiple' => 'multiple', 'size' => 5));
     $output .= html_writer::tag('span', '', array('id' => 'amosfilter_fcmp_actions', 'class' => 'actions'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     // other filter settings
     $output .= html_writer::start_tag('div', array('class' => 'item elementsgroup'));
     $output .= html_writer::start_tag('div', array('class' => 'label'));
     $output .= html_writer::tag('label', get_string('filtermis', 'local_amos'), array('for' => 'amosfilter_fmis'));
     $output .= html_writer::tag('div', get_string('filtermis_desc', 'local_amos'), array('class' => 'description'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::start_tag('div', array('class' => 'element'));
     $fmis = html_writer::checkbox('fmis', 1, $filter->get_data()->missing, get_string('filtermisfmis', 'local_amos'));
     $fmis = html_writer::tag('div', $fmis, array('class' => 'labelled_checkbox'));
     $fhlp = html_writer::checkbox('fhlp', 1, $filter->get_data()->helps, get_string('filtermisfhlp', 'local_amos'));
     $fhlp = html_writer::tag('div', $fhlp, array('class' => 'labelled_checkbox'));
     $fstg = html_writer::checkbox('fstg', 1, $filter->get_data()->stagedonly, get_string('filtermisfstg', 'local_amos'));
     $fstg = html_writer::tag('div', $fstg, array('class' => 'labelled_checkbox'));
     $fgrey = html_writer::start_tag('div', array('id' => 'amosfilter_fgrey', 'class' => 'checkboxgroup'));
     $fgrey .= html_writer::tag('div', html_writer::checkbox('fglo', 1, $filter->get_data()->greylistedonly, get_string('filtermisfglo', 'local_amos'), array('id' => 'amosfilter_fglo')), array('class' => 'labelled_checkbox'));
     $fgrey .= html_writer::tag('div', html_writer::checkbox('fwog', 1, $filter->get_data()->withoutgreylisted, get_string('filtermisfwog', 'local_amos'), array('id' => 'amosfilter_fwog')), array('class' => 'labelled_checkbox'));
     $fgrey .= html_writer::end_tag('div');
     $output .= html_writer::tag('div', $fmis . $fhlp . $fstg . $fgrey, array('id' => 'amosfilter_fmis', 'class' => 'checkboxgroup'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     // must contain string
     $output .= html_writer::start_tag('div', array('class' => 'item text'));
     $output .= html_writer::start_tag('div', array('class' => 'label'));
     $output .= html_writer::tag('label', get_string('filtertxt', 'local_amos'), array('for' => 'amosfilter_ftxt'));
     $output .= html_writer::tag('div', get_string('filtertxt_desc', 'local_amos'), array('class' => 'description'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::start_tag('div', array('class' => 'element'));
     $output .= html_writer::empty_tag('input', array('name' => 'ftxt', 'type' => 'text', 'value' => $filter->get_data()->substring));
     $output .= html_writer::checkbox('ftxr', 1, $filter->get_data()->substringregex, get_string('filtertxtregex', 'local_amos'), array('class' => 'inputmodifier'));
     $output .= html_writer::checkbox('ftxs', 1, $filter->get_data()->substringcs, get_string('filtertxtcasesensitive', 'local_amos'), array('class' => 'inputmodifier'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     // string identifier
     $output .= html_writer::start_tag('div', array('class' => 'item text'));
     $output .= html_writer::start_tag('div', array('class' => 'label'));
     $output .= html_writer::tag('label', get_string('filtersid', 'local_amos'), array('for' => 'amosfilter_fsid'));
     $output .= html_writer::tag('div', get_string('filtersid_desc', 'local_amos'), array('class' => 'description'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::start_tag('div', array('class' => 'element'));
     $output .= html_writer::empty_tag('input', array('name' => 'fsid', 'type' => 'text', 'value' => $filter->get_data()->stringid));
     $output .= html_writer::checkbox('fsix', 1, $filter->get_data()->stringidpartial, get_string('filtersidpartial', 'local_amos'), array('class' => 'inputmodifier'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     // hidden fields
     $output .= html_writer::start_tag('div');
     $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '__lazyform_' . $filter->lazyformname, 'value' => 1));
     $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
     $output .= html_writer::end_tag('div');
     // submit
     $output .= html_writer::start_tag('div', array('class' => 'item submit'));
     $output .= html_writer::start_tag('div', array('class' => 'label'));
     $output .= html_writer::tag('label', '&nbsp;', array('for' => 'amosfilter_fsbm'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::start_tag('div', array('class' => 'element'));
     $output .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('savefilter', 'local_amos'), 'class' => 'submit'));
     $output .= html_writer::tag('span', '', array('id' => 'amosfilter_submitted_icon'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     // permalink
     $permalink = $filter->get_permalink();
     if (!is_null($permalink)) {
         $output .= html_writer::start_tag('div', array('class' => 'item static'));
         $output .= html_writer::tag('div', '', array('class' => 'label'));
         $output .= html_writer::start_tag('div', array('class' => 'element'));
         $output .= html_writer::link($permalink, get_string('permalink', 'local_amos'));
         $output .= html_writer::end_tag('div');
         $output .= html_writer::end_tag('div');
     }
     // block wrapper for xhtml strictness
     $output = html_writer::tag('div', $output, array('id' => 'amosfilter'));
     // form
     $attributes = array('method' => 'post', 'action' => $filter->handler->out(), 'id' => 'amosfilter_form', 'class' => 'lazyform ' . $filter->lazyformname);
     $output = html_writer::tag('form', $output, $attributes);
     $output = html_writer::tag('div', $output, array('class' => 'filterwrapper'));
     return $output;
 }