Skip to content

Commit f59e35c

Browse files
committed
Módulo para controle de segunda tentativa
1 parent d61bcd2 commit f59e35c

9 files changed

+301
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ReattemptChecker is a quiz access rule that prevents students who passed a quiz from reattempting it.
2+
3+
It was developed to work with Moodle 2.6+. However, it might work with other versions. Please let us know if it worked for your version.
4+
5+
/* ==== How to use the plugin === */
6+
1. Install the plugin.
7+
2. Go to to a quiz page.
8+
3. Edit settings.
9+
4. Scroll down to 'Extra restrictions on attempts' and put a value in the field labeled 'To reattempt the quiz, require a GRADE less than'.
10+
5. Please note that it is a GRADE and not a percentage.
11+
6. Save settings.
12+
7. When the student pass the quiz, the plugin will prevent any further attempts.
13+
8. You can change the text appears to students by following the steps below.
14+
9. Enjoy!
15+
16+
17+
/* === How to change the text appears to students === */
18+
1. Go to site Administration.
19+
2. Language.
20+
3. Language Customisation.
21+
4. Choose and load the language you want to customise, e.g. English.
22+
5. Select the file called 'quiz_access_reattemptchecker'.
23+
6. Press 'Show strings'.
24+
7. Put the strings you want in the fields under 'Local customisation'.
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
18+
require_once($CFG->dirroot . '/mod/quiz/backup/moodle2/backup_mod_quiz_access_subplugin.class.php');
19+
20+
defined('MOODLE_INTERNAL') || die();
21+
22+
23+
/*
24+
* @package quizaccess_reattemptchecker
25+
* @copyright 2015 Amir Shurrab
26+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27+
*/
28+
29+
class backup_quizaccess_reattemptchecker_subplugin extends backup_mod_quiz_access_subplugin {
30+
31+
protected function define_quiz_subplugin_structure() {
32+
33+
// Create XML elements.
34+
$subplugin = $this->get_subplugin_element();
35+
$subplugin_wrapper = new backup_nested_element($this->get_recommended_name());
36+
$subplugin_table_settings = new backup_nested_element('quizaccess_reattemptchecker',
37+
null, array('reattemptchecker'));
38+
39+
// Connect XML elements into the tree.
40+
$subplugin->add_child($subplugin_wrapper);
41+
$subplugin_wrapper->add_child($subplugin_table_settings);
42+
43+
// Set source to populate the data.
44+
$subplugin_table_settings->set_source_table('quizaccess_reattemptchecker',
45+
array('quizid' => backup::VAR_ACTIVITYID));
46+
47+
return $subplugin;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
18+
require_once($CFG->dirroot . '/mod/quiz/backup/moodle2/restore_mod_quiz_access_subplugin.class.php');
19+
20+
defined('MOODLE_INTERNAL') || die();
21+
22+
23+
/**
24+
* Restore code for the quizaccess_reattemptchecker plugin.
25+
* @package quizaccess_reattemptchecker
26+
* @copyright 2015 Amir Shurrab
27+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28+
*/
29+
30+
class restore_quizaccess_reattemptchecker_subplugin extends restore_mod_quiz_access_subplugin {
31+
32+
protected function define_quiz_subplugin_structure() {
33+
34+
$paths = array();
35+
36+
$elename = $this->get_namefor('');
37+
$elepath = $this->get_pathfor('/quizaccess_reattemptchecker');
38+
$paths[] = new restore_path_element($elename, $elepath);
39+
40+
return $paths;
41+
}
42+
43+
/**
44+
* Processes the quizaccess_reattemptchecker element, if it is in the file.
45+
* @param array $data the data read from the XML file.
46+
*/
47+
public function process_quizaccess_reattemptchecker($data) {
48+
global $DB;
49+
50+
$data = (object)$data;
51+
$data->quizid = $this->get_new_parentid('quiz');
52+
$DB->insert_record('quizaccess_reattemptchecker', $data);
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<XMLDB PATH="mod/quiz/accessrule/reattemptchecker/db" VERSION="20111003" COMMENT="XMLDB file for Moodle mod/quiz/accessrul/reattemptchecker"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="../../../../../lib/xmldb/xmldb.xsd"
5+
>
6+
<TABLES>
7+
<TABLE NAME="quizaccess_reattemptchecker" COMMENT="Stores the additional setting required by this accessrule">
8+
<FIELDS>
9+
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="quizid"/>
10+
<FIELD NAME="quizid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="false" COMMENT="Foreign key to quiz.id." PREVIOUS="id" NEXT="reattemptchecker"/>
11+
<FIELD NAME="reattemptchecker" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Passing GRADE required to prevent reattempting the quiz" PREVIOUS="quizid"/>
12+
</FIELDS>
13+
<KEYS>
14+
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="quizid"/>
15+
<KEY NAME="quizid" TYPE="foreign-unique" FIELDS="quizid" REFTABLE="quiz" REFFIELDS="id" PREVIOUS="primary"/>
16+
</KEYS>
17+
</TABLE>
18+
</TABLES>
19+
</XMLDB>
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* @package quizaccess_reattemptchecker
19+
* @copyright 2015 Amir Shurrab
20+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21+
*/
22+
23+
defined('MOODLE_INTERNAL') || die();
24+
25+
$string['pluginname'] = 'Reattempt Checker - a quiz access rule';
26+
$string['preventpassed'] = 'To reattempt the quiz, require a <i>GRADE</i> less than';
27+
$string['preventpassed_help'] = 'Students must have a grade less than the specified grade to be able to reattempt. This is designed to prevent students who have passed from reattempting the quiz.';
28+
$string['accessprevented'] = 'You have already passed this quiz, and may not make further attempts.';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>
16+
17+
18+
defined('MOODLE_INTERNAL') || die();
19+
20+
require_once($CFG->dirroot . '/mod/quiz/accessrule/accessrulebase.php');
21+
22+
/*
23+
* @package quizaccess_reattemptchecker
24+
* @copyright 2015 Amir Shurrab
25+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26+
*/
27+
28+
/**
29+
* A rule requiring the students have not achieved a pass grade
30+
*/
31+
class quizaccess_reattemptchecker extends quiz_access_rule_base {
32+
33+
34+
public static function make(quiz $quizobj, $timenow, $canignoretimelimits) {
35+
36+
if (empty($quizobj->get_quiz()->reattemptchecker)) {
37+
return null;
38+
}
39+
40+
return new self($quizobj, $timenow);
41+
}
42+
43+
public static function add_settings_form_fields(
44+
mod_quiz_mod_form $quizform, MoodleQuickForm $mform) {
45+
46+
$mform->addElement('text', 'reattemptchecker', get_string("preventpassed", "quizaccess_reattemptchecker"), 'maxlength="3" size="3"');
47+
$mform->setType('reattemptchecker', PARAM_INT);
48+
$mform->addHelpButton('reattemptchecker',
49+
'preventpassed', 'quizaccess_reattemptchecker');
50+
}
51+
52+
public static function save_settings($quiz) {
53+
global $DB;
54+
if (empty($quiz->reattemptchecker)) {
55+
$DB->delete_records('quizaccess_reattemptchecker', array('quizid' => $quiz->id));
56+
} else {
57+
if ($record = $DB->get_record('quizaccess_reattemptchecker', array('quizid' => $quiz->id))) {
58+
$record->reattemptchecker = $quiz->reattemptchecker;
59+
$DB->update_record('quizaccess_reattemptchecker', $record);
60+
} else {
61+
$record = new stdClass();
62+
$record->quizid = $quiz->id;
63+
$record->reattemptchecker = $quiz->reattemptchecker;
64+
$DB->insert_record('quizaccess_reattemptchecker', $record);
65+
}
66+
}
67+
}
68+
69+
public static function get_settings_sql($quizid) {
70+
return array(
71+
'reattemptchecker',
72+
'LEFT JOIN {quizaccess_reattemptchecker} reattemptchecker ON reattemptchecker.quizid = quiz.id',
73+
array());
74+
}
75+
76+
public function prevent_new_attempt($numattempts, $lastattempt) {
77+
global $DB;
78+
79+
if ($numattempts == 0) {
80+
return false;
81+
}
82+
83+
// Check if preventonpass is set, and whether the student has passed the minimum passing grade.
84+
$previousattempts = $DB->get_records_select('quiz_attempts',
85+
"quiz = :quizid AND userid = :userid AND timefinish > 0 and preview != 1",
86+
array('quizid' => $this->quiz->id, 'userid' => $lastattempt->userid));
87+
88+
if (quiz_calculate_best_grade($this->quiz, $previousattempts) >= $this->quiz->reattemptchecker) {
89+
return get_string('accessprevented', 'quizaccess_reattemptchecker');
90+
}
91+
92+
return false;
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* @package quizaccess_reattemptchecker
19+
* @copyright 2015 Amir Shurrab
20+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21+
*/
22+
23+
24+
defined('MOODLE_INTERNAL') || die();
25+
26+
27+
$plugin->version = 2014111006;
28+
$plugin->requires = 2013111800;
29+
$plugin->cron = 0;
30+
$plugin->component = 'quizaccess_reattemptchecker';
31+
$plugin->maturity = MATURITY_STABLE;
32+
$plugin->release = 'v1.0 for Moodle 2.6, 2.7, 2.8, 2.9';

0 commit comments

Comments
 (0)