Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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.
  13  //
  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/>.
  16  
  17  /**
  18   * Drag-and-drop onto image question definition class.
  19   *
  20   * @package    qtype_ddimageortext
  21   * @copyright  2009 The Open University
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once($CFG->dirroot . '/question/type/ddimageortext/questionbase.php');
  29  
  30  
  31  /**
  32   * Represents a drag-and-drop onto image question.
  33   *
  34   * @copyright  2009 The Open University
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class qtype_ddimageortext_question extends qtype_ddtoimage_question_base {
  38  
  39  }
  40  
  41  
  42  /**
  43   * Represents one of the choices (draggable images).
  44   *
  45   * @copyright  2009 The Open University
  46   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  47   */
  48  class qtype_ddimageortext_drag_item {
  49      /** @var int Drag item id */
  50      public $id;
  51  
  52      /** @var string Text for the drag item */
  53      public $text;
  54  
  55      /** @var int Number of the item */
  56      public $no;
  57  
  58      /** @var int Group of the item */
  59      public $group;
  60  
  61      /** @var bool If the drag item can be used multiple times or not */
  62      public $infinite;
  63  
  64      /**
  65       * Drag item object setup.
  66       *
  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
  72       */
  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;
  79      }
  80  
  81      /**
  82       * Returns the group of this item.
  83       *
  84       * @return int
  85       */
  86      public function choice_group() {
  87          return $this->group;
  88      }
  89  
  90      /**
  91       * Creates summary text of for the drag item.
  92       *
  93       * @return string
  94       */
  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);
 100          }
 101      }
 102  }
 103  /**
 104   * Represents one of the places (drop zones).
 105   *
 106   * @copyright  2009 The Open University
 107   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 108   */
 109  class qtype_ddimageortext_drop_zone {
 110      /** @var int Number of the item */
 111      public $no;
 112  
 113      /** @var string Alt text for the drop zone item */
 114      public $text;
 115  
 116      /** @var int Group of the item */
 117      public $group;
 118  
 119      /** @var array X and Y location of the drop zone */
 120      public $xy;
 121  
 122      /**
 123       * Create a drop zone object.
 124       *
 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
 130       */
 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);
 136      }
 137  
 138      /**
 139       * Creates summary text of for the drop zone
 140       *
 141       * @return string
 142       */
 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);
 150          }
 151          return $summariseplace;
 152      }
 153  }