Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
// This file is part of Moodle - http://moodle.org/
4
//
5
// Moodle is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// Moodle is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
/**
19
 * Action for processing page answers by users
20
 *
21
 * @package mod_lesson
22
 * @copyright  2009 Sam Hemelryk
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 **/
25
 
26
/** Require the specific libraries */
27
require_once("../../config.php");
28
require_once($CFG->dirroot.'/mod/lesson/locallib.php');
29
 
30
$id = required_param('id', PARAM_INT);
31
 
32
$cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);
33
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
34
$lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST), $cm, $course);
35
 
36
require_login($course, false, $cm);
37
require_sesskey();
38
 
39
// Apply overrides.
40
$lesson->update_effective_access($USER->id);
41
 
42
$context = $lesson->context;
43
$canmanage = $lesson->can_manage();
44
$lessonoutput = $PAGE->get_renderer('mod_lesson');
45
 
46
$url = new moodle_url('/mod/lesson/continue.php', array('id'=>$cm->id));
47
$PAGE->set_url($url);
48
$PAGE->set_pagetype('mod-lesson-view');
49
$PAGE->navbar->add(get_string('continue', 'lesson'));
50
 
51
// This is the code updates the lesson time for a timed test
52
// get time information for this user
53
if (!$canmanage) {
54
    $lesson->displayleft = lesson_displayleftif($lesson);
55
    $timer = $lesson->update_timer();
56
    if (!$lesson->check_time($timer)) {
57
        redirect(new moodle_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => LESSON_EOL, 'outoftime' => 'normal')));
58
        die; // Shouldn't be reached, but make sure.
59
    }
60
} else {
61
    $timer = new stdClass;
62
}
63
 
64
// record answer (if necessary) and show response (if none say if answer is correct or not)
65
$page = $lesson->load_page(required_param('pageid', PARAM_INT));
66
 
67
$reviewmode = $lesson->is_in_review_mode();
68
 
69
// Process the page responses.
70
$result = $lesson->process_page_responses($page);
71
 
72
if ($result->nodefaultresponse || $result->inmediatejump) {
73
    // Don't display feedback or force a redirecto to newpageid.
74
    redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id,'pageid'=>$result->newpageid)));
75
}
76
 
77
// Set Messages.
78
$lesson->add_messages_on_page_process($page, $result, $reviewmode);
79
$PAGE->set_secondary_active_tab('modulepage');
80
$PAGE->set_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id));
81
$PAGE->set_subpage($page->id);
82
 
83
/// Print the header, heading and tabs
84
lesson_add_fake_blocks($PAGE, $cm, $lesson, $timer);
85
echo $lessonoutput->header($lesson, $cm, 'view', true, $page->id, get_string('continue', 'lesson'));
86
 
87
$editbuttons = new \mod_lesson\output\edit_action_buttons($lesson, $page->id ?? null);
88
echo $lessonoutput->render($editbuttons);
89
 
90
if ($lesson->displayleft) {
91
    echo '<a name="maincontent" id="maincontent" title="'.get_string('anchortitle', 'lesson').'"></a>';
92
}
93
// This calculates and prints the ongoing score message
94
if ($lesson->ongoing && !$reviewmode) {
95
    echo $lessonoutput->ongoing_score($lesson);
96
}
97
if (!$reviewmode) {
98
    echo format_text($result->feedback, FORMAT_MOODLE, array('context' => $context, 'noclean' => true));
99
}
100
 
101
// User is modifying attempts - save button and some instructions
102
if (isset($USER->modattempts[$lesson->id])) {
103
    $content = $OUTPUT->box(get_string("gotoendoflesson", "lesson"), 'center');
104
    $content .= $OUTPUT->box(get_string("or", "lesson"), 'center');
105
    $content .= $OUTPUT->box(get_string("continuetonextpage", "lesson"), 'center');
106
    $url = new moodle_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => LESSON_EOL));
107
    echo $content . $OUTPUT->single_button($url, get_string('finish', 'lesson'));
108
}
109
 
110
// Review button back
111
if (!$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$reviewmode && $lesson->review && !$result->maxattemptsreached) {
112
    $url = new moodle_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id));
113
    echo $OUTPUT->single_button($url, get_string('reviewquestionback', 'lesson'));
114
}
115
 
116
$url = new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id, 'pageid'=>$result->newpageid));
117
 
118
if ($lesson->review && !$result->correctanswer && !$result->noanswer && !$result->isessayquestion && !$result->maxattemptsreached) {
119
    // If both the "Yes, I'd like to try again" and "No, I just want to go on  to the next question" point to the same
120
    // page then don't show the "No, I just want to go on to the next question" button. It's confusing.
121
    if ($page->id != $result->newpageid) {
122
        // Button to continue the lesson (the page to go is configured by the teacher).
123
        echo $OUTPUT->single_button($url, get_string('reviewquestioncontinue', 'lesson'));
124
    }
125
} else {
126
    // Normal continue button
127
    echo $OUTPUT->single_button($url, get_string('continue', 'lesson'));
128
}
129
 
130
echo $lessonoutput->footer();