Skip to content

Commit

Permalink
Merge branch 'master' into install_master
Browse files Browse the repository at this point in the history
  • Loading branch information
AMOS bot committed Nov 19, 2011
2 parents 00db87a + fe41ba7 commit 967bc47
Show file tree
Hide file tree
Showing 38 changed files with 356 additions and 104 deletions.
9 changes: 8 additions & 1 deletion backup/moodle2/restore_stepslib.php
Expand Up @@ -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() {
Expand Down
17 changes: 17 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -6916,6 +6916,23 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2011110200.02);
}

if ($oldversion < 2011111500.01) {
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, 2011111500.01);
}

return true;
}

9 changes: 7 additions & 2 deletions lib/moodlelib.php
Expand Up @@ -8725,12 +8725,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
Expand Down
12 changes: 2 additions & 10 deletions lib/questionlib.php
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/simpletest/testcompletionlib.php
Expand Up @@ -527,7 +527,7 @@ function test_get_progress_all() {
$c->__construct((object)array('id'=>42));

// 1) Basic usage
$c->expectAt(0,'get_tracked_users',array(false, array(), 0, '', '', ''));
$c->expectAt(0,'get_tracked_users',array(false, array(), 0, '', '', '', null));
$c->setReturnValueAt(0,'get_tracked_users',array(
(object)array('id'=>100,'firstname'=>'Woot','lastname'=>'Plugh'),
(object)array('id'=>201,'firstname'=>'Vroom','lastname'=>'Xyzzy'),
Expand Down Expand Up @@ -556,7 +556,7 @@ function test_get_progress_all() {
),$c->get_progress_all(false));

// 2) With more than 1,000 results
$c->expectAt(1,'get_tracked_users',array(true, 3, 0, '', '', ''));
$c->expectAt(1,'get_tracked_users',array(true, 3, 0, '', '', '', null));

$tracked=array();
$ids=array();
Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/lib.php
Expand Up @@ -3540,7 +3540,7 @@ function assignment_get_coursemodule_info($coursemodule) {
}
if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$info->content = format_module_intro('assignment', $assignment, $coursemodule->id, false);
$result->content = format_module_intro('assignment', $assignment, $coursemodule->id, false);
}
return $result;
} else {
Expand Down
3 changes: 2 additions & 1 deletion mod/forum/lib.php
Expand Up @@ -5943,8 +5943,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)
Expand Down
9 changes: 8 additions & 1 deletion mod/quiz/attemptlib.php
Expand Up @@ -418,10 +418,17 @@ class quiz_attempt {
* @param object $quiz the quiz object for this attempt and user.
* @param object $cm the course_module object for this quiz.
* @param object $course the row from the course table for the course we belong to.
* @param bool $loadquestions (optional) if true, the default, load all the details
* of the state of each question. Else just set up the basic details of the attempt.
*/
public function __construct($attempt, $quiz, $cm, $course) {
public function __construct($attempt, $quiz, $cm, $course, $loadquestions = true) {
$this->attempt = $attempt;
$this->quizobj = new quiz($quiz, $cm, $course);

if (!$loadquestions) {
return;
}

$this->quba = question_engine::load_questions_usage_by_activity($this->attempt->uniqueid);
$this->determine_layout();
$this->number_questions();
Expand Down
8 changes: 4 additions & 4 deletions mod/quiz/editlib.php
Expand Up @@ -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>';
Expand All @@ -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>';

Expand Down Expand Up @@ -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">' .
Expand Down Expand Up @@ -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) {
Expand Down
71 changes: 56 additions & 15 deletions mod/quiz/grade.php
Expand Up @@ -26,27 +26,68 @@


require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');


$id = required_param('id', PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);

if (!$cm = get_coursemodule_from_id('quiz', $id)) {
print_error('invalidcoursemodule');
}
if (!$quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
print_error('invalidquizid');
}
if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
print_error('coursemisconf');
$cm = get_coursemodule_from_id('quiz', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);

$reportlist = quiz_report_list(context_module::instance($cm->id));
if (empty($reportlist) || $userid == $USER->id) {
// If the user cannot see reports, or can see reports but is looking
// at their own grades, redirect them to the view.php page.
// (The looking at their own grades case is unlikely, since users who
// appear in the gradebook are unlikely to be able to see quiz reports,
// but it is possible.)
redirect(new moodle_url('/mod/quiz/view.php', array('id' => $cm->id)));
}

require_login($course, false, $cm);
// Now we know the user is interested in reports. If they are interested in a
// specific other user, try to send them to the most appropriate attempt review page.
if ($userid) {

$reportlist = quiz_report_list(get_context_instance(CONTEXT_MODULE, $cm->id));
if (!empty($reportlist)) {
redirect(new moodle_url('/mod/quiz/report.php', array(
'id' => $cm->id, 'mode' => reset($reportlist))));
} else {
redirect(new moodle_url('/mod/quiz/view.php', array('id' => $cm->id)));
// Work out which attempt is most significant from a grading point of view.
$attempts = quiz_get_user_attempts($quiz->id, $userid, 'finished');
$attempt = null;
switch ($quiz->grademethod) {
case QUIZ_ATTEMPTFIRST:
$attempt = reset($attempts);
break;

case QUIZ_ATTEMPTLAST:
case QUIZ_GRADEAVERAGE:
$attempt = end($attempts);
break;

case QUIZ_GRADEHIGHEST:
$maxmark = 0;
foreach ($attempts as $at) {
// >=, since we want to most recent relevant attempt.
if ((float) $at->sumgrades >= $maxmark) {
$maxmark = $at->sumgrades;
$attempt = $at;
}
}
break;
}

// If the user can review the relevant attempt, redirect to it.
if ($attempt) {
$attemptobj = new quiz_attempt($attempt, $quiz, $cm, $course, false);
if ($attemptobj->is_review_allowed()) {
redirect($attemptobj->review_url());
}
}

// Otherwise, fall thorugh to the generic case.
}

// Send the user to the first report they can see.
redirect(new moodle_url('/mod/quiz/report.php', array(
'id' => $cm->id, 'mode' => reset($reportlist))));
2 changes: 1 addition & 1 deletion mod/quiz/module.js
Expand Up @@ -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');
Expand Down
10 changes: 9 additions & 1 deletion mod/quiz/report/attemptsreport.php
Expand Up @@ -621,13 +621,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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/startattempt.php
Expand Up @@ -101,7 +101,7 @@
$output = $PAGE->get_renderer('mod_quiz');
if (!$quizobj->is_preview_user() && $messages) {
print_error('attempterror', 'quiz', $quizobj->view_url(),
$output->print_messages($messages));
$output->access_messages($messages));
}

if ($accessmanager->is_preflight_check_required($currentattemptid)) {
Expand Down
9 changes: 8 additions & 1 deletion mod/quiz/styles.css
Expand Up @@ -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,
Expand Down Expand Up @@ -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;}
2 changes: 1 addition & 1 deletion mod/quiz/summary.php
Expand Up @@ -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));
}
if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) {
redirect($attemptobj->start_attempt_url(null, $page));
Expand Down
2 changes: 1 addition & 1 deletion mod/scorm/lib.php
Expand Up @@ -510,7 +510,7 @@ function scorm_cron () {
$cfg_scorm = get_config('scorm');
if (!empty($cfg_scorm->allowaicchacp)) {
$expiretime = time() - ($cfg_scorm->aicchacpkeepsessiondata*24*60*60);
$DB->delete_records_select('scorm_aicc_session', 'WHERE timemodified < ?', array($expiretime));
$DB->delete_records_select('scorm_aicc_session', 'timemodified < ?', array($expiretime));
}
}

Expand Down
4 changes: 4 additions & 0 deletions mod/wiki/styles.css
Expand Up @@ -171,6 +171,10 @@
float: right;
}

.dir-rtl .wiki_diffuserleft {
float: left;
}

.wiki_diffuserright {
float: left;
}
Expand Down
4 changes: 2 additions & 2 deletions question/behaviour/adaptive/behaviour.php
Expand Up @@ -38,8 +38,8 @@
class qbehaviour_adaptive extends question_behaviour_with_save {
const IS_ARCHETYPAL = true;

public function required_question_definition_type() {
return 'question_automatically_gradable';
public function is_compatible_question(question_definition $question) {
return $question instanceof question_automatically_gradable;
}

public function get_expected_data() {
Expand Down

0 comments on commit 967bc47

Please sign in to comment.