Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   1  <?php
   2  
   3      require_once("../../config.php");
   4      require_once ("lib.php");
   5  
   6      $id = required_param('id', PARAM_INT);    // Course Module ID
   7  
   8      $PAGE->set_url('/mod/survey/index.php', array('id'=>$id));
   9  
  10      if (!$course = $DB->get_record('course', array('id'=>$id))) {
  11          throw new \moodle_exception('invalidcourseid');
  12      }
  13  
  14      require_course_login($course);
  15      $PAGE->set_pagelayout('incourse');
  16  
  17      $params = array(
  18          'context' => context_course::instance($course->id),
  19          'courseid' => $course->id
  20      );
  21      $event = \mod_survey\event\course_module_instance_list_viewed::create($params);
  22      $event->trigger();
  23  
  24      $strsurveys = get_string("modulenameplural", "survey");
  25      $strname = get_string("name");
  26      $strstatus = get_string("status");
  27      $strdone  = get_string("done", "survey");
  28      $strnotdone  = get_string("notdone", "survey");
  29  
  30      $PAGE->navbar->add($strsurveys);
  31      $PAGE->set_title($strsurveys);
  32      $PAGE->set_heading($course->fullname);
  33      echo $OUTPUT->header();
  34      if (!$PAGE->has_secondary_navigation()) {
  35          echo $OUTPUT->heading($strsurveys);
  36      }
  37  
  38      if (! $surveys = get_all_instances_in_course("survey", $course)) {
  39          notice(get_string('thereareno', 'moodle', $strsurveys), "../../course/view.php?id=$course->id");
  40      }
  41  
  42      $usesections = course_format_uses_sections($course->format);
  43  
  44      $table = new html_table();
  45  
  46      if ($usesections) {
  47          $strsectionname = get_string('sectionname', 'format_'.$course->format);
  48          $table->head  = array ($strsectionname, $strname, $strstatus);
  49      } else {
  50          $table->head  = array ($strname, $strstatus);
  51      }
  52  
  53      $currentsection = '';
  54  
  55      foreach ($surveys as $survey) {
  56          if (isloggedin() and survey_already_done($survey->id, $USER->id)) {
  57              $ss = $strdone;
  58          } else {
  59              $ss = $strnotdone;
  60          }
  61          $printsection = "";
  62          if ($usesections) {
  63              if ($survey->section !== $currentsection) {
  64                  if ($survey->section) {
  65                      $printsection = get_section_name($course, $survey->section);
  66                  }
  67                  if ($currentsection !== "") {
  68                      $table->data[] = 'hr';
  69                  }
  70                  $currentsection = $survey->section;
  71              }
  72          }
  73          //Calculate the href
  74          if (!$survey->visible) {
  75              //Show dimmed if the mod is hidden
  76              $tt_href = "<a class=\"dimmed\" href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
  77          } else {
  78              //Show normal if the mod is visible
  79              $tt_href = "<a href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
  80          }
  81  
  82          if ($usesections) {
  83              $table->data[] = array ($printsection, $tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
  84          } else {
  85              $table->data[] = array ($tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
  86          }
  87      }
  88  
  89      echo "<br />";
  90      echo html_writer::table($table);
  91      echo $OUTPUT->footer();
  92  
  93