weekly release 4.5dev
[moodle.git] / question / type / ddimageortext / question.php
blob94c2f861b554d29482a8edd0c94500c64f4bee7a
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
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');
31 /**
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 {
42 /**
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 */
50 public $id;
52 /** @var string Text for the drag item */
53 public $text;
55 /** @var int Number of the item */
56 public $no;
58 /** @var int Group of the item */
59 public $group;
61 /** @var bool If the drag item can be used multiple times or not */
62 public $infinite;
64 /**
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) {
74 $this->id = $id;
75 $this->text = $alttextlabel;
76 $this->no = $no;
77 $this->group = $group;
78 $this->infinite = $infinite;
81 /**
82 * Returns the group of this item.
84 * @return int
86 public function choice_group() {
87 return $this->group;
90 /**
91 * Creates summary text of for the drag item.
93 * @return string
95 public function summarise() {
96 if (trim($this->text) != '') {
97 return get_string('summarisechoice', 'qtype_ddimageortext', $this);
98 } else {
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 */
111 public $no;
113 /** @var string Alt text for the drop zone item */
114 public $text;
116 /** @var int Group of the item */
117 public $group;
119 /** @var array X and Y location of the drop zone */
120 public $xy;
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 = '') {
132 $this->no = $no;
133 $this->text = $alttextlabel;
134 $this->group = $group;
135 $this->xy = array($x, $y);
139 * Creates summary text of for the drop zone
141 * @return string
143 public function summarise() {
144 if (trim($this->text) != '') {
145 $summariseplace =
146 get_string('summariseplace', 'qtype_ddimageortext', $this);
147 } else {
148 $summariseplace =
149 get_string('summariseplaceno', 'qtype_ddimageortext', $this->no);
151 return $summariseplace;