ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
assClozeGap Class Reference

Class for cloze question gaps. More...

+ Inheritance diagram for assClozeGap:
+ Collaboration diagram for assClozeGap:

Public Member Functions

 __construct ($a_type)
 assClozeGap constructor More...
 
 getType ()
 Gets the cloze gap type. More...
 
 setType ($a_type=0)
 Sets the cloze gap type. More...
 
 getItems (ilArrayElementShuffler $shuffler)
 Gets the items of a cloze gap. More...
 
 getItemsRaw ()
 Gets the items of a cloze gap. More...
 
 getItemCount ()
 Gets the item count. More...
 
 addItem ($a_item)
 Adds a gap item. More...
 
 setItemPoints ($order, $points)
 Sets the points for a given item. More...
 
 deleteItem ($order)
 Deletes an item at a given index. More...
 
 setItemLowerBound ($order, $bound)
 Sets the lower bound for a given item. More...
 
 setItemUpperBound ($order, $bound)
 Sets the upper bound for a given item. More...
 
 getItem ($a_index)
 Gets the item with a given index. More...
 
 clearItems ()
 Removes all gap items. More...
 
 setShuffle ($a_shuffle=true)
 Sets the shuffle state of the items. More...
 
 getShuffle ()
 Gets the shuffle state of the items. More...
 
 getMaxWidth ()
 Returns the maximum width of the gap. More...
 
 getBestSolutionIndexes ()
 Returns the indexes of the best solutions for the gap. More...
 
 getBestSolutionOutput (ilArrayElementShuffler $shuffler, $combinations=null)
 
 setGapSize ($gap_size)
 
 getGapSize ()
 

Data Fields

 $type
 Type of gap. More...
 
 $items
 
 $shuffle
 

Private Attributes

 $gap_size = 0
 

Detailed Description

Class for cloze question gaps.

assClozeGap is a class for the abstraction of cloze gaps. It represents a text gap.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 18 of file class.assClozeGap.php.

Constructor & Destructor Documentation

◆ __construct()

assClozeGap::__construct (   $a_type)

assClozeGap constructor

Parameters
int$a_type

Definition at line 55 of file class.assClozeGap.php.

56 {
57 $this->type = $a_type;
58 $this->items = array();
59 $this->shuffle = true;
60 }
$a_type
Definition: workflow.php:92

References $a_type.

Member Function Documentation

◆ addItem()

assClozeGap::addItem (   $a_item)

Adds a gap item.

Adds a gap item

Parameters
object$a_itemCloze gap item @access public
See also
$items

Definition at line 140 of file class.assClozeGap.php.

141 {
142 $order = $a_item->getOrder();
143 if (array_key_exists($order, $this->items)) {
144 $newitems = array();
145 for ($i = 0; $i < $order; $i++) {
146 array_push($newitems, $this->items[$i]);
147 }
148 array_push($newitems, $a_item);
149 for ($i = $order; $i < count($this->items); $i++) {
150 array_push($newitems, $this->items[$i]);
151 }
152 $i = 0;
153 foreach ($newitems as $idx => $item) {
154 $newitems[$idx]->setOrder($i);
155 $i++;
156 }
157 $this->items = $newitems;
158 } else {
159 array_push($this->items, $a_item);
160 }
161 }
$i
Definition: disco.tpl.php:19

References $i.

◆ clearItems()

assClozeGap::clearItems ( )

Removes all gap items.

Removes all gap items

@access public

See also
$items

Definition at line 267 of file class.assClozeGap.php.

268 {
269 $this->items = array();
270 }

◆ deleteItem()

assClozeGap::deleteItem (   $order)

Deletes an item at a given index.

Deletes an item at a given index

Parameters
integer$0order Order of the item @access public
See also
$items

Definition at line 191 of file class.assClozeGap.php.

192 {
193 if (array_key_exists($order, $this->items)) {
194 unset($this->items[$order]);
195 $order = 0;
196 foreach ($this->items as $key => $item) {
197 $this->items[$key]->setOrder($order);
198 $order++;
199 }
200 }
201 }
$key
Definition: croninfo.php:18

References $key.

◆ getBestSolutionIndexes()

assClozeGap::getBestSolutionIndexes ( )

Returns the indexes of the best solutions for the gap.

Returns the indexes of the best solutions for the gap

Returns
array The indexs of the best solutions @access public

Definition at line 321 of file class.assClozeGap.php.

322 {
323 $maxpoints = 0;
324 foreach ($this->items as $key => $item) {
325 if ($item->getPoints() > $maxpoints) {
326 $maxpoints = $item->getPoints();
327 }
328 }
329 $keys = array();
330 foreach ($this->items as $key => $item) {
331 if ($item->getPoints() == $maxpoints) {
332 array_push($keys, $key);
333 }
334 }
335 return $keys;
336 }
$keys

References $key, and $keys.

◆ getBestSolutionOutput()

assClozeGap::getBestSolutionOutput ( ilArrayElementShuffler  $shuffler,
  $combinations = null 
)
Parameters
ilArrayElementShuffler$shuffler
null  |  array$combinations
Returns
string

Definition at line 343 of file class.assClozeGap.php.

344 {
345 global $lng;
346 switch ($this->getType()) {
347 case CLOZE_TEXT:
348 case CLOZE_SELECT:
349 $best_solutions = array();
350 if ($combinations !== null && $combinations['best_solution'] == 1) {
351 $best_solutions[$combinations['points']] = array();
352 array_push($best_solutions[$combinations['points']], $combinations['answer']);
353 } else {
354 foreach ($this->getItems($shuffler) as $answer) {
355 if (isset($best_solutions[$answer->getPoints()]) && is_array($best_solutions[$answer->getPoints()])) {
356 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
357 } else {
358 $best_solutions[$answer->getPoints()] = array();
359 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
360 }
361 }
362 }
363
364 krsort($best_solutions, SORT_NUMERIC);
365 reset($best_solutions);
366 $found = current($best_solutions);
367 return join(" " . $lng->txt("or") . " ", $found);
368 break;
369 case CLOZE_NUMERIC:
370 $maxpoints = 0;
371 $foundvalue = "";
372 foreach ($this->getItems($shuffler) as $answer) {
373 if ($answer->getPoints() >= $maxpoints) {
374 $maxpoints = $answer->getPoints();
375 $foundvalue = $answer->getAnswertext();
376 }
377 }
378 return $foundvalue;
379 break;
380 default:
381 return "";
382 }
383 }
getItems(ilArrayElementShuffler $shuffler)
Gets the items of a cloze gap.
getType()
Gets the cloze gap type.
const CLOZE_NUMERIC
const CLOZE_SELECT
const CLOZE_TEXT
Cloze question constants.
global $lng
Definition: privfeed.php:17

References $lng, CLOZE_NUMERIC, CLOZE_SELECT, CLOZE_TEXT, getItems(), and getType().

+ Here is the call graph for this function:

◆ getGapSize()

assClozeGap::getGapSize ( )
Returns
int

Definition at line 396 of file class.assClozeGap.php.

397 {
398 return $this->gap_size;
399 }

References $gap_size.

◆ getItem()

assClozeGap::getItem (   $a_index)

Gets the item with a given index.

Gets the item with a given index

Parameters
integer$a_indexItem index @access public
See also
$items

Definition at line 250 of file class.assClozeGap.php.

251 {
252 if (array_key_exists($a_index, $this->items)) {
253 return $this->items[$a_index];
254 } else {
255 return null;
256 }
257 }

◆ getItemCount()

assClozeGap::getItemCount ( )

Gets the item count.

Gets the item count

Returns
integer The item count @access public
See also
$items

Definition at line 126 of file class.assClozeGap.php.

127 {
128 return count($this->items);
129 }

◆ getItems()

assClozeGap::getItems ( ilArrayElementShuffler  $shuffler)

Gets the items of a cloze gap.

Parameters
ilArrayElementShuffler$shuffler
Returns
array The list of items

Definition at line 94 of file class.assClozeGap.php.

95 {
96 if ($this->getShuffle()) {
97 return $shuffler->shuffle($this->items);
98 }
99
100 return $this->items;
101 }
getShuffle()
Gets the shuffle state of the items.

References $items, getShuffle(), and ilArrayElementShuffler\shuffle().

Referenced by getBestSolutionOutput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getItemsRaw()

assClozeGap::getItemsRaw ( )

Gets the items of a cloze gap.

Gets the items of a cloze gap

Returns
array The list of items @access public
See also
$items

Definition at line 112 of file class.assClozeGap.php.

113 {
114 return $this->items;
115 }

References $items.

◆ getMaxWidth()

assClozeGap::getMaxWidth ( )

Returns the maximum width of the gap.

Returns the maximum width of the gap

Returns
integer The maximum width of the gap defined by the longest answer @access public

Definition at line 302 of file class.assClozeGap.php.

303 {
304 $maxwidth = 0;
305 foreach ($this->items as $item) {
306 if (strlen($item->getAnswertext()) > $maxwidth) {
307 $maxwidth = strlen($item->getAnswertext());
308 }
309 }
310 return $maxwidth;
311 }

◆ getShuffle()

assClozeGap::getShuffle ( )

Gets the shuffle state of the items.

Returns
boolean Shuffle state

Definition at line 289 of file class.assClozeGap.php.

290 {
291 return $this->shuffle;
292 }

References $shuffle.

Referenced by getItems().

+ Here is the caller graph for this function:

◆ getType()

assClozeGap::getType ( )

Gets the cloze gap type.

Gets the cloze gap type

Returns
integer cloze gap type
See also
$type for mapping.

Definition at line 71 of file class.assClozeGap.php.

72 {
73 return $this->type;
74 }
$type
Type of gap.

References $type.

Referenced by getBestSolutionOutput().

+ Here is the caller graph for this function:

◆ setGapSize()

assClozeGap::setGapSize (   $gap_size)
Parameters
integer$gap_size

Definition at line 388 of file class.assClozeGap.php.

389 {
390 $this->gap_size = $gap_size;
391 }

References $gap_size.

◆ setItemLowerBound()

assClozeGap::setItemLowerBound (   $order,
  $bound 
)

Sets the lower bound for a given item.

Sets the lower bound for a given item

Parameters
integer$orderOrder of the item
double$boundLower bounds of the item @access public
See also
$items

Definition at line 213 of file class.assClozeGap.php.

214 {
215 foreach ($this->items as $key => $item) {
216 if ($item->getOrder() == $order) {
217 $item->setLowerBound($bound);
218 }
219 }
220 }

References $key.

◆ setItemPoints()

assClozeGap::setItemPoints (   $order,
  $points 
)

Sets the points for a given item.

Sets the points for a given item

Parameters
integer$orderOrder of the item
double$pointsPoints of the item @access public
See also
$items

Definition at line 173 of file class.assClozeGap.php.

174 {
175 foreach ($this->items as $key => $item) {
176 if ($item->getOrder() == $order) {
177 $item->setPoints($points);
178 }
179 }
180 }

References $key.

◆ setItemUpperBound()

assClozeGap::setItemUpperBound (   $order,
  $bound 
)

Sets the upper bound for a given item.

Sets the upper bound for a given item

Parameters
integer$orderOrder of the item
double$boundUpper bound of the item @access public
See also
$items

Definition at line 232 of file class.assClozeGap.php.

233 {
234 foreach ($this->items as $key => $item) {
235 if ($item->getOrder() == $order) {
236 $item->setUpperBound($bound);
237 }
238 }
239 }

References $key.

◆ setShuffle()

assClozeGap::setShuffle (   $a_shuffle = true)

Sets the shuffle state of the items.

Sets the shuffle state of the items

Parameters
boolean$a_shuffleShuffle state

Definition at line 279 of file class.assClozeGap.php.

280 {
281 $this->shuffle = (bool) $a_shuffle;
282 }

◆ setType()

assClozeGap::setType (   $a_type = 0)

Sets the cloze gap type.

Parameters
integer$a_typecloze gap type
See also
$type for mapping.

Definition at line 83 of file class.assClozeGap.php.

84 {
85 $this->type = $a_type;
86 }

References $a_type.

Field Documentation

◆ $gap_size

assClozeGap::$gap_size = 0
private

Definition at line 47 of file class.assClozeGap.php.

Referenced by getGapSize(), and setGapSize().

◆ $items

assClozeGap::$items

Definition at line 38 of file class.assClozeGap.php.

Referenced by getItems(), and getItemsRaw().

◆ $shuffle

assClozeGap::$shuffle

Definition at line 45 of file class.assClozeGap.php.

Referenced by getShuffle().

◆ $type

int assClozeGap::$type

Type of gap.

An integer value indicating the type of the gap 0 == text gap, 1 == select gap, 2 == numeric gap

Definition at line 29 of file class.assClozeGap.php.

Referenced by getType().


The documentation for this class was generated from the following file: