$viewusersattemptscap = has_capability('mod/treasurehunt:viewusershistoricalattempts', $context); echo treasurehunt_view_info($treasurehunt, $course->id); if (has_capability('mod/treasurehunt:play', $context, null, false) && time() > $treasurehunt->allowattemptsfromdate && $userid == $USER->id && $groupid == -1 || has_capability('mod/treasurehunt:play', $context, $userid, false) && $viewusersattemptscap && $groupid == -1 && $userid != $USER->id || count(get_enrolled_users($context, 'mod/treasurehunt:play', $groupid)) && $viewusersattemptscap && $treasurehunt->groupmode) { try { $teacherreview = true; $username = ''; if ($groupid != -1) { $username = groups_get_group_name($groupid); $params = treasurehunt_get_group_road($groupid, $treasurehunt->id, $username); } else { if ($userid == $USER->id) { $teacherreview = false; } else { $username = treasurehunt_get_user_fullname_from_id($userid); } $params = treasurehunt_get_user_group_and_road($userid, $treasurehunt, $cm->id, $teacherreview, $username); if ($userid == $USER->id) { if ($params->groupid) { $username = groups_get_group_name($params->groupid); } else { $username = treasurehunt_get_user_fullname_from_id($userid); } } } echo treasurehunt_view_user_historical_attempts($treasurehunt, $params->groupid, $userid, $params->roadid, $cm->id, $username, $teacherreview); } catch (Exception $e) { echo $output->notification($e->getMessage()); } } if (has_capability('mod/treasurehunt:managetreasurehunt', $context) || has_capability('mod/treasurehunt:viewusershistoricalattempts', $context) || time() > $treasurehunt->allowattemptsfromdate) { echo treasurehunt_view_users_progress_table($cm, $course->id, $context);
'context' => $PAGE->context, )); $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();
public static function user_progress($treasurehuntid, $attempttimestamp, $roadtimestamp, $playwithoutmoving, $groupmode, $initialize, $selectedanswerid, $qoaremoved, $location) { global $USER, $DB; $params = self::validate_parameters(self::user_progress_parameters(), array('treasurehuntid' => $treasurehuntid, "attempttimestamp" => $attempttimestamp, "roadtimestamp" => $roadtimestamp, 'playwithoutmoving' => $playwithoutmoving, 'groupmode' => $groupmode, 'initialize' => $initialize, 'selectedanswerid' => $selectedanswerid, 'qoaremoved' => $qoaremoved)); $cm = get_coursemodule_from_instance('treasurehunt', $params['treasurehuntid']); $treasurehunt = $DB->get_record('treasurehunt', array('id' => $cm->instance), '*', MUST_EXIST); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/treasurehunt:play', $context, null, false); // Get the group and road to which the user belongs. $userparams = treasurehunt_get_user_group_and_road($USER->id, $treasurehunt, $cm->id); // Get the total number of stages of the road of the user. $nostages = treasurehunt_get_total_stages($userparams->roadid); // Check if the user has finished the road. $roadfinished = treasurehunt_check_if_user_has_finished($USER->id, $userparams->groupid, $userparams->roadid); $changesingroupmode = false; $qoaremoved = $params['qoaremoved']; if ($params['groupmode'] != $treasurehunt->groupmode) { $changesingroupmode = true; } // Get the info of the newly discovered stages if any , and the new timestamp if they have changed. $updates = treasurehunt_check_attempts_updates($params['attempttimestamp'], $userparams->groupid, $USER->id, $userparams->roadid, $changesingroupmode); if ($updates->newroadtimestamp != $params['roadtimestamp']) { $updateroad = true; } else { $updateroad = false; } $available = treasurehunt_is_available($treasurehunt); $playmode = $params['playwithoutmoving']; if ($available->available && !$roadfinished) { $changesinplaymode = false; $playmode = treasurehunt_get_play_mode($USER->id, $userparams->groupid, $userparams->roadid, $treasurehunt); if ($params['playwithoutmoving'] != $playmode) { $changesinplaymode = true; } // Check if the user has correctly completed the question and the required activity. $qocsolved = treasurehunt_check_question_and_activity_solved($params['selectedanswerid'], $USER->id, $userparams->groupid, $userparams->roadid, $updateroad, $context, $treasurehunt, $nostages, $qoaremoved); if ($qocsolved->msg !== '') { $status['msg'] = $qocsolved->msg; $status['code'] = 0; } if ($qocsolved->success) { $playmode = treasurehunt_get_play_mode($USER->id, $userparams->groupid, $userparams->roadid, $treasurehunt); } if (count($qocsolved->updates)) { $updates->strings = array_merge($updates->strings, $qocsolved->updates); } if ($qocsolved->newattempt) { $updates->newattempttimestamp = $qocsolved->attempttimestamp; } if ($qocsolved->attemptsolved) { $updates->attemptsolved = true; } if ($qocsolved->roadfinished) { $roadfinished = true; } $qoaremoved = $qocsolved->qoaremoved; if (!$updates->geometrysolved && $location && !$updateroad && !$changesinplaymode && !$changesingroupmode) { $checklocation = treasurehunt_check_user_location($USER->id, $userparams->groupid, $userparams->roadid, treasurehunt_geojson_to_object($location), $context, $treasurehunt, $nostages); if ($checklocation->newattempt) { $updates->newattempttimestamp = $checklocation->attempttimestamp; $updates->newgeometry = true; } if ($checklocation->newstage) { $updates->geometrysolved = true; if ($checklocation->success) { $playmode = treasurehunt_get_play_mode($USER->id, $userparams->groupid, $userparams->roadid, $treasurehunt); } } if ($checklocation->roadfinished) { $roadfinished = true; } if ($checklocation->update !== '') { $updates->strings[] = $checklocation->update; } $status['msg'] = $checklocation->msg; $status['code'] = 0; } } $historicalattempts = array(); // If there was any new attempt, reload the history of attempts. if ($updates->newattempttimestamp != $params['attempttimestamp'] || $params['initialize']) { $historicalattempts = treasurehunt_get_user_historical_attempts($userparams->groupid, $USER->id, $userparams->roadid); } $lastsuccessfulstage = array(); if ($updates->geometrysolved || !$available->available || $updateroad || $updates->attemptsolved || $params['initialize'] || $changesingroupmode) { $lastsuccessfulstage = treasurehunt_get_last_successful_stage($USER->id, $userparams->groupid, $userparams->roadid, $nostages, $available->outoftime, $available->actnotavailableyet, $context); } if ($updates->newgeometry || $updateroad || $roadfinished || $params['initialize'] || $changesingroupmode) { list($userattempts, $firststagegeom) = treasurehunt_get_user_progress($userparams->roadid, $userparams->groupid, $USER->id, $treasurehuntid, $context); } // If the road has been edited, warning the user. if ($updateroad) { if ($location) { $status['msg'] = get_string('errsendinglocation', 'treasurehunt'); $status['code'] = 1; } if ($params['selectedanswerid']) { $status['msg'] = get_string('errsendinganswer', 'treasurehunt'); $status['code'] = 1; } } // If the activity is out of time and not being initialized, warning the user. if ($available->outoftime && !$params['initialize']) { $updates->strings[] = get_string('timeexceeded', 'treasurehunt'); } if ($available->actnotavailableyet) { $updates->strings[] = get_string('actnotavailableyet', 'treasurehunt'); } if (!$status) { $status['msg'] = get_string('userprogress', 'treasurehunt'); $status['code'] = 0; } if ($params['playwithoutmoving'] != $playmode) { if (!$playmode) { $updates->strings[] = get_string('changetoplaywithmove', 'treasurehunt'); } else { $updates->strings[] = get_string('changetoplaywithoutmoving', 'treasurehunt'); } } $result = array(); $result['infomsg'] = $updates->strings; $result['attempttimestamp'] = $updates->newattempttimestamp; $result['roadtimestamp'] = $updates->newroadtimestamp; $result['status'] = $status; if ($userattempts || $firststagegeom) { if ($firststagegeom) { $result['firststagegeom'] = $firststagegeom; } $result['attempts'] = $userattempts; } if ($lastsuccessfulstage) { $result['lastsuccessfulstage'] = $lastsuccessfulstage; } $result['roadfinished'] = $roadfinished; $result['available'] = $available->available; $result['playwithoutmoving'] = intval($playmode); $result['groupmode'] = intval($treasurehunt->groupmode); $result['historicalattempts'] = $historicalattempts; $result['qoaremoved'] = $qoaremoved; return $result; }