ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 ()
 
 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 146 of file class.assClozeGap.php.

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

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

Referenced by getItems().

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

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

291  {
292  $this->items = array();
293  }

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

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

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

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

◆ getBestSolutionOutput()

assClozeGap::getBestSolutionOutput ( )

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

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

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

◆ getGapSize()

assClozeGap::getGapSize ( )
Returns
int

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

References $gap_size.

457  {
458  return $this->gap_size;
459  }

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

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

◆ getItemCount()

assClozeGap::getItemCount ( )

Gets the item count.

Gets the item count

Returns
integer The item count public
See also
$items

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

133  {
134  return count($this->items);
135  }

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

References $items, and arrayShuffle().

Referenced by getBestSolutionOutput().

98  {
99  if ($this->shuffle)
100  {
101  return $this->arrayShuffle($this->items);
102  }
103  else
104  {
105  return $this->items;
106  }
107  }
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 118 of file class.assClozeGap.php.

References $items.

119  {
120  return $this->items;
121  }

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

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

◆ getShuffle()

assClozeGap::getShuffle ( )

Gets the shuffle state of the items.

Returns
boolean Shuffle state

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

References $shuffle.

313  {
314  return $this->shuffle;
315  }

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

References $gap_size.

449  {
450  $this->gap_size = $gap_size;
451  }

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

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

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

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

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

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

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

303  {
304  $this->shuffle = (bool) $a_shuffle;
305  }

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