Exemplo n.º 1
0
 /**
  * Adds an input element to the complete form
  *
  * @param stdClass $item
  * @param mod_feedback_complete_form $form
  */
 public function complete_form_element($item, $form)
 {
     $name = $this->get_display_name($item);
     $inputname = $item->typ . '_' . $item->id;
     if ($form->get_mode() != mod_feedback_complete_form::MODE_COMPLETE) {
         $form->add_form_element($item, ['static', $inputname, $name], false, false);
     } else {
         $form->add_form_element($item, ['recaptcha', $inputname, $name], false, false);
     }
     // Add recaptcha validation to the form.
     $form->add_validation_rule(function ($values, $files) use($item, $form) {
         $elementname = $item->typ . '_' . $item->id;
         $recaptchaelement = $form->get_form_element($elementname);
         if (empty($values['recaptcha_response_field'])) {
             return array($elementname => get_string('required'));
         } else {
             if (!empty($values['recaptcha_challenge_field'])) {
                 $challengefield = $values['recaptcha_challenge_field'];
                 $responsefield = $values['recaptcha_response_field'];
                 if (true !== ($result = $recaptchaelement->verify($challengefield, $responsefield))) {
                     return array($elementname => $result);
                 }
             } else {
                 return array($elementname => get_string('missingrecaptchachallengefield'));
             }
         }
         return true;
     });
 }
Exemplo n.º 2
0
 /**
  * Adds an input element to the complete form
  *
  * @param stdClass $item
  * @param mod_feedback_complete_form $form
  */
 public function complete_form_element($item, $form)
 {
     $name = $this->get_display_name($item);
     $inputname = $item->typ . '_' . $item->id;
     list($cols, $rows) = explode("|", $item->presentation);
     $form->add_form_element($item, ['textarea', $inputname, $name, array('rows' => $rows, 'cols' => $cols)]);
     $form->set_element_type($inputname, PARAM_NOTAGS);
 }
Exemplo n.º 3
0
 /**
  * Adds an input element to the complete form
  *
  * @param stdClass $item
  * @param mod_feedback_complete_form $form
  */
 public function complete_form_element($item, $form)
 {
     $form->add_form_element($item, ['static', $item->typ . '_' . $item->id, '', '<hr class="feedback_pagebreak">']);
 }
Exemplo n.º 4
0
 /**
  * Adds an input element to the complete form
  *
  * @param stdClass $item
  * @param mod_feedback_complete_form $form
  */
 public function complete_form_element($item, $form)
 {
     $name = $this->get_display_name($item);
     $inputname = $item->typ . '_' . $item->id;
     $form->add_form_element($item, ['text', $inputname, $name], true, false);
     $form->set_element_type($inputname, PARAM_NOTAGS);
     $tmpvalue = $this->format_float($form->get_item_value($item));
     $form->set_element_default($inputname, $tmpvalue);
     // Add form validation rule to check for boundaries.
     $form->add_validation_rule(function ($values, $files) use($item) {
         $inputname = $item->typ . '_' . $item->id;
         list($rangefrom, $rangeto) = explode('|', $item->presentation);
         if (!isset($values[$inputname]) || trim($values[$inputname]) === '') {
             return $item->required ? array($inputname => get_string('required')) : true;
         }
         $value = unformat_float($values[$inputname], true);
         if ($value === false) {
             return array($inputname => get_string('invalidnum', 'error'));
         }
         if (is_numeric($rangefrom) && $value < floatval($rangefrom) || is_numeric($rangeto) && $value > floatval($rangeto)) {
             return array($inputname => get_string('numberoutofrange', 'feedback'));
         }
         return true;
     });
 }
Exemplo n.º 5
0
 /**
  * Adds an input element to the complete form
  *
  * @param stdClass $item
  * @param mod_feedback_complete_form $form
  */
 public function complete_form_element($item, $form)
 {
     global $DB;
     if (!$item->feedback and $item->template) {
         // This is a template.
         $template = $DB->get_record('feedback_template', array('id' => $item->template));
         if ($template->ispublic) {
             $context = context_system::instance();
         } else {
             $context = context_course::instance($template->course);
         }
         $filearea = 'template';
     } else {
         // This is a question in the current feedback.
         $context = $form->get_cm()->context;
         $filearea = 'item';
     }
     $output = file_rewrite_pluginfile_urls($item->presentation, 'pluginfile.php', $context->id, 'mod_feedback', $filearea, $item->id);
     $formatoptions = array('overflowdiv' => true, 'noclean' => true);
     $output = format_text($output, FORMAT_HTML, $formatoptions);
     $inputname = $item->typ . '_' . $item->id;
     $name = $this->get_display_name($item);
     $form->add_form_element($item, ['static', $inputname, $name, $output], false, false);
 }
Exemplo n.º 6
0
 /**
  * Adds an input element to the complete form
  *
  * @param stdClass $item
  * @param mod_feedback_complete_form $form
  */
 public function complete_form_element($item, $form)
 {
     $info = $this->get_info($item);
     $name = $this->get_display_name($item);
     $class = 'multichoicerated-' . $info->subtype;
     $inputname = $item->typ . '_' . $item->id;
     $options = $this->get_options($item);
     if ($info->subtype === 'd' || $form->is_frozen()) {
         $el = $form->add_form_element($item, ['select', $inputname, $name, array('' => '') + $options, array('class' => $class)]);
     } else {
         $objs = array();
         foreach ($options as $idx => $label) {
             $objs[] = ['radio', $inputname, '', $label, $idx];
         }
         $separator = $info->horizontal ? ' ' : '<br>';
         $class .= ' multichoicerated-' . ($info->horizontal ? 'horizontal' : 'vertical');
         $el = $form->add_form_group_element($item, 'group_' . $inputname, $name, $objs, $separator, $class);
         // Set previously input values.
         $form->set_element_default($inputname, $form->get_item_value($item));
         // Process "required" rule.
         if ($item->required) {
             $form->add_validation_rule(function ($values, $files) use($item) {
                 $inputname = $item->typ . '_' . $item->id;
                 return empty($values[$inputname]) ? array('group_' . $inputname => get_string('required')) : true;
             });
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Adds an input element to the complete form
  *
  * @param stdClass $item
  * @param mod_feedback_complete_form $form
  */
 public function complete_form_element($item, $form)
 {
     $name = $this->get_display_name($item);
     $inputname = $item->typ . '_' . $item->id;
     list($size, $maxlength) = explode("|", $item->presentation);
     $form->add_form_element($item, ['text', $inputname, $name, ['maxlength' => $maxlength, 'size' => $size]]);
     $form->set_element_type($inputname, PARAM_NOTAGS);
     $form->add_element_rule($inputname, get_string('maximumchars', '', $maxlength), 'maxlength', $maxlength, 'client');
 }
Exemplo n.º 8
0
require 'tabs.php';
/// Print the main part of the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
if ($userid || $showcompleted) {
    // Print the response of the given user.
    $completedrecord = $feedbackstructure->get_completed();
    if ($userid) {
        $usr = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
        $responsetitle = userdate($completedrecord->timemodified) . ' (' . fullname($usr) . ')';
    } else {
        $responsetitle = get_string('response_nr', 'feedback') . ': ' . $completedrecord->random_response . ' (' . get_string('anonymous', 'feedback') . ')';
    }
    echo $OUTPUT->heading($responsetitle, 4);
    $form = new mod_feedback_complete_form(mod_feedback_complete_form::MODE_VIEW_RESPONSE, $feedbackstructure, 'feedback_viewresponse_form');
    $form->display();
    list($prevresponseurl, $returnurl, $nextresponseurl) = $userid ? $responsestable->get_reponse_navigation_links($completedrecord) : $anonresponsestable->get_reponse_navigation_links($completedrecord);
    echo html_writer::start_div('response_navigation');
    echo $prevresponseurl ? html_writer::link($prevresponseurl, get_string('prev'), ['class' => 'prev_response']) : '';
    echo html_writer::link($returnurl, get_string('back'), ['class' => 'back_to_list']);
    echo $nextresponseurl ? html_writer::link($nextresponseurl, get_string('next'), ['class' => 'next_response']) : '';
    echo html_writer::end_div();
} else {
    // Print the list of responses.
    $courseselectform->display();
    // Show non-anonymous responses (always retrieve them even if current feedback is anonymous).
    $totalrows = $responsestable->get_total_responses_count();
    if (!$feedbackstructure->is_anonymous() || $totalrows) {
        echo $OUTPUT->heading(get_string('non_anonymous_entries', 'feedback', $totalrows), 4);
        $responsestable->display();
Exemplo n.º 9
0
 /**
  * Adds an input element to the complete form
  *
  * @param stdClass $item
  * @param mod_feedback_complete_form $form
  */
 public function complete_form_element($item, $form)
 {
     if ($form->get_mode() == mod_feedback_complete_form::MODE_VIEW_RESPONSE) {
         $value = strval($form->get_item_value($item));
     } else {
         $value = $this->get_current_value($item, $form->get_feedback(), $form->get_current_course_id());
     }
     $printval = $this->get_printval($item, (object) ['value' => $value]);
     $class = '';
     switch ($item->presentation) {
         case self::MODE_RESPONSETIME:
             $class = 'info-responsetime';
             $value = $value ? self::CURRENTTIMESTAMP : '';
             break;
         case self::MODE_COURSE:
             $class = 'info-course';
             break;
         case self::MODE_CATEGORY:
             $class = 'info-category';
             break;
     }
     $name = $this->get_display_name($item);
     $inputname = $item->typ . '_' . $item->id;
     $element = $form->add_form_element($item, ['select', $inputname, $name, array($value => $printval), array('class' => $class)], false, false);
     $form->set_element_default($inputname, $value);
     $element->freeze();
     if ($form->get_mode() == mod_feedback_complete_form::MODE_COMPLETE) {
         $element->setPersistantFreeze(true);
     }
 }
Exemplo n.º 10
0
 /**
  * Adds an input element to the complete form
  *
  * This element has many options - it can be displayed as group or radio elements,
  * group of checkboxes or a dropdown list.
  *
  * @param stdClass $item
  * @param mod_feedback_complete_form $form
  */
 public function complete_form_element($item, $form)
 {
     $info = $this->get_info($item);
     $name = $this->get_display_name($item);
     $class = 'multichoice-' . $info->subtype;
     $inputname = $item->typ . '_' . $item->id;
     $options = $this->get_options($item);
     $separator = !empty($info->horizontal) ? ' ' : '<br>';
     $tmpvalue = $form->get_item_value($item);
     if ($info->subtype === 'd' || $info->subtype === 'r' && $form->is_frozen()) {
         // Display as a dropdown in the complete form or a single value in the response view.
         $element = $form->add_form_element($item, ['select', $inputname . '[0]', $name, array(0 => '') + $options, array('class' => $class)], false, false);
         $form->set_element_default($inputname . '[0]', $tmpvalue);
     } else {
         if ($info->subtype === 'c' && $form->is_frozen()) {
             // Display list of checkbox values in the response view.
             $objs = [];
             foreach (explode(FEEDBACK_MULTICHOICE_LINE_SEP, $form->get_item_value($item)) as $v) {
                 $objs[] = ['static', $inputname . "[{$v}]", '', isset($options[$v]) ? $options[$v] : ''];
             }
             $element = $form->add_form_group_element($item, 'group_' . $inputname, $name, $objs, $separator, $class);
         } else {
             // Display group or radio or checkbox elements.
             $class .= ' multichoice-' . ($info->horizontal ? 'horizontal' : 'vertical');
             $objs = [];
             if ($info->subtype === 'c') {
                 // Checkboxes.
                 $objs[] = ['hidden', $inputname . '[0]', 0];
                 $form->set_element_type($inputname . '[0]', PARAM_INT);
                 foreach ($options as $idx => $label) {
                     $objs[] = ['advcheckbox', $inputname . '[' . $idx . ']', '', $label, null, array(0, $idx)];
                     $form->set_element_type($inputname . '[' . $idx . ']', PARAM_INT);
                 }
                 $element = $form->add_form_group_element($item, 'group_' . $inputname, $name, $objs, $separator, $class);
                 if ($tmpvalue) {
                     foreach (explode(FEEDBACK_MULTICHOICE_LINE_SEP, $tmpvalue) as $v) {
                         $form->set_element_default($inputname . '[' . $v . ']', $v);
                     }
                 }
             } else {
                 // Radio.
                 foreach ($options as $idx => $label) {
                     $objs[] = ['radio', $inputname . '[0]', '', $label, $idx];
                 }
                 $element = $form->add_form_group_element($item, 'group_' . $inputname, $name, $objs, $separator, $class);
                 $form->set_element_default($inputname . '[0]', $tmpvalue);
             }
         }
     }
     // Process 'required' rule.
     if ($item->required) {
         $elementname = $element->getName();
         $form->add_validation_rule(function ($values, $files) use($elementname, $item) {
             $inputname = $item->typ . '_' . $item->id;
             return empty($values[$inputname]) || !array_filter($values[$inputname]) ? array($elementname => get_string('required')) : true;
         });
     }
 }
Exemplo n.º 11
0
    echo $OUTPUT->notification(get_string('feedback_is_not_open', 'feedback'));
    echo $OUTPUT->continue_button(course_get_url($courseid ?: $feedback->course));
    echo $OUTPUT->box_end();
    echo $OUTPUT->footer();
    exit;
}
// Mark activity viewed for completion-tracking.
$completion = new completion_info($course);
if (isloggedin() && !isguestuser()) {
    $completion->set_module_viewed($cm);
}
// Check if user is prevented from re-submission.
$cansubmit = $feedbackcompletion->can_submit();
// Initialise the form processing feedback completion.
if (!$feedbackcompletion->is_empty() && $cansubmit) {
    $form = new mod_feedback_complete_form(mod_feedback_complete_form::MODE_COMPLETE, $feedbackcompletion, 'feedback_complete_form', array('gopage' => $gopage));
    if ($form->is_cancelled()) {
        // Form was cancelled - return to the course page.
        redirect(course_get_url($courseid ?: $course));
    } else {
        if ($form->is_submitted() && ($form->is_validated() || optional_param('gopreviouspage', null, PARAM_RAW))) {
            // Form was submitted (skip validation for "Previous page" button).
            $data = $form->get_submitted_data();
            if (!isset($SESSION->feedback->is_started) or !$SESSION->feedback->is_started == true) {
                print_error('error', '', $CFG->wwwroot . '/course/view.php?id=' . $course->id);
            }
            $feedbackcompletion->save_response_tmp($data);
            if (!empty($data->savevalues) || !empty($data->gonextpage)) {
                if (($nextpage = $feedbackcompletion->get_next_page($gopage)) !== null) {
                    redirect(new moodle_url($PAGE->url, array('gopage' => $nextpage)));
                } else {