Example #1
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 #2
0
 public function test_list_components()
 {
     $stage = new mlang_stage();
     $component = new mlang_component('workshop', 'en', mlang_version::by_branch('MOODLE_19_STABLE'));
     $component->add_string(new mlang_string('modulename', 'Workshop'));
     $stage->add($component);
     $component->clear();
     $component = new mlang_component('auth', 'en', mlang_version::by_branch('MOODLE_20_STABLE'));
     $component->add_string(new mlang_string('foo', 'Bar'));
     $stage->add($component);
     $component->clear();
     $component = new mlang_component('langconfig', 'cs', mlang_version::by_branch('MOODLE_19_STABLE'));
     $component->add_string(new mlang_string('thislanguage', 'CS'));
     $stage->add($component);
     $component->clear();
     $stage->commit('Registering two English components', array('source' => 'unittest'));
     $comps = mlang_tools::list_components();
     $this->assertIsA($comps, 'array');
     $this->assertEqual(count($comps), 2);
     $this->assertTrue(array_key_exists('workshop', $comps));
     $this->assertTrue(array_key_exists('auth', $comps));
     // todo test caching
 }
Example #3
0
 /**
  * Prepare permanent link for the given filter data
  *
  * @param moodle_url $baseurl
  * @param stdClass $fdata as returned by {@see self::get_data()}
  * @return moodle_url $permalink
  */
 public function set_permalink(moodle_url $baseurl, stdClass $fdata)
 {
     $this->permalink = new moodle_url($baseurl, array('t' => time()));
     $this->permalink->param('v', implode(',', $fdata->version));
     // list of languages or '*' if all are selected
     $all = mlang_tools::list_languages(false);
     foreach ($fdata->language as $selected) {
         unset($all[$selected]);
     }
     if (empty($all)) {
         $this->permalink->param('l', '*');
     } else {
         $this->permalink->param('l', implode(',', $fdata->language));
     }
     unset($all);
     // list of components or '*' if all are selected
     $all = mlang_tools::list_components();
     foreach ($fdata->component as $selected) {
         unset($all[$selected]);
     }
     if (empty($all)) {
         $this->permalink->param('c', '*');
     } else {
         $this->permalink->param('c', implode(',', $fdata->component));
     }
     unset($all);
     // substring and stringid
     $this->permalink->param('s', $fdata->substring);
     $this->permalink->param('d', $fdata->stringid);
     // checkboxes
     if ($fdata->missing) {
         $this->permalink->param('m', 1);
     }
     if ($fdata->helps) {
         $this->permalink->param('h', 1);
     }
     if ($fdata->substringregex) {
         $this->permalink->param('r', 1);
     }
     if ($fdata->substringcs) {
         $this->permalink->param('i', 1);
     }
     if ($fdata->stringidpartial) {
         $this->permalink->param('p', 1);
     }
     if ($fdata->stagedonly) {
         $this->permalink->param('g', 1);
     }
     if ($fdata->greylistedonly) {
         $this->permalink->param('o', 1);
     }
     if ($fdata->withoutgreylisted) {
         $this->permalink->param('w', 1);
     }
     return $this->permalink;
 }
Example #4
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;
 }