Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00025
00037 class assClozeGap
00038 {
00047 var $type;
00048
00056 var $items;
00057
00063 var $shuffle;
00064
00075 function assClozeGap($a_type)
00076 {
00077 $this->type = $a_type;
00078 $this->items = array();
00079 $this->shuffle = FALSE;
00080 }
00081
00091 function getType()
00092 {
00093 return $this->type;
00094 }
00095
00105 function setType($a_type = 0)
00106 {
00107 $this->type = $a_type;
00108 }
00109
00119 function getItems()
00120 {
00121 if ($this->shuffle)
00122 {
00123 return $this->arrayShuffle($this->items);
00124 }
00125 else
00126 {
00127 return $this->items;
00128 }
00129 }
00130
00140 function getItemsRaw()
00141 {
00142 return $this->items;
00143 }
00144
00154 function getItemCount()
00155 {
00156 return count($this->items);
00157 }
00158
00168 function addItem($a_item)
00169 {
00170 array_push($this->items, $a_item);
00171 }
00172
00183 function setItemPoints($order, $points)
00184 {
00185 foreach ($this->items as $key => $item)
00186 {
00187 if ($item->getOrder() == $order)
00188 {
00189 $item->setPoints($points);
00190 }
00191 }
00192 }
00193
00203 function deleteItem($order)
00204 {
00205 if (array_key_exists($order, $this->items))
00206 {
00207 unset($this->items[$order]);
00208 $order = 0;
00209 foreach ($this->items as $key => $item)
00210 {
00211 $this->items[$key]->setOrder($order);
00212 $order++;
00213 }
00214 }
00215 }
00216
00227 function setItemLowerBound($order, $bound)
00228 {
00229 foreach ($this->items as $key => $item)
00230 {
00231 if ($item->getOrder() == $order)
00232 {
00233 $item->setLowerBound($bound);
00234 }
00235 }
00236 }
00237
00248 function setItemUpperBound($order, $bound)
00249 {
00250 foreach ($this->items as $key => $item)
00251 {
00252 if ($item->getOrder() == $order)
00253 {
00254 $item->setUpperBound($bound);
00255 }
00256 }
00257 }
00258
00268 function getItem($a_index)
00269 {
00270 if (array_key_exists($a_index, $this->items))
00271 {
00272 return $this->items[$a_index];
00273 }
00274 else
00275 {
00276 return NULL;
00277 }
00278 }
00279
00288 function clearItems()
00289 {
00290 $this->items = array();
00291 }
00292
00302 function setShuffle($a_shuffle = TRUE)
00303 {
00304 $this->shuffle = $a_shuffle ? TRUE : FALSE;
00305 }
00306
00316 function getShuffle()
00317 {
00318 return $this->shuffle;
00319 }
00320
00329 function arrayShuffle($array)
00330 {
00331 mt_srand((double)microtime()*1000000);
00332 $i = count($array);
00333 if ($i > 0)
00334 {
00335 while(--$i)
00336 {
00337 $j = mt_rand(0, $i);
00338 if ($i != $j)
00339 {
00340
00341 $tmp = $array[$j];
00342 $array[$j] = $array[$i];
00343 $array[$i] = $tmp;
00344 }
00345 }
00346 }
00347 return $array;
00348 }
00349
00358 function getMaxWidth()
00359 {
00360 $maxwidth = 0;
00361 foreach ($this->items as $item)
00362 {
00363 if (strlen($item->getAnswerText()) > $maxwidth)
00364 {
00365 $maxwidth = strlen($item->getAnswerText());
00366 }
00367 }
00368 return $maxwidth;
00369 }
00370
00379 function getBestSolutionIndexes()
00380 {
00381 $maxpoints = 0;
00382 foreach ($this->items as $key => $item)
00383 {
00384 if ($item->getPoints() > $maxpoints)
00385 {
00386 $maxpoints = $item->getPoints();
00387 }
00388 }
00389 $keys = array();
00390 foreach ($this->items as $key => $item)
00391 {
00392 if ($item->getPoints() == $maxpoints)
00393 {
00394 array_push($keys, $key);
00395 }
00396 }
00397 return $keys;
00398 }
00399
00400 function getBestSolutionOutput()
00401 {
00402 global $lng;
00403 switch ($this->getType())
00404 {
00405 case CLOZE_TEXT:
00406 case CLOZE_SELECT:
00407 $best_solutions = array();
00408 foreach ($this->getItems() as $answer)
00409 {
00410 if (is_array($best_solutions[$answer->getPoints()]))
00411 {
00412 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
00413 }
00414 else
00415 {
00416 $best_solutions[$answer->getPoints()] = array();
00417 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
00418 }
00419 }
00420 krsort($best_solutions, SORT_NUMERIC);
00421 reset($best_solutions);
00422 $found = current($best_solutions);
00423 return join(" " . $lng->txt("or") . " ", $found);
00424 break;
00425 case CLOZE_NUMERIC:
00426 $maxpoints = 0;
00427 $foundvalue = "";
00428 foreach ($this->getItems() as $answer)
00429 {
00430 if ($answer->getPoints() >= $maxpoints)
00431 {
00432 $maxpoints = $answer->getPoints();
00433 $foundvalue = $answer->getAnswertext();
00434 }
00435 }
00436 return $foundvalue;
00437 break;
00438 default:
00439 return "";
00440 }
00441 }
00442 }
00443
00444 ?>