Ejemplo n.º 1
0
 * @copyright  2010 David Mudrak <*****@*****.**>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once dirname(__FILE__) . '/locallib.php';
require_once dirname(__FILE__) . '/mlanglib.php';
require_once dirname(__FILE__) . '/merge_form.php';
require_login(SITEID, false);
require_capability('local/amos:commit', get_system_context());
// for langpack maintainers only
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/local/amos/merge.php');
navigation_node::override_active_url(new moodle_url('/local/amos/stage.php'));
$PAGE->set_title('AMOS ' . get_string('merge', 'local_amos'));
$PAGE->set_heading('AMOS ' . get_string('merge', 'local_amos'));
$mergeform = new local_amos_merge_form(null, local_amos_merge_options());
if ($data = $mergeform->get_data()) {
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $sourceversion = mlang_version::by_code($data->sourceversion);
    $targetversion = mlang_version::by_code($data->targetversion);
    if (is_null($sourceversion) or is_null($targetversion)) {
        notice('Invalid version selected', new moodle_url('/local/amos/stage.php'));
    }
    $tree = mlang_tools::components_tree(array('branch' => $sourceversion->code, 'lang' => $data->language));
    $sourcecomponentnames = array_keys(reset(reset($tree)));
    unset($tree);
    foreach ($sourcecomponentnames as $sourcecomponentname) {
        // get a snapshot of both components and merge source into target
        $sourcecomponent = mlang_component::from_snapshot($sourcecomponentname, $data->language, $sourceversion);
        $targetcomponent = mlang_component::from_snapshot($sourcecomponent->name, $sourcecomponent->lang, $targetversion);
        mlang_tools::merge($sourcecomponent, $targetcomponent);
Ejemplo n.º 2
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;
         }
     }
 }