Ejemplo n.º 1
0
echo '<div>';
echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"" . sesskey() . "\" />";
echo $OUTPUT->box(format_module_intro('survey', $survey, $cm->id), 'generalbox boxaligncenter bowidthnormal', 'intro');
echo '<div>' . get_string('allquestionrequireanswer', 'survey') . '</div>';
// Get all the major questions in order.
$questions = survey_get_questions($survey);
global $qnum;
// TODO: ugly globals hack for survey_print_*().
global $checklist;
// TODO: ugly globals hack for survey_print_*().
$qnum = 0;
$checklist = array();
foreach ($questions as $question) {
    if ($question->type >= 0) {
        $question = survey_translate_question($question);
        if ($question->multi) {
            survey_print_multi($question);
        } else {
            survey_print_single($question);
        }
    }
}
if (!is_enrolled($context)) {
    echo '</div>';
    echo "</form>";
    echo $OUTPUT->footer();
    exit;
}
$checkarray = array('questions' => array());
if (!empty($checklist)) {
Ejemplo n.º 2
0
 /**
  * Get the complete list of questions for the survey, including subquestions.
  *
  * @param int $surveyid the survey instance id
  * @return array of warnings and the question list
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function get_questions($surveyid)
 {
     global $DB, $USER;
     $params = self::validate_parameters(self::get_questions_parameters(), array('surveyid' => $surveyid));
     $warnings = array();
     // Request and permission validation.
     $survey = $DB->get_record('survey', array('id' => $params['surveyid']), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($survey, 'survey');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/survey:participate', $context);
     $mainquestions = survey_get_questions($survey);
     foreach ($mainquestions as $question) {
         if ($question->type >= 0) {
             // Parent is used in subquestions.
             $question->parent = 0;
             $questions[] = survey_translate_question($question);
             // Check if the question has subquestions.
             if ($question->multi) {
                 $subquestions = survey_get_subquestions($question);
                 foreach ($subquestions as $sq) {
                     $sq->parent = $question->id;
                     $questions[] = survey_translate_question($sq);
                 }
             }
         }
     }
     $result = array();
     $result['questions'] = $questions;
     $result['warnings'] = $warnings;
     return $result;
 }