Skip to content

Commit

Permalink
Merge branch 'MDL-43089' of git://github.com/mkassaei/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Oct 6, 2014
2 parents d79fd5c + e1a2d0d commit 2eb24eb
Show file tree
Hide file tree
Showing 114 changed files with 12,202 additions and 2,307 deletions.
5 changes: 3 additions & 2 deletions mod/quiz/addrandom.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
null,
$contexts->having_cap('moodle/question:add'));

$mform = new quiz_add_random_form(new moodle_url('/mod/quiz/addrandom.php'), $contexts);
$mform = new quiz_add_random_form(new moodle_url('/mod/quiz/addrandom.php'),
array('contexts' => $contexts, 'cat' => $pagevars['cat']));

if ($mform->is_cancelled()) {
redirect($returnurl);
Expand All @@ -96,7 +97,7 @@
'It seems a form was submitted without any button being pressed???');
}

quiz_add_random_questions($quiz, $addonpage, $categoryid, 1, $includesubcategories);
quiz_add_random_questions($quiz, $addonpage, $categoryid, $data->numbertoadd, $includesubcategories);
quiz_delete_previews($quiz);
quiz_update_sumgrades($quiz);
redirect($returnurl);
Expand Down
25 changes: 22 additions & 3 deletions mod/quiz/addrandomform.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function definition() {
global $CFG, $DB;
$mform =& $this->_form;

$contexts = $this->_customdata;
$contexts = $this->_customdata['contexts'];
$usablecontexts = $contexts->having_cap('moodle/question:useall');

// Random from existing category section.
Expand All @@ -49,9 +49,13 @@ protected function definition() {

$mform->addElement('questioncategory', 'category', get_string('category'),
array('contexts' => $usablecontexts, 'top' => false));
$mform->setDefault('category', $this->_customdata['cat']);

$mform->addElement('checkbox', 'includesubcategories', '', get_string('recurse', 'quiz'));

$mform->addElement('select', 'numbertoadd', get_string('randomnumber', 'quiz'),
$this->get_number_of_questions_to_add_choices());

$mform->addElement('submit', 'existingcategory', get_string('addrandomquestion', 'quiz'));

// Random from a new category section.
Expand All @@ -68,7 +72,7 @@ protected function definition() {
$mform->addElement('submit', 'newcategory',
get_string('createcategoryandaddrandomquestion', 'quiz'));

// Submit buttons.
// Cancel button.
$mform->addElement('cancel');
$mform->closeHeaderBefore('cancel');

Expand All @@ -89,5 +93,20 @@ public function validation($fromform, $files) {

return $errors;
}
}

/**
* Return an arbitrary array for the dropdown menu
* @return array of integers array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
*/
private function get_number_of_questions_to_add_choices() {
$maxrand = 100;
$randomcount = array();
for ($i = 1; $i <= min(10, $maxrand); $i++) {
$randomcount[$i] = $i;
}
for ($i = 20; $i <= min(100, $maxrand); $i += 10) {
$randomcount[$i] = $i;
}
return $randomcount;
}
}
14 changes: 12 additions & 2 deletions mod/quiz/attemptlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,17 @@ public function __construct($quiz, $cm, $course, $getcontext = true) {
* @param int $userid the the userid.
* @return quiz the new quiz object
*/
public static function create($quizid, $userid) {
public static function create($quizid, $userid = null) {
global $DB;

$quiz = quiz_access_manager::load_quiz_and_settings($quizid);
$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id, false, MUST_EXIST);

// Update quiz with override information.
$quiz = quiz_update_effective_access($quiz, $userid);
if ($userid) {
$quiz = quiz_update_effective_access($quiz, $userid);
}

return new quiz($quiz, $cm, $course);
}
Expand Down Expand Up @@ -153,6 +155,14 @@ public function load_questions($questionids = null) {
get_question_options($questionstoprocess);
}

/**
* Get an instance of the {@link \mod_quiz\structure} class for this quiz.
* @return \mod_quiz\structure describes the questions in the quiz.
*/
public function get_structure() {
return \mod_quiz\structure::create_for_quiz($this);
}

// Simple getters ==========================================================
/** @return int the course id. */
public function get_courseid() {
Expand Down
4 changes: 2 additions & 2 deletions mod/quiz/classes/admin_review_setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Admin settings class for the quiz review opitions.
* Admin settings class for the quiz review options.
*
* @package mod_quiz
* @copyright 2008 Tim Hunt
Expand All @@ -27,7 +27,7 @@


/**
* Admin settings class for the quiz review opitions.
* Admin settings class for the quiz review options.
*
* @copyright 2008 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand Down
Loading

0 comments on commit 2eb24eb

Please sign in to comment.