MDL-47494 question General code cleanup

Remove old browser CSS.
Fix code style problems.
Add many PHPdocs.
Set @package uniformly.
This commit is contained in:
Eric Merrill 2015-09-18 08:58:41 -04:00 committed by Tim Hunt
parent 031152cc83
commit 8bc1d28b1a
39 changed files with 506 additions and 114 deletions

View file

@ -31,9 +31,9 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_qtype_ddimageortext_plugin extends backup_qtype_plugin {
/**
* Returns the question type this is.
*
* @return string question type name, like 'ddimageortext'.
*/
protected static function qtype_name() {

View file

@ -30,13 +30,19 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin {
/**
* Returns the qtype name.
*
* @return string The type name
*/
protected static function qtype_name() {
return 'ddimageortext';
}
/**
* Returns the paths to be handled by the plugin at question level.
*
* @return array
*/
protected function define_question_plugin_structure() {
@ -60,6 +66,8 @@ class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin {
/**
* Process the qtype/{qtypename} element.
*
* @param array|object $data Drag and drop data to work with.
*/
public function process_dds($data) {
global $DB;
@ -88,6 +96,8 @@ class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin {
/**
* Process the qtype/drags/drag element.
*
* @param array|object $data Drag and drop drag data to work with.
*/
public function process_drag($data) {
global $DB;
@ -113,7 +123,9 @@ class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin {
}
/**
* Process the qtype/drags/drag element.
* Process the qtype/drags/drop element.
*
* @param array|object $data Drad and drop drops data to work with.
*/
public function process_drop($data) {
global $DB;
@ -136,8 +148,11 @@ class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin {
$this->set_mapping("{$prefix}_drops", $oldid, $newitemid);
}
}
/**
* Return the contents of this qtype to be processed by the links decoder.
*
* @return array
*/
public static function define_decode_contents() {

View file

@ -35,7 +35,6 @@ require_once($CFG->dirroot . '/question/type/ddimageortext/edit_ddtoimage_form_b
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddimageortext_edit_form extends qtype_ddtoimage_edit_form_base {
public function qtype() {
return 'ddimageortext';
}

View file

@ -17,10 +17,9 @@
/**
* Base class for editing form for the drag-and-drop images onto images question type.
*
* @package qtype
* @subpackage ddimageortext
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_ddimageortext
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@ -32,13 +31,25 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
/**
* Maximum number of different groups of drag items there can be in a question.
*/
const MAX_GROUPS = 8;
/**
* The default starting number of drop zones.
*/
const START_NUM_ITEMS = 6;
/**
* The number of drop zones that get added at a time.
*/
const ADD_NUM_ITEMS = 3;
/**
*
* Options shared by all file pickers in the form.
*
* @return array Array of filepicker options.
*/
public static function file_picker_options() {
$filepickeroptions = array();
@ -51,6 +62,7 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
/**
* definition_inner adds all specific fields to the form.
*
* @param MoodleQuickForm $mform (the form being built).
*/
protected function definition_inner($mform) {
@ -76,9 +88,14 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
$this->add_interactive_settings(true, true);
}
/**
* Make and add drop zones to the form.
*
* @param object $mform The Moodle form object.
* @param int $imagerepeats The initial number of repeat elements.
*/
protected function definition_drop_zones($mform, $imagerepeats) {
$mform->addElement('header', 'dropzoneheader',
get_string('dropzoneheader', 'qtype_'.$this->qtype()));
$mform->addElement('header', 'dropzoneheader', get_string('dropzoneheader', 'qtype_'.$this->qtype()));
$countdropzones = 0;
if (isset($this->question->id)) {
@ -97,16 +114,51 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
'nodropzone', 'adddropzone', self::ADD_NUM_ITEMS,
get_string('addmoredropzones', 'qtype_ddimageortext'), true);
}
/**
* Returns an array with a drop zone form element.
*
* @param object $mform The Moodle form object.
* @param int $imagerepeats The number of repeat images.
* @return array Array with the dropzone element.
*/
abstract protected function drop_zone($mform, $imagerepeats);
/**
* Returns an array of default drop zone repeat options.
*
* @return array
*/
abstract protected function drop_zones_repeated_options();
/**
* Builds and adds the needed form items for draggable items.
*
* @param object $mform The Moodle form object.
* @param int $itemrepeatsatstart The initial number of repeat elements.
*/
abstract protected function definition_draggable_items($mform, $itemrepeatsatstart);
/**
* Creates and returns a set of form elements to make a draggable item.
*
* @param object $mform The Moodle form object.
* @return array An array of form elements.
*/
abstract protected function draggable_item($mform);
/**
* Returns an array of default repeat options.
*
* @return array
*/
abstract protected function draggable_items_repeated_options();
/**
* Returns an array of starting number of repeats, and the total number of repeats.
*
* @return array
*/
protected function get_drag_item_repeats() {
$countimages = 0;
if (isset($this->question->id)) {
@ -128,8 +180,17 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
return array($itemrepeatsatstart, $imagerepeats);
}
/**
* Performce the needed JS setup for this question type.
*/
abstract public function js_call();
/**
* Checks to see if a file has been uploaded.
*
* @param string $draftitemid The draft id
* @return bool True if files exist, false if not.
*/
public static function file_uploaded($draftitemid) {
$draftareafiles = file_get_drafarea_files($draftitemid);
do {
@ -141,5 +202,4 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
return true;
}
}

View file

@ -15,11 +15,11 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Language file Drag and Drop image or text.
*
* @package qtype
* @subpackage ddimageortext
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_ddimageortext
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['addmoredropzones'] = 'Blanks for {no} more drop zones';
@ -67,4 +67,4 @@ $string['summariseplace'] = '{$a->no}. {$a->text}';
$string['summarisechoiceno'] = 'Item {$a}';
$string['summariseplaceno'] = 'Drop zone {$a}';
$string['xleft'] = 'Left';
$string['ytop'] = 'Top';
$string['ytop'] = 'Top';

View file

@ -17,10 +17,9 @@
/**
* Serve question type files
*
* @package qtype
* @subpackage ddimageortext
* @copyright Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_ddimageortext
* @copyright Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -29,10 +28,17 @@ defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for ddimageortext questions.
*
* @param object $course The course we are in
* @param object $cm Course module
* @param object $context The context object
* @param string $filearea the name of the file area.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @param array $options additional options affecting the file serving
*/
function qtype_ddimageortext_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_ddimageortext',
$filearea, $args, $forcedownload, $options);
question_pluginfile($course, $context, 'qtype_ddimageortext', $filearea, $args, $forcedownload, $options);
}

View file

@ -46,12 +46,30 @@ class qtype_ddimageortext_question extends qtype_ddtoimage_question_base {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddimageortext_drag_item {
/** @var int Drag item id */
public $id;
/** @var string Text for the drag item */
public $text;
/** @var int Number of the item */
public $no;
/** @var int Group of the item */
public $group;
/** @var bool If the drag item can be used multiple times or not */
public $infinite;
/**
* Drag item object setup.
*
* @param string $alttextlabel The alt text of the drag item
* @param int $no Which number drag item this is
* @param int $group Group of the drag item
* @param bool $infinite True if the item can be used an unlimited number of times
* @param int $id id of the item
*/
public function __construct($alttextlabel, $no, $group = 1, $infinite = false, $id = 0) {
$this->id = $id;
$this->text = $alttextlabel;
@ -59,10 +77,21 @@ class qtype_ddimageortext_drag_item {
$this->group = $group;
$this->infinite = $infinite;
}
/**
* Returns the group of this item.
*
* @return int
*/
public function choice_group() {
return $this->group;
}
/**
* Creates summary text of for the drag item.
*
* @return string
*/
public function summarise() {
if (trim($this->text) != '') {
return get_string('summarisechoice', 'qtype_ddimageortext', $this);
@ -78,11 +107,27 @@ class qtype_ddimageortext_drag_item {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddimageortext_drop_zone {
/** @var int Number of the item */
public $no;
/** @var string Alt text for the drop zone item */
public $text;
/** @var int Group of the item */
public $group;
/** @var array X and Y location of the drop zone */
public $xy;
/**
* Create a drop zone object.
*
* @param string $alttextlabel The alt text of the drop zone
* @param int $no Which number drop zone this is
* @param int $group Group of the drop zone
* @param int $x X location
* @param int $y Y location
*/
public function __construct($alttextlabel, $no, $group = 1, $x = '', $y = '') {
$this->no = $no;
$this->text = $alttextlabel;
@ -90,6 +135,11 @@ class qtype_ddimageortext_drop_zone {
$this->xy = array($x, $y);
}
/**
* Creates summary text of for the drop zone
*
* @return string
*/
public function summarise() {
if (trim($this->text) != '') {
$summariseplace =
@ -100,4 +150,4 @@ class qtype_ddimageortext_drop_zone {
}
return $summariseplace;
}
}
}

View file

@ -37,6 +37,11 @@ require_once($CFG->dirroot . '/question/type/gapselect/questiontypebase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddtoimage_base extends question_type {
/**
* Returns the choice group key.
*
* @return string
*/
protected function choice_group_key() {
return 'draggroup';
}
@ -145,8 +150,8 @@ class qtype_ddtoimage_base extends question_type {
* Convert files into text output in the given format.
* This method is copied from qformat_default as a quick fix, as the method there is
* protected.
* @param array
* @param string encoding method
* @param array $files
* @param int $indent Number of spaces to indent
* @return string $string
*/
public function write_files($files, $indent) {

View file

@ -129,6 +129,14 @@ class qtype_ddtoimage_renderer_base extends qtype_with_combined_feedback_rendere
return $output;
}
/**
* Returns the URL for an image
*
* @param object $qa Question attempt object
* @param string $filearea File area descriptor
* @param int $itemid Item id to get
* @return string Output url, or null if not found
*/
protected static function get_url_for_image(question_attempt $qa, $filearea, $itemid = 0) {
$question = $qa->get_question();
$qubaid = $qa->get_usage_id();
@ -154,6 +162,15 @@ class qtype_ddtoimage_renderer_base extends qtype_with_combined_feedback_rendere
return null;
}
/**
* Returns a hidden field for a qt variable
*
* @param object $qa Question attempt object
* @param string $varname The hidden var name
* @param string $value The hidden value
* @param array $classes Any additional css classes to apply
* @return array Array with field name and the html of the tag
*/
protected function hidden_field_for_qt_var(question_attempt $qa, $varname, $value = null,
$classes = null) {
if ($value === null) {

View file

@ -18,12 +18,10 @@
border: 1px solid black;
cursor: move;
background-color: #B0C4DE;
display: -moz-inline-stack;
display:inline-block;
height: auto;
width: auto;
zoom: 1;
*display: inline;
}
.que.ddimageortext .group1, form.mform fieldset#id_previewareaheader .group1 {
@ -78,19 +76,11 @@
.que.ddimageortext div.dragitems div.draghome, .que.ddimageortext div.dragitems div.drag,
form.mform fieldset#id_previewareaheader div.draghome, form.mform fieldset#id_previewareaheader div.drag {
font:13px/1.231 arial,helvetica,clean,sans-serif;
*font-size:small; /* for IE */
*font:x-small; /* for IE in quirks mode */
}
form.mform fieldset#id_previewareaheader div.drag.yui3-dd-dragging,
.que.ddimageortext div.drag.yui3-dd-dragging {
z-index: 3;
-moz-box-shadow: 3px 3px 4px #000;
-webkit-box-shadow: 3px 3px 4px #000;
box-shadow: 3px 3px 4px #000;
/* For IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')";
/* For IE 5.5 - 7 */
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
}
/* Editing form. Style repeated elements*/
/*Top*/

View file

@ -46,7 +46,7 @@ class behat_qtype_ddimageortext extends behat_base {
/**
* Get the xpath for a given drop box.
* @param string $dragitem the number of the drop box.
* @param string $placenumber the number of the drop box.
* @return string the xpath expression.
*/
protected function drop_xpath($placenumber) {

View file

@ -95,6 +95,8 @@ class qtype_ddimageortext_test_helper extends question_test_helper {
}
/**
* Make a mathematical ddimageortext question.
*
* @return qtype_ddimageortext_question
*/
public function make_ddimageortext_question_maths() {
@ -152,12 +154,15 @@ class qtype_ddimageortext_test_helper extends question_test_helper {
$fromform->name = 'Geography cross-section';
$fromform->questiontext = array(
'text' => '<p>Identify the features in this cross-section by dragging the labels into the boxes.</p>
<p><em>Use the mouse to drag the boxed words into the empty boxes. Alternatively, use the tab key to select an empty box, then use the space key to cycle through the options.</em></p>',
<p><em>Use the mouse to drag the boxed words into the empty boxes. '.
'Alternatively, use the tab key to select an empty box, '.
'then use the space key to cycle through the options.</em></p>',
'format' => FORMAT_HTML,
);
$fromform->defaultmark = 1;
$fromform->generalfeedback = array(
'text' => '<p>More information about the major features of the Earth\'s surface can be found in Block 3, Section 6.2.</p>',
'text' => '<p>More information about the major features of the Earth\'s surface '.
'can be found in Block 3, Section 6.2.</p>',
'format' => FORMAT_HTML,
);
$fromform->bgimage = $bgdraftitemid;
@ -197,7 +202,7 @@ class qtype_ddimageortext_test_helper extends question_test_helper {
test_question_maker::set_standard_combined_feedback_form_data($fromform);
$fromform->penalty ='0.3333333';
$fromform->penalty = '0.3333333';
$fromform->hint = array(
array(
'text' => '<p>Incorrect placements will be removed.</p>',
@ -205,10 +210,12 @@ class qtype_ddimageortext_test_helper extends question_test_helper {
),
array(
'text' => '<ul>
<li>The abyssal plain is a flat almost featureless expanse of ocean floor 4km to 6km below sea-level.</li>
<li>The abyssal plain is a flat almost featureless expanse of ocean '.
'floor 4km to 6km below sea-level.</li>
<li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
<li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
<li>The continental slope is the relatively steep part of the ocean floor beyond the continental shelf.</li>
<li>The continental slope is the relatively steep part of the ocean floor '.
'beyond the continental shelf.</li>
<li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
<li>A mountain belt is a long range of mountains.</li>
<li>An island arc is a chain of volcanic islands.</li>
@ -222,10 +229,12 @@ class qtype_ddimageortext_test_helper extends question_test_helper {
),
array(
'text' => '<ul>
<li>The abyssal plain is a flat almost featureless expanse of ocean floor 4km to 6km below sea-level.</li>
<li>The abyssal plain is a flat almost featureless expanse of ocean '.
'floor 4km to 6km below sea-level.</li>
<li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
<li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
<li>The continental slope is the relatively steep part of the ocean floor beyond the continental shelf.</li>
<li>The continental slope is the relatively steep part of the ocean floor '.
'beyond the continental shelf.</li>
<li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
<li>A mountain belt is a long range of mountains.</li>
<li>An island arc is a chain of volcanic islands.</li>

View file

@ -351,4 +351,3 @@ M.qtype_ddimageortext = M.qtype_ddimageortext || {};
M.qtype_ddimageortext.init_form = function(config) {
return new DDIMAGEORTEXT_FORM(config);
};

View file

@ -31,9 +31,9 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_qtype_ddmarker_plugin extends backup_qtype_plugin {
/**
* Get the name of this question type.
*
* @return string the question type, like 'ddmarker'.
*/
protected static function qtype_name() {

View file

@ -32,13 +32,19 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_qtype_ddmarker_plugin extends restore_qtype_plugin {
/**
* Returns the qtype name.
*
* @return string The type name
*/
protected static function qtype_name() {
return 'ddmarker';
}
/**
* Returns the paths to be handled by the plugin at question level.
*
* @return array
*/
protected function define_question_plugin_structure() {
@ -61,7 +67,9 @@ class restore_qtype_ddmarker_plugin extends restore_qtype_plugin {
}
/**
* Process the qtype/{qtypename} element
* Process the qtype/{qtypename} element.
*
* @param array|object $data Drag and drop data to work with.
*/
public function process_dds($data) {
global $DB;
@ -90,6 +98,8 @@ class restore_qtype_ddmarker_plugin extends restore_qtype_plugin {
/**
* Process the qtype/drags/drag element.
*
* @param array|object $data Drag and drop drag data to work with.
*/
public function process_drag($data) {
global $DB;
@ -115,7 +125,9 @@ class restore_qtype_ddmarker_plugin extends restore_qtype_plugin {
}
/**
* Process the qtype/drags/drag element.
* Process the qtype/drags/drop element.
*
* @param array|object $data Drag and drop drops data to work with.
*/
public function process_drop($data) {
global $DB;
@ -141,6 +153,8 @@ class restore_qtype_ddmarker_plugin extends restore_qtype_plugin {
/**
* Return the contents of this qtype to be processed by the links decoder
*
* @return array
*/
public static function define_decode_contents() {

View file

@ -39,7 +39,6 @@ define('QTYPE_DDMARKER_ALLOWED_TAGS_IN_MARKER', '<br><i><em><b><strong><sup><sub
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
public function qtype() {
return 'ddmarker';
}
@ -67,6 +66,7 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
array($params));
}
protected function definition_draggable_items($mform, $itemrepeatsatstart) {
$mform->addElement('header', 'draggableitemheader',
get_string('markers', 'qtype_ddmarker'));
@ -197,10 +197,14 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
return $question;
}
/**
* Perform the necessary preprocessing for the hint fields.
* @param object $question the data being passed to the form.
* @return object $question the modified data.
*
* @param object $question The data being passed to the form.
* @param bool $withclearwrong Clear wrong hints.
* @param bool $withshownumpartscorrect Show number correct.
* @return object The modified data.
*/
protected function data_preprocessing_hints($question, $withclearwrong = false,
$withshownumpartscorrect = false) {
@ -263,6 +267,12 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
return $errors;
}
/**
* Gets the width and height of a draft image.
*
* @param int $draftitemid ID of the draft image
* @return array Return array of the width and height of the draft image.
*/
public function get_image_size_in_draft_area($draftitemid) {
global $USER;
$usercontext = context_user::instance($USER->id);

View file

@ -26,7 +26,15 @@
defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for essay questions.
* Checks file access for ddmarker questions.
*
* @param object $course The course we are in
* @param object $cm Course module
* @param object $context The context object
* @param string $filearea the name of the file area.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @param array $options additional options affecting the file serving
*/
function qtype_ddmarker_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG;

View file

@ -55,7 +55,9 @@ class qtype_ddmarker_question extends qtype_ddtoimage_question_base {
}
}
/**
* @param int $key stem number
* Get a choice identifier
*
* @param int $choice stem number
* @return string the question-type variable name.
*/
public function choice($choice) {
@ -398,21 +400,47 @@ class qtype_ddmarker_question extends qtype_ddtoimage_question_base {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddmarker_drag_item {
/** @var string Label for the drag item */
public $text;
/** @var int Number of the item */
public $no;
/** @var int Group of the item */
public $infinite;
/** @var int Number of drags */
public $noofdrags;
/**
* Drag item object setup.
*
* @param string $label The label text of the drag item
* @param int $no Which number drag item this is
* @param bool $infinite True if the item can be used an unlimited number of times
* @param int $noofdrags
*/
public function __construct($label, $no, $infinite, $noofdrags) {
$this->text = $label;
$this->infinite = $infinite;
$this->no = $no;
$this->noofdrags = $noofdrags;
}
/**
* Returns the group of this item.
*
* @return int
*/
public function choice_group() {
return 1;
}
/**
* Creates summary text of for the drag item.
*
* @return string
*/
public function summarise() {
return $this->text;
}
@ -424,25 +452,55 @@ class qtype_ddmarker_drag_item {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddmarker_drop_zone {
/** @var int Group of the item */
public $group = 1;
/** @var int Number of the item */
public $no;
/** @var object Shape of the item */
public $shape;
/** @var array Location of the item */
public $coords;
/**
* Setup a drop zone object.
*
* @param int $no Which number drop zone this is
* @param int $shape Shape of the drop zone
* @param array $coords Coordinates of the zone
*/
public function __construct($no, $shape, $coords) {
$this->no = $no;
$this->shape = qtype_ddmarker_shape::create($shape, $coords);
$this->coords = $coords;
}
/**
* Creates summary text of for the drop zone
*
* @return string
*/
public function summarise() {
return get_string('summariseplaceno', 'qtype_ddmarker', $this->no);
}
/**
* Indicates if the it coordinates are in this drop zone.
*
* @param array $xy Array of X and Y location
* @return bool
*/
public function drop_hit($xy) {
return $this->shape->is_point_in_shape($xy);
}
/**
* Gets the center point of this zone
*
* @return array X and Y location
*/
public function correct_coords() {
return $this->shape->center_point();
}

View file

@ -17,11 +17,10 @@
/**
* Question type class for the drag-and-drop images onto images question type.
*
* @package qtype
* @subpackage ddmarker
* @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_ddmarker
* @copyright 2012 The Open University
* @author Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -33,6 +32,8 @@ define('QTYPE_DDMARKER_BGIMAGE_MAXWIDTH', 600);
define('QTYPE_DDMARKER_BGIMAGE_MAXHEIGHT', 400);
/**
* Question hint for ddmarker.
*
* An extension of {@link question_hint} for questions like match and multiple
* choice with multile answers, where there are options for whether to show the
* number of parts right at each stage, and to reset the wrong parts.

View file

@ -17,11 +17,10 @@
/**
* Drag-and-drop markers question renderer class.
*
* @package qtype
* @subpackage ddmarker
* @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_ddmarker
* @copyright 2012 The Open University
* @author Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View file

@ -31,9 +31,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class qtype_ddmarker_shape {
/** @var bool Indicates if there is an error */
protected $error = false;
/** @var string The shape class prefix */
protected static $classnameprefix = 'qtype_ddmarker_shape_';
public function __construct($coordsstring) {
}
@ -48,8 +51,18 @@ abstract class qtype_ddmarker_shape {
abstract protected function outlying_coords_to_test();
/**
* Returns the center location of the shape.
*
* @return array X and Y location
*/
abstract public function center_point();
/**
* Test if all passed parameters consist of only numbers.
*
* @return bool True if only numbers
*/
protected function is_only_numbers() {
$args = func_get_args();
foreach ($args as $arg) {
@ -60,6 +73,14 @@ abstract class qtype_ddmarker_shape {
return true;
}
/**
* Checks if the point is within the bounding box made by top left and bottom right
*
* @param array $pointxy Array of the point (x, y)
* @param array $xleftytop Top left point of bounding box
* @param array $xrightybottom Bottom left point of bounding box
* @return bool
*/
protected function is_point_in_bounding_box($pointxy, $xleftytop, $xrightybottom) {
if ($pointxy[0] <= $xleftytop[0]) {
return false;
@ -73,6 +94,11 @@ abstract class qtype_ddmarker_shape {
return true;
}
/**
* Gets any coordinate error
*
* @return string|bool String of the error or false if there is no error
*/
public function get_coords_interpreter_error() {
if ($this->error) {
$a = new stdClass();
@ -85,17 +111,28 @@ abstract class qtype_ddmarker_shape {
}
/**
* Check if the location is within the shape.
*
* @param array $xy $xy[0] is x, $xy[1] is y
* @return boolean is point inside shape
*/
abstract public function is_point_in_shape($xy);
/**
* Returns the name of the shape.
*
* @return string
*/
public static function name() {
return substr(get_called_class(), strlen(self::$classnameprefix));
}
protected static $classnameprefix = 'qtype_ddmarker_shape_';
/**
* Return a human readable name of the shape.
*
* @param bool $lowercase True if it should be lowercase.
* @return string
*/
public static function human_readable_name($lowercase = false) {
$stringid = 'shape_'.self::name();
if ($lowercase) {
@ -119,9 +156,24 @@ abstract class qtype_ddmarker_shape {
asort($shapearray);
return $shapearray;
}
/**
* Checks if the passed shape exists.
*
* @param string $shape The shape name
* @return bool
*/
public static function exists($shape) {
return class_exists((self::$classnameprefix).$shape);
}
/**
* Creates a new shape of the specified type.
*
* @param string $shape The shape to create
* @param string $coordsstring The string describing the coordinates
* @return object
*/
public static function create($shape, $coordsstring) {
$classname = (self::$classnameprefix).$shape;
return new $classname($coordsstring);
@ -136,9 +188,16 @@ abstract class qtype_ddmarker_shape {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddmarker_shape_rectangle extends qtype_ddmarker_shape {
/** @var int Width of shape */
protected $width;
/** @var int Height of shape */
protected $height;
/** @var int Left location */
protected $xleft;
/** @var int Top location */
protected $ytop;
public function __construct($coordsstring) {
@ -196,9 +255,13 @@ class qtype_ddmarker_shape_rectangle extends qtype_ddmarker_shape {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddmarker_shape_circle extends qtype_ddmarker_shape {
/** @var int X center */
protected $xcentre;
/** @var int Y center */
protected $ycentre;
/** @var int Radius of circle */
protected $radius;
public function __construct($coordsstring) {
@ -415,7 +478,10 @@ class qtype_ddmarker_shape_polygon extends qtype_ddmarker_shape {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddmarker_point {
/** @var int X location */
public $x;
/** @var int Y location */
public $y;
public function __construct($x, $y) {
$this->x = $x;
@ -438,7 +504,10 @@ class qtype_ddmarker_point {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddmarker_segment {
/** @var object First point */
public $a;
/** @var object Second point */
public $b;
public function __construct(qtype_ddmarker_point $a, qtype_ddmarker_point $b) {

View file

@ -78,8 +78,6 @@ form.mform fieldset#id_previewareaheader div.markertexts span.markertext {
}
.que.ddmarker .dragitem.yui3-dd-dragging span.markertext {
z-index: 3;
-moz-box-shadow: 3px 3px 4px #000;
-webkit-box-shadow: 3px 3px 4px #000;
box-shadow: 3px 3px 4px #000;
}
#page-question-type-ddmarker .ddarea .grid {

View file

@ -17,11 +17,10 @@
/**
* Test helpers for the drag-and-drop markers question type.
*
* @package qtype
* @subpackage ddmarker
* @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_ddmarker
* @copyright 2012 The Open University
* @author Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -152,12 +151,14 @@ class qtype_ddmarker_test_helper extends question_test_helper {
$fromform->name = 'Milton Keynes landmarks';
$fromform->questiontext = array(
'text' => 'Please place the markers on the map of Milton Keynes and be aware that there is more than one railway station.',
'text' => 'Please place the markers on the map of Milton Keynes and be aware that '.
'there is more than one railway station.',
'format' => FORMAT_HTML,
);
$fromform->defaultmark = 1;
$fromform->generalfeedback = array(
'text' => 'The Open University is at the junction of Brickhill Street and Groveway. There are three railway stations, Wolverton, Milton Keynes Central and Bletchley.',
'text' => 'The Open University is at the junction of Brickhill Street and Groveway. '.
'There are three railway stations, Wolverton, Milton Keynes Central and Bletchley.',
'format' => FORMAT_HTML,
);
$fromform->bgimage = $bgdraftitemid;
@ -177,7 +178,7 @@ class qtype_ddmarker_test_helper extends question_test_helper {
test_question_maker::set_standard_combined_feedback_form_data($fromform);
$fromform->penalty ='0.3333333';
$fromform->penalty = '0.3333333';
$fromform->hint = array(
array(
'text' => 'You are trying to place four markers on the map.',

View file

@ -58,7 +58,8 @@ class qtype_ddmarker_shapes_test extends basic_testcase {
}
public function test_polygon_valdiation_test_repeated_point() {
$shape = new qtype_ddmarker_shape_polygon('70,220;90,200;95,150;120,150;140,200;150,230;150,230;150,240;120,240;110,240;90,240');
$shape = new qtype_ddmarker_shape_polygon('70,220;90,200;95,150;120,150;140,200;150,230;'.
'150,230;150,240;120,240;110,240;90,240');
$this->assertEquals(get_string('formerror_repeatedpoint', 'qtype_ddmarker',
array('shape' => 'polygon', 'coordsstring' => get_string('shape_polygon_coords', 'qtype_ddmarker'))),
$shape->get_coords_interpreter_error());

View file

@ -15,6 +15,8 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Backup code for ddwtos.
*
* @package qtype_ddwtos
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

View file

@ -15,6 +15,8 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore code for qtype_ddwtos.
*
* @package qtype_ddwtos
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@ -25,8 +27,7 @@ defined('MOODLE_INTERNAL') || die();
/**
* restore plugin class that provides the necessary information
* needed to restore one ddwtos qtype plugin.
* Restore plugin class that provides the necessary information needed to restore one ddwtos qtype plugin.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@ -35,6 +36,8 @@ class restore_qtype_ddwtos_plugin extends restore_qtype_plugin {
/**
* Returns the paths to be handled by the plugin at question level.
*
* @return array
*/
protected function define_question_plugin_structure() {
@ -53,6 +56,8 @@ class restore_qtype_ddwtos_plugin extends restore_qtype_plugin {
/**
* Process the qtype/ddwtos element.
*
* @param array|object $data ddwtos object to work with.
*/
public function process_ddwtos($data) {
global $DB;
@ -78,6 +83,8 @@ class restore_qtype_ddwtos_plugin extends restore_qtype_plugin {
/**
* Return the contents of this qtype to be processed by the links decoder.
*
* @return array
*/
public static function define_decode_contents() {

View file

@ -17,10 +17,9 @@
/**
* Defines the editing form for the drag-and-drop words into sentences question type.
*
* @package qtype
* @subpackage ddwtos
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_ddwtos
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View file

@ -15,6 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Lang file for ddwtos.
*
* @package qtype_ddwtos
* @copyright 2011 The Open University

View file

@ -17,18 +17,25 @@
/**
* Serve question type files
*
* @package qtype
* @subpackage ddwtos
* @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_ddwtos
* @copyright 2012 The Open University
* @author Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for essay questions.
* Checks file access for ddwtos questions.
*
* @param object $course The course we are in
* @param object $cm Course module
* @param object $context The context object
* @param string $filearea the name of the file area.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @param array $options additional options affecting the file serving
*/
function qtype_ddwtos_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG;

View file

@ -17,10 +17,9 @@
/**
* Drag-and-drop words into sentences question definition class.
*
* @package qtype
* @subpackage ddwtos
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_ddwtos
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -50,16 +49,33 @@ class qtype_ddwtos_question extends qtype_gapselect_question_base {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddwtos_choice {
/** @var string Text for the choice */
public $text;
/** @var int Group of the choice */
public $draggroup;
/** @var bool If the choice can be used an unlimited number of times */
public $infinite;
/**
* Initialize a choice object.
*
* @param string $text The text of the choice
* @param int $draggroup Group of the drop choice
* @param bool $infinite True if the item can be used an unlimited number of times
*/
public function __construct($text, $draggroup = 1, $infinite = false) {
$this->text = $text;
$this->draggroup = $draggroup;
$this->infinite = $infinite;
}
/**
* Returns the group of this item.
*
* @return int
*/
public function choice_group() {
return $this->draggroup;
}

View file

@ -17,10 +17,9 @@
/**
* Question type class for the drag-and-drop words into sentences question type.
*
* @package qtype
* @subpackage ddwtos
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_ddwtos
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View file

@ -17,10 +17,9 @@
/**
* Drag-and-drop words into sentences question renderer class.
*
* @package qtype
* @subpackage ddwtos
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_ddwtos
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View file

@ -33,13 +33,7 @@
}
.que.ddwtos .drag.yui3-dd-dragging {
z-index: 3;
-moz-box-shadow: 3px 3px 4px #000;
-webkit-box-shadow: 3px 3px 4px #000;
box-shadow: 3px 3px 4px #000;
/* For IE 5.5 - 7 */
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
/* For IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')";
}
.que.ddwtos .drop.yui3-dd-drop-over.yui3-dd-drop-active-valid {

View file

@ -17,10 +17,9 @@
/**
* Test helpers for the drag-and-drop words into sentences question type.
*
* @package qtype
* @subpackage ddwtos
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_ddwtos
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View file

@ -54,6 +54,8 @@ class qtype_ddwtos_test extends question_testcase {
}
/**
* Get some test question data.
*
* @return object the data to construct a question like
* {@link qtype_ddwtos_test_helper::make_ddwtos_question_fox()}.
*/

View file

@ -35,6 +35,8 @@ class restore_qtype_gapselect_plugin extends restore_qtype_plugin {
/**
* Returns the paths to be handled by the plugin at question level.
*
* @return array
*/
protected function define_question_plugin_structure() {
@ -54,6 +56,8 @@ class restore_qtype_gapselect_plugin extends restore_qtype_plugin {
/**
* Process the qtype/gapselect element
*
* @param array|object $data gapselect object to work with.
*/
public function process_gapselect($data) {
global $DB;
@ -79,6 +83,8 @@ class restore_qtype_gapselect_plugin extends restore_qtype_plugin {
/**
* Return the contents of this qtype to be processed by the links decoder
*
* @return array
*/
public static function define_decode_contents() {

View file

@ -32,7 +32,9 @@ 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. */
/**
* 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. */
@ -82,6 +84,12 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
return '';
}
/**
* Returns a message indicating what tags are allowed.
*
* @param string $badtag The disallowed tag that was supplied
* @return string Message indicating what tags are allowed
*/
private function allowed_tags_message($badtag) {
$a = new stdClass();
$a->tag = htmlspecialchars($badtag);
@ -93,6 +101,12 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
}
}
/**
* Returns a prinatble list of allowed HTML tags.
*
* @param array $allowedhtmltags An array for tag strings that are allowed
* @return string A printable list of tags
*/
private function get_list_of_printable_allowed_tags($allowedhtmltags) {
$allowedtaglist = array();
foreach ($allowedhtmltags as $htmltag) {
@ -115,6 +129,11 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
$this->add_interactive_settings(true, true);
}
/**
* Defines form elements for answer choices.
*
* @param object $mform The Moodle form object being built
*/
protected function definition_answer_choice(&$mform) {
$mform->addElement('header', 'choicehdr', get_string('choices', 'qtype_gapselect'));
$mform->setExpanded('choicehdr', 1);
@ -147,6 +166,12 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
get_string('addmorechoiceblanks', 'qtype_gapselect'), true);
}
/**
* Creates an array with elements for a choice group.
*
* @param object $mform The Moodle form we are working with
* @return array Array for form elements
*/
protected function choice_group($mform) {
$options = array();
for ($i = 1; $i <= self::MAX_GROUPS; $i += 1) {
@ -160,6 +185,11 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
return $grouparray;
}
/**
* Returns an array for form repeat options.
*
* @return array Array of repeate options
*/
protected function repeated_options() {
$repeatedoptions = array();
$repeatedoptions['choicegroup']['default'] = '1';
@ -218,6 +248,13 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
return $errors;
}
/**
* Finds errors in question slots.
*
* @param string $questiontext The question text
* @param array $choices Question choices
* @return string|bool Error message or false if no errors
*/
private function validate_slots($questiontext, $choices) {
$error = 'Please check the Question text: ';
if (!$questiontext) {

View file

@ -46,14 +46,28 @@ class qtype_gapselect_question extends qtype_gapselect_question_base {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_gapselect_choice {
/** @var string Text for the choice */
public $text;
/** @var int Selection group of the choice */
public $selectgroup;
/**
* Creates summary text of for the drag item.
*
* @param string $text The text of the choice
* @param int $selectgroup The select group of the choice
*/
public function __construct($text, $selectgroup = 1) {
$this->text = $text;
$this->selectgroup = $selectgroup;
}
/**
* Returns the group of this item.
*
* @return int
*/
public function choice_group() {
return $this->selectgroup;
}

View file

@ -214,6 +214,7 @@ abstract class qtype_gapselect_base extends question_type {
* in a 2 dimentional array.
*
* @param object $question
* @param object $state Question state object
* @return array of groups
*/
protected function get_array_of_groups($question, $state) {