ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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
 getType ()
 Gets the cloze gap type.
 setType ($a_type=0)
 Sets the cloze gap type.
 getItems ()
 Gets the items of a cloze gap.
 getItemsRaw ()
 Gets the items of a cloze gap.
 getItemCount ()
 Gets the item count.
 addItem ($a_item)
 Adds a gap item.
 setItemPoints ($order, $points)
 Sets the points for a given item.
 deleteItem ($order)
 Deletes an item at a given index.
 setItemLowerBound ($order, $bound)
 Sets the lower bound for a given item.
 setItemUpperBound ($order, $bound)
 Sets the upper bound for a given item.
 getItem ($a_index)
 Gets the item with a given index.
 clearItems ()
 Removes all gap items.
 setShuffle ($a_shuffle=true)
 Sets the shuffle state of the items.
 getShuffle ()
 Gets the shuffle state of the items.
 arrayShuffle ($array)
 Shuffles the values of a given array.
 getMaxWidth ()
 Returns the maximum width of the gap.
 getBestSolutionIndexes ()
 Returns the indexes of the best solutions for the gap.
 getBestSolutionOutput ()
 setGapSize ($gap_size)
 getGapSize ()

Data Fields

 $type
 Type of gap.
 $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:
class.assClozeGap.php 49767 2014-04-30 09:05:14Z nkrzywon

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

Member Function Documentation

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.

{
$order = $a_item->getOrder();
if (array_key_exists($order, $this->items))
{
$newitems = array();
for ($i = 0; $i < $order; $i++)
{
array_push($newitems, $this->items[$i]);
}
array_push($newitems, $a_item);
for ($i = $order; $i < count($this->items); $i++)
{
array_push($newitems, $this->items[$i]);
}
$i = 0;
foreach ($newitems as $idx => $item)
{
$newitems[$idx]->setOrder($i);
$i++;
}
$this->items = $newitems;
}
else
{
array_push($this->items, $a_item);
}
}
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.

Reimplemented in assClozeSelectGap.

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

Referenced by getItems().

{
mt_srand((double)microtime()*1000000);
$i = count($array);
if ($i > 0)
{
while(--$i)
{
$j = mt_rand(0, $i);
if ($i != $j)
{
// swap elements
$tmp = $array[$j];
$array[$j] = $array[$i];
$array[$i] = $tmp;
}
}
}
return $array;
}

+ Here is the caller graph for this function:

assClozeGap::assClozeGap (   $a_type)

assClozeGap constructor

Parameters
int$a_type

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

{
$this->type = $a_type;
$this->items = array();
$this->shuffle = true;
}
assClozeGap::clearItems ( )

Removes all gap items.

Removes all gap items

public

See Also
$items

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

{
$this->items = array();
}
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.

{
if (array_key_exists($order, $this->items))
{
unset($this->items[$order]);
$order = 0;
foreach ($this->items as $key => $item)
{
$this->items[$key]->setOrder($order);
$order++;
}
}
}
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.

{
$maxpoints = 0;
foreach ($this->items as $key => $item)
{
if ($item->getPoints() > $maxpoints)
{
$maxpoints = $item->getPoints();
}
}
$keys = array();
foreach ($this->items as $key => $item)
{
if ($item->getPoints() == $maxpoints)
{
array_push($keys, $key);
}
}
return $keys;
}
assClozeGap::getBestSolutionOutput ( )

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

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

{
global $lng;
switch ($this->getType())
{
case CLOZE_TEXT:
$best_solutions = array();
foreach ($this->getItems() as $answer)
{
if (is_array($best_solutions[$answer->getPoints()]))
{
array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
}
else
{
$best_solutions[$answer->getPoints()] = array();
array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
}
}
krsort($best_solutions, SORT_NUMERIC);
reset($best_solutions);
$found = current($best_solutions);
return join(" " . $lng->txt("or") . " ", $found);
break;
$maxpoints = 0;
$foundvalue = "";
foreach ($this->getItems() as $answer)
{
if ($answer->getPoints() >= $maxpoints)
{
$maxpoints = $answer->getPoints();
$foundvalue = $answer->getAnswertext();
}
}
return $foundvalue;
break;
default:
return "";
}
}

+ Here is the call graph for this function:

assClozeGap::getGapSize ( )
Returns
int

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

References $gap_size.

{
}
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.

{
if (array_key_exists($a_index, $this->items))
{
return $this->items[$a_index];
}
else
{
return NULL;
}
}
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.

{
return count($this->items);
}
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

Reimplemented in assClozeSelectGap.

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

References $items, and arrayShuffle().

Referenced by getBestSolutionOutput().

{
if ($this->shuffle)
{
return $this->arrayShuffle($this->items);
}
else
{
return $this->items;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

{
return $this->items;
}
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.

{
$maxwidth = 0;
foreach ($this->items as $item)
{
if (strlen($item->getAnswertext()) > $maxwidth)
{
$maxwidth = strlen($item->getAnswertext());
}
}
return $maxwidth;
}
assClozeGap::getShuffle ( )

Gets the shuffle state of the items.

Returns
boolean Shuffle state

Reimplemented in assClozeSelectGap.

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

References $shuffle.

{
}
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().

{
return $this->type;
}

+ Here is the caller graph for this function:

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

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

References $gap_size.

{
$this->gap_size = $gap_size;
}
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.

{
foreach ($this->items as $key => $item)
{
if ($item->getOrder() == $order)
{
$item->setLowerBound($bound);
}
}
}
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.

{
foreach ($this->items as $key => $item)
{
if ($item->getOrder() == $order)
{
$item->setPoints($points);
}
}
}
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.

{
foreach ($this->items as $key => $item)
{
if ($item->getOrder() == $order)
{
$item->setUpperBound($bound);
}
}
}
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.

{
$this->shuffle = (bool) $a_shuffle;
}
assClozeGap::setType (   $a_type = 0)

Sets the cloze gap type.

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

Reimplemented in assClozeSelectGap.

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

{
$this->type = $a_type;
}

Field Documentation

assClozeGap::$gap_size = 0
private

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

Referenced by getGapSize(), and setGapSize().

assClozeGap::$items

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

Referenced by getItems(), assClozeSelectGap\getItems(), and getItemsRaw().

assClozeGap::$shuffle

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

Referenced by getShuffle().

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: