Mandatory survey after login

Mandatory survey after login

by Andrei Băutu -
Number of replies: 1
Picture of Plugin developers

I am using Moodle 3.2.2 and I am looking for a solution to display a survey (meaning some kind of poll, not necessarily a survey activity) to all users of the site after they login and keep prompting it after each login until they submit an answer. Any solution you would recommend?

This is similar to https://moodle.org/mod/forum/discuss.php?d=243983, but I couldn't find an answer there.

Average of ratings: -
In reply to Andrei Băutu

Re: Mandatory survey after login

by Andrei Băutu -
Picture of Plugin developers

For future use:

In config.php include the following conde:

function redirect_to_feedback_page_if_available($id, $courseid = SITEID) {
  global $CFG, $PAGE, $USER, $DB;
  require_once($CFG->dirroot . '/mod/feedback/lib.php');
  // Check access to the given courseid.
  if ($courseid AND $courseid != SITEID) {
    return;
  }

  list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
  require_course_login($course, true, $cm);

  $context = context_module::instance($cm->id);
  $feedback = $DB->get_record("feedback", array("id" => $cm->instance), '*', MUST_EXIST);

  $feedbackcompletion = new mod_feedback_completion($feedback, $cm, $courseid);
  if (!has_capability('mod/feedback:edititems', $context) && !$feedbackcompletion->check_course_is_mapped()) {
    return;
  }

  if (!$feedbackcompletion->can_complete()) {
    return;
  }

  // Check if the feedback is open (timeopen, timeclose).
  if (!$feedbackcompletion->is_open()) {
    return;
  }

  // Initialise the form processing feedback completion.
  if ($feedbackcompletion->is_empty() || !$feedbackcompletion->can_submit()) {
    return;
  }

  return "/mod/feedback/complete.php?id=$cm->id";
}

Then edit /login/lib.php, find core_login_get_return_url and add following lines (15313 is the feedback id I want to show users)

    } else if ($feedbackurl = redirect_to_feedback_page_if_available(15313)) {
        $urltogo = $feedbackurl;

after the lines:

    if (user_not_fully_set_up($USER, true)) {
        $urltogo = $CFG->wwwroot.'/user/edit.php';
        // We don't delete $SESSION->wantsurl yet, so we get there later.