ILIAS  Release_4_4_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 ()

Data Fields

 $type
 Type of gap.
 $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:
class.assClozeGap.php 45317 2013-10-09 12:29:20Z mbecker

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 144 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 329 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 53 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 288 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 203 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 379 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 400 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::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.

{
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 130 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 95 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 116 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 358 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 310 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 69 of file class.assClozeGap.php.

References $type.

Referenced by getBestSolutionOutput().

{
return $this->type;
}

+ Here is the caller graph for this function:

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.

{
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 183 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 248 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 300 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 81 of file class.assClozeGap.php.

{
$this->type = $a_type;
}

Field Documentation

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: