ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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.

References $a_type, and array.

56  {
57  $this->type = $a_type;
58  $this->items = array();
59  $this->shuffle = true;
60  }
$a_type
Definition: workflow.php:93
Create styles array
The data for the language used.

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.

References array.

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  }
Create styles array
The data for the language used.

◆ clearItems()

assClozeGap::clearItems ( )

Removes all gap items.

Removes all gap items

public

See also
$items

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

References array.

286  {
287  $this->items = array();
288  }
Create styles array
The data for the language used.

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

References array.

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  }
Create styles array
The data for the language used.

◆ getBestSolutionOutput()

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

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

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

368  {
369  global $lng;
370  switch ($this->getType())
371  {
372  case CLOZE_TEXT:
373  case CLOZE_SELECT:
374  $best_solutions = array();
375  if($combinations !== null && $combinations['best_solution'] == 1)
376  {
377  $best_solutions[$combinations['points']] = array();
378  array_push($best_solutions[$combinations['points']], $combinations['answer']);
379  }
380  else
381  {
382  foreach ($this->getItems($shuffler) as $answer)
383  {
384  if (isset($best_solutions[$answer->getPoints()]) && is_array($best_solutions[$answer->getPoints()]))
385  {
386  array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
387  }
388  else
389  {
390  $best_solutions[$answer->getPoints()] = array();
391  array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
392  }
393  }
394  }
395 
396  krsort($best_solutions, SORT_NUMERIC);
397  reset($best_solutions);
398  $found = current($best_solutions);
399  return join(" " . $lng->txt("or") . " ", $found);
400  break;
401  case CLOZE_NUMERIC:
402  $maxpoints = 0;
403  $foundvalue = "";
404  foreach ($this->getItems($shuffler) as $answer)
405  {
406  if ($answer->getPoints() >= $maxpoints)
407  {
408  $maxpoints = $answer->getPoints();
409  $foundvalue = $answer->getAnswertext();
410  }
411  }
412  return $foundvalue;
413  break;
414  default:
415  return "";
416  }
417  }
const CLOZE_TEXT
Cloze question constants.
const CLOZE_SELECT
Create styles array
The data for the language used.
getItems(ilArrayElementShuffler $shuffler)
Gets the items of a cloze gap.
global $lng
Definition: privfeed.php:17
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 430 of file class.assClozeGap.php.

References $gap_size.

431  {
432  return $this->gap_size;
433  }

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

References $gap_size.

423  {
424  $this->gap_size = $gap_size;
425  }

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

References $a_type.

84  {
85  $this->type = $a_type;
86  }
$a_type
Definition: workflow.php:93

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: