Exemple #1
0
$attemptids = optional_param_array('attemptid', array(), PARAM_INT);
// array of attempt ids for delete action
$notify = optional_param('notify', '', PARAM_ALPHA);
$url = new moodle_url('/mod/randchoice/view.php', array('id' => $id));
if ($action !== '') {
    $url->param('action', $action);
}
$PAGE->set_url($url);
if (!($cm = get_coursemodule_from_id('randchoice', $id))) {
    print_error('invalidcoursemodule');
}
if (!($course = $DB->get_record("course", array("id" => $cm->course)))) {
    print_error('coursemisconf');
}
require_course_login($course, false, $cm);
if (!($randchoice = randchoice_get_randchoice($cm->instance))) {
    print_error('invalidcoursemodule');
}
$strrandchoice = get_string('modulename', 'randchoice');
$strrandchoices = get_string('modulenameplural', 'randchoice');
$context = context_module::instance($cm->id);
if ($action == 'delrandchoice' and confirm_sesskey() and is_enrolled($context, NULL, 'mod/randchoice:choose') and $randchoice->allowupdate) {
    $answercount = $DB->count_records('randchoice_answers', array('randchoiceid' => $randchoice->id, 'userid' => $USER->id));
    if ($answercount > 0) {
        $DB->delete_records('randchoice_answers', array('randchoiceid' => $randchoice->id, 'userid' => $USER->id));
        // Update completion state
        $completion = new completion_info($course);
        if ($completion->is_enabled($cm) && $randchoice->completionsubmit) {
            $completion->update_state($cm, COMPLETION_INCOMPLETE);
        }
        redirect("view.php?id={$cm->id}");
Exemple #2
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $randchoicenode The node to add module settings to
 */
function randchoice_extend_settings_navigation(settings_navigation $settings, navigation_node $randchoicenode)
{
    global $PAGE;
    if (has_capability('mod/randchoice:readresponses', $PAGE->cm->context)) {
        $groupmode = groups_get_activity_groupmode($PAGE->cm);
        if ($groupmode) {
            groups_get_activity_group($PAGE->cm, true);
        }
        $randchoice = randchoice_get_randchoice($PAGE->cm->instance);
        // Check if we want to include responses from inactive users.
        $onlyactive = $randchoice->includeinactive ? false : true;
        // Big function, approx 6 SQL calls per user.
        $allresponses = randchoice_get_response_data($randchoice, $PAGE->cm, $groupmode, $onlyactive);
        $responsecount = 0;
        foreach ($allresponses as $optionid => $userlist) {
            if ($optionid) {
                $responsecount += count($userlist);
            }
        }
        $randchoicenode->add(get_string("viewallresponses", "randchoice", $responsecount), new moodle_url('/mod/randchoice/report.php', array('id' => $PAGE->cm->id)));
    }
}