Esempio n. 1
0
}
/// Display the choice and possibly results
$eventdata = array();
$eventdata['objectid'] = $choice->id;
$eventdata['context'] = $context;
$event = \mod_choice\event\course_module_viewed::create($eventdata);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->trigger();
/// Check to see if groups are being used in this choice
$groupmode = groups_get_activity_groupmode($cm);
if ($groupmode) {
    groups_get_activity_group($cm, true);
    groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/choice/view.php?id=' . $id);
}
$allresponses = choice_get_response_data($choice, $cm, $groupmode);
// Big function, approx 6 SQL calls per user
if (has_capability('mod/choice:readresponses', $context)) {
    choice_show_reportlink($allresponses, $cm);
}
echo '<div class="clearer"></div>';
if ($choice->intro) {
    echo $OUTPUT->box(format_module_intro('choice', $choice, $cm->id), 'generalbox', 'intro');
}
$timenow = time();
$current = false;
// Initialise for later
//if user has already made a selection, and they are not allowed to update it or if choice is not open, show their selected answer.
if (isloggedin() && ($current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) && (empty($choice->allowupdate) || $timenow > $choice->timeclose)) {
    echo $OUTPUT->box(get_string("yourselection", "choice", userdate($choice->timeopen)) . ": " . format_string(choice_get_option_text($choice, $current->optionid)), 'generalbox', 'yourselection');
}
Esempio n. 2
0
        }
    }
}
/// Display the choice and possibly results
$eventdata = array();
$eventdata['objectid'] = $choice->id;
$eventdata['context'] = $context;
/// Check to see if groups are being used in this choice
$groupmode = groups_get_activity_groupmode($cm);
if ($groupmode) {
    groups_get_activity_group($cm, true);
    groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/choice/view.php?id=' . $id);
}
// Check if we want to include responses from inactive users.
$onlyactive = $choice->includeinactive ? false : true;
$allresponses = choice_get_response_data($choice, $cm, $groupmode, $onlyactive);
// Big function, approx 6 SQL calls per user.
if (has_capability('mod/choice:readresponses', $context)) {
    choice_show_reportlink($allresponses, $cm);
}
echo '<div class="clearer"></div>';
if ($choice->intro) {
    echo $OUTPUT->box(format_module_intro('choice', $choice, $cm->id), 'generalbox', 'intro');
}
$timenow = time();
$current = choice_get_my_response($choice);
//if user has already made a selection, and they are not allowed to update it or if choice is not open, show their selected answer.
if (isloggedin() && !empty($current) && (empty($choice->allowupdate) || $timenow > $choice->timeclose)) {
    $choicetexts = array();
    foreach ($current as $c) {
        $choicetexts[] = format_string(choice_get_option_text($choice, $c->optionid));
Esempio n. 3
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $choicenode The node to add module settings to
 */
function choice_extend_settings_navigation(settings_navigation $settings, navigation_node $choicenode)
{
    global $PAGE;
    if (has_capability('mod/choice:readresponses', $PAGE->cm->context)) {
        $groupmode = groups_get_activity_groupmode($PAGE->cm);
        if ($groupmode) {
            groups_get_activity_group($PAGE->cm, true);
        }
        $choice = choice_get_choice($PAGE->cm->instance);
        // Check if we want to include responses from inactive users.
        $onlyactive = $choice->includeinactive ? false : true;
        // Big function, approx 6 SQL calls per user.
        $allresponses = choice_get_response_data($choice, $PAGE->cm, $groupmode, $onlyactive);
        $responsecount = 0;
        foreach ($allresponses as $optionid => $userlist) {
            if ($optionid) {
                $responsecount += count($userlist);
            }
        }
        $choicenode->add(get_string("viewallresponses", "choice", $responsecount), new moodle_url('/mod/choice/report.php', array('id' => $PAGE->cm->id)));
    }
}
Esempio n. 4
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $choicenode The node to add module settings to
 */
function choice_extend_settings_navigation(settings_navigation $settings, navigation_node $choicenode)
{
    global $PAGE;
    if (has_capability('mod/choice:readresponses', $PAGE->cm->context)) {
        $groupmode = groups_get_activity_groupmode($PAGE->cm);
        if ($groupmode) {
            groups_get_activity_group($PAGE->cm, true);
        }
        // We only actually need the choice id here
        $choice = new stdClass();
        $choice->id = $PAGE->cm->instance;
        $allresponses = choice_get_response_data($choice, $PAGE->cm, $groupmode);
        // Big function, approx 6 SQL calls per user
        $responsecount = 0;
        foreach ($allresponses as $optionid => $userlist) {
            if ($optionid) {
                $responsecount += count($userlist);
            }
        }
        $choicenode->add(get_string("viewallresponses", "choice", $responsecount), new moodle_url('/mod/choice/report.php', array('id' => $PAGE->cm->id)));
    }
}
Esempio n. 5
0
    } else {
        echo $OUTPUT->header();
    }


/// Display the choice and possibly results
    add_to_log($course->id, "choice", "view", "view.php?id=$cm->id", $choice->id, $cm->id);

    /// Check to see if groups are being used in this choice
    $groupmode = groups_get_activity_groupmode($cm);

    if ($groupmode) {
        groups_get_activity_group($cm, true);
        groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/choice/view.php?id='.$id);
    }
    $allresponses = choice_get_response_data($choice, $cm, $groupmode);   // Big function, approx 6 SQL calls per user


    if (has_capability('mod/choice:readresponses', $context)) {
        choice_show_reportlink($allresponses, $cm);
    }

    echo '<div class="clearer"></div>';

    if ($choice->intro) {
        echo $OUTPUT->box(format_module_intro('choice', $choice, $cm->id), 'generalbox', 'intro');
    }

    $timenow = time();
    $current = false;  // Initialise for later
    //if user has already made a selection, and they are not allowed to update it or if choice is not open, show their selected answer.
 /**
  * Loads data from the database.
  * Note: even if the function fails, it may still have overwritten some or all existing data in the object.
  * @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
  * @return bool True if successful, or false otherwise
  */
 function load($id)
 {
     // Make sure the ID is valid
     $id = (int) $id;
     if ($id <= 0) {
         return false;
     }
     // Fetch the course module data
     if (!($this->cm = get_coursemodule_from_id('choice', $id))) {
         sloodle_debug("Failed to load course module instance #{$id}.<br/>");
         return false;
     }
     // Make sure the module is visible
     if ($this->cm->visible == 0) {
         sloodle_debug("Error: course module instance #{$id} not visible.<br/>");
         return false;
     }
     // Load from the primary table: choice instance
     if (!($this->moodle_choice_instance = get_record('choice', 'id', $this->cm->instance))) {
         sloodle_debug("Failed to load choice with instance ID #{$cm->instance}.<br/>");
         return false;
     }
     // Fetch options
     $this->options = array();
     if ($options = get_records('choice_options', 'choiceid', $this->moodle_choice_instance->id)) {
         // Get response data (this uses the standard choice function, in "moodle/mod/choice/lib.php")
         $allresponses = choice_get_response_data($this->moodle_choice_instance, $this->cm, 0);
         foreach ($options as $opt) {
             // Create our option object and add our data
             $this->options[$opt->id] = new SloodleChoiceOption();
             $this->options[$opt->id]->id = $opt->id;
             $this->options[$opt->id]->text = $opt->text;
             $this->options[$opt->id]->maxselections = $opt->maxanswers;
             $this->options[$opt->id]->timemodified = (int) $opt->timemodified;
             // Count the number of selections made
             $numsels = 0;
             if (isset($allresponses[$opt->id])) {
                 $numsels = count($allresponses[$opt->id]);
             }
             $this->options[$opt->id]->numselections = $numsels;
         }
     }
     // Determine how many people on the course have not yet answered
     $users = get_course_users($this->cm->course);
     if (!is_array($users)) {
         $users = array();
     }
     $num_users = count($users);
     $numanswers = (int) count_records('choice_answers', 'choiceid', $this->moodle_choice_instance->id);
     $this->numunanswered = max(0, $num_users - $numanswers);
     return true;
 }
Esempio n. 7
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);
 }