Esempio n. 1
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;
         }
     }
 }
Esempio n. 2
0
        die;
    }
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $stash->apply($stage);
    $stage->store();
    redirect(new moodle_url('/local/amos/stage.php'));
}
if ($pop) {
    require_sesskey();
    require_capability('local/amos:stage', get_system_context());
    $stash = mlang_stash::instance_from_id($pop);
    if ($stash->ownerid != $USER->id) {
        print_error('stashaccessdenied', 'local_amos');
        die;
    }
    $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
    $stash->apply($stage);
    $stage->store();
    $stash->drop();
    redirect(new moodle_url('/local/amos/stage.php'));
}
if ($drop) {
    require_sesskey();
    $stash = mlang_stash::instance_from_id($drop);
    if ($stash->ownerid != $USER->id) {
        print_error('stashaccessdenied', 'local_amos');
        die;
    }
    $stash->drop();
    redirect($PAGE->url);
}
Esempio n. 3
0
 /**
  * Factory method returning an instance of the stage for the given user
  *
  * For now, we use sesskey() as the only supported stage name. In the future, users will
  * have control over their stages, giving them names etc.
  *
  * @param int $userid the owner of the stage
  * @param string $stageid stage name
  * @return mlang_persistent_stage instance
  */
 public static function instance_for_user($userid, $stageid)
 {
     $stage = new mlang_persistent_stage($userid, $stageid);
     $stage->restore();
     return $stage;
 }