Ejemplo n.º 1
1
 /**
  * Form definition.
  */
 public function definition()
 {
     global $CFG, $PAGE;
     $mform =& $this->_form;
     $mform->addElement('header', 'general', '');
     $mform->addElement('hidden', 'type', $this->_customdata['type']);
     $mform->setType('type', PARAM_ALPHA);
     // This is similar to how the selects are created for the role tables,
     // without using a Moodle form element.
     $select = html_writer::select(array(13 => 'ArrayOpt13', 42 => 'ArrayOpt4', 666 => 'ArrayOpt666'), 'arraytest[]', array(13, 42), false, array('multiple' => 'multiple', 'size' => 10));
     $mform->addElement('static', 'arraybit', $select);
     switch ($this->_customdata['control']) {
         case 'c':
             // Create a whole stack of checkboxes.
             for ($i = 0; $i < $this->_customdata['fieldcount']; $i++) {
                 $mform->addElement('advcheckbox', 'test_c' . $i, 'Checkbox ' . $i);
             }
             break;
         case 'a':
             // Create a very large array input type field.
             $options = array();
             $values = array();
             for ($i = 0; $i < $this->_customdata['fieldcount']; $i++) {
                 $options[$i] = 'BigArray ' . $i;
                 if ($i !== 3) {
                     $values[] = $i;
                 }
             }
             $select = html_writer::select($options, 'test_a[]', $values, false, array('multiple' => 'multiple', 'size' => 50));
             $mform->addElement('static', 'bigarraybit', $select);
             break;
     }
     // For the sake of it, let's have a second array.
     $select = html_writer::select(array(13 => 'Array2Opt13', 42 => 'Array2Opt4', 666 => 'Array2Opt666'), 'array2test[]', array(13, 42), false, array('multiple' => 'multiple', 'size' => 10));
     $mform->addElement('static', 'array2bit', $select);
     $mform->addElement('submit', 'submitbutton', 'Submit here!');
 }
Ejemplo n.º 2
1
/**
 * Callback function called from question_list() function
 * (which is called from showbank())
 */
function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmoptions)
{
    global $OUTPUT;
    $out = '';
    $catcontext = get_context_instance_by_id($category->contextid);
    if (has_capability('moodle/question:useall', $catcontext)) {
        if ($cmoptions->hasattempts) {
            $disabled = ' disabled="disabled"';
        } else {
            $disabled = '';
        }
        $randomusablequestions = question_bank::get_qtype('random')->get_available_questions_from_category($category->id, $recurse);
        $maxrand = count($randomusablequestions);
        if ($maxrand > 0) {
            for ($i = 1; $i <= min(10, $maxrand); $i++) {
                $randomcount[$i] = $i;
            }
            for ($i = 20; $i <= min(100, $maxrand); $i += 10) {
                $randomcount[$i] = $i;
            }
        } else {
            $randomcount[0] = 0;
            $disabled = ' disabled="disabled"';
        }
        $out = '<strong><label for="menurandomcount">' . get_string('addrandomfromcategory', 'quiz') . '</label></strong><br />';
        $attributes = array();
        $attributes['disabled'] = $disabled ? 'disabled' : null;
        $select = html_writer::select($randomcount, 'randomcount', '1', null, $attributes);
        $out .= get_string('addrandom', 'quiz', $select);
        $out .= '<input type="hidden" name="recurse" value="' . $recurse . '" />';
        $out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
        $out .= ' <input type="submit" name="addrandom" value="' . get_string('addtoquiz', 'quiz') . '"' . $disabled . ' />';
        $out .= $OUTPUT->help_icon('addarandomquestion', 'quiz');
    }
    return $out;
}
Ejemplo n.º 3
1
    }
    $table->print_html();
}
if ($bulkoperations) {
    echo '<br /><div class="buttons">';
    echo '<input type="button" id="checkall" value="' . get_string('selectall') . '" /> ';
    echo '<input type="button" id="checknone" value="' . get_string('deselectall') . '" /> ';
    $displaylist = array();
    $displaylist['messageselect.php'] = get_string('messageselectadd');
    if (!empty($CFG->enablenotes) && has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) {
        $displaylist['addnote.php'] = get_string('addnewnote', 'notes');
        $displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes');
    }
    echo $OUTPUT->help_icon('withselectedusers');
    echo html_writer::tag('label', get_string("withselectedusers"), array('for' => 'formactionid'));
    echo html_writer::select($displaylist, 'formaction', '', array('' => 'choosedots'), array('id' => 'formactionid'));
    echo '<input type="hidden" name="id" value="' . $course->id . '" />';
    echo '<noscript style="display:inline">';
    echo '<div><input type="submit" value="' . get_string('ok') . '" /></div>';
    echo '</noscript>';
    echo '</div></div>';
    echo '</form>';
    $module = array('name' => 'core_user', 'fullpath' => '/user/module.js');
    $PAGE->requires->js_init_call('M.core_user.init_participation', null, false, $module);
}
// Show a search box if all participants don't fit on a single screen.
if ($totalcount > $perpage) {
    echo '<form action="index.php" class="searchform"><div><input type="hidden" name="id" value="' . $course->id . '" />';
    echo '<label for="search">' . get_string('search', 'search') . ' </label>';
    echo '<input type="text" id="search" name="search" value="' . s($search) . '" />&nbsp;<input type="submit" value="' . get_string('search') . '" /></div></form>' . "\n";
}
 public function display($discussion)
 {
     // Obtain list of other forums in this course where the user has the
     // 'move discussion' feature
     $course = $discussion->get_forum()->get_course();
     $modinfo = get_fast_modinfo($course);
     $results = array();
     foreach ($modinfo->instances['forumng'] as $other) {
         // Don't let user move discussion to its current forum
         if ($other->instance == $discussion->get_forum()->get_id() || $other->id == $discussion->get_forum()->get_course_module_id()) {
             continue;
         }
         $othercontext = context_module::instance($other->id);
         if (has_capability('mod/forumng:movediscussions', $othercontext)) {
             $results[$other->id] = $other->name;
         }
     }
     if (count($results) == 0) {
         return '';
     }
     // Make list alphabetical
     uasort($results, array('forumngfeature_move', 'sort_ignore_case'));
     // Build select using the list
     $out = mod_forumng_utils::get_renderer();
     $select = html_writer::select($results, 'target', '', array('' => get_string('movethisdiscussionto', 'forumngfeature_move')));
     return '<form method="post" action="feature/move/move.php"><div>' . $discussion->get_link_params(mod_forumng::PARAM_FORM) . $select . '<input class="forumng-zero-disable" ' . 'type="submit" value="' . get_string('move') . '" /></div></form>';
 }
Ejemplo n.º 5
0
 function display_search_field($content = '')
 {
     global $CFG, $DB;
     $varcharcontent = $DB->sql_compare_text('content', 255);
     $sql = "SELECT DISTINCT {$varcharcontent} AS content\n                  FROM {data_content}\n                 WHERE fieldid=? AND content IS NOT NULL";
     $usedoptions = array();
     if ($used = $DB->get_records_sql($sql, array($this->field->id))) {
         foreach ($used as $data) {
             $value = $data->content;
             if ($value === '') {
                 continue;
             }
             $usedoptions[$value] = $value;
         }
     }
     $options = array();
     foreach (explode("\n", $this->field->param1) as $option) {
         $option = trim($option);
         if (!isset($usedoptions[$option])) {
             continue;
         }
         $options[$option] = $option;
     }
     if (!$options) {
         // oh, nothing to search for
         return '';
     }
     $return = html_writer::label(get_string('namemenu', 'data'), 'menuf_' . $this->field->id, false, array('class' => 'accesshide'));
     $return .= html_writer::select($options, 'f_' . $this->field->id, $content);
     return $return;
 }
Ejemplo n.º 6
0
 protected function embedded_element(question_attempt $qa, $place, question_display_options $options)
 {
     $question = $qa->get_question();
     $group = $question->places[$place];
     $fieldname = $question->field($place);
     $value = $qa->get_last_qt_var($question->field($place));
     $attributes = array('id' => $this->box_id($qa, 'p' . $place));
     $groupclass = 'group' . $group;
     if ($options->readonly) {
         $attributes['disabled'] = 'disabled';
     }
     $orderedchoices = $question->get_ordered_choices($group);
     $selectoptions = array();
     foreach ($orderedchoices as $orderedchoicevalue => $orderedchoice) {
         $selectoptions[$orderedchoicevalue] = $orderedchoice->text;
     }
     $feedbackimage = '';
     if ($options->correctness) {
         $response = $qa->get_last_qt_data();
         if (array_key_exists($fieldname, $response)) {
             $fraction = (int) ($response[$fieldname] == $question->get_right_choice_for($place));
             $attributes['class'] = $this->feedback_class($fraction);
             $feedbackimage = $this->feedback_image($fraction);
         }
     }
     $selecthtml = html_writer::select($selectoptions, $qa->get_qt_field_name($fieldname), $value, get_string('choosedots'), $attributes) . ' ' . $feedbackimage;
     return html_writer::tag('span', $selecthtml, array('class' => 'control ' . $groupclass));
 }
Ejemplo n.º 7
0
 public function display_options_adv()
 {
     echo "<br />\n";
     $options = array(self::ONLYUNUSED => get_string('onlyunused', 'local_unusedquestions'), self::ONLYUSED => get_string('onlyused', 'local_unusedquestions'));
     $attr = array('class' => 'searchoptions');
     echo html_writer::select($options, 'onlyused', $this->onlyused, array(self::ONLYANY => get_string('usedandunused', 'local_unusedquestions')), $attr);
 }
Ejemplo n.º 8
0
 private function construct_ablock_select(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $response = $qa->get_last_qt_data();
     $stemorder = $question->get_stem_order();
     $choices = $this->format_choices($question);
     $o = html_writer::start_tag('table', array('class' => 'answer'));
     $o .= html_writer::start_tag('tbody');
     $parity = 0;
     foreach ($stemorder as $key => $stemid) {
         $o .= html_writer::start_tag('tr', array('class' => 'r' . $parity));
         $o .= html_writer::tag('td', $question->format_text($question->stems[$stemid], $question->stemformat[$stemid], $qa, 'qtype_order', 'subquestion', $stemid), array('class' => 'text'));
         $classes = 'control';
         $feedback = $this->get_feedback_class_image($qa, $options, $key);
         if ($feedback->class) {
             $classes .= ' ' . $feedback->class;
         }
         $selected = $this->get_selected($question, $response, $key);
         $o .= html_writer::tag('td', html_writer::select($choices, $qa->get_qt_field_name($question->get_field_name($key)), $selected, array('0' => 'choose'), array('disabled' => $options->readonly)) . ' ' . $feedback->image, array('class' => $classes));
         $o .= html_writer::end_tag('tr');
         $parity = 1 - $parity;
     }
     $o .= html_writer::end_tag('tbody');
     $o .= html_writer::end_tag('table');
     return $o;
 }
Ejemplo n.º 9
0
 public function subquestion(question_attempt $qa, question_display_options $options, qtype_combined_combinable_base $subq, $placeno)
 {
     $question = $subq->question;
     $place = $placeno + 1;
     $group = $question->places[$place];
     $fieldname = $subq->step_data_name($question->field($place));
     $value = $qa->get_last_qt_var($fieldname);
     $attributes = array('id' => str_replace(':', '_', $qa->get_qt_field_name($fieldname)));
     if ($options->readonly) {
         $attributes['disabled'] = 'disabled';
     }
     $orderedchoices = $question->get_ordered_choices($group);
     $selectoptions = array();
     foreach ($orderedchoices as $orderedchoicevalue => $orderedchoice) {
         $selectoptions[$orderedchoicevalue] = $orderedchoice->text;
     }
     $feedbackimage = '';
     if ($options->correctness) {
         $response = $qa->get_last_qt_data();
         if (array_key_exists($fieldname, $response)) {
             $fraction = (int) ($response[$fieldname] == $question->get_right_choice_for($place));
             $attributes['class'] = $this->feedback_class($fraction);
             $feedbackimage = $this->feedback_image($fraction);
         }
     }
     $selecthtml = html_writer::select($selectoptions, $qa->get_qt_field_name($fieldname), $value, get_string('choosedots'), $attributes) . ' ' . $feedbackimage;
     return html_writer::tag('span', $selecthtml, array('class' => 'control'));
 }
Ejemplo n.º 10
0
 public function render(stack_input_state $state, $fieldname, $readonly)
 {
     $attributes = array();
     if ($readonly) {
         $attributes['disabled'] = 'disabled';
     }
     return html_writer::select(self::get_choices(), $fieldname, $this->contents_to_maxima($state->contents), '', $attributes);
 }
Ejemplo n.º 11
0
 public function render(stack_input_state $state, $fieldname, $readonly)
 {
     $values = $this->get_choices();
     if (empty($values)) {
         return stack_string('ddl_empty');
     }
     $attributes = array();
     if ($readonly) {
         $attributes['disabled'] = 'disabled';
     }
     return html_writer::select($values, $fieldname, $this->contents_to_maxima($state->contents), array('' => stack_string('notanswered')), $attributes);
 }
Ejemplo n.º 12
0
 function display_search_field($value = '')
 {
     global $CFG, $DB;
     $varcharlat = $DB->sql_compare_text('content');
     $varcharlong = $DB->sql_compare_text('content1');
     $latlongsrs = $DB->get_recordset_sql("SELECT DISTINCT {$varcharlat} AS la, {$varcharlong} AS lo\n               FROM {data_content}\n              WHERE fieldid = ?\n             ORDER BY {$varcharlat}, {$varcharlong}", array($this->field->id));
     $options = array();
     foreach ($latlongsrs as $latlong) {
         $options[$latlong->la . ',' . $latlong->lo] = $latlong->la . ',' . $latlong->lo;
     }
     $latlongsrs->close();
     return html_writer::select($options, 'f_' . $this->field->id, $value);
 }
Ejemplo n.º 13
0
 function display_search_field($value = '')
 {
     global $CFG, $DB;
     $varcharcontent = $DB->sql_compare_text('content', 255);
     $used = $DB->get_records_sql("SELECT DISTINCT {$varcharcontent} AS content\n               FROM {data_content}\n              WHERE fieldid=?\n             ORDER BY {$varcharcontent}", array($this->field->id));
     $options = array();
     if (!empty($used)) {
         foreach ($used as $rec) {
             $options[$rec->content] = $rec->content;
             //Build following indicies from the sql.
         }
     }
     return html_writer::select($options, 'f_' . $this->field->id, $value);
 }
Ejemplo n.º 14
0
    /**
     * Renders the list of available steps according to the submitted filters.
     *
     * @param mixed $stepsdefinitions Available steps array.
     * @param moodleform $form
     * @return string HTML code
     */
    public function render_stepsdefinitions($stepsdefinitions, $form) {

        $html = $this->generic_info();

        // Form.
        ob_start();
        $form->display();
        $html .= ob_get_contents();
        ob_end_clean();

        if (empty($stepsdefinitions)) {
            $stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
        } else {

            $stepsdefinitions = implode('', $stepsdefinitions);

            // Replace text selector type arguments with a user-friendly select.
            $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\d?_STRING)/',
                function ($matches) {
                    return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
                },
                $stepsdefinitions
            );

            // Replace selector type arguments with a user-friendly select.
            $stepsdefinitions = preg_replace_callback('/(SELECTOR\d?_STRING)/',
                function ($matches) {
                    return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
                },
                $stepsdefinitions
            );

            // Replace simple OR options.
            $regex = '#\(\?P<[^>]+>([^\)|]+\|[^\)]+)\)#';
            $stepsdefinitions = preg_replace_callback($regex,
                function($matches){
                    return html_writer::select(explode('|', $matches[1]), uniqid());
                },
                $stepsdefinitions
            );

        }

        // Steps definitions.
        $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));

        $html .= $this->output->footer();

        return $html;
    }
Ejemplo n.º 15
0
 /**
  * Renders the list of available steps according to the submitted filters.
  *
  * @param mixed $stepsdefinitions Available steps array.
  * @param moodleform $form
  * @return string HTML code
  */
 public function render_stepsdefinitions($stepsdefinitions, $form)
 {
     $title = get_string('pluginname', 'tool_behat');
     // Header.
     $html = $this->output->header();
     $html .= $this->output->heading($title);
     // Info.
     $installurl = behat_command::DOCS_URL . '#Installation';
     $installlink = html_writer::tag('a', $installurl, array('href' => $installurl, 'target' => '_blank'));
     $writetestsurl = behat_command::DOCS_URL . '#Writting_features';
     $writetestslink = html_writer::tag('a', $writetestsurl, array('href' => $writetestsurl, 'target' => '_blank'));
     $writestepsurl = behat_command::DOCS_URL . '#Adding_steps_definitions';
     $writestepslink = html_writer::tag('a', $writestepsurl, array('href' => $writestepsurl, 'target' => '_blank'));
     $infos = array(get_string('installinfo', 'tool_behat', $installlink), get_string('newtestsinfo', 'tool_behat', $writetestslink), get_string('newstepsinfo', 'tool_behat', $writestepslink));
     // List of steps.
     $html .= $this->output->box_start();
     $html .= html_writer::tag('h1', get_string('infoheading', 'tool_behat'));
     $html .= html_writer::tag('div', get_string('aim', 'tool_behat'));
     $html .= html_writer::start_tag('div');
     $html .= html_writer::start_tag('ul');
     $html .= html_writer::start_tag('li');
     $html .= implode(html_writer::end_tag('li') . html_writer::start_tag('li'), $infos);
     $html .= html_writer::end_tag('li');
     $html .= html_writer::end_tag('ul');
     $html .= html_writer::end_tag('div');
     $html .= $this->output->box_end();
     // Form.
     ob_start();
     $form->display();
     $html .= ob_get_contents();
     ob_end_clean();
     if (empty($stepsdefinitions)) {
         $stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
     } else {
         $stepsdefinitions = implode('', $stepsdefinitions);
         // Replace text selector type arguments with a user-friendly select.
         $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\\d?_STRING)/', function ($matches) {
             return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
         }, $stepsdefinitions);
         // Replace selector type arguments with a user-friendly select.
         $stepsdefinitions = preg_replace_callback('/(SELECTOR\\d?_STRING)/', function ($matches) {
             return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
         }, $stepsdefinitions);
     }
     // Steps definitions.
     $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));
     $html .= $this->output->footer();
     return $html;
 }
Ejemplo n.º 16
0
 function display_search_field($value = '')
 {
     global $CFG, $DB;
     $varcharcontent = $DB->sql_compare_text('content', 255);
     $used = $DB->get_records_sql("SELECT DISTINCT {$varcharcontent} AS content\n               FROM {data_content}\n              WHERE fieldid=?\n             ORDER BY {$varcharcontent}", array($this->field->id));
     $options = array();
     if (!empty($used)) {
         foreach ($used as $rec) {
             $options[$rec->content] = $rec->content;
             //Build following indicies from the sql.
         }
     }
     $return = html_writer::label(get_string('nameradiobutton', 'data'), 'menuf_' . $this->field->id, false, array('class' => 'accesshide'));
     $return .= html_writer::select($options, 'f_' . $this->field->id, $value);
     return $return;
 }
Ejemplo n.º 17
0
 function display_search_field($value = '')
 {
     global $CFG, $DB;
     $varcharlat = $DB->sql_compare_text('content');
     $varcharlong = $DB->sql_compare_text('content1');
     $latlongsrs = $DB->get_recordset_sql("SELECT DISTINCT {$varcharlat} AS la, {$varcharlong} AS lo\n               FROM {data_content}\n              WHERE fieldid = ?\n             ORDER BY {$varcharlat}, {$varcharlong}", array($this->field->id));
     $options = array();
     foreach ($latlongsrs as $latlong) {
         $latitude = format_float($latlong->la, 4);
         $longitude = format_float($latlong->lo, 4);
         $options[$latlong->la . ',' . $latlong->lo] = $latitude . ' ' . $longitude;
     }
     $latlongsrs->close();
     $return = html_writer::label(get_string('latlong', 'data'), 'menuf_' . $this->field->id, false, array('class' => 'accesshide'));
     $return .= html_writer::select($options, 'f_' . $this->field->id, $value);
     return $return;
 }
 public function display_options_adv()
 {
     global $DB;
     global $output;
     require_login();
     $tags = $this->get_tags_used();
     $attr = array('multiple' => 'true', 'class' => 'searchoptions large searchbytags');
     if (count($tags) > 10) {
         $attr['size'] = 10;
     }
     echo html_writer::label('Show questions with tags:', 'tags[]');
     echo "<br />\n";
     echo html_writer::select($tags, 'tags[]', $this->tags, array('' => '--show all--'), $attr);
     echo "<br />\n";
     echo html_writer::label('Show questions WITHOUT tags:', 'tags[]');
     echo "<br />\n";
     echo html_writer::select($tags, 'nottags[]', $this->nottags, array('' => '--show all--'), $attr);
     echo "<br />\n";
 }
Ejemplo n.º 19
0
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $stemorder = $question->get_stem_order();
     $response = $qa->get_last_qt_data();
     $choices = $this->format_choices($question);
     $result = '';
     $result .= html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext'));
     $result .= html_writer::start_tag('div', array('class' => 'ablock'));
     $result .= html_writer::start_tag('table', array('class' => 'answer'));
     $result .= html_writer::start_tag('tbody');
     $parity = 0;
     $i = 1;
     foreach ($stemorder as $key => $stemid) {
         $result .= html_writer::start_tag('tr', array('class' => 'r' . $parity));
         $fieldname = 'sub' . $key;
         $result .= html_writer::tag('td', $this->format_stem_text($qa, $stemid), array('class' => 'text'));
         $classes = 'control';
         $feedbackimage = '';
         if (array_key_exists($fieldname, $response)) {
             $selected = $response[$fieldname];
         } else {
             $selected = 0;
         }
         $fraction = (int) ($selected && $selected == $question->get_right_choice_for($stemid));
         if ($options->correctness && $selected) {
             $classes .= ' ' . $this->feedback_class($fraction);
             $feedbackimage = $this->feedback_image($fraction);
         }
         $result .= html_writer::tag('td', html_writer::label(get_string('answer', 'qtype_match', $i), 'menu' . $qa->get_qt_field_name('sub' . $key), false, array('class' => 'accesshide')) . html_writer::select($choices, $qa->get_qt_field_name('sub' . $key), $selected, array('0' => 'choose'), array('disabled' => $options->readonly)) . ' ' . $feedbackimage, array('class' => $classes));
         $result .= html_writer::end_tag('tr');
         $parity = 1 - $parity;
         $i++;
     }
     $result .= html_writer::end_tag('tbody');
     $result .= html_writer::end_tag('table');
     $result .= html_writer::end_tag('div');
     // Closes <div class="ablock">.
     if ($qa->get_state() == question_state::$invalid) {
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error($response), array('class' => 'validationerror'));
     }
     return $result;
 }
Ejemplo n.º 20
0
 /**
  * Renders the list of available steps according to the submitted filters.
  *
  * @param mixed $stepsdefinitions Available steps array.
  * @param moodleform $form
  * @return string HTML code
  */
 public function render_stepsdefinitions($stepsdefinitions, $form)
 {
     $html = $this->generic_info();
     // Form.
     ob_start();
     $form->display();
     $html .= ob_get_contents();
     ob_end_clean();
     if (empty($stepsdefinitions)) {
         $stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
     } else {
         $stepsdefinitions = implode('', $stepsdefinitions);
         // Replace text selector type arguments with a user-friendly select.
         $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\\d?_STRING)/', function ($matches) {
             return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
         }, $stepsdefinitions);
         // Replace selector type arguments with a user-friendly select.
         $stepsdefinitions = preg_replace_callback('/(SELECTOR\\d?_STRING)/', function ($matches) {
             return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
         }, $stepsdefinitions);
         // Replace simple OR options.
         $regex = '#\\(\\?P<[^>]+>([^\\)|]+\\|[^\\)]+)\\)#';
         $stepsdefinitions = preg_replace_callback($regex, function ($matches) {
             return html_writer::select(explode('|', $matches[1]), uniqid());
         }, $stepsdefinitions);
         $stepsdefinitions = preg_replace_callback('/(FIELD_VALUE_STRING)/', function ($matches) {
             global $CFG;
             // Creating a link to a popup with the help.
             $url = new moodle_url('/help.php', array('component' => 'tool_behat', 'identifier' => 'fieldvalueargument', 'lang' => current_language()));
             // Note: this title is displayed only if JS is disabled,
             // otherwise the link will have the new ajax tooltip.
             $title = get_string('fieldvalueargument', 'tool_behat');
             $title = get_string('helpprefix2', '', trim($title, ". \t"));
             $attributes = array('href' => $url, 'title' => $title, 'aria-haspopup' => 'true', 'target' => '_blank');
             $output = html_writer::tag('a', 'FIELD_VALUE_STRING', $attributes);
             return html_writer::tag('span', $output, array('class' => 'helptooltip'));
         }, $stepsdefinitions);
     }
     // Steps definitions.
     $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));
     $html .= $this->output->footer();
     return $html;
 }
 public function display($discussion)
 {
     require_once dirname(__FILE__) . '/lib.php';
     if (is_a($discussion, 'mod_forumng_discussion')) {
         // Obtain list of other forums in this course where the user has the
         // 'move discussion' feature.
         $course = $discussion->get_forum()->get_course();
         $modinfo = get_fast_modinfo($course);
         $results = array();
         foreach ($modinfo->instances['forumng'] as $other) {
             // Don't let user move discussion to its current forum.
             if ($other->instance == $discussion->get_forum()->get_id() || $other->id == $discussion->get_forum()->get_course_module_id()) {
                 continue;
             }
             $othercontext = context_module::instance($other->id);
             if (has_capability('mod/forumng:movediscussions', $othercontext)) {
                 $results[$other->id] = $other->name;
             }
         }
         if (count($results) == 0) {
             return '';
         }
         // Make list alphabetical.
         uasort($results, 'sort_ignore_case');
         // Build select using the list.
         $out = mod_forumng_utils::get_renderer();
         $select = html_writer::select($results, 'target', '', array('' => get_string('movethisdiscussionto', 'forumngfeature_move')));
         return '<form method="post" action="feature/move/move.php"><div>' . $discussion->get_link_params(mod_forumng::PARAM_FORM) . $select . '<input class="forumng-zero-disable" ' . 'type="submit" value="' . get_string('move') . '" /></div></form>';
     } else {
         // Display button.
         $params['exclude'] = 'forumng-deleted';
         $excludedget = array_merge($params, $_GET);
         if (is_a($discussion, 'mod_forumng')) {
             return forumngfeature_discussion_list::get_button($discussion, get_string('move', 'forumngfeature_move'), 'feature/move/moveall.php', false, $excludedget, '', 'forumng-dselectorbutton', '', '');
         }
     }
 }
 /**
  * list current marker
  *
  * @param stdClass $row - The row of data
  * @return id the user->id of the marker.
  */
 public function col_allocatedmarker(stdClass $row)
 {
     static $markers = null;
     static $markerlist = array();
     if ($markers === null) {
         list($sort, $params) = users_order_by_sql();
         $markers = get_users_by_capability($this->assignment->get_context(), 'mod/assign:grade', '', $sort);
         $markerlist[0] = get_string('choosemarker', 'assign');
         foreach ($markers as $marker) {
             $markerlist[$marker->id] = fullname($marker);
         }
     }
     if (empty($markerlist)) {
         // TODO: add some form of notification here that no markers are available.
         return '';
     }
     if ($this->is_downloading()) {
         if (isset($markers[$row->allocatedmarker])) {
             return fullname($markers[$row->allocatedmarker]);
         } else {
             return '';
         }
     }
     if ($this->quickgrading && has_capability('mod/assign:manageallocations', $this->assignment->get_context()) && (empty($row->workflowstate) || $row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INMARKING || $row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED)) {
         $name = 'quickgrade_' . $row->id . '_allocatedmarker';
         return html_writer::select($markerlist, $name, $row->allocatedmarker, false);
     } else {
         if (!empty($row->allocatedmarker)) {
             $output = '';
             if ($this->quickgrading) {
                 // Add hidden field for quickgrading page.
                 $name = 'quickgrade_' . $row->id . '_allocatedmarker';
                 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $name, 'value' => $row->allocatedmarker));
             }
             $output .= $markerlist[$row->allocatedmarker];
             return $output;
         }
     }
 }
Ejemplo n.º 23
0
/**
 * Prints a grade menu (as part of an existing form) with help
 * Showing all possible numerical grades and scales
 *
 * @todo Finish documenting this function
 * @todo Deprecate: this is only used in a few contrib modules
 *
 * @global object
 * @param int $courseid The course ID
 * @param string $name
 * @param string $current
 * @param boolean $includenograde Include those with no grades
 * @param boolean $return If set to true returns rather than echo's
 * @return string|bool Depending on value of $return
 */
function print_grade_menu($courseid, $name, $current, $includenograde = true, $return = false)
{
    global $CFG, $OUTPUT;
    $output = '';
    $strscale = get_string('scale');
    $strscales = get_string('scales');
    $scales = get_scales_menu($courseid);
    foreach ($scales as $i => $scalename) {
        $grades[-$i] = $strscale . ': ' . $scalename;
    }
    if ($includenograde) {
        $grades[0] = get_string('nograde');
    }
    for ($i = 100; $i >= 1; $i--) {
        $grades[$i] = $i;
    }
    $output .= html_writer::select($grades, $name, $current, false);
    $linkobject = '<span class="helplink"><img class="iconhelp" alt="' . $strscales . '" src="' . $OUTPUT->pix_url('help') . '" /></span>';
    $link = new moodle_url('/course/scales.php', array('id' => $courseid, 'list' => 1));
    $action = new popup_action('click', $link, 'ratingscales', array('height' => 400, 'width' => 500));
    $output .= $OUTPUT->action_link($link, $linkobject, $action, array('title' => $strscales));
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
Ejemplo n.º 24
0
 public function construct_dataset_menus($form, $mandatorydatasets, $optionaldatasets)
 {
     global $OUTPUT;
     $datasetmenus = array();
     foreach ($mandatorydatasets as $datasetname) {
         if (!isset($datasetmenus[$datasetname])) {
             list($options, $selected) = $this->dataset_options($form, $datasetname);
             unset($options['0']);
             // Mandatory...
             $datasetmenus[$datasetname] = html_writer::select($options, 'dataset[]', $selected, null);
         }
     }
     foreach ($optionaldatasets as $datasetname) {
         if (!isset($datasetmenus[$datasetname])) {
             list($options, $selected) = $this->dataset_options($form, $datasetname);
             $datasetmenus[$datasetname] = html_writer::select($options, 'dataset[]', $selected, null);
         }
     }
     return $datasetmenus;
 }
Ejemplo n.º 25
0
 protected function writequestion($question)
 {
     global $OUTPUT;
     // Turns question into string.
     // Question reflects database fields for general question and specific to type.
     // If a category switch, just ignore.
     if ($question->qtype == 'category') {
         return '';
     }
     // Initial string.
     $expout = "";
     $id = $question->id;
     // Add comment and div tags.
     $expout .= "<!-- question: {$id}  name: {$question->name} -->\n";
     $expout .= "<div class=\"question\">\n";
     // Add header.
     $expout .= "<h3>{$question->name}</h3>\n";
     // Format and add the question text.
     $text = question_rewrite_question_preview_urls($question->questiontext, $question->id, $question->contextid, 'question', 'questiontext', $question->id, $question->contextid, 'qformat_xhtml');
     $expout .= '<p class="questiontext">' . format_text($text, $question->questiontextformat, array('noclean' => true)) . "</p>\n";
     // Selection depends on question type.
     switch ($question->qtype) {
         case 'truefalse':
             $sttrue = get_string('true', 'qtype_truefalse');
             $stfalse = get_string('false', 'qtype_truefalse');
             $expout .= "<ul class=\"truefalse\">\n";
             $expout .= "  <li><input name=\"quest_{$id}\" type=\"radio\" value=\"{$sttrue}\" />{$sttrue}</li>\n";
             $expout .= "  <li><input name=\"quest_{$id}\" type=\"radio\" value=\"{$stfalse}\" />{$stfalse}</li>\n";
             $expout .= "</ul>\n";
             break;
         case 'multichoice':
             $expout .= "<ul class=\"multichoice\">\n";
             foreach ($question->options->answers as $answer) {
                 $answertext = $this->repchar($answer->answer);
                 if ($question->options->single) {
                     $expout .= "  <li><input name=\"quest_{$id}\" type=\"radio\" value=\"" . s($answertext) . "\" />{$answertext}</li>\n";
                 } else {
                     $expout .= "  <li><input name=\"quest_{$id}\" type=\"checkbox\" value=\"" . s($answertext) . "\" />{$answertext}</li>\n";
                 }
             }
             $expout .= "</ul>\n";
             break;
         case 'shortanswer':
             $expout .= html_writer::start_tag('ul', array('class' => 'shortanswer'));
             $expout .= html_writer::start_tag('li');
             $expout .= html_writer::label(get_string('answer'), 'quest_' . $id, false, array('class' => 'accesshide'));
             $expout .= html_writer::empty_tag('input', array('id' => "quest_{$id}", 'name' => "quest_{$id}", 'type' => 'text'));
             $expout .= html_writer::end_tag('li');
             $expout .= html_writer::end_tag('ul');
             break;
         case 'numerical':
             $expout .= html_writer::start_tag('ul', array('class' => 'numerical'));
             $expout .= html_writer::start_tag('li');
             $expout .= html_writer::label(get_string('answer'), 'quest_' . $id, false, array('class' => 'accesshide'));
             $expout .= html_writer::empty_tag('input', array('id' => "quest_{$id}", 'name' => "quest_{$id}", 'type' => 'text'));
             $expout .= html_writer::end_tag('li');
             $expout .= html_writer::end_tag('ul');
             break;
         case 'match':
             $expout .= html_writer::start_tag('ul', array('class' => 'match'));
             // Build answer list.
             $answerlist = array();
             foreach ($question->options->subquestions as $subquestion) {
                 $answerlist[] = $this->repchar($subquestion->answertext);
             }
             shuffle($answerlist);
             // Random display order.
             // Build select options.
             $selectoptions = array();
             foreach ($answerlist as $ans) {
                 $selectoptions[s($ans)] = s($ans);
             }
             // Display.
             $option = 0;
             foreach ($question->options->subquestions as $subquestion) {
                 // Build drop down for answers.
                 $questiontext = $this->repchar($subquestion->questiontext);
                 if ($questiontext != '') {
                     $dropdown = html_writer::label(get_string('answer', 'qtype_match', $option + 1), 'quest_' . $id . '_' . $option, false, array('class' => 'accesshide'));
                     $dropdown .= html_writer::select($selectoptions, "quest_{$id}_{$option}", '', false, array('id' => "quest_{$id}_{$option}"));
                     $expout .= html_writer::tag('li', $questiontext);
                     $expout .= $dropdown;
                     $option++;
                 }
             }
             $expout .= html_writer::end_tag('ul');
             break;
         case 'description':
             break;
         case 'multianswer':
         default:
             $expout .= "<!-- export of {$question->qtype} type is not supported  -->\n";
     }
     // Close off div.
     $expout .= "</div>\n\n\n";
     return $expout;
 }
 /**
  * Renderers bulk actions that can be performed on courses.
  *
  * @param coursecat $category The currently selected category and the category in which courses that
  *      are selectable belong.
  * @return string
  */
 public function course_bulk_actions(coursecat $category)
 {
     $html = html_writer::start_div('course-bulk-actions bulk-actions');
     if ($category->can_move_courses_out_of()) {
         $options = coursecat::make_categories_list('moodle/category:manage');
         $select = html_writer::select($options, 'movecoursesto', '', array('' => 'choosedots'), array('aria-labelledby' => 'moveselectedcoursesto'));
         $submit = array('type' => 'submit', 'name' => 'bulkmovecourses', 'value' => get_string('move'));
         $html .= $this->detail_pair(html_writer::span(get_string('moveselectedcoursesto'), '', array('id' => 'moveselectedcoursesto')), $select . html_writer::empty_tag('input', $submit));
     }
     $html .= html_writer::end_div();
     return $html;
 }
Ejemplo n.º 27
0
    public function subquestion(question_attempt $qa, question_display_options $options,
            $index, question_graded_automatically $subq) {

        $fieldprefix = 'sub' . $index . '_';
        $fieldname = $fieldprefix . 'answer';

        $response = $qa->get_last_qt_var($fieldname);
        $choices = array();
        $matchinganswer = new question_answer(0, '', null, '', FORMAT_HTML);
        $rightanswer = null;
        foreach ($subq->get_order($qa) as $value => $ansid) {
            $ans = $subq->answers[$ansid];
            $choices[$value] = $subq->format_text($ans->answer, $ans->answerformat,
                    $qa, 'question', 'answer', $ansid);
            if ($subq->is_choice_selected($response, $value)) {
                $matchinganswer = $ans;
            }
        }

        $inputattributes = array(
            'id' => $qa->get_qt_field_name($fieldname),
        );
        if ($options->readonly) {
            $inputattributes['disabled'] = 'disabled';
        }

        $feedbackimg = '';
        if ($options->correctness) {
            $inputattributes['class'] = $this->feedback_class($matchinganswer->fraction);
            $feedbackimg = $this->feedback_image($matchinganswer->fraction);
        }
        $select = html_writer::select($choices, $qa->get_qt_field_name($fieldname),
                $response, array('' => ''), $inputattributes);

        $order = $subq->get_order($qa);
        $correctresponses = $subq->get_correct_response();
        $rightanswer = $subq->answers[$order[reset($correctresponses)]];
        if (!$matchinganswer) {
            $matchinganswer = new question_answer(0, '', null, '', FORMAT_HTML);
        }
        $feedbackpopup = $this->feedback_popup($subq, $matchinganswer->fraction,
                $subq->format_text($matchinganswer->feedback, $matchinganswer->feedbackformat,
                        $qa, 'question', 'answerfeedback', $matchinganswer->id),
                $subq->format_text($rightanswer->answer, $rightanswer->answerformat,
                        $qa, 'question', 'answer', $rightanswer->id), $options);

        $output = html_writer::start_tag('span', array('class' => 'subquestion'));
        $output .= html_writer::tag('label', get_string('answer'),
                array('class' => 'subq accesshide', 'for' => $inputattributes['id']));
        $output .= $select;
        $output .= $feedbackimg;
        $output .= $feedbackpopup;
        $output .= html_writer::end_tag('span');

        return $output;
    }
Ejemplo n.º 28
0
 /**
  * Invoke method, every class will have its own
  * returns true/false on completion, setting both
  * errormsg and output as necessary
  */
 function invoke()
 {
     parent::invoke();
     $result = true;
     // Set own core attributes
     $this->does_generate = ACTION_GENERATE_HTML;
     // These are always here
     global $CFG, $XMLDB, $DB, $OUTPUT;
     // Do the job, setting result as needed
     // Get the dir containing the file
     $dirpath = required_param('dir', PARAM_PATH);
     $dirpath = $CFG->dirroot . $dirpath;
     // Get the correct dirs
     if (!empty($XMLDB->dbdirs)) {
         $dbdir = $XMLDB->dbdirs[$dirpath];
     } else {
         return false;
     }
     if (!empty($XMLDB->editeddirs)) {
         $editeddir = $XMLDB->editeddirs[$dirpath];
         $structure = $editeddir->xml_file->getStructure();
     }
     $tableparam = optional_param('table', NULL, PARAM_CLEAN);
     // If no table, show form
     if (!$tableparam) {
         // No postaction here
         $this->postaction = NULL;
         // Get list of tables
         $dbtables = $DB->get_tables();
         $selecttables = array();
         foreach ($dbtables as $dbtable) {
             $i = $structure->findTableInArray($dbtable);
             if ($i === NULL) {
                 $selecttables[$dbtable] = $dbtable;
             }
         }
         // Get list of after tables
         $aftertables = array();
         if ($tables = $structure->getTables()) {
             foreach ($tables as $aftertable) {
                 $aftertables[$aftertable->getName()] = $aftertable->getName();
             }
         }
         if (!$selecttables) {
             $this->errormsg = 'No tables available to be retrofitted';
             return false;
         }
         // Now build the form
         $o = '<form id="form" action="index.php" method="post">';
         $o .= '<div>';
         $o .= '    <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
         $o .= '    <input type="hidden" name ="action" value="new_table_from_mysql" />';
         $o .= '    <input type="hidden" name ="postaction" value="edit_table" />';
         $o .= '    <input type="hidden" name ="sesskey" value="' . sesskey() . '" />';
         $o .= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
         $o .= '      <tr><td><label for="menutable" accesskey="t">' . $this->str['createtable'] . ' </label>' . html_writer::select($selecttables, 'table') . '<label for="menuafter" accesskey="a">' . $this->str['aftertable'] . ' </label>' . html_writer::select($aftertables, 'after') . '</td></tr>';
         $o .= '      <tr><td colspan="2" align="center"><input type="submit" value="' . $this->str['create'] . '" /></td></tr>';
         $o .= '      <tr><td colspan="2" align="center"><a href="index.php?action=edit_xml_file&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a></td></tr>';
         $o .= '    </table>';
         $o .= '</div></form>';
         $this->output = $o;
         // If table, retrofit information and, if everything works,
         // go to the table edit action
     } else {
         // Get some params (table is mandatory here)
         $tableparam = required_param('table', PARAM_CLEAN);
         $afterparam = required_param('after', PARAM_CLEAN);
         // Create one new xmldb_table
         $table = new xmldb_table(strtolower(trim($tableparam)));
         $table->setComment($table->getName() . ' table retrofitted from MySQL');
         // Get fields info from ADODb
         $dbfields = $DB->get_columns($tableparam);
         if ($dbfields) {
             foreach ($dbfields as $dbfield) {
                 // Create new XMLDB field
                 $field = new xmldb_field($dbfield->name);
                 // Set field with info retrofitted
                 $field->setFromADOField($dbfield);
                 // Add field to the table
                 $table->addField($field);
             }
         }
         // Get PK, UK and indexes info from ADODb
         $dbindexes = $DB->get_indexes($tableparam);
         if ($dbindexes) {
             $lastkey = NULL;
             //To temp store the last key processed
             foreach ($dbindexes as $indexname => $dbindex) {
                 // Add the indexname to the array
                 $dbindex['name'] = $indexname;
                 // We are handling one xmldb_key (primaries + uniques)
                 if ($dbindex['unique']) {
                     $key = new xmldb_key(strtolower($dbindex['name']));
                     // Set key with info retrofitted
                     $key->setFromADOKey($dbindex);
                     // Set default comment to PKs
                     if ($key->getType() == XMLDB_KEY_PRIMARY) {
                     }
                     // Add key to the table
                     $table->addKey($key);
                     // We are handling one xmldb_index (non-uniques)
                 } else {
                     $index = new xmldb_index(strtolower($dbindex['name']));
                     // Set index with info retrofitted
                     $index->setFromADOIndex($dbindex);
                     // Add index to the table
                     $table->addIndex($index);
                 }
             }
         }
         // Finally, add the whole retroffited table to the structure
         // in the place specified
         $structure->addTable($table, $afterparam);
     }
     // Launch postaction if exists (leave this here!)
     if ($this->getPostAction() && $result) {
         return $this->launch($this->getPostAction());
     }
     // Return ok if arrived here
     return $result;
 }
Ejemplo n.º 29
0
    /**
     *  Display all the submissions ready for grading
     *
     * @global object
     * @global object
     * @global object
     * @global object
     * @param string $message
     * @return bool|void
     */
    function display_submissions($message='') {
        global $CFG, $DB, $USER, $DB, $OUTPUT, $PAGE;
        require_once($CFG->libdir.'/gradelib.php');

        /* first we check to see if the form has just been submitted
         * to request user_preference updates
         */

       $filters = array(self::FILTER_ALL             => get_string('all'),
                        self::FILTER_SUBMITTED       => get_string('submitted', 'assignment'),
                        self::FILTER_REQUIRE_GRADING => get_string('requiregrading', 'assignment'));

        $updatepref = optional_param('updatepref', 0, PARAM_INT);

        if (isset($_POST['updatepref'])){
            $perpage = optional_param('perpage', 10, PARAM_INT);
            $perpage = ($perpage <= 0) ? 10 : $perpage ;
            $filter = optional_param('filter', 0, PARAM_INT);
            set_user_preference('assignment_perpage', $perpage);
            set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
            set_user_preference('assignment_filter', $filter);
        }

        /* next we get perpage and quickgrade (allow quick grade) params
         * from database
         */
        $perpage    = get_user_preferences('assignment_perpage', 10);
        $quickgrade = get_user_preferences('assignment_quickgrade', 0);
        $filter = get_user_preferences('assignment_filter', 0);
        $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);

        if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
            $uses_outcomes = true;
        } else {
            $uses_outcomes = false;
        }

        $page    = optional_param('page', 0, PARAM_INT);
        $strsaveallfeedback = get_string('saveallfeedback', 'assignment');

    /// Some shortcuts to make the code read better

        $course     = $this->course;
        $assignment = $this->assignment;
        $cm         = $this->cm;

        $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet
        add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->cm->id, $this->assignment->id, $this->cm->id);

        $PAGE->set_title(format_string($this->assignment->name,true));
        $PAGE->set_heading($this->course->fullname);
        echo $OUTPUT->header();

        echo '<div class="usersubmissions">';

        //hook to allow plagiarism plugins to update status/print links.
        plagiarism_update_status($this->course, $this->cm);

        /// Print quickgrade form around the table
        if ($quickgrade) {
            $formattrs = array();
            $formattrs['action'] = new moodle_url('/mod/assignment/submissions.php');
            $formattrs['id'] = 'fastg';
            $formattrs['method'] = 'post';

            echo html_writer::start_tag('form', $formattrs);
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id',      'value'=> $this->cm->id));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode',    'value'=> 'fastgrade'));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page',    'value'=> $page));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));
        }

        $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
        if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
            echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">'
                . get_string('seeallcoursegrades', 'grades') . '</a></div>';
        }

        if (!empty($message)) {
            echo $message;   // display messages here if any
        }

        $context = get_context_instance(CONTEXT_MODULE, $cm->id);

    /// Check to see if groups are being used in this assignment

        /// find out current groups mode
        $groupmode = groups_get_activity_groupmode($cm);
        $currentgroup = groups_get_activity_group($cm, true);
        groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id);

        /// Get all ppl that are allowed to submit assignments
        list($esql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $currentgroup);

        if ($filter == self::FILTER_ALL) {
            $sql = "SELECT u.id FROM {user} u ".
                   "LEFT JOIN ($esql) eu ON eu.id=u.id ".
                   "WHERE u.deleted = 0 AND eu.id=u.id ";
        } else {
            $wherefilter = '';
            if($filter == self::FILTER_SUBMITTED) {
               $wherefilter = ' AND s.timemodified > 0';
            } else if($filter == self::FILTER_REQUIRE_GRADING) {
                $wherefilter = ' AND s.timemarked < s.timemodified ';
            }

            $sql = "SELECT u.id FROM {user} u ".
                   "LEFT JOIN ($esql) eu ON eu.id=u.id ".
                   "LEFT JOIN {assignment_submissions} s ON (u.id = s.userid) " .
                   "WHERE u.deleted = 0 AND eu.id=u.id ".
                   'AND s.assignment = '. $this->assignment->id .
                    $wherefilter;
        }

        $users = $DB->get_records_sql($sql, $params);
        if (!empty($users)) {
            $users = array_keys($users);
        }

        // if groupmembersonly used, remove users who are not in any group
        if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
            if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
                $users = array_intersect($users, array_keys($groupingusers));
            }
        }

        $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
        if ($uses_outcomes) {
            $tablecolumns[] = 'outcome'; // no sorting based on outcomes column
        }

        $tableheaders = array('',
                              get_string('fullname'),
                              get_string('grade'),
                              get_string('comment', 'assignment'),
                              get_string('lastmodified').' ('.get_string('submission', 'assignment').')',
                              get_string('lastmodified').' ('.get_string('grade').')',
                              get_string('status'),
                              get_string('finalgrade', 'grades'));
        if ($uses_outcomes) {
            $tableheaders[] = get_string('outcome', 'grades');
        }

        require_once($CFG->libdir.'/tablelib.php');
        $table = new flexible_table('mod-assignment-submissions');

        $table->define_columns($tablecolumns);
        $table->define_headers($tableheaders);
        $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&amp;currentgroup='.$currentgroup);

        $table->sortable(true, 'lastname');//sorted by lastname by default
        $table->collapsible(true);
        $table->initialbars(true);

        $table->column_suppress('picture');
        $table->column_suppress('fullname');

        $table->column_class('picture', 'picture');
        $table->column_class('fullname', 'fullname');
        $table->column_class('grade', 'grade');
        $table->column_class('submissioncomment', 'comment');
        $table->column_class('timemodified', 'timemodified');
        $table->column_class('timemarked', 'timemarked');
        $table->column_class('status', 'status');
        $table->column_class('finalgrade', 'finalgrade');
        if ($uses_outcomes) {
            $table->column_class('outcome', 'outcome');
        }

        $table->set_attribute('cellspacing', '0');
        $table->set_attribute('id', 'attempts');
        $table->set_attribute('class', 'submissions');
        $table->set_attribute('width', '100%');
        //$table->set_attribute('align', 'center');

        $table->no_sorting('finalgrade');
        $table->no_sorting('outcome');

        // Start working -- this is necessary as soon as the niceties are over
        $table->setup();

        if (empty($users)) {
            echo $OUTPUT->heading(get_string('nosubmitusers','assignment'));
            echo '</div>';
            return true;
        }
        if ($this->assignment->assignmenttype=='upload' || $this->assignment->assignmenttype=='online' || $this->assignment->assignmenttype=='uploadsingle') { //TODO: this is an ugly hack, where is the plugin spirit? (skodak)
            echo '<div style="text-align:right"><a href="submissions.php?id='.$this->cm->id.'&amp;download=zip">'.get_string('downloadall', 'assignment').'</a></div>';
        }
    /// Construct the SQL

        list($where, $params) = $table->get_sql_where();
        if ($where) {
            $where .= ' AND ';
        }

        if ($filter == self::FILTER_SUBMITTED) {
           $where .= 's.timemodified > 0 AND ';
        } else if($filter == self::FILTER_REQUIRE_GRADING) {
           $where .= 's.timemarked < s.timemodified AND ';
        }

        if ($sort = $table->get_sql_sort()) {
            $sort = ' ORDER BY '.$sort;
        }

        $ufields = user_picture::fields('u');

        $select = "SELECT $ufields,
                          s.id AS submissionid, s.grade, s.submissioncomment,
                          s.timemodified, s.timemarked,
                          COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ";
        $sql = 'FROM {user} u '.
               'LEFT JOIN {assignment_submissions} s ON u.id = s.userid
                AND s.assignment = '.$this->assignment->id.' '.
               'WHERE '.$where.'u.id IN ('.implode(',',$users).') ';

        $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size());

        $table->pagesize($perpage, count($users));

        ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
        $offset = $page * $perpage;
        $strupdate = get_string('update');
        $strgrade  = get_string('grade');
        $grademenu = make_grades_menu($this->assignment->grade);

        if ($ausers !== false) {
            $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
            $endposition = $offset + $perpage;
            $currentposition = 0;
            foreach ($ausers as $auser) {
                if ($currentposition == $offset && $offset < $endposition) {
                    $final_grade = $grading_info->items[0]->grades[$auser->id];
                    $grademax = $grading_info->items[0]->grademax;
                    $final_grade->formatted_grade = round($final_grade->grade,2) .' / ' . round($grademax,2);
                    $locked_overridden = 'locked';
                    if ($final_grade->overridden) {
                        $locked_overridden = 'overridden';
                    }

                /// Calculate user status
                    $auser->status = ($auser->timemarked > 0) && ($auser->timemarked >= $auser->timemodified);
                    $picture = $OUTPUT->user_picture($auser);

                    if (empty($auser->submissionid)) {
                        $auser->grade = -1; //no submission yet
                    }

                    if (!empty($auser->submissionid)) {
                    ///Prints student answer and student modified date
                    ///attach file or print link to student answer, depending on the type of the assignment.
                    ///Refer to print_student_answer in inherited classes.
                        if ($auser->timemodified > 0) {
                            $studentmodified = '<div id="ts'.$auser->id.'">'.$this->print_student_answer($auser->id)
                                             . userdate($auser->timemodified).'</div>';
                        } else {
                            $studentmodified = '<div id="ts'.$auser->id.'">&nbsp;</div>';
                        }
                    ///Print grade, dropdown or text
                        if ($auser->timemarked > 0) {
                            $teachermodified = '<div id="tt'.$auser->id.'">'.userdate($auser->timemarked).'</div>';

                            if ($final_grade->locked or $final_grade->overridden) {
                                $grade = '<div id="g'.$auser->id.'" class="'. $locked_overridden .'">'.$final_grade->formatted_grade.'</div>';
                            } else if ($quickgrade) {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                                $grade = '<div id="g'.$auser->id.'">'. $menu .'</div>';
                            } else {
                                $grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
                            }

                        } else {
                            $teachermodified = '<div id="tt'.$auser->id.'">&nbsp;</div>';
                            if ($final_grade->locked or $final_grade->overridden) {
                                $grade = '<div id="g'.$auser->id.'" class="'. $locked_overridden .'">'.$final_grade->formatted_grade.'</div>';
                            } else if ($quickgrade) {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                                $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';
                            } else {
                                $grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
                            }
                        }
                    ///Print Comment
                        if ($final_grade->locked or $final_grade->overridden) {
                            $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($final_grade->str_feedback),15).'</div>';

                        } else if ($quickgrade) {
                            $comment = '<div id="com'.$auser->id.'">'
                                     . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'
                                     . $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>';
                        } else {
                            $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($auser->submissioncomment),15).'</div>';
                        }
                    } else {
                        $studentmodified = '<div id="ts'.$auser->id.'">&nbsp;</div>';
                        $teachermodified = '<div id="tt'.$auser->id.'">&nbsp;</div>';
                        $status          = '<div id="st'.$auser->id.'">&nbsp;</div>';

                        if ($final_grade->locked or $final_grade->overridden) {
                            $grade = '<div id="g'.$auser->id.'">'.$final_grade->formatted_grade . '</div>';
                        } else if ($quickgrade) {   // allow editing
                            $attributes = array();
                            $attributes['tabindex'] = $tabindex++;
                            $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                            $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';
                        } else {
                            $grade = '<div id="g'.$auser->id.'">-</div>';
                        }

                        if ($final_grade->locked or $final_grade->overridden) {
                            $comment = '<div id="com'.$auser->id.'">'.$final_grade->str_feedback.'</div>';
                        } else if ($quickgrade) {
                            $comment = '<div id="com'.$auser->id.'">'
                                     . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'
                                     . $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>';
                        } else {
                            $comment = '<div id="com'.$auser->id.'">&nbsp;</div>';
                        }
                    }

                    if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1
                        $auser->status = 0;
                    } else {
                        $auser->status = 1;
                    }

                    $buttontext = ($auser->status == 1) ? $strupdate : $strgrade;

                    ///No more buttons, we use popups ;-).
                    $popup_url = '/mod/assignment/submissions.php?id='.$this->cm->id
                               . '&amp;userid='.$auser->id.'&amp;mode=single'.'&amp;filter='.$filter.'&amp;offset='.$offset++;

                    $button = $OUTPUT->action_link($popup_url, $buttontext);

                    $status  = '<div id="up'.$auser->id.'" class="s'.$auser->status.'">'.$button.'</div>';

                    $finalgrade = '<span id="finalgrade_'.$auser->id.'">'.$final_grade->str_grade.'</span>';

                    $outcomes = '';

                    if ($uses_outcomes) {

                        foreach($grading_info->outcomes as $n=>$outcome) {
                            $outcomes .= '<div class="outcome"><label>'.$outcome->name.'</label>';
                            $options = make_grades_menu(-$outcome->scaleid);

                            if ($outcome->grades[$auser->id]->locked or !$quickgrade) {
                                $options[0] = get_string('nooutcome', 'grades');
                                $outcomes .= ': <span id="outcome_'.$n.'_'.$auser->id.'">'.$options[$outcome->grades[$auser->id]->grade].'</span>';
                            } else {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $attributes['id'] = 'outcome_'.$n.'_'.$auser->id;
                                $outcomes .= ' '.html_writer::select($options, 'outcome_'.$n.'['.$auser->id.']', $outcome->grades[$auser->id]->grade, array(0=>get_string('nooutcome', 'grades')), $attributes);
                            }
                            $outcomes .= '</div>';
                        }
                    }

                    $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&amp;course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $this->context)) . '</a>';
                    $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade);
                    if ($uses_outcomes) {
                        $row[] = $outcomes;
                    }

                    $table->add_data($row);
                }
                $currentposition++;
            }
        }

        $table->print_html();  /// Print the whole table

        /// Print quickgrade form around the table
        if ($quickgrade && $table->started_output){
            $mailinfopref = false;
            if (get_user_preferences('assignment_mailinfo', 1)) {
                $mailinfopref = true;
            }
            $emailnotification =  html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification','assignment'));

            $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'assignment');
            echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification'));

            $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'assignment')));
            echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton'));

            echo html_writer::end_tag('form');
        } else if ($quickgrade) {
            echo html_writer::end_tag('form');
        }

        echo '</div>';
        /// End of fast grading form

        /// Mini form for setting user preference

        $formaction = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id));
        $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref'));

        $mform->addElement('hidden', 'updatepref');
        $mform->setDefault('updatepref', 1);
        $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'assignment'));
        $mform->addElement('select', 'filter', get_string('show'),  $filters);

        $mform->setDefault('filter', $filter);

        $mform->addElement('text', 'perpage', get_string('pagesize', 'assignment'), array('size'=>1));
        $mform->setDefault('perpage', $perpage);

        $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade','assignment'));
        $mform->setDefault('quickgrade', $quickgrade);
        $mform->addHelpButton('quickgrade', 'quickgrade', 'assignment');

        $mform->addElement('submit', 'savepreferences', get_string('savepreferences'));

        $mform->display();

        echo $OUTPUT->footer();
    }
Ejemplo n.º 30
-1
// Check to see if we have a normalisation message to send.
if (!empty($normalisationmessage)) {
    echo $OUTPUT->notification($normalisationmessage, 'notifymessage');
}
echo html_writer::table($grade_edit_tree->table);
echo '<div id="gradetreesubmit">';
if (!$moving) {
    echo '<input class="advanced" type="submit" value="' . get_string('savechanges') . '" />';
}
// We don't print a bulk move menu if there are no other categories than course category
if (!$moving && count($grade_edit_tree->categories) > 1) {
    echo '<br /><br />';
    echo '<input type="hidden" name="bulkmove" value="0" id="bulkmoveinput" />';
    $attributes = array('id' => 'menumoveafter', 'class' => 'ignoredirty');
    echo html_writer::label(get_string('moveselectedto', 'grades'), 'menumoveafter');
    echo html_writer::select($grade_edit_tree->categories, 'moveafter', '', array('' => 'choosedots'), $attributes);
    $OUTPUT->add_action_handler(new component_action('change', 'submit_bulk_move'), 'menumoveafter');
    echo '<div id="noscriptgradetreeform" class="hiddenifjs">
            <input type="submit" value="' . get_string('go') . '" />
          </div>';
}
echo '</div>';
echo '</div></form>';
echo $OUTPUT->box_end();
// Print action buttons
echo $OUTPUT->container_start('buttons mdl-align');
if ($moving) {
    echo $OUTPUT->single_button(new moodle_url('index.php', array('id' => $course->id)), get_string('cancel'), 'get');
} else {
    echo $OUTPUT->single_button(new moodle_url('category.php', array('courseid' => $course->id)), get_string('addcategory', 'grades'), 'get');
    echo $OUTPUT->single_button(new moodle_url('item.php', array('courseid' => $course->id)), get_string('additem', 'grades'), 'get');