Commit 8bc1d28b authored by Eric Merrill's avatar Eric Merrill Committed by Tim Hunt
Browse files

MDL-47494 question General code cleanup

Remove old browser CSS.
Fix code style problems.
Add many PHPdocs.
Set @package uniformly.
parent 031152cc
...@@ -31,9 +31,9 @@ defined('MOODLE_INTERNAL') || die(); ...@@ -31,9 +31,9 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class backup_qtype_ddimageortext_plugin extends backup_qtype_plugin { class backup_qtype_ddimageortext_plugin extends backup_qtype_plugin {
/** /**
* Returns the question type this is. * Returns the question type this is.
*
* @return string question type name, like 'ddimageortext'. * @return string question type name, like 'ddimageortext'.
*/ */
protected static function qtype_name() { protected static function qtype_name() {
......
...@@ -30,13 +30,19 @@ defined('MOODLE_INTERNAL') || die(); ...@@ -30,13 +30,19 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin { class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin {
/**
* Returns the qtype name.
*
* @return string The type name
*/
protected static function qtype_name() { protected static function qtype_name() {
return 'ddimageortext'; return 'ddimageortext';
} }
/** /**
* Returns the paths to be handled by the plugin at question level. * Returns the paths to be handled by the plugin at question level.
*
* @return array
*/ */
protected function define_question_plugin_structure() { protected function define_question_plugin_structure() {
...@@ -60,6 +66,8 @@ class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin { ...@@ -60,6 +66,8 @@ class restore_qtype_ddimageortext_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) { public function process_dds($data) {
global $DB; global $DB;
...@@ -88,6 +96,8 @@ class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin { ...@@ -88,6 +96,8 @@ class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin {
/** /**
* Process the qtype/drags/drag element. * Process the qtype/drags/drag element.
*
* @param array|object $data Drag and drop drag data to work with.
*/ */
public function process_drag($data) { public function process_drag($data) {
global $DB; global $DB;
...@@ -113,7 +123,9 @@ class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin { ...@@ -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) { public function process_drop($data) {
global $DB; global $DB;
...@@ -136,8 +148,11 @@ class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin { ...@@ -136,8 +148,11 @@ class restore_qtype_ddimageortext_plugin extends restore_qtype_plugin {
$this->set_mapping("{$prefix}_drops", $oldid, $newitemid); $this->set_mapping("{$prefix}_drops", $oldid, $newitemid);
} }
} }
/** /**
* Return the contents of this qtype to be processed by the links decoder. * Return the contents of this qtype to be processed by the links decoder.
*
* @return array
*/ */
public static function define_decode_contents() { public static function define_decode_contents() {
......
...@@ -35,7 +35,6 @@ require_once($CFG->dirroot . '/question/type/ddimageortext/edit_ddtoimage_form_b ...@@ -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 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class qtype_ddimageortext_edit_form extends qtype_ddtoimage_edit_form_base { class qtype_ddimageortext_edit_form extends qtype_ddtoimage_edit_form_base {
public function qtype() { public function qtype() {
return 'ddimageortext'; return 'ddimageortext';
} }
......
...@@ -17,10 +17,9 @@ ...@@ -17,10 +17,9 @@
/** /**
* Base class for editing form for the drag-and-drop images onto images question type. * Base class for editing form for the drag-and-drop images onto images question type.
* *
* @package qtype * @package qtype_ddimageortext
* @subpackage ddimageortext * @copyright 2011 The Open University
* @copyright 2011 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
...@@ -32,13 +31,25 @@ 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 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
abstract class qtype_ddtoimage_edit_form_base extends question_edit_form { 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; const MAX_GROUPS = 8;
/**
* The default starting number of drop zones.
*/
const START_NUM_ITEMS = 6; const START_NUM_ITEMS = 6;
/**
* The number of drop zones that get added at a time.
*/
const ADD_NUM_ITEMS = 3; const ADD_NUM_ITEMS = 3;
/** /**
*
* Options shared by all file pickers in the form. * Options shared by all file pickers in the form.
*
* @return array Array of filepicker options.
*/ */
public static function file_picker_options() { public static function file_picker_options() {
$filepickeroptions = array(); $filepickeroptions = array();
...@@ -51,6 +62,7 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form { ...@@ -51,6 +62,7 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
/** /**
* definition_inner adds all specific fields to the form. * definition_inner adds all specific fields to the form.
*
* @param MoodleQuickForm $mform (the form being built). * @param MoodleQuickForm $mform (the form being built).
*/ */
protected function definition_inner($mform) { protected function definition_inner($mform) {
...@@ -76,9 +88,14 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form { ...@@ -76,9 +88,14 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
$this->add_interactive_settings(true, true); $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) { protected function definition_drop_zones($mform, $imagerepeats) {
$mform->addElement('header', 'dropzoneheader', $mform->addElement('header', 'dropzoneheader', get_string('dropzoneheader', 'qtype_'.$this->qtype()));
get_string('dropzoneheader', 'qtype_'.$this->qtype()));
$countdropzones = 0; $countdropzones = 0;
if (isset($this->question->id)) { if (isset($this->question->id)) {
...@@ -97,16 +114,51 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form { ...@@ -97,16 +114,51 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
'nodropzone', 'adddropzone', self::ADD_NUM_ITEMS, 'nodropzone', 'adddropzone', self::ADD_NUM_ITEMS,
get_string('addmoredropzones', 'qtype_ddimageortext'), true); 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); 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(); 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); 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); abstract protected function draggable_item($mform);
/**
* Returns an array of default repeat options.
*
* @return array
*/
abstract protected function draggable_items_repeated_options(); 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() { protected function get_drag_item_repeats() {
$countimages = 0; $countimages = 0;
if (isset($this->question->id)) { if (isset($this->question->id)) {
...@@ -128,8 +180,17 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form { ...@@ -128,8 +180,17 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
return array($itemrepeatsatstart, $imagerepeats); return array($itemrepeatsatstart, $imagerepeats);
} }
/**
* Performce the needed JS setup for this question type.
*/
abstract public function js_call(); 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) { public static function file_uploaded($draftitemid) {
$draftareafiles = file_get_drafarea_files($draftitemid); $draftareafiles = file_get_drafarea_files($draftitemid);
do { do {
...@@ -141,5 +202,4 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form { ...@@ -141,5 +202,4 @@ abstract class qtype_ddtoimage_edit_form_base extends question_edit_form {
return true; return true;
} }
} }
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Language file Drag and Drop image or text.
* *
* @package qtype * @package qtype_ddimageortext
* @subpackage ddimageortext * @copyright 2011 The Open University
* @copyright 2011 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
$string['addmoredropzones'] = 'Blanks for {no} more drop zones'; $string['addmoredropzones'] = 'Blanks for {no} more drop zones';
...@@ -67,4 +67,4 @@ $string['summariseplace'] = '{$a->no}. {$a->text}'; ...@@ -67,4 +67,4 @@ $string['summariseplace'] = '{$a->no}. {$a->text}';
$string['summarisechoiceno'] = 'Item {$a}'; $string['summarisechoiceno'] = 'Item {$a}';
$string['summariseplaceno'] = 'Drop zone {$a}'; $string['summariseplaceno'] = 'Drop zone {$a}';
$string['xleft'] = 'Left'; $string['xleft'] = 'Left';
$string['ytop'] = 'Top'; $string['ytop'] = 'Top';
\ No newline at end of file
...@@ -17,10 +17,9 @@ ...@@ -17,10 +17,9 @@
/** /**
* Serve question type files * Serve question type files
* *
* @package qtype * @package qtype_ddimageortext
* @subpackage ddimageortext * @copyright Dongsheng Cai <dongsheng@moodle.com>
* @copyright Dongsheng Cai <dongsheng@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
...@@ -29,10 +28,17 @@ defined('MOODLE_INTERNAL') || die(); ...@@ -29,10 +28,17 @@ defined('MOODLE_INTERNAL') || die();
/** /**
* Checks file access for ddimageortext questions. * 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()) { function qtype_ddimageortext_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG; global $CFG;
require_once($CFG->libdir . '/questionlib.php'); require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_ddimageortext', question_pluginfile($course, $context, 'qtype_ddimageortext', $filearea, $args, $forcedownload, $options);
$filearea, $args, $forcedownload, $options);
} }
...@@ -46,12 +46,30 @@ class qtype_ddimageortext_question extends qtype_ddtoimage_question_base { ...@@ -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 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class qtype_ddimageortext_drag_item { class qtype_ddimageortext_drag_item {
/** @var int Drag item id */
public $id; public $id;
/** @var string Text for the drag item */
public $text; public $text;
/** @var int Number of the item */
public $no; public $no;
/** @var int Group of the item */
public $group; public $group;
/** @var bool If the drag item can be used multiple times or not */
public $infinite; 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) { public function __construct($alttextlabel, $no, $group = 1, $infinite = false, $id = 0) {
$this->id = $id; $this->id = $id;
$this->text = $alttextlabel; $this->text = $alttextlabel;
...@@ -59,10 +77,21 @@ class qtype_ddimageortext_drag_item { ...@@ -59,10 +77,21 @@ class qtype_ddimageortext_drag_item {
$this->group = $group; $this->group = $group;
$this->infinite = $infinite; $this->infinite = $infinite;
} }
/**
* Returns the group of this item.
*
* @return int
*/
public function choice_group() { public function choice_group() {
return $this->group; return $this->group;
} }
/**
* Creates summary text of for the drag item.
*
* @return string
*/
public function summarise() { public function summarise() {
if (trim($this->text) != '') { if (trim($this->text) != '') {
return get_string('summarisechoice', 'qtype_ddimageortext', $this); return get_string('summarisechoice', 'qtype_ddimageortext', $this);
...@@ -78,11 +107,27 @@ class qtype_ddimageortext_drag_item { ...@@ -78,11 +107,27 @@ class qtype_ddimageortext_drag_item {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class qtype_ddimageortext_drop_zone { class qtype_ddimageortext_drop_zone {
/** @var int Number of the item */
public $no; public $no;
/** @var string Alt text for the drop zone item */
public $text; public $text;
/** @var int Group of the item */
public $group; public $group;
/** @var array X and Y location of the drop zone */
public $xy; 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 = '') { public function __construct($alttextlabel, $no, $group = 1, $x = '', $y = '') {
$this->no = $no; $this->no = $no;
$this->text = $alttextlabel; $this->text = $alttextlabel;
...@@ -90,6 +135,11 @@ class qtype_ddimageortext_drop_zone { ...@@ -90,6 +135,11 @@ class qtype_ddimageortext_drop_zone {
$this->xy = array($x, $y); $this->xy = array($x, $y);
} }
/**
* Creates summary text of for the drop zone
*
* @return string
*/
public function summarise() { public function summarise() {
if (trim($this->text) != '') { if (trim($this->text) != '') {
$summariseplace = $summariseplace =
...@@ -100,4 +150,4 @@ class qtype_ddimageortext_drop_zone { ...@@ -100,4 +150,4 @@ class qtype_ddimageortext_drop_zone {
} }
return $summariseplace; return $summariseplace;
} }
} }
\ No newline at end of file
...@@ -37,6 +37,11 @@ require_once($CFG->dirroot . '/question/type/gapselect/questiontypebase.php'); ...@@ -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 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class qtype_ddtoimage_base extends question_type { class qtype_ddtoimage_base extends question_type {
/**
* Returns the choice group key.
*
* @return string
*/
protected function choice_group_key() { protected function choice_group_key() {
return 'draggroup'; return 'draggroup';
} }
...@@ -145,8 +150,8 @@ class qtype_ddtoimage_base extends question_type { ...@@ -145,8 +150,8 @@ class qtype_ddtoimage_base extends question_type {
* Convert files into text output in the given format. * 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 * This method is copied from qformat_default as a quick fix, as the method there is
* protected. * protected.
* @param array * @param array $files
* @param string encoding method * @param int $indent Number of spaces to indent
* @return string $string * @return string $string
*/ */
public function write_files($files, $indent) { public function write_files($files, $indent) {
......
...@@ -129,6 +129,14 @@ class qtype_ddtoimage_renderer_base extends qtype_with_combined_feedback_rendere ...@@ -129,6 +129,14 @@ class qtype_ddtoimage_renderer_base extends qtype_with_combined_feedback_rendere
return $output; 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) { protected static function get_url_for_image(question_attempt $qa, $filearea, $itemid = 0) {
$question = $qa->get_question(); $question = $qa->get_question();
$qubaid = $qa->get_usage_id(); $qubaid = $qa->get_usage_id();
...@@ -154,6 +162,15 @@ class qtype_ddtoimage_renderer_base extends qtype_with_combined_feedback_rendere ...@@ -154,6 +162,15 @@ class qtype_ddtoimage_renderer_base extends qtype_with_combined_feedback_rendere
return null; 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, protected function hidden_field_for_qt_var(question_attempt $qa, $varname, $value = null,
$classes = null) { $classes = null) {
if ($value === null) { if ($value === null) {
......
...@@ -18,12 +18,10 @@ ...@@ -18,12 +18,10 @@
border: 1px solid black; border: 1px solid black;
cursor: move; cursor: move;
background-color: #B0C4DE; background-color: #B0C4DE;
display: -moz-inline-stack;
display:inline-block; display:inline-block;
height: auto; height: auto;
width: auto; width: auto;
zoom: 1; zoom: 1;
*display: inline;
} }
.que.ddimageortext .group1, form.mform fieldset#id_previewareaheader .group1 { .que.ddimageortext .group1, form.mform fieldset#id_previewareaheader .group1 {
...@@ -78,19 +76,11 @@ ...@@ -78,19 +76,11 @@