Пример #1
1
 protected function other_preference_fields(MoodleQuickForm $mform)
 {
     $mform->addGroup(array($mform->createElement('advcheckbox', 'qtext', '', get_string('questiontext', 'quiz_responses')), $mform->createElement('advcheckbox', 'resp', '', get_string('response', 'quiz_responses')), $mform->createElement('advcheckbox', 'right', '', get_string('rightanswer', 'quiz_responses'))), 'coloptions', get_string('showthe', 'quiz_responses'), array(' '), false);
     $mform->disabledIf('qtext', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     $mform->disabledIf('resp', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     $mform->disabledIf('right', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
 }
 protected function standard_attempt_fields(MoodleQuickForm $mform)
 {
     $mform->addElement('select', 'attempts', get_string('reportattemptsfrom', 'quiz'), array(quiz_attempts_report::ENROLLED_WITH => get_string('reportuserswith', 'quiz'), quiz_attempts_report::ENROLLED_WITHOUT => get_string('reportuserswithout', 'quiz'), quiz_attempts_report::ENROLLED_ALL => get_string('reportuserswithorwithout', 'quiz'), quiz_attempts_report::ALL_WITH => get_string('reportusersall', 'quiz')));
     $stategroup = array($mform->createElement('advcheckbox', 'stateinprogress', '', get_string('stateinprogress', 'quiz')), $mform->createElement('advcheckbox', 'stateoverdue', '', get_string('stateoverdue', 'quiz')), $mform->createElement('advcheckbox', 'statefinished', '', get_string('statefinished', 'quiz')), $mform->createElement('advcheckbox', 'stateabandoned', '', get_string('stateabandoned', 'quiz')));
     $mform->addGroup($stategroup, 'stateoptions', get_string('reportattemptsthatare', 'quiz'), array(' '), false);
     $mform->setDefault('stateinprogress', 1);
     $mform->setDefault('stateoverdue', 1);
     $mform->setDefault('statefinished', 1);
     $mform->setDefault('stateabandoned', 1);
     $mform->disabledIf('stateinprogress', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     $mform->disabledIf('stateoverdue', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     $mform->disabledIf('statefinished', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     $mform->disabledIf('stateabandoned', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     if (quiz_report_can_filter_only_graded($this->_customdata['quiz'])) {
         $gm = html_writer::tag('span', quiz_get_grading_option_name($this->_customdata['quiz']->grademethod), array('class' => 'highlight'));
         $mform->addElement('advcheckbox', 'onlygraded', get_string('reportshowonly', 'quiz'), get_string('optonlygradedattempts', 'quiz_overview', $gm));
         $mform->disabledIf('onlygraded', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
         $mform->disabledIf('onlygraded', 'statefinished', 'notchecked');
     }
 }
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 function definition_inner(&$mform)
 {
     $mform->addElement('header', 'globalvarshdr', get_string('globalvarshdr', 'qtype_coordinates'));
     $mform->removeElement('defaultgrade');
     $mform->addElement('hidden', 'defaultgrade');
     $mform->setType('defaultgrade', PARAM_RAW);
     $mform->removeElement('penalty');
     $mform->addElement('hidden', 'penalty');
     $mform->setType('penalty', PARAM_NUMBER);
     $mform->setDefault('penalty', 0.1);
     $mform->addElement('static', 'help_coordinates', get_string('help'), get_string('helponquestionoptions', 'qtype_coordinates'));
     $mform->addElement('textarea', 'varsrandom', get_string('varsrandom', 'qtype_coordinates'), array('rows' => 4, 'cols' => 70, 'course' => $this->coursefilesid));
     $mform->addElement('textarea', 'varsglobal', get_string('varsglobal', 'qtype_coordinates'), array('rows' => 6, 'cols' => 70, 'course' => $this->coursefilesid));
     $mform->addElement('select', 'showperanswermark', get_string('showperanswermark', 'qtype_coordinates'), array(get_string('choiceno', 'qtype_coordinates'), get_string('choiceyes', 'qtype_coordinates')));
     $mform->setDefault('showperanswermark', 1);
     $mform->addElement('select', 'peranswersubmit', get_string('peranswersubmit', 'qtype_coordinates'), array(get_string('choiceno', 'qtype_coordinates'), get_string('choiceyes', 'qtype_coordinates')));
     $mform->setDefault('peranswersubmit', 1);
     $mform->addElement('text', 'retrymarkseq', get_string('retrymarkseq', 'qtype_coordinates'), array('size' => 30));
     $show_group = array();
     $show_group[] =& $mform->createElement('checkbox', 'vars2', '', get_string('vars2', 'qtype_coordinates'), 'onclick="coordinates_form_display(\'vars2\', this.checked)"');
     $show_group[] =& $mform->createElement('checkbox', 'preunit', '', get_string('preunit', 'qtype_coordinates'), 'onclick="coordinates_form_display(\'preunit\', this.checked)"');
     $show_group[] =& $mform->createElement('checkbox', 'otherrule', '', get_string('otherrule', 'qtype_coordinates'), 'onclick="coordinates_form_display(\'otherrule\', this.checked)"');
     //$show_group[] =& $mform->createElement('checkbox','subqtext','',get_string('subqtext','qtype_coordinates'),
     //    'onclick="coordinates_form_display(\'subqtext\', this.checked)"');
     //$show_group[] =& $mform->createElement('checkbox','feedback','',get_string('feedback','qtype_coordinates'),
     //    'onclick="coordinates_form_display(\'feedback\', this.checked)"');
     $show_group[] =& $mform->createElement('checkbox', 'correctnessraw', '', get_string('correctnessraw', 'qtype_coordinates'), 'onclick="coordinates_form_correctness(this.checked)"');
     $mform->addGroup($show_group, 'showoptions', get_string('showoptions', 'qtype_coordinates'), array(' '), true);
     $creategrades = get_grade_options();
     $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_coordinates', '{no}'), $creategrades->gradeoptions, 1, 1);
 }
Пример #4
0
 /**
  * @param MoodleQuickForm $mform
  */
 function add_submit_buttons($mform)
 {
     $buttons = array();
     $buttons[] =& $mform->createElement('submit', 'submitbutton', get_string('filter', 'local_mr'));
     $buttons[] =& $mform->createElement('submit', 'resetbutton', get_string('reset', 'local_mr'));
     $mform->addGroup($buttons, 'buttons', '', array(' '), false);
     $mform->registerNoSubmitButton('reset');
 }
Пример #5
0
 /**
  * Get the settings for onlinetext submission plugin
  *
  * @param MoodleQuickForm $mform The form to add elements to
  * @return void
  */
 public function get_settings(MoodleQuickForm $mform)
 {
     global $CFG, $COURSE;
     $defaultwordlimit = $this->get_config('wordlimit') == 0 ? '' : $this->get_config('wordlimit');
     $defaultwordlimitenabled = $this->get_config('wordlimitenabled');
     $options = array('size' => '6', 'maxlength' => '6');
     $name = get_string('wordlimit', 'assignsubmission_onlinetext');
     // Create a text box that can be enabled/disabled for onlinetext word limit.
     $wordlimitgrp = array();
     $wordlimitgrp[] = $mform->createElement('text', 'assignsubmission_onlinetext_wordlimit', '', $options);
     $wordlimitgrp[] = $mform->createElement('checkbox', 'assignsubmission_onlinetext_wordlimit_enabled', '', get_string('enable'));
     $mform->addGroup($wordlimitgrp, 'assignsubmission_onlinetext_wordlimit_group', $name, ' ', false);
     $mform->addHelpButton('assignsubmission_onlinetext_wordlimit_group', 'wordlimit', 'assignsubmission_onlinetext');
     $mform->disabledIf('assignsubmission_onlinetext_wordlimit', 'assignsubmission_onlinetext_wordlimit_enabled', 'notchecked');
     // Add numeric rule to text field.
     $wordlimitgrprules = array();
     $wordlimitgrprules['assignsubmission_onlinetext_wordlimit'][] = array(null, 'numeric', null, 'client');
     $mform->addGroupRule('assignsubmission_onlinetext_wordlimit_group', $wordlimitgrprules);
     // Rest of group setup.
     $mform->setDefault('assignsubmission_onlinetext_wordlimit', $defaultwordlimit);
     $mform->setDefault('assignsubmission_onlinetext_wordlimit_enabled', $defaultwordlimitenabled);
     $mform->setType('assignsubmission_onlinetext_wordlimit', PARAM_INT);
     $mform->disabledIf('assignsubmission_onlinetext_wordlimit_group', 'assignsubmission_onlinetext_enabled', 'notchecked');
 }
Пример #6
0
 /**
  * Add settings to edit plugin form.
  *
  * @param MoodleQuickForm $mform The form to add the configuration settings to.
  *                               This form is modified directly (not returned).
  * @return void
  */
 public function add_all_plugin_settings(MoodleQuickForm $mform)
 {
     $mform->addElement('header', 'submissiontypes', get_string('submissiontypes', 'assign'));
     $submissionpluginsenabled = array();
     $group = $mform->addGroup(array(), 'submissionplugins', get_string('submissiontypes', 'assign'), array(' '), false);
     foreach ($this->submissionplugins as $plugin) {
         $this->add_plugin_settings($plugin, $mform, $submissionpluginsenabled);
     }
     $group->setElements($submissionpluginsenabled);
     $mform->addElement('header', 'feedbacktypes', get_string('feedbacktypes', 'assign'));
     $feedbackpluginsenabled = array();
     $group = $mform->addGroup(array(), 'feedbackplugins', get_string('feedbacktypes', 'assign'), array(' '), false);
     foreach ($this->feedbackplugins as $plugin) {
         $this->add_plugin_settings($plugin, $mform, $feedbackpluginsenabled);
     }
     $group->setElements($feedbackpluginsenabled);
     $mform->setExpanded('submissiontypes');
 }
Пример #7
0
 /**
  * Renders a search form
  *
  * @param string $search Search string
  * @return string HTML
  */
 protected function helper_search_form($search)
 {
     global $CFG;
     require_once $CFG->libdir . '/formslib.php';
     $mform = new MoodleQuickForm('searchform', 'POST', $this->page->url);
     $mform->addElement('hidden', 'sesskey', sesskey());
     $el[] = $mform->createElement('text', 'search', get_string('search'), array('size' => 20));
     $mform->setDefault('search', $search);
     $el[] = $mform->createElement('submit', 'submitsearch', get_string('search'));
     $el[] = $mform->createElement('submit', 'clearsearch', get_string('clear'));
     $mform->addGroup($el, 'searchgroup', get_string('searchname', 'badges'), ' ', false);
     ob_start();
     $mform->display();
     $out = ob_get_clean();
     return $out;
 }
 protected function form_dependencies(\MoodleQuickForm $mform, $questionnaire)
 {
     // Dependence fields.
     if ($questionnaire->navigate) {
         $position = $this->position !== 0 ? $this->position : count($questionnaire->questions) + 1;
         $dependencies = questionnaire_get_dependencies($questionnaire->questions, $position);
         $canchangeparent = true;
         if (count($dependencies) > 1) {
             if (isset($this->qid)) {
                 $haschildren = questionnaire_get_descendants($questionnaire->questions, $this->qid);
                 if (count($haschildren) !== 0) {
                     $canchangeparent = false;
                     $parent = questionnaire_get_parent($this);
                     $fixeddependency = $parent[$this->id]['parent'];
                 }
             }
             if ($canchangeparent) {
                 $this->dependquestion = isset($this->dependquestion) ? $this->dependquestion . ',' . $this->dependchoice : '0,0';
                 $group = array($mform->createElement('selectgroups', 'dependquestion', '', $dependencies));
                 $mform->addGroup($group, 'selectdependency', get_string('dependquestion', 'questionnaire'), '', false);
                 $mform->addHelpButton('selectdependency', 'dependquestion', 'questionnaire');
             } else {
                 $mform->addElement('static', 'selectdependency', get_string('dependquestion', 'questionnaire'), '<div class="dimmed_text">' . $fixeddependency . '</div>');
             }
             $mform->addHelpButton('selectdependency', 'dependquestion', 'questionnaire');
         }
     }
 }
 /**
  * Add Previous/Next buttons to a formslib form.
  *
  * @param MoodleQuickForm $mform the MoodleQuickForm object (that is,
  * $form->_form) to add the buttons to
  * @param string $prevstep the ID of the previous step
  * @param string $nextstep the ID of the next step.  If null, go to the
  * next step as defined by the workflow.  If it is workflow::STEP_FINISH,
  * it will submit call the workflow's finish method, rather than the save
  * method.
  * @param string $nextlabel the label for the Next button.  If null,
  * default to the language string for "Next" (or "Finish").
  */
 public static function add_navigation_buttons(MoodleQuickForm $mform, $prevstep = null, $nextstep = null, $nextlabel = null)
 {
     global $CFG;
     require_once $CFG->dirroot . '/elis/core/lib/form/xbutton.php';
     $buttonarray = array();
     $cancelbutton = $mform->createElement('xbutton', 'action', get_string('cancel'), array('value' => 'cancel', 'type' => 'submit'));
     $buttonarray[] = $cancelbutton;
     if ($nextstep === workflow::STEP_FINISH) {
         if ($prevstep) {
             $prevbutton = $mform->createElement('xbutton', '_step', get_string('previous'), array('value' => $prevstep, 'type' => 'submit'));
             $buttonarray[] = $prevbutton;
         }
         $nextbutton = $mform->createElement('xbutton', 'action', $nextlabel === null ? get_string('finish', 'elis_core') : $nextlabel, array('value' => 'finish', 'type' => 'submit'));
     } else {
         if ($prevstep) {
             $prevbutton = $mform->createElement('xbutton', '_next_step', get_string('previous'), array('value' => $prevstep, 'type' => 'submit'));
             $buttonarray[] = $prevbutton;
         }
         $nextbutton = $mform->createElement('xbutton', $nextstep === null ? '' : '_next_step', $nextlabel === null ? get_string('next') : $nextlabel, array('value' => $nextstep, 'type' => 'submit'));
     }
     $buttonarray[] = $nextbutton;
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
 }
Пример #10
0
 protected function form_length(\MoodleQuickForm $mform, $helptext = '')
 {
     $lengroup = array();
     $lengroup[] =& $mform->createElement('radio', 'length', '', get_string('vertical', 'questionnaire'), '0');
     $lengroup[] =& $mform->createElement('radio', 'length', '', get_string('horizontal', 'questionnaire'), '1');
     $mform->addGroup($lengroup, 'lengroup', get_string('alignment', 'questionnaire'), ' ', false);
     $mform->addHelpButton('lengroup', 'alignment', 'questionnaire');
     $mform->setType('length', PARAM_INT);
     return $mform;
 }
 /**
  * Add the form elements defining one PRT node.
  * @param string $prtname the name of the PRT.
  * @param string $name the name of the node.
  * @param array $nextnodechoices the available choices for the next node.
  * @param bool $deletable whether the user is allowed to delete this node.
  * @param MoodleQuickForm $mform the form being assembled.
  */
 protected function definition_prt_node($prtname, $name, $nextnodechoices, $deletable, MoodleQuickForm $mform)
 {
     $nodekey = $name - 1;
     unset($nextnodechoices[$nodekey]);
     $nodegroup = array();
     $nodegroup[] = $mform->createElement('select', $prtname . 'answertest[' . $nodekey . ']', stack_string('answertest'), $this->answertestchoices);
     $nodegroup[] = $mform->createElement('text', $prtname . 'sans[' . $nodekey . ']', stack_string('sans'), array('size' => 15));
     $nodegroup[] = $mform->createElement('text', $prtname . 'tans[' . $nodekey . ']', stack_string('tans'), array('size' => 15));
     $nodegroup[] = $mform->createElement('text', $prtname . 'testoptions[' . $nodekey . ']', stack_string('testoptions'), array('size' => 5));
     $nodegroup[] = $mform->createElement('selectyesno', $prtname . 'quiet[' . $nodekey . ']', stack_string('quiet'));
     $mform->addGroup($nodegroup, $prtname . 'node[' . $nodekey . ']', html_writer::tag('b', stack_string('nodex', $name)), null, false);
     $mform->addHelpButton($prtname . 'node[' . $nodekey . ']', 'nodehelp', 'qtype_stack');
     $mform->setType($prtname . 'sans[' . $nodekey . ']', PARAM_RAW);
     $mform->setType($prtname . 'tans[' . $nodekey . ']', PARAM_RAW);
     $mform->setType($prtname . 'testoptions[' . $nodekey . ']', PARAM_RAW);
     // Create the section of the form for each node - the branches.
     foreach (array('true', 'false') as $branch) {
         $branchgroup = array();
         $branchgroup[] = $mform->createElement('select', $prtname . $branch . 'scoremode[' . $nodekey . ']', stack_string('scoremode'), $this->scoremodechoices);
         if ($nodekey > 0) {
             if ($branch === 'true') {
                 $mform->setDefault($prtname . $branch . 'scoremode[' . $nodekey . ']', '+');
             } else {
                 $mform->setDefault($prtname . $branch . 'scoremode[' . $nodekey . ']', '-');
             }
         }
         $branchgroup[] = $mform->createElement('text', $prtname . $branch . 'score[' . $nodekey . ']', stack_string('score'), array('size' => 2));
         $mform->setDefault($prtname . $branch . 'score[' . $nodekey . ']', (int) ($branch === 'true' && $nodekey == 0));
         $branchgroup[] = $mform->createElement('text', $prtname . $branch . 'penalty[' . $nodekey . ']', stack_string('penalty'), array('size' => 2));
         $branchgroup[] = $mform->createElement('select', $prtname . $branch . 'nextnode[' . $nodekey . ']', stack_string('next'), $nextnodechoices);
         $branchgroup[] = $mform->createElement('text', $prtname . $branch . 'answernote[' . $nodekey . ']', stack_string('answernote'), array('size' => 10));
         $mform->setDefault($prtname . $branch . 'answernote[' . $nodekey . ']', stack_string('answernotedefault' . $branch, array('prtname' => $prtname, 'nodename' => $name)));
         $mform->addGroup($branchgroup, $prtname . 'nodewhen' . $branch . '[' . $nodekey . ']', stack_string('nodexwhen' . $branch, $name), null, false);
         $mform->addHelpButton($prtname . 'nodewhen' . $branch . '[' . $nodekey . ']', $branch . 'branch', 'qtype_stack');
         $mform->setType($prtname . $branch . 'score[' . $nodekey . ']', PARAM_RAW);
         $mform->setType($prtname . $branch . 'penalty[' . $nodekey . ']', PARAM_RAW);
         $mform->setType($prtname . $branch . 'answernote[' . $nodekey . ']', PARAM_RAW);
         $mform->addElement('editor', $prtname . $branch . 'feedback[' . $nodekey . ']', stack_string('nodex' . $branch . 'feedback', $name), array('rows' => 1), $this->editoroptions);
         $mform->addHelpButton($prtname . $branch . 'feedback[' . $nodekey . ']', 'branchfeedback', 'qtype_stack');
     }
     if ($deletable) {
         $mform->addElement('submit', $prtname . 'nodedelete' . $nodekey, stack_string('nodexdelete', $name));
         $mform->registerNoSubmitButton($prtname . 'nodedelete' . $nodekey);
     }
 }
Пример #12
0
/**
 * Populate mform with a new question
 * @param MoodleQuickForm $mform
 * @param unknown_type $number
 * @param unknown_type $options
 * @param array $keys array of letters or symbols to numerate the options i.e. A,B,C,D...
 * @param unknown_type $defaults
 */
function create_question(MoodleQuickForm $mform, $number, $options, $keys, $warnings = null)
{
    //print_object($options);
    //print_object($number);
    $returnobj = new stdClass();
    //	if (isset($defaults['invalid']))
    //		$invalid = $defaults['invalid'];
    //	else
    //		$invalid = null;
    $i = 0;
    $questionarray = array();
    $warn = '';
    $icon = '';
    /**
     * option to unmark all others. Marked if all options are clear
     */
    if ($options[0]->questiontype == 'CIRCLE') {
        $questionarray[] =& MoodleQuickForm::createElement('radio', '' . $number, '', get_string('unmarked', 'blended'), $number . 'none');
        $mform->setDefault('' . $number, $number . 'none');
    }
    foreach ($options as $option) {
        $option->key = $keys[$i];
        /**
         * Report about any warning of error with this option
         */
        if (isset($warnings[$option->id])) {
            $warn .= $warn ? ',' : '';
            $warn .= " {$option->key}";
            $icon = '<img src="images/warning.png" width="16" alt="' . get_string('MarkWarning', 'blended') . '"/>';
        }
        if (isset($warnings[$option->id])) {
            $warnOptionStyle = $icon;
        } else {
            $warnOptionStyle = '';
        }
        if ($option->questiontype == 'SQUARE') {
            $questionarray[] =& MoodleQuickForm::createElement('advcheckbox', $option->label, '', $warnOptionStyle . $option->key, array('group' => 1));
            $returnobj->radioindex = null;
        } else {
            if ($option->questiontype == 'CIRCLE') {
                $questionarray[] =& MoodleQuickForm::createElement('radio', '' . $number, '', $warnOptionStyle . $option->key, $option->label);
                $returnobj->radioindex = $number;
            }
        }
        $i++;
    }
    foreach ($options as $option) {
        if ($option->value == 1) {
            $mform->setDefault('' . $number, $option->label);
        }
    }
    $questionName = 'Pregunta ' . $number;
    if ($warn) {
        $questionName = $questionName . $icon;
    }
    $mform->addGroup($questionarray, $number, $questionName, array(''), false);
    if ($warn) {
        $mform->setHelpButton($number, array('MarkWarning', get_string('MarkWarning', 'blended'), 'blended'), false);
    }
    /**
     * TODO resolver manejo de opciones inválidas
     * Enter description here ...
     * @var unknown_type
     */
    $invalid = 0;
    if ($invalid == 1) {
        $returnobj->invalid = 1;
        //$mform->addElement('hidden', 'invalid', $invalidquestions);
        mtrace('<CENTER>La pregunta número ' . $number . ' es inválida. Se han encontrado múltiples respuestas 
		para una pregunta de selección simple. <BR><BR></CENTER>');
    } else {
        $returnobj->invalid = null;
    }
    return $returnobj;
}
Пример #13
0
 /**
  * Outputs the content of the administration tab and manages actions taken in this tab
  */
 public function view_administration()
 {
     global $SESSION, $OUTPUT, $PAGE, $DB, $USER, $CFG;
     $output = $PAGE->get_renderer('mod_grouptool');
     $id = $this->cm->id;
     $context = context_course::instance($this->course->id);
     // Get applicable roles!
     $rolenames = array();
     if ($roles = get_profile_roles($context)) {
         foreach ($roles as $role) {
             $rolenames[$role->id] = strip_tags(role_get_name($role, $context));
         }
     }
     $filter = optional_param('filter', null, PARAM_INT);
     if ($filter !== null) {
         set_user_preference('mod_grouptool_group_filter', $filter, $USER->id);
     } else {
         $filter = get_user_preferences('mod_grouptool_group_filter', self::FILTER_ACTIVE, $USER->id);
     }
     $inactivetabs = array();
     $filtertabs['active'] = new tabobject(self::FILTER_ACTIVE, $CFG->wwwroot . '/mod/grouptool/view.php?id=' . $id . '&amp;tab=group_admin&filter=' . self::FILTER_ACTIVE, get_string('active', 'grouptool'), '', false);
     $filtertabs['inactive'] = new tabobject(self::FILTER_INACTIVE, $CFG->wwwroot . '/mod/grouptool/view.php?id=' . $id . '&amp;tab=group_admin&filter=' . self::FILTER_INACTIVE, get_string('inactive'), '', false);
     $filtertabs['all'] = new tabobject(self::FILTER_ALL, $CFG->wwwroot . '/mod/grouptool/view.php?id=' . $id . '&amp;tab=group_admin&filter=' . self::FILTER_ALL, get_string('all'), '', false);
     echo html_writer::tag('div', $OUTPUT->tabtree($filtertabs, $filter, $inactivetabs), array('id' => 'filtertabs'));
     // Check if everything has been confirmed, so we can finally start working!
     if (optional_param('confirm', 0, PARAM_BOOL)) {
         if (isset($SESSION->grouptool->view_administration->createGroupings)) {
             require_capability('mod/grouptool:create_groupings', $this->context);
             $target = required_param('target', PARAM_INT);
             switch ($target) {
                 // ...grpg_target | grpg_groupingname | use_all (0 sel | 1 all).
                 case 0:
                     // Invalid - no action! TODO Add message!
                     $error = true;
                     $preview = '';
                     break;
                 case -2:
                     // One grouping per group!
                     list($error, $preview) = $this->create_group_groupings();
                     break;
                 case -1:
                     // One new grouping for all!
                     list($error, $preview) = $this->update_grouping($target, required_param('name', PARAM_ALPHANUMEXT));
                     break;
                 default:
                     list($error, $preview) = $this->update_grouping($target);
                     break;
             }
             $preview = html_writer::tag('div', $preview, array('class' => 'centered'));
             echo $OUTPUT->box($preview, 'generalbox');
         }
         unset($SESSION->grouptool->view_administration);
     }
     if ($rename = optional_param('rename', 0, PARAM_INT)) {
         // Show Rename Form!
         $gform = new \mod_grouptool\group_rename_form(null, array('id' => $this->cm->id, 'instance' => $this->cm->instance, 'rename' => $rename));
         if (!$gform->is_cancelled() && ($fromform = $gform->get_data())) {
             $group = new stdClass();
             $group->id = $fromform->rename;
             $group->name = $fromform->name;
             $group->courseid = $fromform->courseid;
             groups_update_group($group);
         } else {
             if (!$gform->is_cancelled()) {
                 $data = new stdClass();
                 $data->name = $DB->get_field('groups', 'name', array('id' => $rename));
                 $gform->set_data($data);
                 $gform->display();
                 echo $OUTPUT->footer();
                 die;
             }
         }
     }
     if ($resize = optional_param('resize', 0, PARAM_INT)) {
         // Show Rename Form!
         $gform = new \mod_grouptool\group_resize_form(null, array('id' => $this->cm->id, 'instance' => $this->cm->instance, 'resize' => $resize));
         if (!$gform->is_cancelled() && ($fromform = $gform->get_data())) {
             if (empty($fromform->size)) {
                 $DB->set_field('grouptool_agrps', 'grpsize', null, array('groupid' => $fromform->resize, 'grouptoolid' => $this->cm->id));
             } else {
                 $group = new stdClass();
                 $group->id = $DB->get_field('grouptool_agrps', 'id', array('groupid' => $fromform->resize, 'grouptoolid' => $this->cm->instance));
                 $group->grpsize = $fromform->size;
                 $DB->update_record('grouptool_agrps', $group);
             }
         } else {
             if (!$gform->is_cancelled()) {
                 $data = new stdClass();
                 $data->size = $DB->get_field('grouptool_agrps', 'grpsize', array('groupid' => $resize, 'grouptoolid' => $this->cm->instance));
                 $gform->set_data($data);
                 $gform->display();
                 echo $OUTPUT->footer();
                 die;
             }
         }
     }
     if ($delete = optional_param('delete', 0, PARAM_INT)) {
         if (!optional_param('confirm', 0, PARAM_BOOL)) {
             // Show Confirm!
             $cancel = new moodle_url($PAGE->url);
             $continue = new moodle_url($cancel, array('confirm' => 1, 'delete' => $delete));
             $cancel = new single_button($cancel, get_string('no'), 'post');
             $continue = new single_button($continue, get_string('yes'), 'post');
             $confirmtext = get_string('confirm_delete', 'grouptool');
             echo $this->confirm($confirmtext, $continue, $cancel);
             echo $OUTPUT->footer();
             die;
         } else {
             // Delete it!
             groups_delete_group($delete);
         }
     }
     if ($toggle = optional_param('toggle', 0, PARAM_INT)) {
         if (!empty($toggle)) {
             $conditions = array('grouptoolid' => $this->cm->instance, 'groupid' => $toggle);
             if (!$DB->record_exists('grouptool_agrps', $conditions)) {
                 echo $OUTPUT->box($OUTPUT->notification(get_string('group_not_found', 'grouptool'), 'notifyproblem', $conditions), 'generalbox');
             } else {
                 $record = $DB->get_record('grouptool_agrps', $conditions);
                 if (!empty($record->active)) {
                     $DB->set_field('grouptool_agrps', 'active', 0, $conditions);
                 } else {
                     $DB->set_field('grouptool_agrps', 'active', 1, $conditions);
                 }
             }
         }
     }
     if (($bulkaction = optional_param('bulkaction', null, PARAM_ALPHA)) && ($selected = optional_param_array('selected', array(), PARAM_INT)) && optional_param('start_bulkaction', 0, PARAM_BOOL)) {
         switch ($bulkaction) {
             case 'activate':
                 // ...also via ajax bulk action?
                 // Activate now!
                 $groups = optional_param_array('selected', null, PARAM_INT);
                 if (!empty($groups)) {
                     list($grpsql, $grpparams) = $DB->get_in_or_equal($groups);
                     $DB->set_field_select("grouptool_agrps", "active", 1, " grouptoolid = ? AND groupid " . $grpsql, array_merge(array($this->cm->instance), $grpparams));
                 }
                 echo $OUTPUT->notification(get_string('activated_groups', 'grouptool'), 'notifysuccess');
                 $continue = new moodle_url($PAGE->url, array('tab' => 'group_admin'));
                 echo $this->confirm('', $continue);
                 break;
             case 'deactivate':
                 // ...also via ajax bulk action?
                 // Deactivate now!
                 $groups = optional_param_array('selected', null, PARAM_INT);
                 if (!empty($groups)) {
                     list($grpsql, $grpparams) = $DB->get_in_or_equal($groups);
                     $DB->set_field_select("grouptool_agrps", "active", 0, " grouptoolid = ? AND groupid " . $grpsql, array_merge(array($this->cm->instance), $grpparams));
                 }
                 echo $OUTPUT->notification(get_string('deactivated_groups', 'grouptool'), 'notifysuccess');
                 $continue = new moodle_url($PAGE->url, array('tab' => 'group_admin'));
                 echo $this->confirm('', $continue);
                 break;
             case 'delete':
                 // ...also via ajax bulk action?
                 // Show confirmation dialogue!
                 if (optional_param('confirm', 0, PARAM_BOOL)) {
                     $groups = optional_param_array('selected', null, PARAM_INT);
                     $groups = $DB->get_records_list('groups', 'id', $groups);
                     foreach ($groups as $group) {
                         groups_delete_group($group);
                     }
                     echo $OUTPUT->notification(get_string('successfully_deleted_groups', 'grouptool'), 'notifysuccess');
                     $continue = new moodle_url($PAGE->url, array('tab' => 'group_admin'));
                     echo $this->confirm('', $continue);
                 } else {
                     $cancel = new moodle_url($PAGE->url, array('tab' => 'group_admin'));
                     $params = array('confirm' => 1, 'bulkaction' => 'delete', 'start_bulkaction' => 1);
                     $text = get_string('confirm_delete', 'grouptool') . html_writer::start_tag('ul');
                     $groups = $DB->get_records_list('groups', 'id', $selected);
                     foreach ($selected as $select) {
                         $params['selected[' . $select . ']'] = $select;
                         $text .= html_writer::tag('li', $groups[$select]->name);
                     }
                     $text .= html_writer::end_tag('ul');
                     $continue = new moodle_url($cancel, $params);
                     echo $this->confirm($text, $continue, $cancel);
                     echo $OUTPUT->footer();
                     die;
                 }
                 break;
             case 'grouping':
                 // Show grouping creation form!
                 $selected = optional_param_array('selected', array(), PARAM_INT);
                 $mform = new \mod_grouptool\groupings_creation_form(null, array('id' => $id, 'selected' => $selected));
                 $groups = $DB->get_records_list('groups', 'id', $selected);
                 if ($mform->is_cancelled()) {
                     $bulkaction = null;
                     $selected = array();
                 } else {
                     if ($fromform = $mform->get_data()) {
                         // Some groupings should be created...
                         if ($fromform->target == -2) {
                             // One new grouping per group!
                             foreach ($groups as $group) {
                                 $grouping = new stdClass();
                                 if (!($grouping->id = groups_get_grouping_by_name($this->course->id, $group->name))) {
                                     $grouping = new stdClass();
                                     $grouping->courseid = $this->course->id;
                                     $grouping->name = $group->name;
                                     $grouping->id = groups_create_grouping($grouping);
                                 }
                                 // Insert group!
                                 groups_assign_grouping($grouping->id, $group->id);
                             }
                         } else {
                             if ($fromform->target == -1) {
                                 // One new grouping!
                                 // Create grouping if it doesn't exist...
                                 $grouping = new stdClass();
                                 if (!($grouping->id = groups_get_grouping_by_name($this->course->id, $fromform->name))) {
                                     $grouping = new stdClass();
                                     $grouping->courseid = $this->course->id;
                                     $grouping->name = trim($fromform->name);
                                     $grouping->id = groups_create_grouping($grouping);
                                 }
                                 // Insert groups!
                                 foreach ($groups as $group) {
                                     groups_assign_grouping($grouping->id, $group->id);
                                 }
                             } else {
                                 if ($fromform->target > 0) {
                                     // Existing Grouping!
                                     $grouping = groups_get_grouping($fromform->target);
                                     if ($grouping) {
                                         foreach ($groups as $group) {
                                             groups_assign_grouping($grouping->id, $group->id);
                                         }
                                     }
                                 }
                             }
                         }
                         // ...redirect to show sortlist again!
                         $url = new moodle_url('/mod/grouptool/view.php', array('id' => $this->cm->id, 'tab' => 'group_admin', 'filter' => $filter));
                         $text = $OUTPUT->notification(get_string('groupings_created_and_groups_added', 'grouptool'), 'notifymessage');
                         echo $this->confirm($text, $url);
                     } else {
                         $mform->display();
                     }
                 }
                 break;
         }
     }
     if (!$bulkaction || !$selected || !optional_param('start_bulkaction', 0, PARAM_BOOL)) {
         // Show form!
         $formaction = new moodle_url('/mod/grouptool/view.php', array('id' => $this->cm->id, 'tab' => 'group_admin', 'filter' => $filter));
         $mform = new MoodleQuickForm('bulk', 'post', $formaction, '');
         $mform->addElement('hidden', 'sesskey');
         $mform->setDefault('sesskey', sesskey());
         $sortlist = new \mod_grouptool\output\sortlist($this->course->id, $this->cm, $filter);
         $sortlistcontroller = new \mod_grouptool\output\sortlist_controller($sortlist);
         $mform->addElement('html', $output->render($sortlistcontroller));
         $mform->addElement('html', $output->render($sortlist));
         $actions = array('' => get_string('choose', 'grouptool'), 'activate' => get_string('setactive', 'grouptool'), 'deactivate' => get_string('setinactive', 'grouptool'), 'delete' => get_string('delete'), 'grouping' => get_string('createinsertgrouping', 'grouptool'));
         $grp = array();
         $grp[] =& $mform->createElement('static', 'with_selection', '', get_string('with_selection', 'grouptool'));
         $grp[] =& $mform->createElement('select', 'bulkaction', '', $actions);
         $grp[] =& $mform->createElement('submit', 'start_bulkaction', get_string('start', 'grouptool'));
         $mform->addGroup($grp, 'actiongrp', '', ' ', false);
         $mform->disable_form_change_checker();
         $mform->display();
         switch ($filter) {
             case self::FILTER_ACTIVE:
                 $curfilter = 'active';
                 break;
             case self::FILTER_INACTIVE:
                 $curfilter = 'inactive';
                 break;
             case self::FILTER_ALL:
                 $curfilter = 'all';
                 break;
         }
         $PAGE->requires->yui_module('moodle-mod_grouptool-administration', 'M.mod_grouptool.init_administration', array(array('lang' => current_language(), 'contextid' => $this->context->id, 'filter' => $curfilter, 'filterid' => $filter, 'globalsize' => $this->grouptool->grpsize)));
         $PAGE->requires->strings_for_js(array('active', 'inactive', 'confirm_delete'), 'mod_grouptool');
         $PAGE->requires->string_for_js('ajax_edit_size_help', 'mod_grouptool');
         $PAGE->requires->strings_for_js(array('yes', 'no'), 'moodle');
     }
 }
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 function definition_inner(&$mform)
 {
     // Add the select control which will select the comparison type to use
     $mform->addElement('select', 'compareby', get_string('compareby', 'qtype_algebra'), array("sage" => get_string('comparesage', 'qtype_algebra'), "eval" => get_string('compareeval', 'qtype_algebra'), "equiv" => get_string('compareequiv', 'qtype_algebra')));
     $mform->setDefault('compareby', 'eval');
     $mform->setHelpButton('compareby', array('comp_algorithm', get_string('compalgorithm', 'qtype_algebra'), 'qtype_algebra'));
     // Add the control to select the number of checks to perform
     // First create an array with all the allowed values. We will then use this array
     // with the array_combine function to create a single array where the keys are the
     // same as the array values
     $chk_array = array('1', '2', '3', '5', '7', '10', '20', '30', '50', '70', '100', '200', '300', '500', '700', '1000');
     // Add the select element using the array_combine method discussed above
     $mform->addElement('select', 'nchecks', get_string('nchecks', 'qtype_algebra'), array_combine($chk_array, $chk_array));
     // Set the default number of checks to perform
     $mform->setDefault('nchecks', '10');
     $mform->setHelpButton('nchecks', array('eval_checks', get_string('evalchecks', 'qtype_algebra'), 'qtype_algebra'));
     // Add the box to set the tolerance to use when performing evaluation checks
     $mform->addElement('text', 'tolerance', get_string('tolerance', 'qtype_algebra'));
     $mform->setType('tolerance', PARAM_NUMBER);
     $mform->setDefault('tolerance', '0.001');
     $mform->setHelpButton('tolerance', array('check_tolerance', get_string('checktolerance', 'qtype_algebra'), 'qtype_algebra'));
     // Add an entry for the answer box prefix
     $mform->addElement('text', 'answerprefix', get_string('answerprefix', 'qtype_algebra'), array('size' => 55));
     $mform->setType('answerprefix', PARAM_RAW);
     $mform->setHelpButton('answerprefix', array('answer_prefix', get_string('answerboxprefix', 'qtype_algebra'), 'qtype_algebra'));
     // Add an entry for a disallowed expression
     $mform->addElement('text', 'disallow', get_string('disallow', 'qtype_algebra'), array('size' => 55));
     $mform->setType('disallow', PARAM_RAW);
     $mform->setHelpButton('disallow', array('disallowed_ans', get_string('disallowanswer', 'qtype_algebra'), 'qtype_algebra'));
     // Create an array which will store the function checkboxes
     $func_group = array();
     // Create an array to add spacers between the boxes
     $spacers = array('<br>');
     // Add the initial all functions box to the list of check boxes
     $func_group[] =& $mform->createElement('checkbox', 'all', '', get_string('allfunctions', 'qtype_algebra'));
     // Create a checkbox element for each function understood by the parser
     for ($i = 0; $i < count(qtype_algebra_parser::$functions); $i++) {
         $func = qtype_algebra_parser::$functions[$i];
         $func_group[] =& $mform->createElement('checkbox', $func, '', $func);
         if ($i % 6 == 5) {
             $spacers[] = '<br>';
         } else {
             $spacers[] = str_repeat('&nbsp;', 8 - strlen($func));
         }
     }
     // Create and add the group of function controls to the form
     $mform->addGroup($func_group, 'allowedfuncs', get_string('allowedfuncs', 'qtype_algebra'), $spacers, true);
     $mform->disabledIf('allowedfuncs', 'allowedfuncs[all]', 'checked');
     $mform->setDefault('allowedfuncs[all]', 'checked');
     $mform->setHelpButton('allowedfuncs', array('allowed_funcs', get_string('allowedfunctions', 'qtype_algebra'), 'qtype_algebra'));
     // Create the array for the list of variables used in the question
     $repeated = array();
     // Create the array for the list of repeated options used by the variable subforms
     $repeatedoptions = array();
     // Add the form elements to enter the variables
     $repeated[] =& $mform->createElement('header', 'variablehdr', get_string('variableno', 'qtype_algebra', '{no}'));
     $repeatedoptions['variablehdr']['helpbutton'] = array('variable', get_string('variable', 'qtype_algebra'), 'qtype_algebra');
     $repeated[] =& $mform->createElement('text', 'variable', get_string('variablename', 'qtype_algebra'), array('size' => 20));
     $mform->setType('variable', PARAM_RAW);
     $repeated[] =& $mform->createElement('text', 'varmin', get_string('varmin', 'qtype_algebra'), array('size' => 20));
     $mform->setType('varmin', PARAM_RAW);
     $repeatedoptions['varmin']['default'] = '';
     $repeated[] =& $mform->createElement('text', 'varmax', get_string('varmax', 'qtype_algebra'), array('size' => 20));
     $mform->setType('varmax', PARAM_RAW);
     $repeatedoptions['varmax']['default'] = '';
     // Get the current number of variables defined, if any
     if (isset($this->question->options)) {
         $countvars = count($this->question->options->variables);
     } else {
         $countvars = 0;
     }
     // Come up with the number of variable entries to add to the form at the start
     if ($this->question->formoptions->repeatelements) {
         $repeatsatstart = SYMB_QUESTION_NUMVAR_START > $countvars + SYMB_QUESTION_NUMVAR_ADD ? SYMB_QUESTION_NUMVAR_START : $countvars + SYMB_QUESTION_NUMVAR_ADD;
     } else {
         $repeatsatstart = $countvars;
     }
     $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'novariables', 'addvariables', SYMB_QUESTION_NUMVAR_ADD, get_string('addmorevariableblanks', 'qtype_algebra'));
     // Add the instructions for entering answers to the question
     $mform->addElement('static', 'answersinstruct', get_string('correctanswers', 'quiz'), get_string('filloutoneanswer', 'quiz'));
     $mform->closeHeaderBefore('answersinstruct');
     $creategrades = get_grade_options();
     $gradeoptions = $creategrades->gradeoptions;
     $repeated = array();
     $repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerno', 'qtype_algebra', '{no}'));
     $repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz'), array('size' => 54));
     $repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions);
     $repeated[] =& $mform->createElement('htmleditor', 'feedback', get_string('feedback', 'quiz'), array('course' => $this->coursefilesid));
     if (isset($this->question->options)) {
         $countanswers = count($this->question->options->answers);
     } else {
         $countanswers = 0;
     }
     if ($this->question->formoptions->repeatelements) {
         $repeatsatstart = SYMB_QUESTION_NUMANS_START > $countanswers + SYMB_QUESTION_NUMANS_ADD ? SYMB_QUESTION_NUMANS_START : $countanswers + SYMB_QUESTION_NUMANS_ADD;
     } else {
         $repeatsatstart = $countanswers;
     }
     $repeatedoptions = array();
     $mform->setType('answer', PARAM_RAW);
     $repeatedoptions['fraction']['default'] = 0;
     $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', SYMB_QUESTION_NUMANS_ADD, get_string('addmoreanswerblanks', 'qtype_algebra'));
 }
Пример #15
0
 /**
  * Add Previous/Next buttons to a formslib form.
  *
  * @param MoodleQuickForm $mform the MoodleQuickForm object (that is,
  * $form->_form) to add the buttons to
  * @param string $prevstep the ID of the previous step
  * @param string $nextstep the ID of the next step.  If null, go to the
  * next step as defined by the workflow.  If it is workflow::STEP_FINISH,
  * it will submit call the workflow's finish method, rather than the save
  * method.
  * @param string $nextlabel the label for the Next button.  If null,
  * default to the language string for "Next" (or "Finish").
  * @uses $CFG
  * @uses $FULLME
  */
 public static function add_navigation_buttons(MoodleQuickForm $mform, $prevstep = null, $nextstep = null, $nextlabel = null)
 {
     global $CFG, $FULLME;
     require_once $CFG->dirroot . '/local/eliscore/lib/form/xbutton.php';
     // ELIS-3501: Previous button was broken in IE7, changed to onclick
     $target = null;
     if ($prevstep && ($workflow_id = optional_param('_wfid', 0, PARAM_INT))) {
         $target = new moodle_url($FULLME, array('_wfid' => $workflow_id, '_step' => $prevstep));
         $target = $target->out(false);
     }
     $buttonarray = array();
     $cancelbutton = $mform->createElement('xbutton', 'action', get_string('cancel'), array('value' => 'cancel', 'type' => 'submit'));
     $buttonarray[] = $cancelbutton;
     if ($nextstep === workflow::STEP_FINISH) {
         if ($target) {
             $prevbutton = $mform->createElement('xbutton', 'previous', get_string('previous'), array('value' => $prevstep, 'type' => 'button', 'onclick' => "window.location = '{$target}';"));
             $buttonarray[] = $prevbutton;
         }
         $nextbutton = $mform->createElement('xbutton', 'action', $nextlabel === null ? get_string('finish', 'local_eliscore') : $nextlabel, array('value' => 'finish', 'type' => 'submit'));
     } else {
         if ($target) {
             $prevbutton = $mform->createElement('xbutton', 'previous', get_string('previous'), array('value' => $prevstep, 'type' => 'button', 'onclick' => "window.location = '{$target}';"));
             $buttonarray[] = $prevbutton;
         }
         $nextbutton = $mform->createElement('xbutton', $nextstep === null ? '' : '_next_step', $nextlabel === null ? get_string('next') : $nextlabel, array('value' => $nextstep, 'type' => 'submit'));
     }
     $buttonarray[] = $nextbutton;
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
 }