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
moodle
moodle
Commits
647d9373
Commit
647d9373
authored
Nov 28, 2014
by
Tim Hunt
Browse files
MDL-47494 gapselect: Fix lots of coding style issues.
parent
7b23157b
Changes
14
Hide whitespace changes
Inline
Side-by-side
question/type/gapselect/backup/moodle2/backup_qtype_gapselect_plugin.class.php
View file @
647d9373
...
...
@@ -15,6 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Backup code for the gapselect question type.
* @package qtype_gapselect
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
...
...
question/type/gapselect/backup/moodle2/restore_qtype_gapselect_plugin.class.php
View file @
647d9373
...
...
@@ -15,18 +15,18 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore code for the gapselect question type.
*
* @package qtype_gapselect
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/**
* Restore plugin class that provides the necessary information
* needed to restore one gapselect qtype plugin.
* Restore plugin class for the gapselect question type plugin.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
...
...
question/type/gapselect/combinable/combinable.php
View file @
647d9373
...
...
@@ -73,7 +73,7 @@ class qtype_combined_combinable_gapselect extends qtype_combined_combinable_acce
$answerel
=
array
(
$mform
->
createElement
(
'text'
,
$this
->
form_field_name
(
'answer'
),
get_string
(
'choicex'
,
'qtype_gapselect'
),
array
(
'size'
=>
57
,
'class'
=>
'tweakcss'
)));
array
(
'size'
=>
57
,
'class'
=>
'tweakcss'
)));
if
(
$this
->
questionrec
!==
null
)
{
$countanswers
=
count
(
$this
->
questionrec
->
options
->
answers
);
...
...
@@ -136,7 +136,7 @@ class qtype_combined_combinable_gapselect extends qtype_combined_combinable_acce
}
foreach
(
$this
->
correctchoices
as
$correctchoice
)
{
$answerindex
=
$correctchoice
-
1
;
$answerindex
=
$correctchoice
-
1
;
if
(
!
isset
(
$this
->
formdata
->
answer
[
$answerindex
]))
{
$errors
[
'questiontext'
]
=
get_string
(
'errormissingchoice'
,
'qtype_gapselect'
,
$correctchoice
);
}
else
if
(
''
===
trim
(
$this
->
formdata
->
answer
[
$answerindex
]))
{
...
...
question/type/gapselect/edit_form_base.php
View file @
647d9373
...
...
@@ -17,13 +17,11 @@
/**
* Base class for editing question types like this one.
*
* @package qtype
* @subpackage gapselect
* @package qtype_gapselect
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined
(
'MOODLE_INTERNAL'
)
||
die
();
...
...
@@ -34,6 +32,7 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
qtype_gapselect_edit_form_base
extends
question_edit_form
{
/** @var int maximum number of different groups of drag items there can be in a question. */
const
MAX_GROUPS
=
8
;
/** @var array of HTML tags allowed in choices / drag boxes. */
...
...
@@ -155,7 +154,7 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
}
$grouparray
=
array
();
$grouparray
[]
=
$mform
->
createElement
(
'text'
,
'answer'
,
get_string
(
'answer'
,
'qtype_gapselect'
),
array
(
'size'
=>
30
,
'class'
=>
'tweakcss'
));
get_string
(
'answer'
,
'qtype_gapselect'
),
array
(
'size'
=>
30
,
'class'
=>
'tweakcss'
));
$grouparray
[]
=
$mform
->
createElement
(
'select'
,
'choicegroup'
,
get_string
(
'group'
,
'qtype_gapselect'
),
$options
);
return
$grouparray
;
...
...
@@ -210,7 +209,7 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
foreach
(
$choices
as
$key
=>
$choice
)
{
$answer
=
$choice
[
'answer'
];
// Check whether the
html-
tags are allowed tags.
// Check whether the
HTML
tags are allowed tags.
$tagerror
=
$this
->
get_illegal_tag_error
(
$answer
);
if
(
$tagerror
)
{
$errors
[
'choices['
.
$key
.
']'
]
=
$tagerror
;
...
...
@@ -236,7 +235,7 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
$cleanedslots
=
array
();
foreach
(
$slots
as
$slot
)
{
// The 2 is for'[[' and 4 is for '[[]]'.
$cleanedslots
[]
=
substr
(
$slot
,
2
,
(
strlen
(
$slot
)
-
4
));
$cleanedslots
[]
=
substr
(
$slot
,
2
,
(
strlen
(
$slot
)
-
4
));
}
$slots
=
$cleanedslots
;
...
...
question/type/gapselect/edit_gapselect_form.php
View file @
647d9373
...
...
@@ -35,7 +35,7 @@ require_once($CFG->dirroot . '/question/type/gapselect/edit_form_base.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
qtype_gapselect_edit_form
extends
qtype_gapselect_edit_form_base
{
/
/
HTML tags allowed in answers (choices).
/
** @var array
HTML tags allowed in answers (choices).
*/
protected
$allowedhtmltags
=
array
();
public
function
qtype
()
{
...
...
question/type/gapselect/lib.php
View file @
647d9373
...
...
@@ -17,13 +17,11 @@
/**
* Serve question type files
*
* @package qtype_gapselect
* @copyright 2012 The Open University
* @author Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_gapselect
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/**
...
...
question/type/gapselect/questionbase.php
View file @
647d9373
...
...
@@ -15,8 +15,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Definition class for embedded element in question text question. Parent of
* gap-select, drag and drop and possibly others.
* Definition class for embedded element in question text question.
*
* Used by gap-select, drag and drop and possibly others.
*
* @package qtype_gapselect
* @copyright 2011 The Open University
...
...
@@ -28,8 +29,9 @@ defined('MOODLE_INTERNAL') || die();
/**
* Represents embedded element in question text question. Parent of drag and drop and select from
* drop down list and others.
* Represents embedded element in question text question.
*
* Parent of drag and drop and select from drop down list and others.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
...
...
@@ -38,10 +40,19 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical
/** @var boolean Whether the question stems should be shuffled. */
public
$shufflechoices
;
/** @var string Feedback for any correct response. */
public
$correctfeedback
;
/** @var int format of $correctfeedback. */
public
$correctfeedbackformat
;
/** @var string Feedback for any partially correct response. */
public
$partiallycorrectfeedback
;
/** @var int format of $partiallycorrectfeedback. */
public
$partiallycorrectfeedbackformat
;
/** @var string Feedback for any incorrect response. */
public
$incorrectfeedback
;
/** @var int format of $incorrectfeedback. */
public
$incorrectfeedbackformat
;
/** @var array of arrays. The keys are the choice group numbers. The values
* are arrays of qtype_gapselect_choice objects. */
public
$choices
;
...
...
@@ -174,7 +185,8 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical
}
/**
* @param int $key stem number
* Get the field name corresponding to a given place.
* @param int $place stem number
* @return string the question-type variable name.
*/
public
function
field
(
$place
)
{
...
...
@@ -294,8 +306,7 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical
$choice
=
$this
->
choices
[
$group
][
$choiceno
];
$parts
[
$place
]
=
new
question_classified_response
(
$choiceno
,
html_to_text
(
$choice
->
text
,
0
,
false
),
(
$this
->
get_right_choice_for
(
$place
)
==
$response
[
$fieldname
])
/
count
(
$this
->
places
));
(
$this
->
get_right_choice_for
(
$place
)
==
$response
[
$fieldname
])
/
count
(
$this
->
places
));
}
return
$parts
;
}
...
...
question/type/gapselect/questiontypebase.php
View file @
647d9373
...
...
@@ -22,7 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined
(
'MOODLE_INTERNAL'
)
||
die
();
require_once
(
$CFG
->
libdir
.
'/questionlib.php'
);
...
...
@@ -132,7 +131,7 @@ abstract class qtype_gapselect_base extends question_type {
$this
->
initialise_combined_feedback
(
$question
,
$questiondata
,
true
);
$question
->
choices
=
array
();
$choiceindexmap
=
array
();
$choiceindexmap
=
array
();
// Store the choices in arrays by group.
$i
=
1
;
...
...
@@ -204,7 +203,7 @@ abstract class qtype_gapselect_base extends question_type {
$answers
[
$count
][
'answer'
]
=
$subquestion
->
answer
;
$answers
[
$count
][
'fraction'
]
=
$subquestion
->
fraction
;
$answers
[
$count
]
+=
$this
->
feedback_to_choice_options
(
$subquestion
->
feedback
);
$answers
[
$count
][
'choice'
]
=
$count
+
1
;
$answers
[
$count
][
'choice'
]
=
$count
+
1
;
++
$count
;
}
return
$answers
;
...
...
@@ -220,10 +219,10 @@ abstract class qtype_gapselect_base extends question_type {
protected
function
get_array_of_groups
(
$question
,
$state
)
{
$answers
=
$this
->
get_array_of_choices
(
$question
);
$arr
=
array
();
for
(
$group
=
1
;
$group
<
count
(
$answers
);
$group
++
)
{
for
(
$group
=
1
;
$group
<
count
(
$answers
);
$group
++
)
{
$players
=
$this
->
get_group_of_players
(
$question
,
$state
,
$answers
,
$group
);
if
(
$players
)
{
$arr
[
$group
]
=
$players
;
$arr
[
$group
]
=
$players
;
}
}
return
$arr
;
...
...
@@ -243,13 +242,18 @@ abstract class qtype_gapselect_base extends question_type {
foreach
(
$arrayofplaceholdeers
as
$ph
)
{
foreach
(
$arrayofchoices
as
$key
=>
$choice
)
{
if
(
$key
+
1
==
$ph
)
{
$correctplayers
[]
=
$choice
;
$correctplayers
[]
=
$choice
;
}
}
}
return
$correctplayers
;
}
/**
* Return the list of groups used in a question.
* @param stdClass $question the question data.
* @return array the groups used, or false if an error occurs.
*/
protected
function
get_array_of_placeholders
(
$question
)
{
$qtext
=
$question
->
questiontext
;
$error
=
'<b> ERROR</b>: Please check the form for this question. '
;
...
...
@@ -298,8 +302,7 @@ abstract class qtype_gapselect_base extends question_type {
foreach
(
$question
->
choices
[
$group
]
as
$i
=>
$choice
)
{
$choices
[
$i
]
=
new
question_possible_response
(
html_to_text
(
$choice
->
text
,
0
,
false
),
(
$question
->
rightchoices
[
$place
]
==
$i
)
/
count
(
$question
->
places
));
(
$question
->
rightchoices
[
$place
]
==
$i
)
/
count
(
$question
->
places
));
}
$choices
[
null
]
=
question_possible_response
::
no_response
();
...
...
question/type/gapselect/rendererbase.php
View file @
647d9373
...
...
@@ -27,8 +27,7 @@ defined('MOODLE_INTERNAL') || die();
/**
* Generates the output for question types where the question includes embedded
* interactive elements in the question text.
* Renders question types where the question includes embedded interactive elements.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
...
...
question/type/gapselect/tests/edit_form_test.php
View file @
647d9373
...
...
@@ -36,7 +36,6 @@ require_once($CFG->dirroot . '/question/type/gapselect/edit_form_base.php');
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group qtype_gapselect
*/
class
qtype_gapselect_edit_form_base_testable
extends
qtype_gapselect_edit_form_base
{
public
function
__construct
()
{
...
...
@@ -56,7 +55,6 @@ class qtype_gapselect_edit_form_base_testable extends qtype_gapselect_edit_form_
new
question_edit_contexts
(
$syscontext
));
}
// Make this public so we can test it.
public
function
get_illegal_tag_error
(
$text
)
{
return
parent
::
get_illegal_tag_error
(
$text
);
}
...
...
@@ -79,6 +77,10 @@ class qtype_gapselect_edit_form_base_testable extends qtype_gapselect_edit_form_
*/
class
qtype_gapselect_edit_form_test
extends
advanced_testcase
{
/**
* Helper method.
* @return qtype_gapselect_edit_form_base_testable a new form instance that can be tested.
*/
protected
function
get_form
()
{
$this
->
setAdminUser
();
$this
->
resetAfterTest
();
...
...
question/type/gapselect/tests/helper.php
View file @
647d9373
...
...
@@ -34,6 +34,7 @@ defined('MOODLE_INTERNAL') || die();
*/
class
qtype_gapselect_test_helper
{
/**
* Get an example gapselect question to use for testing. This examples has one of each item.
* @return qtype_gapselect_question
*/
public
static
function
make_a_gapselect_question
()
{
...
...
@@ -71,6 +72,7 @@ class qtype_gapselect_test_helper {
}
/**
* Get an example gapselect question to use for testing. This exmples had unlimited items.
* @return qtype_gapselect_question
*/
public
static
function
make_a_maths_gapselect_question
()
{
...
...
question/type/gapselect/tests/question_test.php
View file @
647d9373
...
...
@@ -35,7 +35,6 @@ require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group qtype_gapselect
*/
class
qtype_gapselect_question_test
extends
basic_testcase
{
...
...
@@ -212,7 +211,7 @@ class qtype_gapselect_question_test extends basic_testcase {
$this
->
assertEquals
(
array
(
1
,
question_state
::
$gradedright
),
$gapselect
->
grade_response
(
array
(
'p1'
=>
'1'
,
'p2'
=>
'1'
,
'p3'
=>
'1'
)));
$this
->
assertEquals
(
array
(
1
/
3
,
question_state
::
$gradedpartial
),
$this
->
assertEquals
(
array
(
1
/
3
,
question_state
::
$gradedpartial
),
$gapselect
->
grade_response
(
array
(
'p1'
=>
'1'
)));
$this
->
assertEquals
(
array
(
0
,
question_state
::
$gradedwrong
),
$gapselect
->
grade_response
(
array
(
'p1'
=>
'2'
,
'p2'
=>
'2'
,
'p3'
=>
'2'
)));
...
...
@@ -237,13 +236,13 @@ class qtype_gapselect_question_test extends basic_testcase {
$gapselect
->
start_attempt
(
new
question_attempt_step
(),
1
);
$this
->
assertEquals
(
array
(
1
=>
new
question_classified_response
(
1
,
'quick'
,
1
/
3
),
1
=>
new
question_classified_response
(
1
,
'quick'
,
1
/
3
),
2
=>
new
question_classified_response
(
2
,
'dog'
,
0
),
3
=>
new
question_classified_response
(
1
,
'lazy'
,
1
/
3
),
3
=>
new
question_classified_response
(
1
,
'lazy'
,
1
/
3
),
),
$gapselect
->
classify_response
(
array
(
'p1'
=>
'1'
,
'p2'
=>
'2'
,
'p3'
=>
'1'
)));
$this
->
assertEquals
(
array
(
1
=>
question_classified_response
::
no_response
(),
2
=>
new
question_classified_response
(
1
,
'fox'
,
1
/
3
),
2
=>
new
question_classified_response
(
1
,
'fox'
,
1
/
3
),
3
=>
new
question_classified_response
(
2
,
'assiduous'
,
0
),
),
$gapselect
->
classify_response
(
array
(
'p1'
=>
'0'
,
'p2'
=>
'1'
,
'p3'
=>
'2'
)));
}
...
...
question/type/gapselect/tests/questiontype_test.php
View file @
647d9373
...
...
@@ -35,7 +35,6 @@ require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group qtype_gapselect
*/
class
qtype_gapselect_test
extends
question_testcase
{
/** @var qtype_gapselect instance of the question type class to test. */
...
...
@@ -49,12 +48,18 @@ class qtype_gapselect_test extends question_testcase {
$this
->
qtype
=
null
;
}
/**
* Asserts that two strings containing XML are the same ignoring the line-endings.
* @param unknown $expectedxml
* @param unknown $xml
*/
public
function
assert_same_xml
(
$expectedxml
,
$xml
)
{
$this
->
assertEquals
(
str_replace
(
"
\r\n
"
,
"
\n
"
,
$expectedxml
),
str_replace
(
"
\r\n
"
,
"
\n
"
,
$xml
));
}
/**
* Get some test question data.
* @return object the data to construct a question like
* {@link qtype_gapselect_test_helper::make_a_gapselect_question()}.
*/
...
...
@@ -131,15 +136,15 @@ class qtype_gapselect_test extends question_testcase {
$this
->
assertEquals
(
array
(
1
=>
array
(
1
=>
new
question_possible_response
(
'quick'
,
1
/
3
),
1
=>
new
question_possible_response
(
'quick'
,
1
/
3
),
2
=>
new
question_possible_response
(
'slow'
,
0
),
null
=>
question_possible_response
::
no_response
()),
2
=>
array
(
1
=>
new
question_possible_response
(
'fox'
,
1
/
3
),
1
=>
new
question_possible_response
(
'fox'
,
1
/
3
),
2
=>
new
question_possible_response
(
'dog'
,
0
),
null
=>
question_possible_response
::
no_response
()),
3
=>
array
(
1
=>
new
question_possible_response
(
'lazy'
,
1
/
3
),
1
=>
new
question_possible_response
(
'lazy'
,
1
/
3
),
2
=>
new
question_possible_response
(
'assiduous'
,
0
),
null
=>
question_possible_response
::
no_response
()),
),
$this
->
qtype
->
get_possible_responses
(
$q
));
...
...
question/type/gapselect/tests/walkthrough_test.php
View file @
647d9373
...
...
@@ -15,8 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains tests that walks a question through the interactive
* behaviour.
* This file contains tests that simulate a user attempt a gapselect question.
*
* @package qtype_gapselect
* @copyright 2012 The Open University
...
...
@@ -36,7 +35,6 @@ require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group qtype_gapselect
*/
class
qtype_gapselect_walkthrough_test
extends
qbehaviour_walkthrough_test_base
{
public
function
test_interactive_behaviour
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment