$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); }
/** * @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; } } }