4 require_once
'Modules/TestQuestionPool/classes/questions/class.ilAssOrderingElement.php';
36 self::IDENTIFIER_TYPE_SOLUTION =>
array(),
37 self::IDENTIFIER_TYPE_RANDOM =>
array()
55 $this->objectInstanceId = ++self::$objectInstanceCounter;
57 $this->questionId = null;
66 $this->objectInstanceId = ++self::$objectInstanceCounter;
70 foreach($this as $key => $element)
111 "SELECT * FROM qpl_a_ordering WHERE question_fi = %s ORDER BY position ASC",
119 $element->setRandomIdentifier(
$row[
'random_id']);
120 $element->setSolutionIdentifier(
$row[
'solution_key']);
122 $element->setPosition(
$row[
'position']);
123 $element->setIndentation(
$row[
"depth"]);
125 $element->setContent(
$row[
'answertext']);
135 public function saveToDb()
141 "DELETE FROM qpl_a_ordering WHERE question_fi = %s",
145 foreach($this as $orderElement)
150 'answer_id' =>
array(
'integer',
$ilDB->nextId(
'qpl_a_ordering') ),
152 'answertext' =>
array(
'text', $orderElement->getContent()),
153 'solution_key' =>
array(
'integer', $orderElement->getSolutionIdentifier() ),
154 'random_id' =>
array(
'integer', $orderElement->getRandomIdentifier() ),
155 'position' =>
array(
'integer', $orderElement->getPosition() ),
156 'depth' =>
array(
'integer', $orderElement->getIndentation() ),
167 foreach($this as $orderingElement)
169 $orderingElement->setContent(
'');
175 return count($this->elements);
180 return $position == 0;
193 $elementList =
new self();
196 foreach($this as $element)
198 if( $element->getPosition() == $currentPosition )
200 $elementList->addElement($dodgingElement);
204 if( $element->getPosition() == $targetPosition )
206 $elementList->addElement($movingElement);
210 $elementList->addElement($element);
213 $dodgingElement->setPosition($currentPosition);
214 $movingElement->setPosition($targetPosition);
221 $elementList =
new self();
224 $positionCounter = 0;
226 foreach($this as $element)
228 if( $element->isSameElement($removeElement) )
233 $element->setPosition($positionCounter++);
234 $elementList->addElement($element);
243 $this->elements =
array();
306 foreach($this as $element)
324 $this->elements[] = $element;
333 if( isset($this->elements[$position]) )
335 return $this->elements[$position];
356 foreach($this as $element)
358 if( $element->getRandomIdentifier() != $randomIdentifier )
384 foreach($this as $element)
386 if( $element->getSolutionIdentifier() != $solutionIdentifier )
427 if( !isset(self::$identifierRegistry[$identifierType][$this->
getQuestionId()]) )
432 return self::$identifierRegistry[$identifierType][$this->
getQuestionId()];
441 $identifier = $this->
fetchIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
448 $identifier = $this->
fetchIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
499 if( !isset(self::$identifierRegistry[$identifierType][$this->
getQuestionId()]) )
506 if( !in_array($identifier, self::$identifierRegistry[$identifierType][$this->
getQuestionId()]) )
508 self::$identifierRegistry[$identifierType][$this->
getQuestionId()][] = $identifier;
520 if( !isset(self::$identifierRegistry[$identifierType][$this->
getQuestionId()]) )
527 if( !in_array($identifier, self::$identifierRegistry[$identifierType][$this->
getQuestionId()]) )
543 switch($identifierType)
560 switch($identifierType)
576 switch($identifierType)
578 case self::IDENTIFIER_TYPE_SOLUTION:
579 return self::isValidSolutionIdentifier($identifier);
581 case self::IDENTIFIER_TYPE_RANDOM:
582 return self::isValidRandomIdentifier($identifier);
595 switch($identifierType)
611 "unknown identifier type given (type: $identifierType)" 622 "could not build random identifier (max tries: $maxTries)" 633 "cannot reorder element due to missing position (random identifier: $randomIdentifier)" 644 'cannot reorder element due to one or more unknown random identifiers '.
645 '(' . implode(
', ', $randomIdentifiers) .
')' 654 $lastSolutionIdentifier = null;
658 if( $lastSolutionIdentifier > $registeredIdentifier )
663 $lastSolutionIdentifier = $registeredIdentifier;
666 return $lastSolutionIdentifier;
676 if( $lastSolutionIdentifier === null )
681 $nextSolutionIdentifier = $lastSolutionIdentifier + self::SOLUTION_IDENTIFIER_VALUE_INTERVAL;
683 return $nextSolutionIdentifier;
692 $usedTriesCounter = 0;
696 if( $usedTriesCounter >= self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES )
703 $lowerBound = self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND;
704 $upperBound = self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND;
705 $randomIdentifier = mt_rand($lowerBound, $upperBound);
708 $testElement->setRandomIdentifier($randomIdentifier);
712 return $randomIdentifier;
717 if( !is_numeric($identifier) )
722 if( $identifier != (
int)$identifier )
727 if( $identifier < 0 )
737 if( !is_numeric($identifier) )
742 if( $identifier != (
int)$identifier )
747 if( $identifier < self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND )
752 if( $identifier > self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND )
762 return self::isValidSolutionIdentifier($position);
767 return self::isValidPosition($indentation);
775 foreach($this as $element)
787 $numIntersectingElements = count(array_intersect(
796 if( $numIntersectingElements != $otherList->countElements() )
803 $otherListRandomIdentifierIndex = $otherList->getRandomIdentifierIndex();
805 foreach($this as $orderingElement)
807 if( !in_array($orderingElement->getRandomIdentifier(), $otherListRandomIdentifierIndex) )
812 $randomIdentifierIndexMatchingsCount = count( array_keys(
813 $otherListRandomIdentifierIndex, $orderingElement->getRandomIdentifier(), false
816 if( $randomIdentifierIndexMatchingsCount != 1 )
822 return $this->
countElements() == $otherList->countElements();
832 $parityTrueElementList =
new self();
833 $parityTrueElementList->setQuestionId($this->
getQuestionId());
835 foreach($this as $thisElement)
837 $otherElement = $otherList->getElementByRandomIdentifier(
838 $thisElement->getRandomIdentifier()
841 if( $otherElement->getPosition() != $thisElement->getPosition() )
846 if( $otherElement->getIndentation() != $thisElement->getIndentation() )
851 $parityTrueElementList->addElement($thisElement);
854 return $parityTrueElementList;
864 $positionsMap = array_flip( array_values($randomIdentifiers) );
866 $orderedElements =
array();
868 foreach($this as $element)
870 if( !isset($positionsMap[$element->getRandomIdentifier()]) )
875 $position = $positionsMap[$element->getRandomIdentifier()];
876 unset($positionsMap[$element->getRandomIdentifier()]);
878 $element->setPosition($position);
879 $orderedElements[$position] = $element;
882 if( count($positionsMap) )
887 ksort($orderedElements);
889 $this->
setElements( array_values($orderedElements) );
897 foreach($this as $element)
899 $element->setIndentation(0);
911 $differenceElementList =
new self();
912 $differenceElementList->setQuestionId($this->
getQuestionId());
914 foreach($differenceRandomIdentifierIndex as $randomIdentifier)
917 $differenceElementList->addElement($element);
920 return $differenceElementList;
929 $differenceRandomIdentifierIndex = array_diff(
933 return $differenceRandomIdentifierIndex;
941 foreach($this as $thisElement)
943 if( !$otherList->elementExistByRandomIdentifier($thisElement->getRandomIdentifier()) )
948 $otherElement = $otherList->getElementByRandomIdentifier(
949 $thisElement->getRandomIdentifier()
952 $thisElement->setContent( $otherElement->getContent() );
964 public function next() {
return next($this->elements); }
969 public function key() {
return key($this->elements); }
974 public function valid() {
return ($this->
key() !== null); }
979 public function rewind() {
return reset($this->elements); }
987 $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
999 $elementList =
new self();
1002 $elementList->setElements($orderingElements);
1004 return $elementList;
__clone()
clone list by additionally cloning the element objects
reorderByRandomIdentifiers($randomIdentifiers)
registerIdentifiers(ilAssOrderingElement $element)
elementExistBySolutionIdentifier($solutionIdentifier)
static isValidPosition($position)
const IDENTIFIER_TYPE_SOLUTION
const JS_ADDED_ELEMENTS_RANDOM_IDENTIFIER_START_VALUE
static $identifierRegistry
isValidIdentifier($identifierType, $identifier)
getRegisteredSolutionIdentifiers()
getLastSolutionIdentifier()
__construct()
ilAssOrderingElementList constructor.
const SOLUTION_IDENTIFIER_START_VALUE
populateIdentifier(ilAssOrderingElement $element, $identifierType, $identifier)
removeElement(ilAssOrderingElement $removeElement)
const RANDOM_IDENTIFIER_RANGE_UPPER_BOUND
setSolutionIdentifier($solutionIdentifier)
isFirstElementPosition($position)
completeContentsFromElementList(self $otherList)
elementExistByPosition($position)
moveElementByPositions($currentPosition, $targetPosition)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
hasSameElementSetByRandomIdentifiers(self $otherList)
static buildInstance($questionId, $orderingElements=array())
setQuestionId($questionId)
elementExistByRandomIdentifier($randomIdentifier)
getSolutionIdentifierIndex()
getRegisteredRandomIdentifiers()
throwMissingReorderPositionException($randomIdentifier)
resetElements()
resets elements
const JS_ADDED_ELEMENTS_RANDOM_IDENTIFIER_VALUE_INTERVAL
static isValidRandomIdentifier($identifier)
const SOLUTION_IDENTIFIER_VALUE_INTERVAL
throwCouldNotBuildRandomIdentifierException($maxTries)
getRegisteredIdentifiers($identifierType)
distributeNewRandomIdentifiers()
getElementByRandomIdentifier($randomIdentifier)
buildIdentifier($identifierType)
loadFromDb()
load elements from database
throwUnknownRandomIdentifiersException($randomIdentifiers)
getElementBySolutionIdentifier($solutionIdentifier)
ensureValidIdentifier(ilAssOrderingElement $element, $identifierType)
throwUnknownIdentifierTypeException($identifierType)
addElement(ilAssOrderingElement $element)
setRandomIdentifier($randomIdentifier)
getDifferenceRandomIdentifierIndex(self $otherElementList)
getIndexedElements($identifierType)
isIdentifierRegistered(ilAssOrderingElement $element, $identifierType)
getRandomIdentifierIndexedElements()
static getFallbackDefaultElement()
getRandomIdentifierIndex()
Create styles array
The data for the language used.
fetchIdentifier(ilAssOrderingElement $element, $identifierType)
const FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER
static isValidSolutionIdentifier($identifier)
const RANDOM_IDENTIFIER_RANGE_LOWER_BOUND
const RANDOM_IDENTIFIER_BUILD_MAX_TRIES
resetElementsIndentations()
resets the indentation to level 0 for all elements in list
buildSolutionIdentifier()
getElementByPosition($position)
getParityTrueElementList(self $otherList)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static $objectInstanceCounter
getSolutionIdentifierIndexedElements()
static isValidIndentation($indentation)
hasValidIdentifiers(ilAssOrderingElement $element)
isLastElementPosition($position)
ensureValidIdentifiers(ilAssOrderingElement $element)
clearElementContents()
clears the contents of all elements
const IDENTIFIER_TYPE_RANDOM
registerIdentifier(ilAssOrderingElement $element, $identifierType)
const SOLUTION_IDENTIFIER_BUILD_MAX_TRIES
getDifferenceElementList(self $otherElementList)