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

Data Fields

 $type
 $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
Version
$Id$

Definition at line 37 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 168 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 public

Reimplemented in assClozeSelectGap.

Definition at line 353 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
string$answertextA string defining the answer text
double$pointsThe number of points given for the selected answer
boolean$correctnessA boolean value indicating the correctness of the answer
integer$orderA nonnegative value representing a possible display or sort order
integer$cloze_typeAn integer representing the answer type public

Definition at line 75 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 312 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 227 of file class.assClozeGap.php.

References $key.

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

References $key.

{
$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 424 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 292 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 154 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 119 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 140 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 382 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.

Gets the shuffle state of the items

Returns
boolean Shuffle state public
See Also
$shuffle

Reimplemented in assClozeSelectGap.

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

References $shuffle.

{
}
assClozeGap::getType ( )

Gets the cloze gap type.

Gets the cloze gap type

Returns
integer cloze gap type public
See Also
$type

Definition at line 91 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 251 of file class.assClozeGap.php.

References $key.

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

References $key, and $points.

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

References $key.

{
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 public
See Also
$shuffle

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

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

Sets the cloze gap type.

Sets the cloze gap type

Parameters
integer$a_typeCloze gap type public
See Also
$type

Reimplemented in assClozeSelectGap.

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

{
$this->type = $a_type;
}

Field Documentation

assClozeGap::$items

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

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

assClozeGap::$shuffle

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

Referenced by getShuffle().

assClozeGap::$type

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

Referenced by getType().


The documentation for this class was generated from the following file: