ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
assClozeGap Class Reference

Class for cloze question gaps. More...

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

Public Member Functions

 assClozeGap ($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)
 
 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.

Member Function Documentation

◆ addItem()

assClozeGap::addItem (   $a_item)

Adds a gap item.

Adds a gap item

Parameters
object$a_itemCloze gap item public
See also
$items

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

142  {
143  $order = $a_item->getOrder();
144  if (array_key_exists($order, $this->items))
145  {
146  $newitems = array();
147  for ($i = 0; $i < $order; $i++)
148  {
149  array_push($newitems, $this->items[$i]);
150  }
151  array_push($newitems, $a_item);
152  for ($i = $order; $i < count($this->items); $i++)
153  {
154  array_push($newitems, $this->items[$i]);
155  }
156  $i = 0;
157  foreach ($newitems as $idx => $item)
158  {
159  $newitems[$idx]->setOrder($i);
160  $i++;
161  }
162  $this->items = $newitems;
163  }
164  else
165  {
166  array_push($this->items, $a_item);
167  }
168  }

◆ assClozeGap()

assClozeGap::assClozeGap (   $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  }

◆ clearItems()

assClozeGap::clearItems ( )

Removes all gap items.

Removes all gap items

public

See also
$items

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

286  {
287  $this->items = array();
288  }

◆ 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 public
See also
$items

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

201  {
202  if (array_key_exists($order, $this->items))
203  {
204  unset($this->items[$order]);
205  $order = 0;
206  foreach ($this->items as $key => $item)
207  {
208  $this->items[$key]->setOrder($order);
209  $order++;
210  }
211  }
212  }

◆ 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 public

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

342  {
343  $maxpoints = 0;
344  foreach ($this->items as $key => $item)
345  {
346  if ($item->getPoints() > $maxpoints)
347  {
348  $maxpoints = $item->getPoints();
349  }
350  }
351  $keys = array();
352  foreach ($this->items as $key => $item)
353  {
354  if ($item->getPoints() == $maxpoints)
355  {
356  array_push($keys, $key);
357  }
358  }
359  return $keys;
360  }

◆ getBestSolutionOutput()

assClozeGap::getBestSolutionOutput ( ilArrayElementShuffler  $shuffler)

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

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

363  {
364  global $lng;
365  switch ($this->getType())
366  {
367  case CLOZE_TEXT:
368  case CLOZE_SELECT:
369  $best_solutions = array();
370  foreach ($this->getItems($shuffler) as $answer)
371  {
372  if (isset($best_solutions[$answer->getPoints()]) && is_array($best_solutions[$answer->getPoints()]))
373  {
374  array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
375  }
376  else
377  {
378  $best_solutions[$answer->getPoints()] = array();
379  array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
380  }
381  }
382  krsort($best_solutions, SORT_NUMERIC);
383  reset($best_solutions);
384  $found = current($best_solutions);
385  return join(" " . $lng->txt("or") . " ", $found);
386  break;
387  case CLOZE_NUMERIC:
388  $maxpoints = 0;
389  $foundvalue = "";
390  foreach ($this->getItems($shuffler) as $answer)
391  {
392  if ($answer->getPoints() >= $maxpoints)
393  {
394  $maxpoints = $answer->getPoints();
395  $foundvalue = $answer->getAnswertext();
396  }
397  }
398  return $foundvalue;
399  break;
400  default:
401  return "";
402  }
403  }
const CLOZE_TEXT
Cloze question constants.
const CLOZE_SELECT
getItems(ilArrayElementShuffler $shuffler)
Gets the items of a cloze gap.
global $lng
Definition: privfeed.php:40
getType()
Gets the cloze gap type.
const CLOZE_NUMERIC
+ Here is the call graph for this function:

◆ getGapSize()

assClozeGap::getGapSize ( )
Returns
int

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

References $gap_size.

417  {
418  return $this->gap_size;
419  }

◆ getItem()

assClozeGap::getItem (   $a_index)

Gets the item with a given index.

Gets the item with a given index

Parameters
integer$a_indexItem index public
See also
$items

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

266  {
267  if (array_key_exists($a_index, $this->items))
268  {
269  return $this->items[$a_index];
270  }
271  else
272  {
273  return NULL;
274  }
275  }

◆ getItemCount()

assClozeGap::getItemCount ( )

Gets the item count.

Gets the item count

Returns
integer The item count public
See also
$items

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

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

◆ 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.

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

Referenced by getBestSolutionOutput().

95  {
96  if ($this->getShuffle())
97  {
98  return $shuffler->shuffle($this->items);
99  }
100 
101  return $this->items;
102  }
getShuffle()
Gets the shuffle state of the items.
+ 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 public
See also
$items

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

References $items.

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

◆ 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 public

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

321  {
322  $maxwidth = 0;
323  foreach ($this->items as $item)
324  {
325  if (strlen($item->getAnswertext()) > $maxwidth)
326  {
327  $maxwidth = strlen($item->getAnswertext());
328  }
329  }
330  return $maxwidth;
331  }

◆ getShuffle()

assClozeGap::getShuffle ( )

Gets the shuffle state of the items.

Returns
boolean Shuffle state

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

References $shuffle.

Referenced by getItems().

308  {
309  return $this->shuffle;
310  }
+ 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.

References $type.

Referenced by getBestSolutionOutput().

72  {
73  return $this->type;
74  }
$type
Type of gap.
+ Here is the caller graph for this function:

◆ setGapSize()

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

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

References $gap_size.

409  {
410  $this->gap_size = $gap_size;
411  }

◆ 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 public
See also
$items

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

225  {
226  foreach ($this->items as $key => $item)
227  {
228  if ($item->getOrder() == $order)
229  {
230  $item->setLowerBound($bound);
231  }
232  }
233  }

◆ 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 public
See also
$items

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

181  {
182  foreach ($this->items as $key => $item)
183  {
184  if ($item->getOrder() == $order)
185  {
186  $item->setPoints($points);
187  }
188  }
189  }

◆ 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 public
See also
$items

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

246  {
247  foreach ($this->items as $key => $item)
248  {
249  if ($item->getOrder() == $order)
250  {
251  $item->setUpperBound($bound);
252  }
253  }
254  }

◆ 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 297 of file class.assClozeGap.php.

298  {
299  $this->shuffle = (bool) $a_shuffle;
300  }

◆ 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  }

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: