예제 #1
0
/**
 * @global object
 * @param object $course
 * @param object $user
 * @param object $mod
 * @param object $randchoice
 * @return string|void
 */
function randchoice_user_complete($course, $user, $mod, $randchoice)
{
    global $DB;
    if ($answer = $DB->get_record('randchoice_answers', array("randchoiceid" => $randchoice->id, "userid" => $user->id))) {
        $result = new stdClass();
        $result->info = "'" . format_string(randchoice_get_option_text($randchoice, $answer->optionid)) . "'";
        $result->time = $answer->timemodified;
        echo get_string("answered", "randchoice") . ": {$result->info}. " . get_string("updated", '', userdate($result->time));
    } else {
        print_string("notanswered", "randchoice");
    }
}
예제 #2
0
// Big function, approx 6 SQL calls per user.
if (has_capability('mod/randchoice:readresponses', $context)) {
    randchoice_show_reportlink($allresponses, $cm);
}
echo '<div class="clearer"></div>';
if ($randchoice->intro) {
    echo $OUTPUT->box(format_module_intro('randchoice', $randchoice, $cm->id), 'generalbox', 'intro');
}
$timenow = time();
//var_dump($timenow); die;
$current = $DB->get_records('randchoice_answers', array('randchoiceid' => $randchoice->id, 'userid' => $USER->id));
//if user has already made a selection, and they are not allowed to update it or if randchoice is not open, show their selected answer.
if (isloggedin() && !empty($current) && (empty($randchoice->allowupdate) || $timenow > $randchoice->timeclose)) {
    $randchoicetexts = array();
    foreach ($current as $c) {
        $randchoicetexts[] = format_string(randchoice_get_option_text($randchoice, $c->optionid));
    }
    echo $OUTPUT->box(get_string("yourselection", "randchoice", userdate($randchoice->timeopen)) . ": " . implode('; ', $randchoicetexts), 'generalbox', 'yourselection');
}
/// Print the form
$randchoiceopen = true;
if ($randchoice->timeclose != 0) {
    if ($randchoice->timeopen > $timenow) {
        if ($randchoice->showpreview) {
            echo $OUTPUT->box(get_string('previewonly', 'randchoice', userdate($randchoice->timeopen)), 'generalbox alert');
        } else {
            echo $OUTPUT->box(get_string("notopenyet", "randchoice", userdate($randchoice->timeopen)), "generalbox notopenyet");
            echo $OUTPUT->footer();
            exit;
        }
    } else {
예제 #3
0
if ($download == "txt" && has_capability('mod/randchoice:downloadresponses', $context)) {
    $filename = clean_filename("{$course->shortname} " . strip_tags(format_string($randchoice->name, true))) . '.txt';
    header("Content-Type: application/download\n");
    header("Content-Disposition: attachment; filename=\"{$filename}\"");
    header("Expires: 0");
    header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
    header("Pragma: public");
    /// Print names of all the fields
    echo get_string("lastname") . "\t" . get_string("firstname") . "\t" . get_string("idnumber") . "\t";
    echo get_string("group") . "\t";
    echo get_string("randchoice", "randchoice") . "\n";
    /// generate the data for the body of the spreadsheet
    $i = 0;
    if ($users) {
        foreach ($users as $option => $userid) {
            $option_text = randchoice_get_option_text($randchoice, $option);
            foreach ($userid as $user) {
                echo $user->lastname;
                echo "\t" . $user->firstname;
                $studentid = " ";
                if (!empty($user->idnumber)) {
                    $studentid = $user->idnumber;
                }
                echo "\t" . $studentid . "\t";
                $ug2 = '';
                if ($usergrps = groups_get_all_groups($course->id, $user->id)) {
                    foreach ($usergrps as $ug) {
                        $ug2 = $ug2 . $ug->name;
                    }
                }
                echo $ug2 . "\t";
예제 #4
0
    $strsectionname = get_string('sectionname', 'format_' . $course->format);
    $table->head = array($strsectionname, get_string("question"), get_string("answer"));
    $table->align = array("center", "left", "left");
} else {
    $table->head = array(get_string("question"), get_string("answer"));
    $table->align = array("left", "left");
}
$currentsection = "";
foreach ($randchoices as $randchoice) {
    if (!empty($answers[$randchoice->id])) {
        $answer = $answers[$randchoice->id];
    } else {
        $answer = "";
    }
    if (!empty($answer->optionid)) {
        $aa = format_string(randchoice_get_option_text($randchoice, $answer->optionid));
    } else {
        $aa = "";
    }
    if ($usesections) {
        $printsection = "";
        if ($randchoice->section !== $currentsection) {
            if ($randchoice->section) {
                $printsection = get_section_name($course, $randchoice->section);
            }
            if ($currentsection !== "") {
                $table->data[] = 'hr';
            }
            $currentsection = $randchoice->section;
        }
    }