ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 
 hasElements ()
 
 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 ()
 
 getHash ()
 

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 314 of file class.ilAssOrderingElementList.php.

315 {
316 if ($this->hasValidIdentifiers($element)) {
317 $this->registerIdentifiers($element);
318 }
319
320 $this->elements[] = $element;
321 }
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 573 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 965 of file class.ilAssOrderingElementList.php.

966 {
967 $elementList = new self();
968
969 $elementList->setQuestionId($questionId);
970 $elementList->setElements($orderingElements);
971
972 return $elementList;
973 }

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 666 of file class.ilAssOrderingElementList.php.

667 {
668 $usedTriesCounter = 0;
669
670 do {
671 if ($usedTriesCounter >= self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES) {
672 $this->throwCouldNotBuildRandomIdentifierException(self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES);
673 }
674
675 $usedTriesCounter++;
676
679 $randomIdentifier = mt_rand($lowerBound, $upperBound);
680
681 $testElement = new ilAssOrderingElement();
682 $testElement->setRandomIdentifier($randomIdentifier);
683 } while ($this->isIdentifierRegistered($testElement, self::IDENTIFIER_TYPE_RANDOM));
684
685 return $randomIdentifier;
686 }
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 649 of file class.ilAssOrderingElementList.php.

650 {
651 $lastSolutionIdentifier = $this->getLastSolutionIdentifier();
652
653 if ($lastSolutionIdentifier === null) {
654 return 0;
655 }
656
657 $nextSolutionIdentifier = $lastSolutionIdentifier + self::SOLUTION_IDENTIFIER_VALUE_INTERVAL;
658
659 return $nextSolutionIdentifier;
660 }

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 165 of file class.ilAssOrderingElementList.php.

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

◆ completeContentsFromElementList()

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

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

895 {
896 foreach ($this as $thisElement) {
897 if (!$otherList->elementExistByRandomIdentifier($thisElement->getRandomIdentifier())) {
898 continue;
899 }
900
901 $otherElement = $otherList->getElementByRandomIdentifier(
902 $thisElement->getRandomIdentifier()
903 );
904
905 $thisElement->setContent($otherElement->getContent());
906 }
907 }

◆ countElements()

ilAssOrderingElementList::countElements ( )

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

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

Referenced by hasElements(), hasSameElementSetByRandomIdentifiers(), and isLastElementPosition().

+ Here is the caller graph for this function:

◆ current()

ilAssOrderingElementList::current ( )
Returns
ilAssOrderingElement

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

913 {
914 return current($this->elements);
915 }

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 739 of file class.ilAssOrderingElementList.php.

740 {
741 foreach ($this as $element) {
742 $element->setRandomIdentifier($this->buildRandomIdentifier());
743 }
744 }

References buildRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistByPosition()

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

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

341 {
342 return ($this->getElementByPosition($position) !== null);
343 }

References getElementByPosition().

+ Here is the call graph for this function:

◆ elementExistByRandomIdentifier()

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

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

367 {
368 return ($this->getElementByRandomIdentifier($randomIdentifier) !== null);
369 }

References getElementByRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistBySolutionIdentifier()

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

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

392 {
393 return ($this->getElementBySolutionIdentifier($solutionIdentifier) !== null);
394 }
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 459 of file class.ilAssOrderingElementList.php.

460 {
461 $identifier = $this->fetchIdentifier($element, $identifierType);
462
463 if (!$this->isValidIdentifier($identifierType, $identifier)) {
464 $identifier = $this->buildIdentifier($identifierType);
465 $this->populateIdentifier($element, $identifierType, $identifier);
466 $this->registerIdentifier($element, $identifierType);
467 }
468 }
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 449 of file class.ilAssOrderingElementList.php.

450 {
451 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
452 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
453 }
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 524 of file class.ilAssOrderingElementList.php.

525 {
526 switch ($identifierType) {
528 case self::IDENTIFIER_TYPE_RANDOM: return $element->getRandomIdentifier();
529 }
530
531 $this->throwUnknownIdentifierTypeException($identifierType);
532 }

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 862 of file class.ilAssOrderingElementList.php.

863 {
864 $differenceRandomIdentifierIndex = $this->getDifferenceRandomIdentifierIndex($otherElementList);
865
866 $differenceElementList = new self();
867 $differenceElementList->setQuestionId($this->getQuestionId());
868
869 foreach ($differenceRandomIdentifierIndex as $randomIdentifier) {
870 $element = $this->getElementByRandomIdentifier($randomIdentifier);
871 $differenceElementList->addElement($element);
872 }
873
874 return $differenceElementList;
875 }
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 881 of file class.ilAssOrderingElementList.php.

882 {
883 $differenceRandomIdentifierIndex = array_diff(
885 $otherElementList->getRandomIdentifierIndex()
886 );
887
888 return $differenceRandomIdentifierIndex;
889 }

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 327 of file class.ilAssOrderingElementList.php.

328 {
329 if (isset($this->elements[$position])) {
330 return $this->elements[$position];
331 }
332
333 return null;
334 }

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 349 of file class.ilAssOrderingElementList.php.

350 {
351 foreach ($this as $element) {
352 if ($element->getRandomIdentifier() != $randomIdentifier) {
353 continue;
354 }
355
356 return $element;
357 }
358
359 return null;
360 }

Referenced by elementExistByRandomIdentifier(), and getDifferenceElementList().

+ Here is the caller graph for this function:

◆ getElementBySolutionIdentifier()

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

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

376 {
377 foreach ($this as $element) {
378 if ($element->getSolutionIdentifier() != $solutionIdentifier) {
379 continue;
380 }
381
382 return $element;
383 }
384 return null;
385 }

Referenced by elementExistBySolutionIdentifier().

+ Here is the caller graph for this function:

◆ getElements()

ilAssOrderingElementList::getElements ( )
Returns
array[ilAssOrderingElement]

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

261 {
262 return $this->elements;
263 }

References $elements.

◆ getFallbackDefaultElement()

static ilAssOrderingElementList::getFallbackDefaultElement ( )
static
Returns
ilAssOrderingElement

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

953 {
954 $element = new ilAssOrderingElement();
955 $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
956
957 return $element;
958 }

Referenced by ilAssOrderingDefaultElementFallback\manipulateFormInputValues().

+ Here is the caller graph for this function:

◆ getHash()

ilAssOrderingElementList::getHash ( )

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

976 {
977 $items = array();
978
979 foreach ($this as $element) {
980 $items[] = implode(':', array(
981 $element->getSolutionIdentifier(),
982 $element->getRandomIdentifier(),
983 $element->getIndentation()
984 ));
985 }
986
987 return md5(serialize($items));
988 }

◆ getIndexedElements()

ilAssOrderingElementList::getIndexedElements (   $identifierType)
protected
Returns
array

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

301 {
302 $elements = array();
303
304 foreach ($this as $element) {
305 $elements[$this->fetchIdentifier($element, $identifierType)] = $element;
306 }
307
308 return $elements;
309 }

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 631 of file class.ilAssOrderingElementList.php.

632 {
633 $lastSolutionIdentifier = null;
634
635 foreach ($this->getRegisteredSolutionIdentifiers() as $registeredIdentifier) {
636 if ($lastSolutionIdentifier > $registeredIdentifier) {
637 continue;
638 }
639
640 $lastSolutionIdentifier = $registeredIdentifier;
641 }
642
643 return $lastSolutionIdentifier;
644 }

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 788 of file class.ilAssOrderingElementList.php.

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

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 276 of file class.ilAssOrderingElementList.php.

277 {
278 return array_keys($this->getRandomIdentifierIndexedElements());
279 }

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 268 of file class.ilAssOrderingElementList.php.

269 {
270 return $this->getIndexedElements(self::IDENTIFIER_TYPE_RANDOM);
271 }

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 416 of file class.ilAssOrderingElementList.php.

417 {
418 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
419 return array();
420 }
421
422 return self::$identifierRegistry[$identifierType][$this->getQuestionId()];
423 }

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 407 of file class.ilAssOrderingElementList.php.

408 {
409 return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_RANDOM);
410 }

References getRegisteredIdentifiers().

+ Here is the call graph for this function:

◆ getRegisteredSolutionIdentifiers()

ilAssOrderingElementList::getRegisteredSolutionIdentifiers ( )
protected
Returns
array

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

400 {
401 return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_SOLUTION);
402 }

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 292 of file class.ilAssOrderingElementList.php.

293 {
294 return array_keys($this->getSolutionIdentifierIndexedElements());
295 }

References getSolutionIdentifierIndexedElements().

+ Here is the call graph for this function:

◆ getSolutionIdentifierIndexedElements()

ilAssOrderingElementList::getSolutionIdentifierIndexedElements ( )
Returns
array

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

285 {
286 return $this->getIndexedElements(self::IDENTIFIER_TYPE_SOLUTION);
287 }

References getIndexedElements().

Referenced by getSolutionIdentifierIndex().

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

◆ hasElements()

ilAssOrderingElementList::hasElements ( )

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

178 {
179 return (bool) $this->countElements();
180 }

References countElements().

+ Here is the call graph for this function:

◆ hasSameElementSetByRandomIdentifiers()

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

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

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

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 429 of file class.ilAssOrderingElementList.php.

430 {
431 $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
432
433 if (!$this->isValidIdentifier(self::IDENTIFIER_TYPE_SOLUTION, $identifier)) {
434 return false;
435 }
436
437 $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
438
439 if (!$this->isValidIdentifier(self::IDENTIFIER_TYPE_RANDOM, $identifier)) {
440 return false;
441 }
442
443 return true;
444 }

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 182 of file class.ilAssOrderingElementList.php.

183 {
184 return $position == 0;
185 }

◆ isIdentifierRegistered()

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

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

504 {
505 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
506 return false;
507 }
508
509 $identifier = $this->fetchIdentifier($element, $identifierType);
510
511 if (!in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
512 return false;
513 }
514
515 return true;
516 }

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 187 of file class.ilAssOrderingElementList.php.

188 {
189 return $position == ($this->countElements() - 1);
190 }

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 555 of file class.ilAssOrderingElementList.php.

556 {
557 switch ($identifierType) {
559 return self::isValidSolutionIdentifier($identifier);
560
562 return self::isValidRandomIdentifier($identifier);
563 }
564
565 $this->throwUnknownIdentifierTypeException($identifierType);
566 }

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 731 of file class.ilAssOrderingElementList.php.

732 {
733 return self::isValidPosition($indentation); // horizontal position ^^
734 }

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 726 of file class.ilAssOrderingElementList.php.

727 {
728 return self::isValidSolutionIdentifier($position); // this was the position earlier
729 }

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 705 of file class.ilAssOrderingElementList.php.

706 {
707 if (!is_numeric($identifier)) {
708 return false;
709 }
710
711 if ($identifier != (int) $identifier) {
712 return false;
713 }
714
715 if ($identifier < self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND) {
716 return false;
717 }
718
719 if ($identifier > self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND) {
720 return false;
721 }
722
723 return true;
724 }

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

+ Here is the caller graph for this function:

◆ isValidSolutionIdentifier()

static ilAssOrderingElementList::isValidSolutionIdentifier (   $identifier)
static

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

689 {
690 if (!is_numeric($identifier)) {
691 return false;
692 }
693
694 if ($identifier != (int) $identifier) {
695 return false;
696 }
697
698 if ($identifier < 0) {
699 return false;
700 }
701
702 return true;
703 }

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

+ Here is the caller graph for this function:

◆ key()

ilAssOrderingElementList::key ( )
Returns
integer|bool

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

929 {
930 return key($this->elements);
931 }

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 global $DIC; /* @var ILIAS\DI\Container $DIC */
108 $ilDB = $DIC['ilDB'];
109
110 $result = $ilDB->queryF(
111 "SELECT * FROM qpl_a_ordering WHERE question_fi = %s ORDER BY position ASC",
112 array('integer'),
113 array($this->getQuestionId())
114 );
115
116 while ($row = $ilDB->fetchAssoc($result)) {
117 $element = new ilAssOrderingElement();
118
119 $element->setRandomIdentifier($row['random_id']);
120 $element->setSolutionIdentifier($row['solution_key']);
121
122 $element->setPosition($row['position']);
123 $element->setIndentation($row["depth"]);
124
125 $element->setContent($row['answertext']);
126
127 $this->addElement($element);
128 $this->registerIdentifiers($element);
129 }
130 }
$result
addElement(ilAssOrderingElement $element)
$row
global $DIC
Definition: saml.php:7
global $ilDB

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

+ Here is the call graph for this function:

◆ moveElementByPositions()

ilAssOrderingElementList::moveElementByPositions (   $currentPosition,
  $targetPosition 
)

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

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

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

+ Here is the call graph for this function:

◆ next()

ilAssOrderingElementList::next ( )
Returns
ilAssOrderingElement

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

921 {
922 return next($this->elements);
923 }

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 540 of file class.ilAssOrderingElementList.php.

541 {
542 switch ($identifierType) {
543 case self::IDENTIFIER_TYPE_SOLUTION: $element->setSolutionIdentifier($identifier); break;
544 case self::IDENTIFIER_TYPE_RANDOM: $element->setRandomIdentifier($identifier); break;
545 default: $this->throwUnknownIdentifierTypeException($identifierType);
546 }
547 }
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 484 of file class.ilAssOrderingElementList.php.

485 {
486 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
487 self::$identifierRegistry[$identifierType][$this->getQuestionId()] = array();
488 }
489
490 $identifier = $this->fetchIdentifier($element, $identifierType);
491
492 if (!in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
493 self::$identifierRegistry[$identifierType][$this->getQuestionId()][] = $identifier;
494 }
495 }

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 473 of file class.ilAssOrderingElementList.php.

474 {
475 $this->registerIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
476 $this->registerIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
477 }

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 220 of file class.ilAssOrderingElementList.php.

221 {
222 $elementList = new self();
223 $elementList->setQuestionId($this->getQuestionId());
224
225 $positionCounter = 0;
226
227 foreach ($this as $element) {
228 if ($element->isSameElement($removeElement)) {
229 continue;
230 }
231
232 $element->setPosition($positionCounter++);
233 $elementList->addElement($element);
234 }
235 }

References getQuestionId().

+ Here is the call graph for this function:

◆ reorderByRandomIdentifiers()

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

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

822 {
823 $positionsMap = array_flip(array_values($randomIdentifiers));
824
825 $orderedElements = array();
826
827 foreach ($this as $element) {
828 if (!isset($positionsMap[$element->getRandomIdentifier()])) {
829 $this->throwMissingReorderPositionException($element->getRandomIdentifier());
830 }
831
832 $position = $positionsMap[$element->getRandomIdentifier()];
833 unset($positionsMap[$element->getRandomIdentifier()]);
834
835 $element->setPosition($position);
836 $orderedElements[$position] = $element;
837 }
838
839 if (count($positionsMap)) {
840 $this->throwUnknownRandomIdentifiersException(array_keys($positionsMap));
841 }
842
843 ksort($orderedElements);
844
845 $this->setElements(array_values($orderedElements));
846 }
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 240 of file class.ilAssOrderingElementList.php.

241 {
242 $this->elements = array();
243 }

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 851 of file class.ilAssOrderingElementList.php.

852 {
853 foreach ($this as $element) {
854 $element->setIndentation(0);
855 }
856 }

◆ rewind()

ilAssOrderingElementList::rewind ( )
Returns
ilAssOrderingElement

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

945 {
946 return reset($this->elements);
947 }

◆ setElements()

ilAssOrderingElementList::setElements (   $elements)
Parameters
$elements

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

249 {
250 $this->resetElements();
251
252 foreach ($elements as $element) {
253 $this->addElement($element);
254 }
255 }

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 598 of file class.ilAssOrderingElementList.php.

599 {
601 "could not build random identifier (max tries: $maxTries)"
602 );
603 }

Referenced by buildRandomIdentifier().

+ Here is the caller graph for this function:

◆ throwMissingReorderPositionException()

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

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

610 {
612 "cannot reorder element due to missing position (random identifier: $randomIdentifier)"
613 );
614 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ throwUnknownIdentifierTypeException()

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

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

588 {
590 "unknown identifier type given (type: $identifierType)"
591 );
592 }

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 620 of file class.ilAssOrderingElementList.php.

621 {
623 'cannot reorder element due to one or more unknown random identifiers ' .
624 '(' . implode(', ', $randomIdentifiers) . ')'
625 );
626 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ valid()

ilAssOrderingElementList::valid ( )
Returns
bool

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

937 {
938 return ($this->key() !== null);
939 }

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: