ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilAssOrderingElementList Class Reference
+ Inheritance diagram for ilAssOrderingElementList:
+ Collaboration diagram for ilAssOrderingElementList:

Public Member Functions

 __construct ()
 ilAssOrderingElementList constructor. More...
 
 __clone ()
 clone list by additionally cloning the element objects More...
 
 getClone ()
 
 getQuestionId ()
 
 setQuestionId ($questionId)
 
 loadFromDb ()
 load elements from database More...
 
 clearElementContents ()
 clears the contents of all elements More...
 
 countElements ()
 
 isFirstElementPosition ($position)
 
 isLastElementPosition ($position)
 
 moveElementByPositions ($currentPosition, $targetPosition)
 
 removeElement (ilAssOrderingElement $removeElement)
 
 resetElements ()
 resets elements More...
 
 setElements ($elements)
 
 getElements ()
 
 getRandomIdentifierIndexedElements ()
 
 getRandomIdentifierIndex ()
 
 getSolutionIdentifierIndexedElements ()
 
 getSolutionIdentifierIndex ()
 
 addElement (ilAssOrderingElement $element)
 
 getElementByPosition ($position)
 
 elementExistByPosition ($position)
 
 getElementByRandomIdentifier ($randomIdentifier)
 
 elementExistByRandomIdentifier ($randomIdentifier)
 
 getElementBySolutionIdentifier ($solutionIdentifier)
 
 elementExistBySolutionIdentifier ($solutionIdentifier)
 
 distributeNewRandomIdentifiers ()
 
 hasSameElementSetByRandomIdentifiers (self $otherList)
 
 getParityTrueElementList (self $otherList)
 
 reorderByRandomIdentifiers ($randomIdentifiers)
 
 resetElementsIndentations ()
 resets the indentation to level 0 for all elements in list More...
 
 getDifferenceElementList (self $otherElementList)
 
 completeContentsFromElementList (self $otherList)
 
 current ()
 
 next ()
 
 key ()
 
 valid ()
 
 rewind ()
 

Static Public Member Functions

static isValidSolutionIdentifier ($identifier)
 
static isValidRandomIdentifier ($identifier)
 
static isValidPosition ($position)
 
static isValidIndentation ($indentation)
 
static getFallbackDefaultElement ()
 
static buildInstance ($questionId, $orderingElements=array())
 

Data Fields

 $objectInstanceId
 
const SOLUTION_IDENTIFIER_BUILD_MAX_TRIES = 1000
 
const SOLUTION_IDENTIFIER_VALUE_INTERVAL = 1
 
const SOLUTION_IDENTIFIER_START_VALUE = 0
 
const RANDOM_IDENTIFIER_BUILD_MAX_TRIES = 1000
 
const RANDOM_IDENTIFIER_RANGE_LOWER_BOUND = 1
 
const RANDOM_IDENTIFIER_RANGE_UPPER_BOUND = 100000
 
const FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER = 0
 
const JS_ADDED_ELEMENTS_RANDOM_IDENTIFIER_START_VALUE = -1
 
const JS_ADDED_ELEMENTS_RANDOM_IDENTIFIER_VALUE_INTERVAL = -1
 
const IDENTIFIER_TYPE_SOLUTION = 'SolutionIds'
 
const IDENTIFIER_TYPE_RANDOM = 'RandomIds'
 

Static Public Attributes

static $objectInstanceCounter = 0
 

Protected Member Functions

 getIndexedElements ($identifierType)
 
 getRegisteredSolutionIdentifiers ()
 
 getRegisteredRandomIdentifiers ()
 
 getRegisteredIdentifiers ($identifierType)
 
 hasValidIdentifiers (ilAssOrderingElement $element)
 
 ensureValidIdentifiers (ilAssOrderingElement $element)
 
 ensureValidIdentifier (ilAssOrderingElement $element, $identifierType)
 
 registerIdentifiers (ilAssOrderingElement $element)
 
 registerIdentifier (ilAssOrderingElement $element, $identifierType)
 
 isIdentifierRegistered (ilAssOrderingElement $element, $identifierType)
 
 fetchIdentifier (ilAssOrderingElement $element, $identifierType)
 
 populateIdentifier (ilAssOrderingElement $element, $identifierType, $identifier)
 
 isValidIdentifier ($identifierType, $identifier)
 
 buildIdentifier ($identifierType)
 
 throwUnknownIdentifierTypeException ($identifierType)
 
 throwCouldNotBuildRandomIdentifierException ($maxTries)
 
 throwMissingReorderPositionException ($randomIdentifier)
 
 throwUnknownRandomIdentifiersException ($randomIdentifiers)
 
 getLastSolutionIdentifier ()
 
 buildSolutionIdentifier ()
 
 buildRandomIdentifier ()
 
 getDifferenceRandomIdentifierIndex (self $otherElementList)
 

Protected Attributes

 $questionId
 
 $elements
 

Static Protected Attributes

static $identifierRegistry
 

Detailed Description

Definition at line 12 of file class.ilAssOrderingElementList.php.

Constructor & Destructor Documentation

◆ __construct()

ilAssOrderingElementList::__construct ( )

ilAssOrderingElementList constructor.

Definition at line 53 of file class.ilAssOrderingElementList.php.

54 {
55 $this->objectInstanceId = ++self::$objectInstanceCounter;
56
57 $this->questionId = null;
58 $this->resetElements();
59 }

References $objectInstanceCounter, and resetElements().

+ Here is the call graph for this function:

Member Function Documentation

◆ __clone()

ilAssOrderingElementList::__clone ( )

clone list by additionally cloning the element objects

Definition at line 64 of file class.ilAssOrderingElementList.php.

65 {
66 $this->objectInstanceId = ++self::$objectInstanceCounter;
67
68 $elements = array();
69
70 foreach ($this as $key => $element) {
71 $elements[$key] = clone $element;
72 }
73
74 $this->elements = $elements;
75 }
$key
Definition: croninfo.php:18

References $elements, $key, and $objectInstanceCounter.

◆ addElement()

ilAssOrderingElementList::addElement ( ilAssOrderingElement  $element)
Parameters
ilAssOrderingElement$element

Definition at line 308 of file class.ilAssOrderingElementList.php.

309 {
310 if ($this->hasValidIdentifiers($element)) {
311 $this->registerIdentifiers($element);
312 }
313
314 $this->elements[] = $element;
315 }
registerIdentifiers(ilAssOrderingElement $element)
hasValidIdentifiers(ilAssOrderingElement $element)

References hasValidIdentifiers(), and registerIdentifiers().

Referenced by loadFromDb(), and setElements().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildIdentifier()

ilAssOrderingElementList::buildIdentifier (   $identifierType)
protected
Parameters
string$identifierType
Returns
integer
Exceptions
ilTestQuestionPoolException

Definition at line 567 of file class.ilAssOrderingElementList.php.

References buildRandomIdentifier(), buildSolutionIdentifier(), IDENTIFIER_TYPE_RANDOM, IDENTIFIER_TYPE_SOLUTION, and throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildInstance()

static ilAssOrderingElementList::buildInstance (   $questionId,
  $orderingElements = array() 
)
static
Parameters
integer$questionId
array[ilAssOrderingElement]$orderingElements
Returns
ilAssOrderingElementList

Definition at line 959 of file class.ilAssOrderingElementList.php.

960 {
961 $elementList = new self();
962
963 $elementList->setQuestionId($questionId);
964 $elementList->setElements($orderingElements);
965
966 return $elementList;
967 }

References $questionId.

Referenced by assOrderingQuestion\fetchSolutionListFromFormSubmissionData(), ilAssNestedOrderingElementsInputGUI\getElementList(), ilAssOrderingImagesInputGUI\getElementList(), ilAssOrderingTextsInputGUI\getElementList(), and assOrderingQuestionGUI\removeElementImage().

+ Here is the caller graph for this function:

◆ buildRandomIdentifier()

ilAssOrderingElementList::buildRandomIdentifier ( )
protected
Returns
int $randomIdentifier
Exceptions
ilTestQuestionPoolException

Definition at line 660 of file class.ilAssOrderingElementList.php.

661 {
662 $usedTriesCounter = 0;
663
664 do {
665 if ($usedTriesCounter >= self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES) {
666 $this->throwCouldNotBuildRandomIdentifierException(self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES);
667 }
668
669 $usedTriesCounter++;
670
673 $randomIdentifier = mt_rand($lowerBound, $upperBound);
674
675 $testElement = new ilAssOrderingElement();
676 $testElement->setRandomIdentifier($randomIdentifier);
677 } while ($this->isIdentifierRegistered($testElement, self::IDENTIFIER_TYPE_RANDOM));
678
679 return $randomIdentifier;
680 }
isIdentifierRegistered(ilAssOrderingElement $element, $identifierType)

References isIdentifierRegistered(), RANDOM_IDENTIFIER_RANGE_LOWER_BOUND, RANDOM_IDENTIFIER_RANGE_UPPER_BOUND, and throwCouldNotBuildRandomIdentifierException().

Referenced by buildIdentifier(), and distributeNewRandomIdentifiers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildSolutionIdentifier()

ilAssOrderingElementList::buildSolutionIdentifier ( )
protected
Returns
integer|null $nextSolutionIdentifier

Definition at line 643 of file class.ilAssOrderingElementList.php.

644 {
645 $lastSolutionIdentifier = $this->getLastSolutionIdentifier();
646
647 if ($lastSolutionIdentifier === null) {
648 return 0;
649 }
650
651 $nextSolutionIdentifier = $lastSolutionIdentifier + self::SOLUTION_IDENTIFIER_VALUE_INTERVAL;
652
653 return $nextSolutionIdentifier;
654 }

References getLastSolutionIdentifier(), and SOLUTION_IDENTIFIER_VALUE_INTERVAL.

Referenced by buildIdentifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearElementContents()

ilAssOrderingElementList::clearElementContents ( )

clears the contents of all elements

Definition at line 164 of file class.ilAssOrderingElementList.php.

165 {
166 foreach ($this as $orderingElement) {
167 $orderingElement->setContent('');
168 }
169 }

◆ completeContentsFromElementList()

ilAssOrderingElementList::completeContentsFromElementList ( self  $otherList)
Parameters
ilAssOrderingElementList$otherList

Definition at line 888 of file class.ilAssOrderingElementList.php.

889 {
890 foreach ($this as $thisElement) {
891 if (!$otherList->elementExistByRandomIdentifier($thisElement->getRandomIdentifier())) {
892 continue;
893 }
894
895 $otherElement = $otherList->getElementByRandomIdentifier(
896 $thisElement->getRandomIdentifier()
897 );
898
899 $thisElement->setContent($otherElement->getContent());
900 }
901 }

◆ countElements()

ilAssOrderingElementList::countElements ( )

Definition at line 171 of file class.ilAssOrderingElementList.php.

172 {
173 return count($this->elements);
174 }

Referenced by hasSameElementSetByRandomIdentifiers(), and isLastElementPosition().

+ Here is the caller graph for this function:

◆ current()

ilAssOrderingElementList::current ( )
Returns
ilAssOrderingElement

Definition at line 906 of file class.ilAssOrderingElementList.php.

907 {
908 return current($this->elements);
909 }

References current().

Referenced by current().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ distributeNewRandomIdentifiers()

ilAssOrderingElementList::distributeNewRandomIdentifiers ( )

Definition at line 733 of file class.ilAssOrderingElementList.php.

734 {
735 foreach ($this as $element) {
736 $element->setRandomIdentifier($this->buildRandomIdentifier());
737 }
738 }

References buildRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistByPosition()

ilAssOrderingElementList::elementExistByPosition (   $position)
Parameters
$position
Returns
bool

Definition at line 334 of file class.ilAssOrderingElementList.php.

335 {
336 return ($this->getElementByPosition($position) !== null);
337 }

References getElementByPosition().

+ Here is the call graph for this function:

◆ elementExistByRandomIdentifier()

ilAssOrderingElementList::elementExistByRandomIdentifier (   $randomIdentifier)
Parameters
$randomIdentifier
Returns
bool

Definition at line 360 of file class.ilAssOrderingElementList.php.

361 {
362 return ($this->getElementByRandomIdentifier($randomIdentifier) !== null);
363 }

References getElementByRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistBySolutionIdentifier()

ilAssOrderingElementList::elementExistBySolutionIdentifier (   $solutionIdentifier)
Parameters
$solutionIdentifier
Returns
bool

Definition at line 385 of file class.ilAssOrderingElementList.php.

386 {
387 return ($this->getElementBySolutionIdentifier($solutionIdentifier) !== null);
388 }
getElementBySolutionIdentifier($solutionIdentifier)

References getElementBySolutionIdentifier().

+ Here is the call graph for this function:

◆ ensureValidIdentifier()

ilAssOrderingElementList::ensureValidIdentifier ( ilAssOrderingElement  $element,
  $identifierType 
)
protected
Parameters
ilAssOrderingElement$element
string$identifierType

Definition at line 453 of file class.ilAssOrderingElementList.php.

454 {
455 $identifier = $this->fetchIdentifier($element, $identifierType);
456
457 if (!$this->isValidIdentifier($identifierType, $identifier)) {
458 $identifier = $this->buildIdentifier($identifierType);
459 $this->populateIdentifier($element, $identifierType, $identifier);
460 $this->registerIdentifier($element, $identifierType);
461 }
462 }
registerIdentifier(ilAssOrderingElement $element, $identifierType)
populateIdentifier(ilAssOrderingElement $element, $identifierType, $identifier)
isValidIdentifier($identifierType, $identifier)
fetchIdentifier(ilAssOrderingElement $element, $identifierType)

References buildIdentifier(), fetchIdentifier(), isValidIdentifier(), populateIdentifier(), and registerIdentifier().

Referenced by ensureValidIdentifiers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ensureValidIdentifiers()

ilAssOrderingElementList::ensureValidIdentifiers ( ilAssOrderingElement  $element)
protected
Parameters
ilAssOrderingElement$element

Definition at line 443 of file class.ilAssOrderingElementList.php.

444 {
445 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
446 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
447 }
ensureValidIdentifier(ilAssOrderingElement $element, $identifierType)

References ensureValidIdentifier().

+ Here is the call graph for this function:

◆ fetchIdentifier()

ilAssOrderingElementList::fetchIdentifier ( ilAssOrderingElement  $element,
  $identifierType 
)
protected
Parameters
ilAssOrderingElement$element
string$identifierType
Returns
int
Exceptions
ilTestQuestionPoolException

Definition at line 518 of file class.ilAssOrderingElementList.php.

519 {
520 switch ($identifierType) {
522 case self::IDENTIFIER_TYPE_RANDOM: return $element->getRandomIdentifier();
523 }
524
525 $this->throwUnknownIdentifierTypeException($identifierType);
526 }

References ilAssOrderingElement\getRandomIdentifier(), ilAssOrderingElement\getSolutionIdentifier(), IDENTIFIER_TYPE_RANDOM, IDENTIFIER_TYPE_SOLUTION, and throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier(), getIndexedElements(), hasValidIdentifiers(), isIdentifierRegistered(), and registerIdentifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getClone()

ilAssOrderingElementList::getClone ( )
Returns
ilAssOrderingElementList

Definition at line 80 of file class.ilAssOrderingElementList.php.

81 {
82 $that = clone $this;
83 return $that;
84 }

◆ getDifferenceElementList()

ilAssOrderingElementList::getDifferenceElementList ( self  $otherElementList)
Parameters
ilAssOrderingElementList$otherElementList
Returns
$differenceElementList ilAssOrderingElementList

Definition at line 856 of file class.ilAssOrderingElementList.php.

857 {
858 $differenceRandomIdentifierIndex = $this->getDifferenceRandomIdentifierIndex($otherElementList);
859
860 $differenceElementList = new self();
861 $differenceElementList->setQuestionId($this->getQuestionId());
862
863 foreach ($differenceRandomIdentifierIndex as $randomIdentifier) {
864 $element = $this->getElementByRandomIdentifier($randomIdentifier);
865 $differenceElementList->addElement($element);
866 }
867
868 return $differenceElementList;
869 }
getDifferenceRandomIdentifierIndex(self $otherElementList)

References getDifferenceRandomIdentifierIndex(), getElementByRandomIdentifier(), and getQuestionId().

+ Here is the call graph for this function:

◆ getDifferenceRandomIdentifierIndex()

ilAssOrderingElementList::getDifferenceRandomIdentifierIndex ( self  $otherElementList)
protected
Parameters
ilAssOrderingElementList$other
Returns
array

Definition at line 875 of file class.ilAssOrderingElementList.php.

876 {
877 $differenceRandomIdentifierIndex = array_diff(
879 $otherElementList->getRandomIdentifierIndex()
880 );
881
882 return $differenceRandomIdentifierIndex;
883 }

References getRandomIdentifierIndex().

Referenced by getDifferenceElementList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getElementByPosition()

ilAssOrderingElementList::getElementByPosition (   $position)
Parameters
$randomIdentifier
Returns
ilAssOrderingElement

Definition at line 321 of file class.ilAssOrderingElementList.php.

322 {
323 if (isset($this->elements[$position])) {
324 return $this->elements[$position];
325 }
326
327 return null;
328 }

Referenced by assOrderingQuestion\calculateReachedPointsForSolution(), elementExistByPosition(), and moveElementByPositions().

+ Here is the caller graph for this function:

◆ getElementByRandomIdentifier()

ilAssOrderingElementList::getElementByRandomIdentifier (   $randomIdentifier)
Parameters
$randomIdentifier
Returns
ilAssOrderingElement

Definition at line 343 of file class.ilAssOrderingElementList.php.

344 {
345 foreach ($this as $element) {
346 if ($element->getRandomIdentifier() != $randomIdentifier) {
347 continue;
348 }
349
350 return $element;
351 }
352
353 return null;
354 }

Referenced by elementExistByRandomIdentifier(), and getDifferenceElementList().

+ Here is the caller graph for this function:

◆ getElementBySolutionIdentifier()

ilAssOrderingElementList::getElementBySolutionIdentifier (   $solutionIdentifier)
Parameters
$randomIdentifier
Returns
ilAssOrderingElement

Definition at line 369 of file class.ilAssOrderingElementList.php.

370 {
371 foreach ($this as $element) {
372 if ($element->getSolutionIdentifier() != $solutionIdentifier) {
373 continue;
374 }
375
376 return $element;
377 }
378 return null;
379 }

Referenced by elementExistBySolutionIdentifier().

+ Here is the caller graph for this function:

◆ getElements()

ilAssOrderingElementList::getElements ( )
Returns
array[ilAssOrderingElement]

Definition at line 254 of file class.ilAssOrderingElementList.php.

255 {
256 return $this->elements;
257 }

References $elements.

◆ getFallbackDefaultElement()

static ilAssOrderingElementList::getFallbackDefaultElement ( )
static
Returns
ilAssOrderingElement

Definition at line 946 of file class.ilAssOrderingElementList.php.

947 {
948 $element = new ilAssOrderingElement();
949 $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
950
951 return $element;
952 }

Referenced by ilAssOrderingDefaultElementFallback\manipulateFormInputValues().

+ Here is the caller graph for this function:

◆ getIndexedElements()

ilAssOrderingElementList::getIndexedElements (   $identifierType)
protected
Returns
array

Definition at line 294 of file class.ilAssOrderingElementList.php.

295 {
296 $elements = array();
297
298 foreach ($this as $element) {
299 $elements[$this->fetchIdentifier($element, $identifierType)] = $element;
300 }
301
302 return $elements;
303 }

References $elements, and fetchIdentifier().

Referenced by getRandomIdentifierIndexedElements(), and getSolutionIdentifierIndexedElements().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastSolutionIdentifier()

ilAssOrderingElementList::getLastSolutionIdentifier ( )
protected
Returns
integer|null $lastSolutionIdentifier

Definition at line 625 of file class.ilAssOrderingElementList.php.

626 {
627 $lastSolutionIdentifier = null;
628
629 foreach ($this->getRegisteredSolutionIdentifiers() as $registeredIdentifier) {
630 if ($lastSolutionIdentifier > $registeredIdentifier) {
631 continue;
632 }
633
634 $lastSolutionIdentifier = $registeredIdentifier;
635 }
636
637 return $lastSolutionIdentifier;
638 }

References getRegisteredSolutionIdentifiers().

Referenced by buildSolutionIdentifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParityTrueElementList()

ilAssOrderingElementList::getParityTrueElementList ( self  $otherList)

Definition at line 782 of file class.ilAssOrderingElementList.php.

783 {
784 if (!$this->hasSameElementSetByRandomIdentifiers($otherList)) {
785 throw new ilTestQuestionPoolException('cannot compare lists having different element sets');
786 }
787
788 $parityTrueElementList = new self();
789 $parityTrueElementList->setQuestionId($this->getQuestionId());
790
791 foreach ($this as $thisElement) {
792 $otherElement = $otherList->getElementByRandomIdentifier(
793 $thisElement->getRandomIdentifier()
794 );
795
796 if ($otherElement->getPosition() != $thisElement->getPosition()) {
797 continue;
798 }
799
800 if ($otherElement->getIndentation() != $thisElement->getIndentation()) {
801 continue;
802 }
803
804 $parityTrueElementList->addElement($thisElement);
805 }
806
807 return $parityTrueElementList;
808 }

References getQuestionId(), and hasSameElementSetByRandomIdentifiers().

+ Here is the call graph for this function:

◆ getQuestionId()

ilAssOrderingElementList::getQuestionId ( )
Returns
integer

Definition at line 89 of file class.ilAssOrderingElementList.php.

90 {
91 return $this->questionId;
92 }

References $questionId.

Referenced by getDifferenceElementList(), getParityTrueElementList(), getRegisteredIdentifiers(), isIdentifierRegistered(), loadFromDb(), moveElementByPositions(), registerIdentifier(), and removeElement().

+ Here is the caller graph for this function:

◆ getRandomIdentifierIndex()

ilAssOrderingElementList::getRandomIdentifierIndex ( )
Returns
array

Definition at line 270 of file class.ilAssOrderingElementList.php.

271 {
272 return array_keys($this->getRandomIdentifierIndexedElements());
273 }

References getRandomIdentifierIndexedElements().

Referenced by getDifferenceRandomIdentifierIndex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRandomIdentifierIndexedElements()

ilAssOrderingElementList::getRandomIdentifierIndexedElements ( )
Returns
array

Definition at line 262 of file class.ilAssOrderingElementList.php.

263 {
264 return $this->getIndexedElements(self::IDENTIFIER_TYPE_RANDOM);
265 }

References getIndexedElements().

Referenced by getRandomIdentifierIndex(), ilAssNestedOrderingElementsInputGUI\setElementList(), ilAssOrderingImagesInputGUI\setElementList(), and ilAssOrderingTextsInputGUI\setElementList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRegisteredIdentifiers()

ilAssOrderingElementList::getRegisteredIdentifiers (   $identifierType)
protected
Parameters
string$identifierType
Returns
array

Definition at line 410 of file class.ilAssOrderingElementList.php.

411 {
412 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
413 return array();
414 }
415
416 return self::$identifierRegistry[$identifierType][$this->getQuestionId()];
417 }

References getQuestionId().

Referenced by getRegisteredRandomIdentifiers(), and getRegisteredSolutionIdentifiers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRegisteredRandomIdentifiers()

ilAssOrderingElementList::getRegisteredRandomIdentifiers ( )
protected
Returns
array

Definition at line 401 of file class.ilAssOrderingElementList.php.

402 {
403 return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_RANDOM);
404 }

References getRegisteredIdentifiers().

+ Here is the call graph for this function:

◆ getRegisteredSolutionIdentifiers()

ilAssOrderingElementList::getRegisteredSolutionIdentifiers ( )
protected
Returns
array

Definition at line 393 of file class.ilAssOrderingElementList.php.

394 {
395 return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_SOLUTION);
396 }

References getRegisteredIdentifiers().

Referenced by getLastSolutionIdentifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSolutionIdentifierIndex()

ilAssOrderingElementList::getSolutionIdentifierIndex ( )
Returns
array

Definition at line 286 of file class.ilAssOrderingElementList.php.

287 {
288 return array_keys($this->getSolutionIdentifierIndexedElements());
289 }

References getSolutionIdentifierIndexedElements().

+ Here is the call graph for this function:

◆ getSolutionIdentifierIndexedElements()

ilAssOrderingElementList::getSolutionIdentifierIndexedElements ( )
Returns
array

Definition at line 278 of file class.ilAssOrderingElementList.php.

279 {
280 return $this->getIndexedElements(self::IDENTIFIER_TYPE_SOLUTION);
281 }

References getIndexedElements().

Referenced by getSolutionIdentifierIndex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasSameElementSetByRandomIdentifiers()

ilAssOrderingElementList::hasSameElementSetByRandomIdentifiers ( self  $otherList)
Parameters
ilAssOrderingElementList$otherList
Returns
bool $hasSameElements

Definition at line 744 of file class.ilAssOrderingElementList.php.

745 {
746 $numIntersectingElements = count(array_intersect(
747 $otherList->getRandomIdentifierIndex(),
748 $this->getRandomIdentifierIndex()
749 ));
750
751 if ($numIntersectingElements != $this->countElements()) {
752 return false;
753 }
754
755 if ($numIntersectingElements != $otherList->countElements()) {
756 return false;
757 }
758
759 return true; // faster ;-)
760
761 $otherListRandomIdentifierIndex = $otherList->getRandomIdentifierIndex();
762
763 foreach ($this as $orderingElement) {
764 if (!in_array($orderingElement->getRandomIdentifier(), $otherListRandomIdentifierIndex)) {
765 return false;
766 }
767
768 $randomIdentifierIndexMatchingsCount = count(array_keys(
769 $otherListRandomIdentifierIndex,
770 $orderingElement->getRandomIdentifier(),
771 false
772 ));
773
774 if ($randomIdentifierIndexMatchingsCount != 1) {
775 return false;
776 }
777 }
778
779 return $this->countElements() == $otherList->countElements();
780 }

References countElements().

Referenced by getParityTrueElementList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasValidIdentifiers()

ilAssOrderingElementList::hasValidIdentifiers ( ilAssOrderingElement  $element)
protected
Parameters
ilAssOrderingElement$element
Returns
bool

Definition at line 423 of file class.ilAssOrderingElementList.php.

424 {
425 $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
426
427 if (!$this->isValidIdentifier(self::IDENTIFIER_TYPE_SOLUTION, $identifier)) {
428 return false;
429 }
430
431 $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
432
433 if (!$this->isValidIdentifier(self::IDENTIFIER_TYPE_RANDOM, $identifier)) {
434 return false;
435 }
436
437 return true;
438 }

References fetchIdentifier(), and isValidIdentifier().

Referenced by addElement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isFirstElementPosition()

ilAssOrderingElementList::isFirstElementPosition (   $position)

Definition at line 176 of file class.ilAssOrderingElementList.php.

177 {
178 return $position == 0;
179 }

◆ isIdentifierRegistered()

ilAssOrderingElementList::isIdentifierRegistered ( ilAssOrderingElement  $element,
  $identifierType 
)
protected
Parameters
ilAssOrderingElement$element
string$identifierType
Returns
bool
Exceptions
ilTestQuestionPoolException

Definition at line 497 of file class.ilAssOrderingElementList.php.

498 {
499 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
500 return false;
501 }
502
503 $identifier = $this->fetchIdentifier($element, $identifierType);
504
505 if (!in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
506 return false;
507 }
508
509 return true;
510 }

References fetchIdentifier(), and getQuestionId().

Referenced by buildRandomIdentifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isLastElementPosition()

ilAssOrderingElementList::isLastElementPosition (   $position)

Definition at line 181 of file class.ilAssOrderingElementList.php.

182 {
183 return $position == ($this->countElements() - 1);
184 }

References countElements().

+ Here is the call graph for this function:

◆ isValidIdentifier()

ilAssOrderingElementList::isValidIdentifier (   $identifierType,
  $identifier 
)
protected
Parameters
string$identifierType
$identifier
Returns
mixed
Exceptions
ilTestQuestionPoolException

Definition at line 549 of file class.ilAssOrderingElementList.php.

550 {
551 switch ($identifierType) {
553 return self::isValidSolutionIdentifier($identifier);
554
556 return self::isValidRandomIdentifier($identifier);
557 }
558
559 $this->throwUnknownIdentifierTypeException($identifierType);
560 }

References IDENTIFIER_TYPE_RANDOM, IDENTIFIER_TYPE_SOLUTION, isValidRandomIdentifier(), isValidSolutionIdentifier(), and throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier(), and hasValidIdentifiers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidIndentation()

static ilAssOrderingElementList::isValidIndentation (   $indentation)
static

Definition at line 725 of file class.ilAssOrderingElementList.php.

726 {
727 return self::isValidPosition($indentation); // horizontal position ^^
728 }

References isValidPosition().

Referenced by ilAssOrderingElement\isExportIdent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidPosition()

static ilAssOrderingElementList::isValidPosition (   $position)
static

Definition at line 720 of file class.ilAssOrderingElementList.php.

721 {
722 return self::isValidSolutionIdentifier($position); // this was the position earlier
723 }

References isValidSolutionIdentifier().

Referenced by ilAssOrderingElement\isExportIdent(), and isValidIndentation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidRandomIdentifier()

static ilAssOrderingElementList::isValidRandomIdentifier (   $identifier)
static

Definition at line 699 of file class.ilAssOrderingElementList.php.

700 {
701 if (!is_numeric($identifier)) {
702 return false;
703 }
704
705 if ($identifier != (int) $identifier) {
706 return false;
707 }
708
709 if ($identifier < self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND) {
710 return false;
711 }
712
713 if ($identifier > self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND) {
714 return false;
715 }
716
717 return true;
718 }

Referenced by ilAssOrderingElement\isExportIdent(), and isValidIdentifier().

+ Here is the caller graph for this function:

◆ isValidSolutionIdentifier()

static ilAssOrderingElementList::isValidSolutionIdentifier (   $identifier)
static

Definition at line 682 of file class.ilAssOrderingElementList.php.

683 {
684 if (!is_numeric($identifier)) {
685 return false;
686 }
687
688 if ($identifier != (int) $identifier) {
689 return false;
690 }
691
692 if ($identifier < 0) {
693 return false;
694 }
695
696 return true;
697 }

Referenced by ilAssOrderingElement\isExportIdent(), isValidIdentifier(), and isValidPosition().

+ Here is the caller graph for this function:

◆ key()

ilAssOrderingElementList::key ( )
Returns
integer|bool

Definition at line 922 of file class.ilAssOrderingElementList.php.

923 {
924 return key($this->elements);
925 }

References key().

Referenced by key(), and valid().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadFromDb()

ilAssOrderingElementList::loadFromDb ( )

load elements from database

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

106 {
107 $ilDB = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['ilDB'] : $GLOBALS['ilDB'];
108
109 $result = $ilDB->queryF(
110 "SELECT * FROM qpl_a_ordering WHERE question_fi = %s ORDER BY position ASC",
111 array('integer'),
112 array($this->getQuestionId())
113 );
114
115 while ($row = $ilDB->fetchAssoc($result)) {
116 $element = new ilAssOrderingElement();
117
118 $element->setRandomIdentifier($row['random_id']);
119 $element->setSolutionIdentifier($row['solution_key']);
120
121 $element->setPosition($row['position']);
122 $element->setIndentation($row["depth"]);
123
124 $element->setContent($row['answertext']);
125
126 $this->addElement($element);
127 $this->registerIdentifiers($element);
128 }
129 }
$result
addElement(ilAssOrderingElement $element)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilDB

References $GLOBALS, $ilDB, $result, $row, addElement(), getQuestionId(), and registerIdentifiers().

+ Here is the call graph for this function:

◆ moveElementByPositions()

ilAssOrderingElementList::moveElementByPositions (   $currentPosition,
  $targetPosition 
)

Definition at line 186 of file class.ilAssOrderingElementList.php.

187 {
188 $movingElement = $this->getElementByPosition($currentPosition);
189 $dodgingElement = $this->getElementByPosition($targetPosition);
190
191 $elementList = new self();
192 $elementList->setQuestionId($this->getQuestionId());
193
194 foreach ($this as $element) {
195 if ($element->getPosition() == $currentPosition) {
196 $elementList->addElement($dodgingElement);
197 continue;
198 }
199
200 if ($element->getPosition() == $targetPosition) {
201 $elementList->addElement($movingElement);
202 continue;
203 }
204
205 $elementList->addElement($element);
206 }
207
208 $dodgingElement->setPosition($currentPosition);
209 $movingElement->setPosition($targetPosition);
210
211 $this->setElements($elementList->getElements());
212 }

References getElementByPosition(), getQuestionId(), and setElements().

+ Here is the call graph for this function:

◆ next()

ilAssOrderingElementList::next ( )
Returns
ilAssOrderingElement

Definition at line 914 of file class.ilAssOrderingElementList.php.

915 {
916 return next($this->elements);
917 }

References next().

Referenced by next().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ populateIdentifier()

ilAssOrderingElementList::populateIdentifier ( ilAssOrderingElement  $element,
  $identifierType,
  $identifier 
)
protected
Parameters
ilAssOrderingElement$element
string$identifierType
$identifier
Exceptions
ilTestQuestionPoolException

Definition at line 534 of file class.ilAssOrderingElementList.php.

535 {
536 switch ($identifierType) {
537 case self::IDENTIFIER_TYPE_SOLUTION: $element->setSolutionIdentifier($identifier); break;
538 case self::IDENTIFIER_TYPE_RANDOM: $element->setRandomIdentifier($identifier); break;
539 default: $this->throwUnknownIdentifierTypeException($identifierType);
540 }
541 }
setRandomIdentifier($randomIdentifier)
setSolutionIdentifier($solutionIdentifier)

References IDENTIFIER_TYPE_RANDOM, IDENTIFIER_TYPE_SOLUTION, ilAssOrderingElement\setRandomIdentifier(), ilAssOrderingElement\setSolutionIdentifier(), and throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerIdentifier()

ilAssOrderingElementList::registerIdentifier ( ilAssOrderingElement  $element,
  $identifierType 
)
protected
Parameters
ilAssOrderingElement$element
string$identifierType
Exceptions
ilTestQuestionPoolException

Definition at line 478 of file class.ilAssOrderingElementList.php.

479 {
480 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
481 self::$identifierRegistry[$identifierType][$this->getQuestionId()] = array();
482 }
483
484 $identifier = $this->fetchIdentifier($element, $identifierType);
485
486 if (!in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
487 self::$identifierRegistry[$identifierType][$this->getQuestionId()][] = $identifier;
488 }
489 }

References fetchIdentifier(), and getQuestionId().

Referenced by ensureValidIdentifier(), and registerIdentifiers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerIdentifiers()

ilAssOrderingElementList::registerIdentifiers ( ilAssOrderingElement  $element)
protected
Parameters
ilAssOrderingElement$element

Definition at line 467 of file class.ilAssOrderingElementList.php.

468 {
469 $this->registerIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
470 $this->registerIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
471 }

References registerIdentifier().

Referenced by addElement(), and loadFromDb().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeElement()

ilAssOrderingElementList::removeElement ( ilAssOrderingElement  $removeElement)

Definition at line 214 of file class.ilAssOrderingElementList.php.

215 {
216 $elementList = new self();
217 $elementList->setQuestionId($this->getQuestionId());
218
219 $positionCounter = 0;
220
221 foreach ($this as $element) {
222 if ($element->isSameElement($removeElement)) {
223 continue;
224 }
225
226 $element->setPosition($positionCounter++);
227 $elementList->addElement($element);
228 }
229 }

References getQuestionId().

+ Here is the call graph for this function:

◆ reorderByRandomIdentifiers()

ilAssOrderingElementList::reorderByRandomIdentifiers (   $randomIdentifiers)
Parameters
$randomIdentifiers
Returns
ilAssOrderingElementList
Exceptions
ilTestQuestionPoolException

Definition at line 815 of file class.ilAssOrderingElementList.php.

816 {
817 $positionsMap = array_flip(array_values($randomIdentifiers));
818
819 $orderedElements = array();
820
821 foreach ($this as $element) {
822 if (!isset($positionsMap[$element->getRandomIdentifier()])) {
823 $this->throwMissingReorderPositionException($element->getRandomIdentifier());
824 }
825
826 $position = $positionsMap[$element->getRandomIdentifier()];
827 unset($positionsMap[$element->getRandomIdentifier()]);
828
829 $element->setPosition($position);
830 $orderedElements[$position] = $element;
831 }
832
833 if (count($positionsMap)) {
834 $this->throwUnknownRandomIdentifiersException(array_keys($positionsMap));
835 }
836
837 ksort($orderedElements);
838
839 $this->setElements(array_values($orderedElements));
840 }
throwMissingReorderPositionException($randomIdentifier)
throwUnknownRandomIdentifiersException($randomIdentifiers)

References setElements(), throwMissingReorderPositionException(), and throwUnknownRandomIdentifiersException().

+ Here is the call graph for this function:

◆ resetElements()

ilAssOrderingElementList::resetElements ( )

resets elements

Definition at line 234 of file class.ilAssOrderingElementList.php.

235 {
236 $this->elements = array();
237 }

Referenced by __construct(), and setElements().

+ Here is the caller graph for this function:

◆ resetElementsIndentations()

ilAssOrderingElementList::resetElementsIndentations ( )

resets the indentation to level 0 for all elements in list

Definition at line 845 of file class.ilAssOrderingElementList.php.

846 {
847 foreach ($this as $element) {
848 $element->setIndentation(0);
849 }
850 }

◆ rewind()

ilAssOrderingElementList::rewind ( )
Returns
ilAssOrderingElement

Definition at line 938 of file class.ilAssOrderingElementList.php.

939 {
940 return reset($this->elements);
941 }

◆ setElements()

ilAssOrderingElementList::setElements (   $elements)
Parameters
$elements

Definition at line 242 of file class.ilAssOrderingElementList.php.

243 {
244 $this->resetElements();
245
246 foreach ($elements as $element) {
247 $this->addElement($element);
248 }
249 }

References $elements, addElement(), and resetElements().

Referenced by moveElementByPositions(), and reorderByRandomIdentifiers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setQuestionId()

ilAssOrderingElementList::setQuestionId (   $questionId)
Parameters
integer$questionId

Definition at line 97 of file class.ilAssOrderingElementList.php.

98 {
99 $this->questionId = $questionId;
100 }

References $questionId.

◆ throwCouldNotBuildRandomIdentifierException()

ilAssOrderingElementList::throwCouldNotBuildRandomIdentifierException (   $maxTries)
protected
Parameters
string$identifierType
Exceptions
ilTestQuestionPoolException

Definition at line 592 of file class.ilAssOrderingElementList.php.

593 {
595 "could not build random identifier (max tries: $maxTries)"
596 );
597 }

Referenced by buildRandomIdentifier().

+ Here is the caller graph for this function:

◆ throwMissingReorderPositionException()

ilAssOrderingElementList::throwMissingReorderPositionException (   $randomIdentifier)
protected
Parameters
string$randomIdentifier
Exceptions
ilTestQuestionPoolException

Definition at line 603 of file class.ilAssOrderingElementList.php.

604 {
606 "cannot reorder element due to missing position (random identifier: $randomIdentifier)"
607 );
608 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ throwUnknownIdentifierTypeException()

ilAssOrderingElementList::throwUnknownIdentifierTypeException (   $identifierType)
protected
Parameters
string$identifierType
Exceptions
ilTestQuestionPoolException

Definition at line 581 of file class.ilAssOrderingElementList.php.

582 {
584 "unknown identifier type given (type: $identifierType)"
585 );
586 }

Referenced by buildIdentifier(), fetchIdentifier(), isValidIdentifier(), and populateIdentifier().

+ Here is the caller graph for this function:

◆ throwUnknownRandomIdentifiersException()

ilAssOrderingElementList::throwUnknownRandomIdentifiersException (   $randomIdentifiers)
protected
Parameters
array$randomIdentifiers
Exceptions
ilTestQuestionPoolException

Definition at line 614 of file class.ilAssOrderingElementList.php.

615 {
617 'cannot reorder element due to one or more unknown random identifiers ' .
618 '(' . implode(', ', $randomIdentifiers) . ')'
619 );
620 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ valid()

ilAssOrderingElementList::valid ( )
Returns
bool

Definition at line 930 of file class.ilAssOrderingElementList.php.

931 {
932 return ($this->key() !== null);
933 }

References key().

+ Here is the call graph for this function:

Field Documentation

◆ $elements

ilAssOrderingElementList::$elements
protected

◆ $identifierRegistry

ilAssOrderingElementList::$identifierRegistry
staticprotected
Initial value:
= array(
self::IDENTIFIER_TYPE_SOLUTION => array(),
self::IDENTIFIER_TYPE_RANDOM => array()
)

Definition at line 35 of file class.ilAssOrderingElementList.php.

◆ $objectInstanceCounter

ilAssOrderingElementList::$objectInstanceCounter = 0
static

Definition at line 14 of file class.ilAssOrderingElementList.php.

Referenced by __clone(), and __construct().

◆ $objectInstanceId

ilAssOrderingElementList::$objectInstanceId

Definition at line 15 of file class.ilAssOrderingElementList.php.

◆ $questionId

ilAssOrderingElementList::$questionId
protected

Definition at line 43 of file class.ilAssOrderingElementList.php.

Referenced by buildInstance(), getQuestionId(), and setQuestionId().

◆ FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER

const ilAssOrderingElementList::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER = 0

Definition at line 25 of file class.ilAssOrderingElementList.php.

◆ IDENTIFIER_TYPE_RANDOM

const ilAssOrderingElementList::IDENTIFIER_TYPE_RANDOM = 'RandomIds'

◆ IDENTIFIER_TYPE_SOLUTION

const ilAssOrderingElementList::IDENTIFIER_TYPE_SOLUTION = 'SolutionIds'

◆ JS_ADDED_ELEMENTS_RANDOM_IDENTIFIER_START_VALUE

const ilAssOrderingElementList::JS_ADDED_ELEMENTS_RANDOM_IDENTIFIER_START_VALUE = -1

Definition at line 26 of file class.ilAssOrderingElementList.php.

◆ JS_ADDED_ELEMENTS_RANDOM_IDENTIFIER_VALUE_INTERVAL

const ilAssOrderingElementList::JS_ADDED_ELEMENTS_RANDOM_IDENTIFIER_VALUE_INTERVAL = -1

Definition at line 27 of file class.ilAssOrderingElementList.php.

◆ RANDOM_IDENTIFIER_BUILD_MAX_TRIES

const ilAssOrderingElementList::RANDOM_IDENTIFIER_BUILD_MAX_TRIES = 1000

Definition at line 21 of file class.ilAssOrderingElementList.php.

◆ RANDOM_IDENTIFIER_RANGE_LOWER_BOUND

const ilAssOrderingElementList::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND = 1

Definition at line 22 of file class.ilAssOrderingElementList.php.

Referenced by buildRandomIdentifier().

◆ RANDOM_IDENTIFIER_RANGE_UPPER_BOUND

const ilAssOrderingElementList::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND = 100000

Definition at line 23 of file class.ilAssOrderingElementList.php.

Referenced by buildRandomIdentifier().

◆ SOLUTION_IDENTIFIER_BUILD_MAX_TRIES

const ilAssOrderingElementList::SOLUTION_IDENTIFIER_BUILD_MAX_TRIES = 1000

Definition at line 17 of file class.ilAssOrderingElementList.php.

◆ SOLUTION_IDENTIFIER_START_VALUE

const ilAssOrderingElementList::SOLUTION_IDENTIFIER_START_VALUE = 0

Definition at line 19 of file class.ilAssOrderingElementList.php.

◆ SOLUTION_IDENTIFIER_VALUE_INTERVAL

const ilAssOrderingElementList::SOLUTION_IDENTIFIER_VALUE_INTERVAL = 1

Definition at line 18 of file class.ilAssOrderingElementList.php.

Referenced by buildSolutionIdentifier().


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