Ejemplo n.º 1
0
function questionnaire_user_complete($course, $user, $mod, $questionnaire)
{
    global $CFG;
    require_once $CFG->dirroot . '/mod/questionnaire/locallib.php';
    if ($responses = questionnaire_get_user_responses($questionnaire->sid, $user->id, $complete = false)) {
        foreach ($responses as $response) {
            if ($response->complete == 'y') {
                echo get_string('submitted', 'questionnaire') . ' ' . userdate($response->submitted) . '<br />';
            } else {
                echo get_string('attemptstillinprogress', 'questionnaire') . ' ' . userdate($response->submitted) . '<br />';
            }
        }
    } else {
        print_string('noresponses', 'questionnaire');
    }
    return true;
}
Ejemplo n.º 2
0
 $class = '';
 if (!$questionnaire->visible) {
     $class = ' class="dimmed"';
 }
 $data[] = "<a{$class} href=\"view.php?id={$cmid}\">{$questionnaire->name}</a>";
 // Close date.
 if ($questionnaire->closedate) {
     $data[] = userdate($questionnaire->closedate);
 } else {
     if ($showclosingheader) {
         $data[] = '';
     }
 }
 if ($showing == 'responses') {
     $status = '';
     if ($responses = questionnaire_get_user_responses($questionnaire->sid, $USER->id, $complete = false)) {
         foreach ($responses as $response) {
             if ($response->complete == 'y') {
                 $status .= get_string('submitted', 'questionnaire') . ' ' . userdate($response->submitted) . '<br />';
             } else {
                 $status .= get_string('attemptstillinprogress', 'questionnaire') . ' ' . userdate($response->submitted) . '<br />';
             }
         }
     }
     $data[] = $status;
 } else {
     if ($showing == 'stats') {
         $data[] = $DB->count_records('questionnaire_response', array('survey_id' => $questionnaire->sid, 'complete' => 'y'));
         if ($survey = $DB->get_record('questionnaire_survey', array('id' => $questionnaire->sid))) {
             // For a public questionnaire, look for the original public questionnaire that it is based on.
             if ($survey->realm == 'public') {
Ejemplo n.º 3
0
/**
 * Prints questionnaire summaries on 'My home' page
 *
 * Prints questionnaire name, due date and attempt information on
 * questionnaires that have a deadline that has not already passed
 * and it is available for taking.
 *
 * @global object
 * @global stdClass
 * @global object
 * @uses CONTEXT_MODULE
 * @param array $courses An array of course objects to get questionnaire instances from
 * @param array $htmlarray Store overview output array( course ID => 'questionnaire' => HTML output )
 * @return void
 */
function questionnaire_print_overview($courses, &$htmlarray)
{
    global $USER, $CFG, $DB, $OUTPUT;
    require_once $CFG->dirroot . '/mod/questionnaire/locallib.php';
    if (!($questionnaires = get_all_instances_in_courses('questionnaire', $courses))) {
        return;
    }
    // Get Necessary Strings.
    $strquestionnaire = get_string('modulename', 'questionnaire');
    $strnotattempted = get_string('noattempts', 'questionnaire');
    $strattempted = get_string('attempted', 'questionnaire');
    $strsavedbutnotsubmitted = get_string('savedbutnotsubmitted', 'questionnaire');
    $now = time();
    foreach ($questionnaires as $questionnaire) {
        // The questionnaire has a deadline.
        if ($questionnaire->closedate != 0 and $questionnaire->closedate >= $now and ($questionnaire->opendate == 0 or $questionnaire->opendate <= $now)) {
            if (!$questionnaire->visible) {
                $class = ' class="dimmed"';
            } else {
                $class = '';
            }
            $str = $OUTPUT->box("{$strquestionnaire}:\n                            <a{$class} href=\"{$CFG->wwwroot}/mod/questionnaire/view.php?id={$questionnaire->coursemodule}\">" . format_string($questionnaire->name) . '</a>', 'name');
            // Deadline.
            $str .= $OUTPUT->box(get_string('closeson', 'questionnaire', userdate($questionnaire->closedate)), 'info');
            $select = 'qid = ' . $questionnaire->id . ' AND userid = ' . $USER->id;
            $attempts = $DB->get_records_select('questionnaire_attempts', $select);
            $nbattempts = count($attempts);
            // Do not display a questionnaire as due if it can only be sumbitted once and it has already been submitted!
            if ($nbattempts != 0 && $questionnaire->qtype == QUESTIONNAIREONCE) {
                continue;
            }
            // Attempt information.
            if (has_capability('mod/questionnaire:manage', context_module::instance($questionnaire->coursemodule))) {
                // Number of user attempts.
                $attempts = $DB->count_records('questionnaire_attempts', array('id' => $questionnaire->id));
                $str .= $OUTPUT->box(get_string('numattemptsmade', 'questionnaire', $attempts), 'info');
            } else {
                if ($responses = questionnaire_get_user_responses($questionnaire->sid, $USER->id, $complete = false)) {
                    foreach ($responses as $response) {
                        if ($response->complete == 'y') {
                            $str .= $OUTPUT->box($strattempted, 'info');
                            break;
                        } else {
                            $str .= $OUTPUT->box($strsavedbutnotsubmitted, 'info');
                        }
                    }
                } else {
                    $str .= $OUTPUT->box($strnotattempted, 'info');
                }
            }
            $str = $OUTPUT->box($str, 'questionnaire overview');
            if (empty($htmlarray[$questionnaire->course]['questionnaire'])) {
                $htmlarray[$questionnaire->course]['questionnaire'] = $str;
            } else {
                $htmlarray[$questionnaire->course]['questionnaire'] .= $str;
            }
        }
    }
}
function questionnaire_user_complete($course, $user, $mod, $questionnaire)
{
    /// Print a detailed representation of what a  user has done with
    /// a given particular instance of this module, for user activity reports.
    if ($responses = questionnaire_get_user_responses($questionnaire->sid, $user->id)) {
        foreach ($responses as $response) {
            echo get_string('submitted', 'questionnaire') . ' ' . userdate($response->submitted) . '<br />';
        }
    } else {
        print_string('noresponses', 'questionnaire');
    }
    return true;
}