Public Member Functions | Data Fields

assClozeGap Class Reference
[Modules/TestQuestionPool]

Class for cloze question gaps. More...

Inheritance 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 <helmut.schottmueller@mac.com>
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_item Cloze gap item public
See also:
$items

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

        {
                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 $array An array which should be shuffled public

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:
string $answertext A string defining the answer text
double $points The number of points given for the selected answer
boolean $correctness A boolean value indicating the correctness of the answer
integer $order A nonnegative value representing a possible display or sort order
integer $cloze_type An integer representing the answer type public

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

        {
                $this->type = $a_type;
                $this->items = array();
                $this->shuffle = FALSE;
        }

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, getItems(), and getType().

        {
                global $lng;
                switch ($this->getType())
                {
                        case CLOZE_TEXT:
                        case CLOZE_SELECT:
                                $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;
                        case CLOZE_NUMERIC:
                                $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_index Item 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 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 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.

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

Gets the shuffle state of the items

Returns:
boolean Shuffle state public
See also:
$shuffle

Reimplemented in assClozeSelectGap.

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

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

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 $order Order of the item
double $bound Lower 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 $order Order of the item
double $points Points 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 $order Order of the item
double $bound Upper 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_shuffle Shuffle state public
See also:
$shuffle

Definition at line 302 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_type Cloze 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.

assClozeGap::$shuffle

Reimplemented in assClozeSelectGap.

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

assClozeGap::$type

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


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