Пример #1
0
/**
 * Create or renew the user edition lock in an instance of treasurehunt.
 * 
 * @param int $treasurehuntid The identifier of treasure hunt.
 * @param int $userid The identifier of user who block the instance.
 * @return int The lock id.
 */
function treasurehunt_renew_edition_lock($treasurehuntid, $userid)
{
    global $DB;
    $table = 'treasurehunt_locks';
    $params = array('treasurehuntid' => $treasurehuntid, 'userid' => $userid);
    $time = time() + treasurehunt_get_setting_lock_time();
    $lock = $DB->get_record($table, $params);
    if (!empty($lock)) {
        $DB->update_record($table, array('id' => $lock->id, 'lockedtill' => $time));
        return $lock->id;
    } else {
        treasurehunt_delete_old_locks($treasurehuntid);
        return $DB->insert_record($table, array('treasurehuntid' => $treasurehuntid, 'userid' => $userid, 'lockedtill' => $time));
    }
}
Пример #2
0
list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'treasurehunt');
$treasurehunt = $DB->get_record('treasurehunt', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
$url = new moodle_url('/mod/treasurehunt/editstage.php', array('cmid' => $cmid));
if (!empty($id)) {
    $url->param('id', $id);
}
if (!empty($roadid)) {
    $url->param('roadid', $roadid);
}
$PAGE->set_url($url);
require_capability('mod/treasurehunt:managetreasurehunt', $context);
if (!treasurehunt_is_edition_loked($treasurehunt->id, $USER->id)) {
    $lockid = treasurehunt_renew_edition_lock($treasurehunt->id, $USER->id);
    $renewlocktime = (treasurehunt_get_setting_lock_time() - 5) * 1000;
    $PAGE->requires->js_call_amd('mod_treasurehunt/renewlock', 'renew_edition_lock', array($treasurehunt->id, $lockid, $renewlocktime));
    if ($id) {
        // if entry is specified
        require_capability('mod/treasurehunt:editstage', $context);
        $title = get_string('editingstage', 'treasurehunt');
        $sql = 'SELECT id,name,cluetext,cluetextformat,cluetexttrust,' . 'activitytoend,roadid,questiontext,questiontextformat,' . 'questiontexttrust,playstagewithoutmoving FROM {treasurehunt_stages}  WHERE id=?';
        $params = array($id);
        if (!($stage = $DB->get_record_sql($sql, $params))) {
            print_error('invalidentry');
        }
        // Si existe la pregunta recojo las respuestas.
        if ($stage->questiontext !== '') {
            // Hago que se muestre la pregunta.
            $stage->addsimplequestion = optional_param('addsimplequestion', 1, PARAM_INT);
            $sqlanswers = 'SELECT a.id,a.answertext,a.answertextformat,a.answertexttrust,' . ' a.correct FROM {treasurehunt_answers} a INNER JOIN' . ' {treasurehunt_stages} r ON r.id=a.stageid WHERE r.id=?';