Exemple #1
0
            echo $OUTPUT->box(get_string('previewonly', 'choice', userdate($choice->timeopen)), 'generalbox alert');
        } else {
            echo $OUTPUT->box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "generalbox notopenyet");
            echo $OUTPUT->footer();
            exit;
        }
    } else {
        if ($timenow > $choice->timeclose) {
            echo $OUTPUT->box(get_string("expired", "choice", userdate($choice->timeclose)), "generalbox expired");
            $choiceopen = false;
        }
    }
}
if ((!$current or $choice->allowupdate) and $choiceopen and is_enrolled($context, NULL, 'mod/choice:choose')) {
    // They haven't made their choice yet or updates allowed and choice is open
    $options = choice_prepare_options($choice, $USER, $cm, $allresponses);
    $renderer = $PAGE->get_renderer('mod_choice');
    echo $renderer->display_options($options, $cm->id, $choice->display, $choice->allowmultiple);
    $choiceformshown = true;
} else {
    $choiceformshown = false;
}
if (!$choiceformshown) {
    $sitecontext = context_system::instance();
    if (isguestuser()) {
        // Guest account
        echo $OUTPUT->confirm(get_string('noguestchoose', 'choice') . '<br /><br />' . get_string('liketologin'), get_login_url(), new moodle_url('/course/view.php', array('id' => $course->id)));
    } else {
        if (!is_enrolled($context)) {
            // Only people enrolled can make a choice
            $SESSION->wantsurl = qualified_me();
Exemple #2
0
 /**
  * Returns options for a specific choice
  *
  * @param int $choiceid the choice instance id
  * @return array of options details
  * @since Moodle 3.0
  */
 public static function get_choice_options($choiceid)
 {
     global $USER;
     $warnings = array();
     $params = self::validate_parameters(self::get_choice_options_parameters(), array('choiceid' => $choiceid));
     if (!($choice = choice_get_choice($params['choiceid']))) {
         throw new moodle_exception("invalidcoursemodule", "error");
     }
     list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/choice:choose', $context);
     $groupmode = groups_get_activity_groupmode($cm);
     $onlyactive = $choice->includeinactive ? false : true;
     $allresponses = choice_get_response_data($choice, $cm, $groupmode, $onlyactive);
     $timenow = time();
     $choiceopen = true;
     $showpreview = false;
     if ($choice->timeclose != 0) {
         if ($choice->timeopen > $timenow) {
             $choiceopen = false;
             $warnings[1] = get_string("notopenyet", "choice", userdate($choice->timeopen));
             if ($choice->showpreview) {
                 $warnings[2] = get_string('previewonly', 'choice', userdate($choice->timeopen));
                 $showpreview = true;
             }
         }
         if ($timenow > $choice->timeclose) {
             $choiceopen = false;
             $warnings[3] = get_string("expired", "choice", userdate($choice->timeclose));
         }
     }
     $optionsarray = array();
     if ($choiceopen or $showpreview) {
         $options = choice_prepare_options($choice, $USER, $cm, $allresponses);
         foreach ($options['options'] as $option) {
             $optionarr = array();
             $optionarr['id'] = $option->attributes->value;
             $optionarr['text'] = external_format_string($option->text, $context->id);
             $optionarr['maxanswers'] = $option->maxanswers;
             $optionarr['displaylayout'] = $option->displaylayout;
             $optionarr['countanswers'] = $option->countanswers;
             foreach (array('checked', 'disabled') as $field) {
                 if (property_exists($option->attributes, $field) and $option->attributes->{$field} == 1) {
                     $optionarr[$field] = 1;
                 } else {
                     $optionarr[$field] = 0;
                 }
             }
             // When showpreview is active, we show options as disabled.
             if ($showpreview or $optionarr['checked'] == 1 and !$choice->allowupdate) {
                 $optionarr['disabled'] = 1;
             }
             $optionsarray[] = $optionarr;
         }
     }
     foreach ($warnings as $key => $message) {
         $warnings[$key] = array('item' => 'choice', 'itemid' => $cm->id, 'warningcode' => $key, 'message' => $message);
     }
     return array('options' => $optionsarray, 'warnings' => $warnings);
 }