Beispiel #1
0
     break;
 case $strviewbyresponse:
 case 'vresp':
     if (empty($questionnaire->survey)) {
         print_error('surveynotexists', 'questionnaire');
     }
     $SESSION->questionnaire->current_tab = 'mybyresponse';
     $select = 'survey_id = ' . $questionnaire->sid . ' AND username = \'' . $userid . '\' AND complete=\'y\'';
     $sort = 'submitted ASC';
     $resps = $DB->get_records_select('questionnaire_response', $select, $params = null, $sort);
     $rids = array_keys($resps);
     if (!$rid) {
         $rid = $rids[0];
     }
     if ($rid) {
         $numresp = $questionnaire->count_submissions($USER->id);
         $titletext = get_string('myresponsetitle', 'questionnaire', $numresp);
     }
     // Print the page header.
     echo $OUTPUT->header();
     // Print the tabs.
     include 'tabs.php';
     echo $OUTPUT->box_start();
     echo $OUTPUT->heading($titletext);
     if (count($resps) > 1) {
         echo '<div style="text-align:center; padding-bottom:5px;">';
         $questionnaire->survey_results_navbar_student($rid, $userid, $instance, $resps);
         echo '</div>';
     }
     $questionnaire->view_response($rid);
     if (count($resps) > 1) {
Beispiel #2
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $questionnairenode The node to add module settings to
 */
function questionnaire_extend_settings_navigation(settings_navigation $settings, navigation_node $questionnairenode)
{
    global $PAGE, $DB, $USER, $CFG;
    $individualresponse = optional_param('individualresponse', false, PARAM_INT);
    $rid = optional_param('rid', false, PARAM_INT);
    // Response id.
    $currentgroupid = optional_param('group', 0, PARAM_INT);
    // Group id.
    require_once $CFG->dirroot . '/mod/questionnaire/questionnaire.class.php';
    $context = $PAGE->cm->context;
    $cmid = $PAGE->cm->id;
    $cm = $PAGE->cm;
    $course = $PAGE->course;
    if (!($questionnaire = $DB->get_record("questionnaire", array("id" => $cm->instance)))) {
        print_error('invalidcoursemodule');
    }
    $courseid = $course->id;
    $questionnaire = new questionnaire(0, $questionnaire, $course, $cm);
    if ($survey = $DB->get_record('questionnaire_survey', array('id' => $questionnaire->sid))) {
        $owner = trim($survey->owner) == trim($courseid);
    } else {
        $survey = false;
        $owner = true;
    }
    // We want to add these new nodes after the Edit settings node, and before the
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
    $keys = $questionnairenode->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false and array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    if (has_capability('mod/questionnaire:manage', $context) && $owner) {
        $url = '/mod/questionnaire/qsettings.php';
        $node = navigation_node::create(get_string('advancedsettings'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'advancedsettings', new pix_icon('t/edit', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if (has_capability('mod/questionnaire:editquestions', $context) && $owner) {
        $url = '/mod/questionnaire/questions.php';
        $node = navigation_node::create(get_string('questions', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'questions', new pix_icon('t/edit', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if (has_capability('mod/questionnaire:preview', $context) && $owner) {
        $url = '/mod/questionnaire/preview.php';
        $node = navigation_node::create(get_string('preview_label', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'preview', new pix_icon('t/preview', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if ($questionnaire->user_can_take($USER->id)) {
        $url = '/mod/questionnaire/complete.php';
        $node = navigation_node::create(get_string('answerquestions', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, '', new pix_icon('i/info', 'answerquestions'));
        $questionnairenode->add_node($node, $beforekey);
    }
    $usernumresp = $questionnaire->count_submissions($USER->id);
    if ($questionnaire->capabilities->readownresponses && $usernumresp > 0) {
        $url = '/mod/questionnaire/myreport.php';
        $node = navigation_node::create(get_string('yourresponses', 'questionnaire'), new moodle_url($url, array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary')), navigation_node::TYPE_SETTING, null, 'yourresponses');
        $myreportnode = $questionnairenode->add_node($node, $beforekey);
        $summary = $myreportnode->add(get_string('summary', 'questionnaire'), new moodle_url('/mod/questionnaire/myreport.php', array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary')));
        $byresponsenode = $myreportnode->add(get_string('viewbyresponse', 'questionnaire'), new moodle_url('/mod/questionnaire/myreport.php', array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 1, 'action' => 'vresp')));
        $allmyresponsesnode = $myreportnode->add(get_string('myresponses', 'questionnaire'), new moodle_url('/mod/questionnaire/myreport.php', array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'vall')));
        if ($questionnaire->capabilities->downloadresponses) {
            $downloadmyresponsesnode = $myreportnode->add(get_string('downloadtext'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'user' => $USER->id, 'action' => 'dwnpg', 'group' => $currentgroupid)));
        }
    }
    $numresp = $questionnaire->count_submissions();
    // Number of responses in currently selected group (or all participants etc.).
    if (isset($SESSION->questionnaire->numselectedresps)) {
        $numselectedresps = $SESSION->questionnaire->numselectedresps;
    } else {
        $numselectedresps = $numresp;
    }
    // If questionnaire is set to separate groups, prevent user who is not member of any group
    // to view All responses.
    $canviewgroups = true;
    $groupmode = groups_get_activity_groupmode($cm, $course);
    if ($groupmode == 1) {
        $canviewgroups = groups_has_membership($cm, $USER->id);
    }
    if ($questionnaire->capabilities->readallresponseanytime && $numresp > 0 && $owner && $numselectedresps > 0 || $questionnaire->capabilities->readallresponses && $numresp > 0 && $canviewgroups && ($questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_ALWAYS || $questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENCLOSED && $questionnaire->is_closed() || $questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENANSWERED && $usernumresp > 0) && $questionnaire->is_survey_owner()) {
        $url = '/mod/questionnaire/report.php';
        $node = navigation_node::create(get_string('viewallresponses', 'questionnaire'), new moodle_url($url, array('instance' => $questionnaire->id, 'action' => 'vall')), navigation_node::TYPE_SETTING, null, 'vall');
        $reportnode = $questionnairenode->add_node($node, $beforekey);
        if ($questionnaire->capabilities->viewsingleresponse) {
            $summarynode = $reportnode->add(get_string('summary', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall')));
        } else {
            $summarynode = $reportnode;
        }
        $defaultordernode = $summarynode->add(get_string('order_default', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall', 'group' => $currentgroupid)));
        $ascendingordernode = $summarynode->add(get_string('order_ascending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallasort', 'group' => $currentgroupid)));
        $descendingordernode = $summarynode->add(get_string('order_descending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallarsort', 'group' => $currentgroupid)));
        if ($questionnaire->capabilities->deleteresponses) {
            $deleteallnode = $summarynode->add(get_string('deleteallresponses', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'delallresp', 'group' => $currentgroupid)));
        }
        if ($questionnaire->capabilities->downloadresponses) {
            $downloadresponsesnode = $summarynode->add(get_string('downloadtextformat', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'dwnpg', 'group' => $currentgroupid)));
        }
        if ($questionnaire->capabilities->viewsingleresponse && $questionnaire->respondenttype != 'anonymous') {
            $byresponsenode = $reportnode->add(get_string('viewbyresponse', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vresp', 'byresponse' => 1, 'group' => $currentgroupid)));
            $viewindividualresponsenode = $byresponsenode->add(get_string('view', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vresp', 'byresponse' => 1, 'group' => $currentgroupid)));
            if ($individualresponse) {
                $deleteindividualresponsenode = $byresponsenode->add(get_string('deleteresp', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'dresp', 'byresponse' => 1, 'rid' => $rid, 'group' => $currentgroupid, 'individualresponse' => 1)));
            }
        }
    }
    if ($questionnaire->capabilities->viewsingleresponse) {
        $url = '/mod/questionnaire/show_nonrespondents.php';
        $node = navigation_node::create(get_string('show_nonrespondents', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'nonrespondents');
        $nonrespondentsnode = $questionnairenode->add_node($node, $beforekey);
    }
}
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $questionnairenode The node to add module settings to
 *
 * $settings is unused, but API requires it. Suppress PHPMD warning.
 *
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
function questionnaire_extend_settings_navigation(settings_navigation $settings, navigation_node $questionnairenode)
{
    global $PAGE, $DB, $USER, $CFG;
    $individualresponse = optional_param('individualresponse', false, PARAM_INT);
    $rid = optional_param('rid', false, PARAM_INT);
    // Response id.
    $currentgroupid = optional_param('group', 0, PARAM_INT);
    // Group id.
    require_once $CFG->dirroot . '/mod/questionnaire/questionnaire.class.php';
    $context = $PAGE->cm->context;
    $cmid = $PAGE->cm->id;
    $cm = $PAGE->cm;
    $course = $PAGE->course;
    if (!($questionnaire = $DB->get_record("questionnaire", array("id" => $cm->instance)))) {
        print_error('invalidcoursemodule');
    }
    $courseid = $course->id;
    $questionnaire = new questionnaire(0, $questionnaire, $course, $cm);
    if ($owner = $DB->get_field('questionnaire_survey', 'owner', array('id' => $questionnaire->sid))) {
        $owner = trim($owner) == trim($courseid);
    } else {
        $owner = true;
    }
    // On view page, currentgroupid is not yet sent as an optional_param, so get it.
    $groupmode = groups_get_activity_groupmode($cm, $course);
    if ($groupmode > 0 && $currentgroupid == 0) {
        $currentgroupid = groups_get_activity_group($questionnaire->cm);
        if (!groups_is_member($currentgroupid, $USER->id)) {
            $currentgroupid = 0;
        }
    }
    // We want to add these new nodes after the Edit settings node, and before the
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
    $keys = $questionnairenode->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false && array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    if (has_capability('mod/questionnaire:manage', $context) && $owner) {
        $url = '/mod/questionnaire/qsettings.php';
        $node = navigation_node::create(get_string('advancedsettings'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'advancedsettings', new pix_icon('t/edit', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if (has_capability('mod/questionnaire:editquestions', $context) && $owner) {
        $url = '/mod/questionnaire/questions.php';
        $node = navigation_node::create(get_string('questions', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'questions', new pix_icon('t/edit', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if (has_capability('mod/questionnaire:preview', $context)) {
        $url = '/mod/questionnaire/preview.php';
        $node = navigation_node::create(get_string('preview_label', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'preview', new pix_icon('t/preview', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if ($questionnaire->user_can_take($USER->id)) {
        $url = '/mod/questionnaire/complete.php';
        if ($questionnaire->user_has_saved_response($USER->id)) {
            $args = ['id' => $cmid, 'resume' => 1];
            $text = get_string('resumesurvey', 'questionnaire');
        } else {
            $args = ['id' => $cmid];
            $text = get_string('answerquestions', 'questionnaire');
        }
        $node = navigation_node::create($text, new moodle_url($url, $args), navigation_node::TYPE_SETTING, null, '', new pix_icon('i/info', 'answerquestions'));
        $questionnairenode->add_node($node, $beforekey);
    }
    $usernumresp = $questionnaire->count_submissions($USER->id);
    if ($questionnaire->capabilities->readownresponses && $usernumresp > 0) {
        $url = '/mod/questionnaire/myreport.php';
        if ($usernumresp > 1) {
            $urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary', 'group' => $currentgroupid);
            $node = navigation_node::create(get_string('yourresponses', 'questionnaire'), new moodle_url($url, $urlargs), navigation_node::TYPE_SETTING, null, 'yourresponses');
            $myreportnode = $questionnairenode->add_node($node, $beforekey);
            $urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary', 'group' => $currentgroupid);
            $myreportnode->add(get_string('summary', 'questionnaire'), new moodle_url($url, $urlargs));
            $urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 1, 'action' => 'vresp', 'group' => $currentgroupid);
            $byresponsenode = $myreportnode->add(get_string('viewindividualresponse', 'questionnaire'), new moodle_url($url, $urlargs));
            $urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'vall', 'group' => $currentgroupid);
            $myreportnode->add(get_string('myresponses', 'questionnaire'), new moodle_url($url, $urlargs));
            if ($questionnaire->capabilities->downloadresponses) {
                $urlargs = array('instance' => $questionnaire->id, 'user' => $USER->id, 'action' => 'dwnpg', 'group' => $currentgroupid);
                $myreportnode->add(get_string('downloadtext'), new moodle_url('/mod/questionnaire/report.php', $urlargs));
            }
        } else {
            $urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 1, 'action' => 'vresp', 'group' => $currentgroupid);
            $node = navigation_node::create(get_string('yourresponse', 'questionnaire'), new moodle_url($url, $urlargs), navigation_node::TYPE_SETTING, null, 'yourresponse');
            $myreportnode = $questionnairenode->add_node($node, $beforekey);
        }
    }
    // If questionnaire is set to separate groups, prevent user who is not member of any group
    // and is not a non-editing teacher to view All responses.
    if ($questionnaire->can_view_all_responses($usernumresp)) {
        $url = '/mod/questionnaire/report.php';
        $node = navigation_node::create(get_string('viewallresponses', 'questionnaire'), new moodle_url($url, array('instance' => $questionnaire->id, 'action' => 'vall')), navigation_node::TYPE_SETTING, null, 'vall');
        $reportnode = $questionnairenode->add_node($node, $beforekey);
        if ($questionnaire->capabilities->viewsingleresponse) {
            $summarynode = $reportnode->add(get_string('summary', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall')));
        } else {
            $summarynode = $reportnode;
        }
        $summarynode->add(get_string('order_default', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall', 'group' => $currentgroupid)));
        $summarynode->add(get_string('order_ascending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallasort', 'group' => $currentgroupid)));
        $summarynode->add(get_string('order_descending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallarsort', 'group' => $currentgroupid)));
        if ($questionnaire->capabilities->deleteresponses) {
            $summarynode->add(get_string('deleteallresponses', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'delallresp', 'group' => $currentgroupid)));
        }
        if ($questionnaire->capabilities->downloadresponses) {
            $summarynode->add(get_string('downloadtextformat', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'dwnpg', 'group' => $currentgroupid)));
        }
        if ($questionnaire->capabilities->viewsingleresponse) {
            $byresponsenode = $reportnode->add(get_string('viewbyresponse', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vresp', 'byresponse' => 1, 'group' => $currentgroupid)));
            $byresponsenode->add(get_string('view', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vresp', 'byresponse' => 1, 'group' => $currentgroupid)));
            if ($individualresponse) {
                $byresponsenode->add(get_string('deleteresp', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'dresp', 'byresponse' => 1, 'rid' => $rid, 'group' => $currentgroupid, 'individualresponse' => 1)));
            }
        }
    }
    $canviewgroups = true;
    $groupmode = groups_get_activity_groupmode($cm, $course);
    if ($groupmode == 1) {
        $canviewgroups = groups_has_membership($cm, $USER->id);
    }
    $canviewallgroups = has_capability('moodle/site:accessallgroups', $context);
    if ($questionnaire->capabilities->viewsingleresponse && ($canviewallgroups || $canviewgroups)) {
        $url = '/mod/questionnaire/show_nonrespondents.php';
        $node = navigation_node::create(get_string('show_nonrespondents', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'nonrespondents');
        $questionnairenode->add_node($node, $beforekey);
    }
}