Пример #1
0
/**
 * Get responses for a particular team builder questionnaire.
 *
 * @param int $id Team Builder id
 * @return An array of student ids => array of answers they selected
 * @author Morgan Harris
 */
function teambuilder_get_responses($id, $student = null)
{
    global $CFG, $DB;
    $teambuilder = $DB->get_record("teambuilder", array("id" => $id));
    if ($student == null) {
        if ($teambuilder->groupid) {
            $students = groups_get_members($teambuilder->groupid, "u.id");
        } else {
            $ctxt = context_course::instance($teambuilder->course);
            $students = get_users_by_capability($ctxt, 'mod/teambuilder:respond', 'u.id');
        }
        $responses = array();
        foreach ($students as $s) {
            $responses[$s->id] = teambuilder_get_responses($id, $s->id);
        }
        return $responses;
    }
    $sql = "SELECT answerid\n            FROM {teambuilder}_response\n            WHERE userid = :userid AND answerid IN (\n                SELECT id FROM {teambuilder_answer}\n                WHERE question IN (\n                    SELECT id FROM {teambuilder_question}\n                    WHERE builder = :builder\n                )\n            )";
    $params = array('userid' => $student, 'builder' => $id);
    $rslt = $DB->get_records_sql($sql, $params);
    $ret = false;
    if (!empty($rslt)) {
        $ret = array_keys($rslt);
    }
    return $ret;
}
Пример #2
0
                <button onclick="removeLastAnswer();" type="button">-</button>
            </td>
        </tr>
        <tr>
            <td></td>
            <td><button id="addNewQuestion" type="button" onclick="addNewQuestion();">Add New Question</button></td>
        </tr>
    </table>
</div>
</div>
HTML;
            }
        } else {
            if ($mode == "preview" || $mode == "student") {
                $questions = teambuilder_get_questions($teambuilder->id, $USER->id);
                $responses = teambuilder_get_responses($teambuilder->id, $USER->id);
                if ($mode == "preview") {
                    $tabs = array();
                    $tabs[] = new tabobject("questionnaire", "view.php?id={$id}&f=1", get_string('questionnaire', 'teambuilder'));
                    $tabs[] = new tabobject("preview", "view.php?id={$id}&preview=1", get_string('preview', 'teambuilder'));
                    $tabs[] = new tabobject("build", "build.php?id={$id}", get_string('buildteams', 'teambuilder'));
                    print_tabs(array($tabs), "preview");
                }
                if ($mode == "student" && empty($feedback)) {
                    if ($responses !== false && !$teambuilder->allowupdate) {
                        $feedback = "You have already completed this questionnaire.";
                    }
                }
                if (isset($feedback) && $feedback) {
                    echo '<div class="ui-widget" style="text-align:center;"><div style="display:inline-block; padding-left:10px; padding-right:10px;" class="ui-state-highlight ui-corner-all"><p>' . $feedback . '</p></div></div>';
                }