2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Drag-and-drop onto image question definition class.
20 * @package qtype_ddimageortext
21 * @copyright 2009 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die();
28 require_once($CFG->dirroot
. '/question/type/ddimageortext/questionbase.php');
32 * Represents a drag-and-drop onto image question.
34 * @copyright 2009 The Open University
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class qtype_ddimageortext_question
extends qtype_ddtoimage_question_base
{
43 * Represents one of the choices (draggable images).
45 * @copyright 2009 The Open University
46 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
48 class qtype_ddimageortext_drag_item
{
49 /** @var int Drag item id */
52 /** @var string Text for the drag item */
55 /** @var int Number of the item */
58 /** @var int Group of the item */
61 /** @var bool If the drag item can be used multiple times or not */
65 * Drag item object setup.
67 * @param string $alttextlabel The alt text of the drag item
68 * @param int $no Which number drag item this is
69 * @param int $group Group of the drag item
70 * @param bool $infinite True if the item can be used an unlimited number of times
71 * @param int $id id of the item
73 public function __construct($alttextlabel, $no, $group = 1, $infinite = false, $id = 0) {
75 $this->text
= $alttextlabel;
77 $this->group
= $group;
78 $this->infinite
= $infinite;
82 * Returns the group of this item.
86 public function choice_group() {
91 * Creates summary text of for the drag item.
95 public function summarise() {
96 if (trim($this->text
) != '') {
97 return get_string('summarisechoice', 'qtype_ddimageortext', $this);
99 return get_string('summarisechoiceno', 'qtype_ddimageortext', $this->no
);
104 * Represents one of the places (drop zones).
106 * @copyright 2009 The Open University
107 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
109 class qtype_ddimageortext_drop_zone
{
110 /** @var int Number of the item */
113 /** @var string Alt text for the drop zone item */
116 /** @var int Group of the item */
119 /** @var array X and Y location of the drop zone */
123 * Create a drop zone object.
125 * @param string $alttextlabel The alt text of the drop zone
126 * @param int $no Which number drop zone this is
127 * @param int $group Group of the drop zone
128 * @param int $x X location
129 * @param int $y Y location
131 public function __construct($alttextlabel, $no, $group = 1, $x = '', $y = '') {
133 $this->text
= $alttextlabel;
134 $this->group
= $group;
135 $this->xy
= array($x, $y);
139 * Creates summary text of for the drop zone
143 public function summarise() {
144 if (trim($this->text
) != '') {
146 get_string('summariseplace', 'qtype_ddimageortext', $this);
149 get_string('summariseplaceno', 'qtype_ddimageortext', $this->no
);
151 return $summariseplace;