ILIAS  release_4-4 Revision
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 ()
 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...
 
 arrayShuffle ($array)
 Shuffles the values of a given array. More...
 
 getMaxWidth ()
 Returns the maximum width of the gap. More...
 
 getBestSolutionIndexes ()
 Returns the indexes of the best solutions for the gap. More...
 
 getBestSolutionOutput ()
 

Data Fields

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

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

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

◆ arrayShuffle()

assClozeGap::arrayShuffle (   $array)

Shuffles the values of a given array.

Shuffles the values of a given array

Parameters
array$arrayAn array which should be shuffled
Returns
array public

: Figure out why this method exists. (See note) MBecker: PHP knows the function shuffle since 4.2 which is out since April 2002. Still, Helmut built this function in 2007 with rev. 13281 ... This needs investigation.

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

Referenced by getItems().

330  {
331  mt_srand((double)microtime()*1000000);
332  $i = count($array);
333  if ($i > 0)
334  {
335  while(--$i)
336  {
337  $j = mt_rand(0, $i);
338  if ($i != $j)
339  {
340  // swap elements
341  $tmp = $array[$j];
342  $array[$j] = $array[$i];
343  $array[$i] = $tmp;
344  }
345  }
346  }
347  return $array;
348  }
+ Here is the caller graph for this function:

◆ assClozeGap()

assClozeGap::assClozeGap (   $a_type)

assClozeGap constructor

Parameters
int$a_type

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

54  {
55  $this->type = $a_type;
56  $this->items = array();
57  $this->shuffle = true;
58  }

◆ clearItems()

assClozeGap::clearItems ( )

Removes all gap items.

Removes all gap items

public

See also
$items

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

289  {
290  $this->items = array();
291  }

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

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

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

380  {
381  $maxpoints = 0;
382  foreach ($this->items as $key => $item)
383  {
384  if ($item->getPoints() > $maxpoints)
385  {
386  $maxpoints = $item->getPoints();
387  }
388  }
389  $keys = array();
390  foreach ($this->items as $key => $item)
391  {
392  if ($item->getPoints() == $maxpoints)
393  {
394  array_push($keys, $key);
395  }
396  }
397  return $keys;
398  }

◆ getBestSolutionOutput()

assClozeGap::getBestSolutionOutput ( )

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

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

401  {
402  global $lng;
403  switch ($this->getType())
404  {
405  case CLOZE_TEXT:
406  case CLOZE_SELECT:
407  $best_solutions = array();
408  foreach ($this->getItems() as $answer)
409  {
410  if (is_array($best_solutions[$answer->getPoints()]))
411  {
412  array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
413  }
414  else
415  {
416  $best_solutions[$answer->getPoints()] = array();
417  array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
418  }
419  }
420  krsort($best_solutions, SORT_NUMERIC);
421  reset($best_solutions);
422  $found = current($best_solutions);
423  return join(" " . $lng->txt("or") . " ", $found);
424  break;
425  case CLOZE_NUMERIC:
426  $maxpoints = 0;
427  $foundvalue = "";
428  foreach ($this->getItems() as $answer)
429  {
430  if ($answer->getPoints() >= $maxpoints)
431  {
432  $maxpoints = $answer->getPoints();
433  $foundvalue = $answer->getAnswertext();
434  }
435  }
436  return $foundvalue;
437  break;
438  default:
439  return "";
440  }
441  }
const CLOZE_TEXT
Cloze question constants.
const CLOZE_SELECT
getItems()
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:

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

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

◆ getItemCount()

assClozeGap::getItemCount ( )

Gets the item count.

Gets the item count

Returns
integer The item count public
See also
$items

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

131  {
132  return count($this->items);
133  }

◆ getItems()

assClozeGap::getItems ( )

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

References $items, and arrayShuffle().

Referenced by getBestSolutionOutput().

96  {
97  if ($this->shuffle)
98  {
99  return $this->arrayShuffle($this->items);
100  }
101  else
102  {
103  return $this->items;
104  }
105  }
arrayShuffle($array)
Shuffles the values of a given array.
+ 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 116 of file class.assClozeGap.php.

References $items.

117  {
118  return $this->items;
119  }

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

359  {
360  $maxwidth = 0;
361  foreach ($this->items as $item)
362  {
363  if (strlen($item->getAnswertext()) > $maxwidth)
364  {
365  $maxwidth = strlen($item->getAnswertext());
366  }
367  }
368  return $maxwidth;
369  }

◆ getShuffle()

assClozeGap::getShuffle ( )

Gets the shuffle state of the items.

Returns
boolean Shuffle state

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

References $shuffle.

311  {
312  return $this->shuffle;
313  }

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

References $type.

Referenced by getBestSolutionOutput().

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

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

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

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

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

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

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

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

301  {
302  $this->shuffle = (bool) $a_shuffle;
303  }

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

82  {
83  $this->type = $a_type;
84  }

Field Documentation

◆ $items

assClozeGap::$items

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

Referenced by getItems(), assClozeSelectGap\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: