Esempio n. 1
0
 * @copyright  2011 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__) . '/execute_form.php';
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);
            }
Esempio 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;
         }
     }
 }