/** * Checks for updates of attempts from timestamp given. * If the group identifier provided is not 0, the group is checked, else the user is checked. * * @param int $timestamp The last known timestamp since user progress has not been updated. * @param int $groupid The identifier of the group to which the user belongs. * @param int $userid The identifier of user. * @param int $roadid The identifier of the road of user. * @param bool $changesingroupmode If the instance has change the group mode. * @return stdClass Update parameters. */ function treasurehunt_check_attempts_updates($timestamp, $groupid, $userid, $roadid, $changesingroupmode) { global $DB; $return = new stdClass(); $return->strings = []; $return->newgeometry = false; $return->attemptsolved = false; $return->geometrysolved = false; $return->geometrysolved = false; $newattempts = array(); list($return->newattempttimestamp, $return->newroadtimestamp) = treasurehunt_get_last_timestamps($userid, $groupid, $roadid); // If there has been a change in the group mode. if ($changesingroupmode) { if ($groupid) { $grouptype = 'a.groupid=?'; $params = array($groupid, $roadid); $return->strings[] = get_string('changetogroupmode', 'treasurehunt'); } else { $grouptype = 'a.groupid=0 AND a.userid=?'; $params = array($userid, $roadid); $return->strings[] = get_string('changetoindividualmode', 'treasurehunt'); } $query = "SELECT a.id,a.type,a.timecreated,a.questionsolved," . "a.success,a.geometrysolved,a.penalty,r.position,a.userid as user " . "FROM {treasurehunt_stages} r INNER JOIN {treasurehunt_attempts} a " . "ON a.stageid=r.id WHERE {$grouptype} AND r.roadid=? ORDER BY " . "a.timecreated ASC"; $newattempts = $DB->get_records_sql($query, $params); } // If the retrieved timestamp is greater than the parameter, has been updates. if ($return->newattempttimestamp > $timestamp && !$changesingroupmode) { // Get user/group actions greater than a given timestamp. if ($groupid) { $grouptype = 'a.groupid=(?)'; $params = array($timestamp, $groupid, $roadid); } else { $grouptype = 'a.groupid=0 AND a.userid=(?)'; $params = array($timestamp, $userid, $roadid); } $query = "SELECT a.id,a.type,a.questionsolved,a.activitysolved,a.timecreated," . "a.success,r.position,a.userid as user,a.geometrysolved " . "FROM {treasurehunt_stages} r INNER JOIN {treasurehunt_attempts} a " . "ON a.stageid=r.id WHERE a.timecreated >? AND {$grouptype} " . "AND r.roadid=? ORDER BY a.timecreated ASC"; $newattempts = $DB->get_records_sql($query, $params); } foreach ($newattempts as $newattempt) { if ($newattempt->type === 'location') { if ($newattempt->geometrysolved) { $return->geometrysolved = true; } $return->newgeometry = true; } else { if ($newattempt->type === 'question' && $newattempt->questionsolved || $newattempt->type === 'activity' && $newattempt->activitysolved) { $return->attemptsolved = true; } } $return->strings[] = treasurehunt_set_string_attempt($newattempt, $groupid); } return $return; }
)); $event->add_record_snapshot('course', $PAGE->course); $event->add_record_snapshot($PAGE->cm->modname, $treasurehunt); $event->trigger(); */ // Print the page header. $PAGE->set_url('/mod/treasurehunt/play.php', array('id' => $cm->id)); $PAGE->set_title(format_string($treasurehunt->name)); $PAGE->set_heading(format_string($course->fullname)); //$PAGE->set_pagelayout('standard'); if ($treasurehunt->allowattemptsfromdate > time()) { $returnurl = new moodle_url('/mod/treasurehunt/view.php', array('id' => $id)); print_error('treasurehuntnotavailable', 'treasurehunt', $returnurl, userdate($treasurehunt->allowattemptsfromdate)); } // Get last timestamp $user = treasurehunt_get_user_group_and_road($USER->id, $treasurehunt, $cm->id); list($lastattempttimestamp, $lastroadtimestamp) = treasurehunt_get_last_timestamps($USER->id, $user->groupid, $user->roadid); $gameupdatetime = treasurehunt_get_setting_game_update_time() * 1000; $PAGE->requires->jquery(); $PAGE->requires->js_call_amd('mod_treasurehunt/play', 'playtreasurehunt', array(treasurehunt_get_strings_play(), $cm->id, $cm->instance, intval($treasurehunt->playwithoutmoving), intval($treasurehunt->groupmode), $lastattempttimestamp, $lastroadtimestamp, $gameupdatetime)); $PAGE->requires->css('/mod/treasurehunt/css/jquerymobile.css'); $PAGE->set_pagelayout('embedded'); /* * Other things you may want to set - remove if not needed. * $PAGE->set_cacheable(false); * $PAGE->set_focuscontrol('some-html-id'); * $PAGE->add_body_class('treasurehunt-'.$somevar); */ $output = $PAGE->get_renderer('mod_treasurehunt'); // Output starts here. echo $output->header(); // Replace the following lines with you own code.