Permalink
Browse files

Merge branch 'MOODLE_21_STABLE' into install_21_STABLE

  • Loading branch information...
AMOS bot
AMOS bot committed Nov 19, 2011
2 parents 7138495 + cf04ce3 commit 81b24b17cf054b9a3794c7f377ea0ce1cb02b763
@@ -802,7 +802,14 @@ public function process_grouping_group($data) {
$data->groupingid = $this->get_new_parentid('grouping'); // Use new parentid
$data->groupid = $this->get_mappingid('group', $data->groupid); // Get from mappings
- $DB->insert_record('groupings_groups', $data); // No need to set this mapping (no child info nor files)
+
+ $params = array();
+ $params['groupingid'] = $data->groupingid;
+ $params['groupid'] = $data->groupid;
+
+ if (!$DB->record_exists('groupings_groups', $params)) {
+ $DB->insert_record('groupings_groups', $data); // No need to set this mapping (no child info nor files)
+ }
}
protected function after_execute() {
View
@@ -6679,6 +6679,23 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2011070101.10);
}
+ if ($oldversion < 2011070102.08) {
+ upgrade_set_timeout(60*20); // this may take a while
+ // Remove duplicate entries from groupings_groups table
+ $sql = 'SELECT MIN(id) AS firstid, groupingid, groupid FROM {groupings_groups} '.
+ 'GROUP BY groupingid, groupid HAVING COUNT(id)>1';
+ $badrs = $DB->get_recordset_sql($sql);
+ foreach ($badrs as $badrec) {
+ $where = 'groupingid = ? and groupid = ? and id > ?';
+ $params = array($badrec->groupingid, $badrec->groupid, $badrec->firstid);
+ $DB->delete_records_select('groupings_groups', $where, $params);
+ }
+ $badrs->close();
+
+ // Main savepoint reached
+ upgrade_main_savepoint(true, 2011070102.08);
+ }
+
return true;
}
View
@@ -8454,12 +8454,17 @@ function generate_password($maxlen=10) {
$filler1 = $fillers[rand(0, strlen($fillers) - 1)];
$password = $word1 . $filler1 . $word2;
} else {
- $maxlen = !empty($CFG->minpasswordlength) ? $CFG->minpasswordlength : 0;
+ $minlen = !empty($CFG->minpasswordlength) ? $CFG->minpasswordlength : 0;
$digits = $CFG->minpassworddigits;
$lower = $CFG->minpasswordlower;
$upper = $CFG->minpasswordupper;
$nonalphanum = $CFG->minpasswordnonalphanum;
- $additional = $maxlen - ($lower + $upper + $digits + $nonalphanum);
+ $total = $lower + $upper + $digits + $nonalphanum;
+ // minlength should be the greater one of the two ( $minlen and $total )
+ $minlen = $minlen < $total ? $total : $minlen;
+ // maxlen can never be smaller than minlen
+ $maxlen = $minlen > $maxlen ? $minlen : $maxlen;
+ $additional = $maxlen - $total;
// Make sure we have enough characters to fulfill
// complexity requirements
View
@@ -825,16 +825,8 @@ function get_question_options(&$questions, $loadtags = false) {
* @return string the HTML for the img tag.
*/
function print_question_icon($question) {
- global $OUTPUT;
-
- $qtype = question_bank::get_qtype($question->qtype, false);
- $namestr = $qtype->menu_name();
-
- // TODO convert to return a moodle_icon object, or whatever the class is.
- $html = '<img src="' . $OUTPUT->pix_url('icon', $qtype->plugin_name()) . '" alt="' .
- $namestr . '" title="' . $namestr . '" />';
-
- return $html;
+ global $PAGE;
+ return $PAGE->get_renderer('question', 'bank')->qtype_icon($question->qtype);
}
/**
View
@@ -6225,8 +6225,9 @@ function forum_tp_mark_posts_read($user, $postids) {
if ($new) {
list($usql, $new_params) = $DB->get_in_or_equal($new);
- $params = array($user->id, $now, $now, $user->id, $cutoffdate);
+ $params = array($user->id, $now, $now, $user->id);
$params = array_merge($params, $new_params);
+ $params[] = $cutoffdate;
$sql = "INSERT INTO {forum_read} (userid, postid, discussionid, forumid, firstread, lastread)
View
@@ -781,7 +781,7 @@ function quiz_print_singlequestion($question, $returnurl, $quiz) {
echo quiz_question_edit_button($quiz->cmid, $question, $returnurl,
quiz_question_tostring($question) . ' ');
echo '<span class="questiontype">';
- print_question_icon($question);
+ echo print_question_icon($question);
echo ' ' . question_bank::get_qtype_name($question->qtype) . '</span>';
echo '<span class="questionpreview">' .
quiz_question_preview_button($quiz, $question, true) . '</span>';
@@ -807,7 +807,7 @@ function quiz_print_randomquestion(&$question, &$pageurl, &$quiz, $quiz_qbanktoo
}
echo '<div class="randomquestionfromcategory">';
- print_question_icon($question);
+ echo print_question_icon($question);
print_random_option_icon($question);
echo ' ' . get_string('randomfromcategory', 'quiz') . '</div>';
@@ -886,7 +886,7 @@ function quiz_print_randomquestion(&$question, &$pageurl, &$quiz, $quiz_qbanktoo
function quiz_print_singlequestion_reordertool($question, $returnurl, $quiz) {
echo '<div class="singlequestion">';
echo '<label for="s' . $question->id . '">';
- print_question_icon($question);
+ echo print_question_icon($question);
echo ' ' . quiz_question_tostring($question);
echo '</label>';
echo '<span class="questionpreview">' .
@@ -920,7 +920,7 @@ function quiz_print_randomquestion_reordertool(&$question, &$pageurl, &$quiz) {
echo '<div class="quiz_randomquestion">';
echo '<div class="randomquestionfromcategory">';
echo $reordercheckboxlabel;
- print_question_icon($question);
+ echo print_question_icon($question);
print_random_option_icon($question);
if ($questioncount == 0) {
View
@@ -170,7 +170,7 @@ M.mod_quiz.nav.init = function(Y) {
if (Y.one('a.endtestlink')) {
Y.on('click', function(e) {
- e.preventDefault(e);
+ e.preventDefault();
Y.one('#followingpage').set('value', -1);
Y.one('#responseform').submit();
}, 'a.endtestlink');
@@ -614,13 +614,21 @@ protected function add_latest_state_join($slot) {
return;
}
+ // This condition roughly filters the list of attempts to be considered.
+ // It is only used in a subselect to help crappy databases (see MDL-30122)
+ // therefore, it is better to use a very simple join, which may include
+ // too many records, than to do a super-accurate join.
+ $qubaids = new qubaid_join("{quiz_attempts} {$alias}quiza", "{$alias}quiza.uniqueid",
+ "{$alias}quiza.quiz = :{$alias}quizid", array("{$alias}quizid" => $this->sql->params['quizid']));
+
$dm = new question_engine_data_mapper();
- $inlineview = $dm->question_attempt_latest_state_view($alias);
+ list($inlineview, $viewparams) = $dm->question_attempt_latest_state_view($alias, $qubaids);
$this->sql->fields .= ",\n$fields";
$this->sql->from .= "\nLEFT JOIN $inlineview ON " .
"$alias.questionusageid = quiza.uniqueid AND $alias.slot = :{$alias}slot";
$this->sql->params[$alias . 'slot'] = $slot;
+ $this->sql->params = array_merge($this->sql->params, $viewparams);
}
/**
@@ -102,7 +102,7 @@
if (!$quizobj->is_preview_user() && $messages) {
$output = $PAGE->get_renderer('mod_quiz');
print_error('attempterror', 'quiz', $quizobj->view_url(),
- $output->print_messages($messages));
+ $output->access_messages($messages));
}
$accessmanager->do_password_check($quizobj->is_preview_user());
View
@@ -96,6 +96,13 @@ div.editq div.question div.content .singlequestion a .questiontext{text-decorati
#page-mod-quiz-mod #reviewoptionshdr fieldset.fgroup span label,
#adminquizreviewoptions span label {margin-left: 0.4em;}
+#page-mod-quiz-mod.dir-rtl #reviewoptionshdr .fitem,
+#adminquizreviewoptions .group {float: right; width: 24%;}
+#page-mod-quiz-mod.dir-rtl #reviewoptionshdr fieldset.fgroup span,
+#adminquizreviewoptions span {float: right; clear: right;}
+#page-mod-quiz-mod.dir-rtl #reviewoptionshdr .fitemtitle,
+#adminquizreviewoptions .fitemtitle {text-align: right;}
+
/** Mod quiz view **/
#page-mod-quiz-view .quizinfo,
#page-mod-quiz-view #page .quizgradefeedback,
@@ -377,4 +384,4 @@ bank window's title is prominent enough*/
.qnum label {padding-right: 0.25em;}
/** settings.php */
-#adminquizreviewoptions {margin-bottom: 0.5em;}
+#adminquizreviewoptions {margin-bottom: 0.5em;}
View
@@ -61,7 +61,7 @@
$output = $PAGE->get_renderer('mod_quiz');
if (!$attemptobj->is_preview_user() && $messages) {
print_error('attempterror', 'quiz', $attemptobj->view_url(),
- $output->print_messages($messages));
+ $output->access_messages($messages));
}
$accessmanager->do_password_check($attemptobj->is_preview_user());
View
@@ -171,6 +171,10 @@
float: right;
}
+.dir-rtl .wiki_diffuserleft {
+ float: left;
+}
+
.wiki_diffuserright {
float: left;
}
@@ -70,8 +70,7 @@
public function __construct(question_attempt $qa, $preferredbehaviour) {
$this->qa = $qa;
$this->question = $qa->get_question();
- $requiredclass = $this->required_question_definition_type();
- if (!$this->question instanceof $requiredclass) {
+ if (!$this->is_compatible_question($this->question)) {
throw new coding_exception('This behaviour (' . $this->get_name() .
') cannot work with this question (' . get_class($this->question) . ')');
}
@@ -81,14 +80,26 @@ public static function get_required_behaviours() {
return array();
}
+ /**
+ * Some behaviours can only work with certing types of question. This method
+ * allows the behaviour to verify that a question is compatible.
+ * @param question_definition $question the question.
+ */
+ public function is_compatible_question(question_definition $question) {
+ $requiredclass = $this->required_question_definition_type();
+ return $this->question instanceof $requiredclass;
+ }
+
/**
* Most behaviours can only work with {@link question_definition}s
* of a particular subtype, or that implement a particular interface.
* This method lets the behaviour document that. The type of
* question passed to the constructor is then checked against this type.
* @return string class/interface name.
*/
- public abstract function required_question_definition_type();
+ protected function required_question_definition_type() {
+ return 'question_definition';
+ }
/**
* @return string the name of this behaviour. For example the name of
View
@@ -1787,7 +1787,7 @@ function print_qtype_to_add_option($qtype) {
echo '<span class="qtypename">';
$fakequestion = new stdClass();
$fakequestion->qtype = $qtype->name();
- print_question_icon($fakequestion);
+ echo print_question_icon($fakequestion);
echo $qtype->menu_name() . '</span><span class="qtypesummary">' .
get_string($qtype->name() . 'summary', 'qtype_' . $qtype->name());
echo "</span></label>\n";
@@ -865,33 +865,42 @@ public function sum_usage_marks_subquery($qubaid) {
END) = 0";
}
- public function question_attempt_latest_state_view($alias) {
- return "(
- SELECT
- {$alias}qa.id AS questionattemptid,
- {$alias}qa.questionusageid,
- {$alias}qa.slot,
- {$alias}qa.behaviour,
- {$alias}qa.questionid,
- {$alias}qa.variant,
- {$alias}qa.maxmark,
- {$alias}qa.minfraction,
- {$alias}qa.flagged,
- {$alias}qa.questionsummary,
- {$alias}qa.rightanswer,
- {$alias}qa.responsesummary,
- {$alias}qa.timemodified,
- {$alias}qas.id AS attemptstepid,
- {$alias}qas.sequencenumber,
- {$alias}qas.state,
- {$alias}qas.fraction,
- {$alias}qas.timecreated,
- {$alias}qas.userid
-
- FROM {question_attempts} {$alias}qa
- JOIN {question_attempt_steps} {$alias}qas ON
- {$alias}qas.id = {$this->latest_step_for_qa_subquery($alias . 'qa.id')}
- ) $alias";
+ /**
+ * Get a subquery that returns the latest step of every qa in some qubas.
+ * Currently, this is only used by the quiz reports. See
+ * {@link quiz_attempt_report_table::add_latest_state_join()}.
+ * @param string $alias alias to use for this inline-view.
+ * @param qubaid_condition $qubaids restriction on which question_usages we
+ * are interested in. This is important for performance.
+ * @return array with two elements, the SQL fragment and any params requried.
+ */
+ public function question_attempt_latest_state_view($alias, qubaid_condition $qubaids) {
+ return array("(
+ SELECT {$alias}qa.id AS questionattemptid,
+ {$alias}qa.questionusageid,
+ {$alias}qa.slot,
+ {$alias}qa.behaviour,
+ {$alias}qa.questionid,
+ {$alias}qa.variant,
+ {$alias}qa.maxmark,
+ {$alias}qa.minfraction,
+ {$alias}qa.flagged,
+ {$alias}qa.questionsummary,
+ {$alias}qa.rightanswer,
+ {$alias}qa.responsesummary,
+ {$alias}qa.timemodified,
+ {$alias}qas.id AS attemptstepid,
+ {$alias}qas.sequencenumber,
+ {$alias}qas.state,
+ {$alias}qas.fraction,
+ {$alias}qas.timecreated,
+ {$alias}qas.userid
+
+ FROM {$qubaids->from_question_attempts($alias . 'qa')}
+ JOIN {question_attempt_steps} {$alias}qas ON
+ {$alias}qas.id = {$this->latest_step_for_qa_subquery($alias . 'qa.id')}
+ WHERE {$qubaids->where()}
+ ) $alias", $qubaids->from_where_params());
}
protected function latest_step_for_qa_subquery($questionattemptid = 'qa.id') {
View
@@ -0,0 +1,49 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Renderers for outputting parts of the question bank.
+ *
+ * @package moodlecore
+ * @subpackage questionbank
+ * @copyright 2011 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+defined('MOODLE_INTERNAL') || die();
+
+
+/**
+ * This renderer outputs parts of the question bank.
+ *
+ * @copyright 2011 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class core_question_bank_renderer extends plugin_renderer_base {
+
+ /**
+ * Output the icon for a question type
+ * @param string $qtype the question type.
+ * @return string HTML fragment.
+ */
+ public function qtype_icon($qtype) {
+ $qtype = question_bank::get_qtype($qtype, false);
+ $namestr = $qtype->local_name();
+
+ return $this->pix_icon('icon', $namestr, $qtype->plugin_name(), array('title' => $namestr));
+ }
+}
@@ -344,7 +344,7 @@ protected function add_combined_feedback_fields($withshownumpartscorrect = false
$mform->setType($feedbackname, PARAM_RAW);
if ($withshownumpartscorrect && $feedbackname == 'partiallycorrectfeedback') {
- $mform->addElement('checkbox', 'shownumcorrect',
+ $mform->addElement('advcheckbox', 'shownumcorrect',
get_string('options', 'question'),
get_string('shownumpartscorrect', 'question'));
}
@@ -361,11 +361,11 @@ protected function get_hint_fields($withclearwrong = false, $withshownumpartscor
$repeatedoptions['hint']['type'] = PARAM_RAW;
if ($withclearwrong) {
- $repeated[] = $mform->createElement('checkbox', 'hintclearwrong',
+ $repeated[] = $mform->createElement('advcheckbox', 'hintclearwrong',
get_string('options', 'question'), get_string('clearwrongparts', 'question'));
}
if ($withshownumpartscorrect) {
- $repeated[] = $mform->createElement('checkbox', 'hintshownumcorrect', '',
+ $repeated[] = $mform->createElement('advcheckbox', 'hintshownumcorrect', '',
get_string('shownumpartscorrect', 'question'));
}
Oops, something went wrong.

0 comments on commit 81b24b1

Please sign in to comment.