Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
integration
prechecker
Commits
25a03faa
Commit
25a03faa
authored
May 12, 2011
by
Tim Hunt
Browse files
MDL-20636 fix many code-checker issues in mod/quiz.
parent
cfd811c8
Changes
77
Expand all
Hide whitespace changes
Inline
Side-by-side
mod/quiz/accessrules.php
View file @
25a03faa
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
...
...
@@ -78,10 +77,12 @@ class quiz_access_manager {
}
if
(
!
empty
(
$quiz
->
popup
))
{
if
(
$quiz
->
popup
==
1
)
{
$this
->
_securewindowrule
=
new
securewindow_access_rule
(
$this
->
_quizobj
,
$this
->
_timenow
);
$this
->
_securewindowrule
=
new
securewindow_access_rule
(
$this
->
_quizobj
,
$this
->
_timenow
);
$this
->
_rules
[]
=
$this
->
_securewindowrule
;
}
elseif
(
$quiz
->
popup
==
2
)
{
$this
->
_safebrowserrule
=
new
safebrowser_access_rule
(
$this
->
_quizobj
,
$this
->
_timenow
);
}
else
if
(
$quiz
->
popup
==
2
)
{
$this
->
_safebrowserrule
=
new
safebrowser_access_rule
(
$this
->
_quizobj
,
$this
->
_timenow
);
$this
->
_rules
[]
=
$this
->
_safebrowserrule
;
}
}
...
...
@@ -154,7 +155,8 @@ class quiz_access_manager {
*
* @param int $numattempts the number of previous attempts this user has made.
* @param object $lastattempt information about the user's last completed attempt.
* @return bool true if there is no way the user will ever be allowed to attempt this quiz again.
* @return bool true if there is no way the user will ever be allowed to attempt
* this quiz again.
*/
public
function
is_finished
(
$numprevattempts
,
$lastattempt
)
{
foreach
(
$this
->
_rules
as
$rule
)
{
...
...
@@ -185,8 +187,8 @@ class quiz_access_manager {
}
}
if
(
$timeleft
!==
false
)
{
/
// Make sure the timer starts just above zero. If $timeleft was <= 0, then
/
// this will just have the effect of causing the quiz to be submitted immediately.
// Make sure the timer starts just above zero. If $timeleft was <= 0, then
// this will just have the effect of causing the quiz to be submitted immediately.
$timerstartvalue
=
max
(
$timeleft
,
1
);
$PAGE
->
requires
->
js_init_call
(
'M.mod_quiz.timer.init'
,
array
(
$timerstartvalue
),
false
,
quiz_get_js_module
());
...
...
@@ -202,7 +204,7 @@ class quiz_access_manager {
/**
* @return bolean if this quiz should only be shown to students with safe browser.
*/
*/
public
function
safebrowser_required
(
$canpreview
)
{
return
!
$canpreview
&&
!
is_null
(
$this
->
_safebrowserrule
);
}
...
...
@@ -268,7 +270,8 @@ class quiz_access_manager {
echo
'<p>'
.
get_string
(
'pleaseclose'
,
'quiz'
)
.
'</p>'
;
$delay
=
0
;
}
$PAGE
->
requires
->
js_function_call
(
'M.mod_quiz.secure_window.close'
,
array
(
$url
,
$delay
));
$PAGE
->
requires
->
js_function_call
(
'M.mod_quiz.secure_window.close'
,
array
(
$url
,
$delay
));
echo
$OUTPUT
->
box_end
();
echo
$OUTPUT
->
footer
();
die
();
...
...
@@ -338,11 +341,11 @@ class quiz_access_manager {
public
function
confirm_start_attempt_message
()
{
$quiz
=
$this
->
_quizobj
->
get_quiz
();
if
(
$quiz
->
timelimit
&&
$quiz
->
attempts
)
{
return
get_string
(
'confirmstartattempttimelimit'
,
'quiz'
,
$quiz
->
attempts
);
return
get_string
(
'confirmstartattempttimelimit'
,
'quiz'
,
$quiz
->
attempts
);
}
else
if
(
$quiz
->
timelimit
)
{
return
get_string
(
'confirmstarttimelimit'
,
'quiz'
);
return
get_string
(
'confirmstarttimelimit'
,
'quiz'
);
}
else
if
(
$quiz
->
attempts
)
{
return
get_string
(
'confirmstartattemptlimit'
,
'quiz'
,
$quiz
->
attempts
);
return
get_string
(
'confirmstartattemptlimit'
,
'quiz'
,
$quiz
->
attempts
);
}
return
''
;
}
...
...
@@ -352,18 +355,20 @@ class quiz_access_manager {
*
* @param string $linktext some text.
* @param object $attempt the attempt object
* @return string some HTML, the $linktext either unmodified or wrapped in a link to the review page.
* @return string some HTML, the $linktext either unmodified or wrapped in a
* link to the review page.
*/
public
function
make_review_link
(
$attempt
,
$canpreview
,
$reviewoptions
)
{
global
$CFG
;
/
// If review of responses is not allowed, or the attempt is still open, don't link.
// If review of responses is not allowed, or the attempt is still open, don't link.
if
(
!
$attempt
->
timefinish
)
{
return
''
;
}
$when
=
quiz_attempt_state
(
$this
->
_quizobj
->
get_quiz
(),
$attempt
);
$reviewoptions
=
mod_quiz_display_options
::
make_from_quiz
(
$this
->
_quizobj
->
get_quiz
(),
$when
);
$reviewoptions
=
mod_quiz_display_options
::
make_from_quiz
(
$this
->
_quizobj
->
get_quiz
(),
$when
);
if
(
!
$reviewoptions
->
attempt
)
{
$message
=
$this
->
cannot_review_message
(
$when
,
true
);
...
...
@@ -376,7 +381,7 @@ class quiz_access_manager {
$linktext
=
get_string
(
'review'
,
'quiz'
);
/
// It is OK to link, does it need to be in a secure window?
// It is OK to link, does it need to be in a secure window?
if
(
$this
->
securewindow_required
(
$canpreview
))
{
return
$this
->
_securewindowrule
->
make_review_link
(
$linktext
,
$attempt
->
id
);
}
else
{
...
...
@@ -403,11 +408,13 @@ class quiz_access_manager {
$langstrsuffix
=
''
;
$dateformat
=
''
;
}
if
(
$when
==
mod_quiz_display_options
::
DURING
||
$when
==
mod_quiz_display_options
::
IMMEDIATELY_AFTER
)
{
if
(
$when
==
mod_quiz_display_options
::
DURING
||
$when
==
mod_quiz_display_options
::
IMMEDIATELY_AFTER
)
{
return
''
;
}
else
if
(
$when
==
mod_quiz_display_options
::
LATER_WHILE_OPEN
&&
$quiz
->
timeclose
&&
$quiz
->
reviewattempt
&
mod_quiz_display_options
::
AFTER_CLOSE
)
{
return
get_string
(
'noreviewuntil'
.
$langstrsuffix
,
'quiz'
,
userdate
(
$quiz
->
timeclose
,
$dateformat
));
}
else
if
(
$when
==
mod_quiz_display_options
::
LATER_WHILE_OPEN
&&
$quiz
->
timeclose
&&
$quiz
->
reviewattempt
&
mod_quiz_display_options
::
AFTER_CLOSE
)
{
return
get_string
(
'noreviewuntil'
.
$langstrsuffix
,
'quiz'
,
userdate
(
$quiz
->
timeclose
,
$dateformat
));
}
else
{
return
get_string
(
'noreview'
.
$langstrsuffix
,
'quiz'
);
}
...
...
@@ -444,14 +451,16 @@ abstract class quiz_access_rule_base {
* Whether or not a user should be allowed to start a new attempt at this quiz now.
* @param int $numattempts the number of previous attempts this user has made.
* @param object $lastattempt information about the user's last completed attempt.
* @return string false if access should be allowed, a message explaining the reason if access should be prevented.
* @return string false if access should be allowed, a message explaining the
* reason if access should be prevented.
*/
public
function
prevent_new_attempt
(
$numprevattempts
,
$lastattempt
)
{
return
false
;
}
/**
* Whether or not a user should be allowed to start a new attempt at this quiz now.
* @return string false if access should be allowed, a message explaining the reason if access should be prevented.
* @return string false if access should be allowed, a message explaining the
* reason if access should be prevented.
*/
public
function
prevent_access
()
{
return
false
;
...
...
@@ -575,11 +584,11 @@ class open_close_date_access_rule extends quiz_access_rule_base {
class
inter_attempt_delay_access_rule
extends
quiz_access_rule_base
{
public
function
prevent_new_attempt
(
$numprevattempts
,
$lastattempt
)
{
if
(
$this
->
_quiz
->
attempts
>
0
&&
$numprevattempts
>=
$this
->
_quiz
->
attempts
)
{
/
// No more attempts allowed anyway.
// No more attempts allowed anyway.
return
false
;
}
if
(
$this
->
_quiz
->
timeclose
!=
0
&&
$this
->
_timenow
>
$this
->
_quiz
->
timeclose
)
{
/
// No more attempts allowed anyway.
// No more attempts allowed anyway.
return
false
;
}
$nextstarttime
=
$this
->
compute_next_start_time
(
$numprevattempts
,
$lastattempt
);
...
...
@@ -606,7 +615,7 @@ class inter_attempt_delay_access_rule extends quiz_access_rule_base {
}
$lastattemptfinish
=
$lastattempt
->
timefinish
;
if
(
$this
->
_quiz
->
timelimit
>
0
){
if
(
$this
->
_quiz
->
timelimit
>
0
)
{
$lastattemptfinish
=
min
(
$lastattemptfinish
,
$lastattempt
->
timestart
+
$this
->
_quiz
->
timelimit
);
}
...
...
@@ -673,17 +682,17 @@ class password_access_rule extends quiz_access_rule_base {
public
function
do_password_check
(
$canpreview
,
$accessmanager
)
{
global
$CFG
,
$SESSION
,
$OUTPUT
,
$PAGE
;
/
// We have already checked the password for this quiz this session, so don't ask again.
// We have already checked the password for this quiz this session, so don't ask again.
if
(
!
empty
(
$SESSION
->
passwordcheckedquizzes
[
$this
->
_quiz
->
id
]))
{
return
;
}
/
// If the user cancelled the password form, send them back to the view page.
// If the user cancelled the password form, send them back to the view page.
if
(
optional_param
(
'cancelpassword'
,
false
,
PARAM_BOOL
))
{
$accessmanager
->
back_to_view_page
(
$canpreview
);
}
/
// If they entered the right password, let them in.
// If they entered the right password, let them in.
$enteredpassword
=
optional_param
(
'quizpassword'
,
''
,
PARAM_RAW
);
$validpassword
=
false
;
if
(
strcmp
(
$this
->
_quiz
->
password
,
$enteredpassword
)
===
0
)
{
...
...
@@ -702,15 +711,16 @@ class password_access_rule extends quiz_access_rule_base {
return
;
}
/
// User entered the wrong password, or has not entered one yet, so display the form.
// User entered the wrong password, or has not entered one yet, so display the form.
$output
=
''
;
/
// Start the page and print the quiz intro, if any.
// Start the page and print the quiz intro, if any.
if
(
$accessmanager
->
securewindow_required
(
$canpreview
))
{
$accessmanager
->
setup_secure_page
(
$this
->
_quizobj
->
get_course
()
->
shortname
.
': '
.
format_string
(
$this
->
_quizobj
->
get_quiz_name
()));
}
else
if
(
$accessmanager
->
safebrowser_required
(
$canpreview
))
{
$PAGE
->
set_title
(
$this
->
_quizobj
->
get_course
()
->
shortname
.
': '
.
format_string
(
$this
->
_quizobj
->
get_quiz_name
()));
$PAGE
->
set_title
(
$this
->
_quizobj
->
get_course
()
->
shortname
.
': '
.
format_string
(
$this
->
_quizobj
->
get_quiz_name
()));
$PAGE
->
set_cacheable
(
false
);
echo
$OUTPUT
->
header
();
}
else
{
...
...
@@ -719,16 +729,17 @@ class password_access_rule extends quiz_access_rule_base {
}
if
(
trim
(
strip_tags
(
$this
->
_quiz
->
intro
)))
{
$output
.
=
$OUTPUT
->
box
(
format_module_intro
(
'quiz'
,
$this
->
_quiz
,
$this
->
_quizobj
->
get_cmid
()),
'generalbox'
,
'intro'
);
$output
.
=
$OUTPUT
->
box
(
format_module_intro
(
'quiz'
,
$this
->
_quiz
,
$this
->
_quizobj
->
get_cmid
()),
'generalbox'
,
'intro'
);
}
$output
.
=
$OUTPUT
->
box_start
(
'generalbox'
,
'passwordbox'
);
/
// If they have previously tried and failed to enter a password, tell them it was wrong.
// If they have previously tried and failed to enter a password, tell them it was wrong.
if
(
!
empty
(
$enteredpassword
))
{
$output
.
=
'<p class="notifyproblem">'
.
get_string
(
'passworderror'
,
'quiz'
)
.
'</p>'
;
}
/
// Print the password entry form.
// Print the password entry form.
$output
.
=
'<p>'
.
get_string
(
'requirepasswordmessage'
,
'quiz'
)
.
"</p>
\n
"
;
$output
.
=
'<form id="passwordform" method="post" action="'
.
$CFG
->
wwwroot
.
'/mod/quiz/startattempt.php" onclick="this.autocomplete=\'off\'">'
.
"
\n
"
;
...
...
@@ -744,10 +755,10 @@ class password_access_rule extends quiz_access_rule_base {
$output
.
=
"</div>
\n
"
;
$output
.
=
"</form>
\n
"
;
/
// Finish page.
// Finish page.
$output
.
=
$OUTPUT
->
box_end
();
/
// return or display form.
// return or display form.
echo
$output
;
echo
$OUTPUT
->
footer
();
exit
;
...
...
mod/quiz/addrandom.php
View file @
25a03faa
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
...
...
mod/quiz/addrandomform.php
View file @
25a03faa
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
...
...
mod/quiz/attempt.php
View file @
25a03faa
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
...
...
mod/quiz/attemptlib.php
View file @
25a03faa
...
...
@@ -39,7 +39,7 @@ defined('MOODLE_INTERNAL') || die();
* @since Moodle 2.0
*/
class
moodle_quiz_exception
extends
moodle_exception
{
public
function
__construct
(
$quizobj
,
$errorcode
,
$a
=
NULL
,
$link
=
''
,
$debuginfo
=
null
)
{
public
function
__construct
(
$quizobj
,
$errorcode
,
$a
=
null
,
$link
=
''
,
$debuginfo
=
null
)
{
if
(
!
$link
)
{
$link
=
$quizobj
->
view_url
();
}
...
...
@@ -128,8 +128,9 @@ class quiz {
array
(
'quizid'
=>
$this
->
quiz
->
id
));
}
/**
* Fully load some or all of the questions for this quiz. You must call {@link preload_questions()} first.
/**
* Fully load some or all of the questions for this quiz. You must call
* {@link preload_questions()} first.
*
* @param array $questionids question ids of the questions to load. null for all.
*/
...
...
@@ -238,12 +239,13 @@ class quiz {
/**
* @param int $timenow the current time as a unix timestamp.
* @return quiz_access_manager and instance of the quiz_access_manager class for this quiz at this time.
* @return quiz_access_manager and instance of the quiz_access_manager class
* for this quiz at this time.
*/
public
function
get_access_manager
(
$timenow
)
{
if
(
is_null
(
$this
->
accessmanager
))
{
$this
->
accessmanager
=
new
quiz_access_manager
(
$this
,
$timenow
,
has_capability
(
'mod/quiz:ignoretimelimits'
,
$this
->
context
,
NULL
,
false
));
has_capability
(
'mod/quiz:ignoretimelimits'
,
$this
->
context
,
null
,
false
));
}
return
$this
->
accessmanager
;
}
...
...
@@ -251,14 +253,14 @@ class quiz {
/**
* Wrapper round the has_capability funciton that automatically passes in the quiz context.
*/
public
function
has_capability
(
$capability
,
$userid
=
NULL
,
$doanything
=
true
)
{
public
function
has_capability
(
$capability
,
$userid
=
null
,
$doanything
=
true
)
{
return
has_capability
(
$capability
,
$this
->
context
,
$userid
,
$doanything
);
}
/**
* Wrapper round the require_capability funciton that automatically passes in the quiz context.
*/
public
function
require_capability
(
$capability
,
$userid
=
NULL
,
$doanything
=
true
)
{
public
function
require_capability
(
$capability
,
$userid
=
null
,
$doanything
=
true
)
{
return
require_capability
(
$capability
,
$this
->
context
,
$userid
,
$doanything
);
}
...
...
@@ -319,8 +321,8 @@ class quiz {
// Private methods =====================================================================
/**
*
Check that the definition of a particular question is loaded, and if not throw an exception.
*
@param $id a questionid.
* Check that the definition of a particular question is loaded, and if not throw an exception.
* @param $id a questionid.
*/
protected
function
ensure_question_loaded
(
$id
)
{
if
(
isset
(
$this
->
questions
[
$id
]
->
_partiallyloaded
))
{
...
...
@@ -372,11 +374,11 @@ class quiz_attempt {
protected
static
function
create_helper
(
$conditions
)
{
global
$DB
;
// TODO deal with the issue that makes this necessary.
//
if (!$DB->record_exists('question_sessions', array('attemptid' => $attempt->uniqueid))) {
//
// this attempt has not yet been upgraded to the new model
//
quiz_upgrade_states($attempt);
//
}
// TODO deal with the issue that makes this necessary.
//
if (!$DB->record_exists('question_sessions', array('attemptid' => $attempt->uniqueid))) {
//
// this attempt has not yet been upgraded to the new model
//
quiz_upgrade_states($attempt);
//
}
$attempt
=
$DB
->
get_record
(
'quiz_attempts'
,
$conditions
,
'*'
,
MUST_EXIST
);
$quiz
=
$DB
->
get_record
(
'quiz'
,
array
(
'id'
=>
$attempt
->
quiz
),
'*'
,
MUST_EXIST
);
...
...
@@ -507,7 +509,8 @@ class quiz_attempt {
/**
* @param int $timenow the current time as a unix timestamp.
* @return quiz_access_manager and instance of the quiz_access_manager class for this quiz at this time.
* @return quiz_access_manager and instance of the quiz_access_manager class
* for this quiz at this time.
*/
public
function
get_access_manager
(
$timenow
)
{
return
$this
->
quizobj
->
get_access_manager
(
$timenow
);
...
...
@@ -538,7 +541,10 @@ class quiz_attempt {
return
$this
->
attempt
->
userid
;
}
/** @return bool whether this attempt has been finished (true) or is still in progress (false). */
/**
* @return bool whether this attempt has been finished (true) or is still
* in progress (false).
*/
public
function
is_finished
()
{
return
$this
->
attempt
->
timefinish
!=
0
;
}
...
...
@@ -588,7 +594,8 @@ class quiz_attempt {
// Check the users have at least one group in common.
$teachersgroups
=
groups_get_activity_allowed_groups
(
$cm
);
$studentsgroups
=
groups_get_all_groups
(
$cm
->
course
,
$this
->
attempt
->
userid
,
$cm
->
groupingid
);
$studentsgroups
=
groups_get_all_groups
(
$cm
->
course
,
$this
->
attempt
->
userid
,
$cm
->
groupingid
);
return
$teachersgroups
&&
$studentsgroups
&&
array_intersect
(
array_keys
(
$teachersgroups
),
array_keys
(
$studentsgroups
));
}
...
...
@@ -605,14 +612,14 @@ class quiz_attempt {
/**
* Wrapper round the has_capability funciton that automatically passes in the quiz context.
*/
public
function
has_capability
(
$capability
,
$userid
=
NULL
,
$doanything
=
true
)
{
public
function
has_capability
(
$capability
,
$userid
=
null
,
$doanything
=
true
)
{
return
$this
->
quizobj
->
has_capability
(
$capability
,
$userid
,
$doanything
);
}
/**
* Wrapper round the require_capability funciton that automatically passes in the quiz context.
*/
public
function
require_capability
(
$capability
,
$userid
=
NULL
,
$doanything
=
true
)
{
public
function
require_capability
(
$capability
,
$userid
=
null
,
$doanything
=
true
)
{
return
$this
->
quizobj
->
require_capability
(
$capability
,
$userid
,
$doanything
);
}
...
...
@@ -715,35 +722,41 @@ class quiz_attempt {
}
/**
* Return the grade obtained on a particular question, if the user is permitted to see it.
* You must previously have called load_question_states to load the state data about this question.
* Return the grade obtained on a particular question, if the user is permitted
* to see it. You must previously have called load_question_states to load the
* state data about this question.
*
* @param int $slot the number used to identify this question within this attempt.
* @return string the formatted grade, to the number of decimal places specified by the quiz.
* @return string the formatted grade, to the number of decimal places specified
* by the quiz.
*/
public
function
get_question_number
(
$slot
)
{
return
$this
->
quba
->
get_question
(
$slot
)
->
_number
;
}
/**
* Return the grade obtained on a particular question, if the user is permitted to see it.
* You must previously have called load_question_states to load the state data about this question.
* Return the grade obtained on a particular question, if the user is permitted
* to see it. You must previously have called load_question_states to load the
* state data about this question.
*
* @param int $slot the number used to identify this question within this attempt.
* @return string the formatted grade, to the number of decimal places specified by the quiz.
* @return string the formatted grade, to the number of decimal places specified
* by the quiz.
*/
public
function
get_question_name
(
$slot
)
{
return
$this
->
quba
->
get_question
(
$slot
)
->
name
;
}
/**
* Return the grade obtained on a particular question, if the user is permitted to see it.
* You must previously have called load_question_states to load the state data about this question.
* Return the grade obtained on a particular question, if the user is permitted
* to see it. You must previously have called load_question_states to load the
* state data about this question.
*
* @param int $slot the number used to identify this question within this attempt.
* @param bool $showcorrectness Whether right/partial/wrong states should
* be distinguised.
* @return string the formatted grade, to the number of decimal places specified by the quiz.
* @return string the formatted grade, to the number of decimal places specified
* by the quiz.
*/
public
function
get_question_status
(
$slot
,
$showcorrectness
)
{
return
$this
->
quba
->
get_question_state_string
(
$slot
,
$showcorrectness
);
...
...
@@ -911,7 +924,8 @@ class quiz_attempt {
$options
=
$this
->
get_display_options
(
true
);
$options
->
hide_all_feedback
();
$options
->
manualcomment
=
question_display_options
::
EDITABLE
;
return
$this
->
quba
->
render_question
(
$slot
,
$options
,
$this
->
quba
->
get_question
(
$slot
)
->
_number
);
return
$this
->
quba
->
render_question
(
$slot
,
$options
,
$this
->
quba
->
get_question
(
$slot
)
->
_number
);
}
/**
...
...
@@ -1054,8 +1068,10 @@ class quiz_attempt {
* Used by {@link attempt_url()} and {@link review_url()}.
*
* @param string $script. Used in the URL like /mod/quiz/$script.php
* @param int $slot identifies the specific question on the page to jump to. 0 to just use the $page parameter.
* @param int $page -1 to look up the page number from the slot, otherwise the page number to go to.
* @param int $slot identifies the specific question on the page to jump to.
* 0 to just use the $page parameter.
* @param int $page -1 to look up the page number from the slot, otherwise
* the page number to go to.
* @param bool $showall if true, return a URL with showall=1, and not page number
* @param int $thispage the page we are currently on. Links to questions on this
* page will just be a fragment #q123. -1 to disable this.
...
...
mod/quiz/backup/moodle2/backup_quiz_activity_task.class.php
View file @
25a03faa
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
...
...
mod/quiz/backup/moodle2/backup_quiz_stepslib.php
View file @
25a03faa
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
...
...
mod/quiz/backup/moodle2/restore_quiz_activity_task.class.php
View file @
25a03faa
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
...
...
@@ -25,7 +24,8 @@
defined
(
'MOODLE_INTERNAL'
)
||
die
();
require_once
(
$CFG
->
dirroot
.
'/mod/quiz/backup/moodle2/restore_quiz_stepslib.php'
);
// Because it exists (must)
require_once
(
$CFG
->
dirroot
.
'/mod/quiz/backup/moodle2/restore_quiz_stepslib.php'
);
// Because it exists (must)
/**
...
...
@@ -60,7 +60,8 @@ class restore_quiz_activity_task extends restore_activity_task {
$contents
=
array
();
$contents
[]
=
new
restore_decode_content
(
'quiz'
,
array
(
'intro'
),
'quiz'
);
$contents
[]
=
new
restore_decode_content
(
'quiz_feedback'
,
array
(
'feedbacktext'
),
'quiz_feedback'
);
$contents
[]
=
new
restore_decode_content
(
'quiz_feedback'
,
array
(
'feedbacktext'
),
'quiz_feedback'
);
return
$contents
;
}
...
...
@@ -72,9 +73,12 @@ class restore_quiz_activity_task extends restore_activity_task {
public
static
function
define_decode_rules
()
{
$rules
=
array
();
$rules
[]
=
new
restore_decode_rule
(
'QUIZVIEWBYID'
,
'/mod/quiz/view.php?id=$1'
,
'course_module'
);
$rules
[]
=
new
restore_decode_rule
(
'QUIZVIEWBYQ'
,
'/mod/quiz/view.php?q=$1'
,
'quiz'
);
$rules
[]
=
new
restore_decode_rule
(
'QUIZINDEX'
,
'/mod/quiz/index.php?id=$1'
,
'course'
);
$rules
[]
=
new
restore_decode_rule
(
'QUIZVIEWBYID'
,
'/mod/quiz/view.php?id=$1'
,
'course_module'
);
$rules
[]
=
new
restore_decode_rule
(
'QUIZVIEWBYQ'
,
'/mod/quiz/view.php?q=$1'
,
'quiz'
);
$rules
[]
=
new
restore_decode_rule
(
'QUIZINDEX'
,
'/mod/quiz/index.php?id=$1'
,
'course'
);
return
$rules
;
...
...
@@ -89,51 +93,77 @@ class restore_quiz_activity_task extends restore_activity_task {
public
static
function
define_restore_log_rules
()
{
$rules
=
array
();
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'add'
,
'view.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'update'
,
'view.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'view'
,
'view.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'preview'
,
'view.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'report'
,
'report.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'editquestions'
,
'view.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'delete attempt'
,
'report.php?id={course_module}'
,
'[oldattempt]'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'edit override'
,
'overrideedit.php?id={quiz_override}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'delete override'
,
'overrides.php.php?cmid={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'addcategory'
,
'view.php?id={course_module}'
,
'{question_category}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'view summary'
,
'summary.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'manualgrade'
,
'comment.php?attempt={quiz_attempt_id}&question={question}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'manualgrading'
,
'report.php?mode=grading&q={quiz}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'add'
,
'view.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'update'
,
'view.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'view'
,
'view.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'preview'
,
'view.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'report'
,
'report.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'editquestions'
,
'view.php?id={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'delete attempt'
,
'report.php?id={course_module}'
,
'[oldattempt]'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'edit override'
,
'overrideedit.php?id={quiz_override}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'delete override'
,
'overrides.php.php?cmid={course_module}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'addcategory'
,
'view.php?id={course_module}'
,
'{question_category}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'view summary'
,
'summary.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'manualgrade'
,
'comment.php?attempt={quiz_attempt_id}&question={question}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'manualgrading'
,
'report.php?mode=grading&q={quiz}'
,
'{quiz}'
);
// All the ones calling to review.php have two rules to handle both old and new urls
// in any case they are always converted to new urls on restore
// TODO: In Moodle 2.x (x >= 5) kill the old rules
// Note we are using the 'quiz_attempt_id' mapping becuase that is the one containing the quiz_attempt->ids
// old an new for quiz-attempt
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'attempt'
,
'review.php?id={course_module}&attempt={quiz_attempt}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt}'
);
// Note we are using the 'quiz_attempt_id' mapping becuase that is the
// one containing the quiz_attempt->ids old an new for quiz-attempt
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'attempt'
,
'review.php?id={course_module}&attempt={quiz_attempt}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt}'
);
// old an new for quiz-submit
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'submit'
,
'review.php?id={course_module}&attempt={quiz_attempt_id}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt_id}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'submit'
,
'review.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'submit'
,
'review.php?id={course_module}&attempt={quiz_attempt_id}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt_id}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'submit'
,
'review.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
// old an new for quiz-review
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'review'
,
'review.php?id={course_module}&attempt={quiz_attempt_id}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt_id}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'review'
,
'review.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'review'
,
'review.php?id={course_module}&attempt={quiz_attempt_id}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt_id}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'review'
,
'review.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
// old an new for quiz-start attemp
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'start attempt'
,
'review.php?id={course_module}&attempt={quiz_attempt_id}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt_id}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'start attempt'
,
'review.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'start attempt'
,
'review.php?id={course_module}&attempt={quiz_attempt_id}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt_id}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'start attempt'
,
'review.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
// old an new for quiz-close attemp
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'close attempt'
,
'review.php?id={course_module}&attempt={quiz_attempt_id}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt_id}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'close attempt'
,
'review.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'close attempt'
,
'review.php?id={course_module}&attempt={quiz_attempt_id}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt_id}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'close attempt'
,
'review.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
// old an new for quiz-continue attempt
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'continue attempt'
,
'review.php?id={course_module}&attempt={quiz_attempt_id}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt_id}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'continue attempt'
,
'review.php?attempt={quiz_attempt_id}'
,
'{quiz}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'continue attempt'
,
'review.php?id={course_module}&attempt={quiz_attempt_id}'
,
'{quiz}'
,
null
,
null
,
'review.php?attempt={quiz_attempt_id}'
);
$rules
[]
=
new
restore_log_rule
(
'quiz'
,
'continue attempt'
,