ILIAS  release_7 Revision v7.30-3-g800a261c036
ilAssOrderingElementList Class Reference
+ Inheritance diagram for ilAssOrderingElementList:
+ Collaboration diagram for ilAssOrderingElementList:

Public Member Functions

 __construct (int $question_id=null, array $elements=[])
 ilAssOrderingElementList constructor. More...
 
 __clone ()
 clone list by additionally cloning the element objects More...
 
 getClone ()
 
 getQuestionId ()
 
 setQuestionId ($question_id)
 
 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)
 
 ensureValidIdentifiers (ilAssOrderingElement $element)
 
 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 ()
 
 withElements (array $elements)
 
 withQuestionId (int $question_id)
 

Static Public Member Functions

static isValidSolutionIdentifier ($identifier)
 
static isValidRandomIdentifier ($identifier)
 
static isValidPosition ($position)
 
static isValidIndentation ($indentation)
 
static getFallbackDefaultElement ()
 
static buildInstance (int $question_id, array $elements=[])
 

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)
 
 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

 $question_id
 
 $elements
 

Static Protected Attributes

static $identifierRegistry
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilAssOrderingElementList::__construct ( int  $question_id = null,
array  $elements = [] 
)

ilAssOrderingElementList constructor.

Parameters
ilAssOrderingElement[]$elements

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

References $elements, $objectInstanceCounter, and $question_id.

Member Function Documentation

◆ __clone()

ilAssOrderingElementList::__clone ( )

clone list by additionally cloning the element objects

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

68 {
69 $this->objectInstanceId = ++self::$objectInstanceCounter;
70
71 $elements = array();
72
73 foreach ($this as $key => $element) {
74 $elements[$key] = clone $element;
75 }
76
77 $this->elements = $elements;
78 }

References $elements, and $objectInstanceCounter.

◆ addElement()

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

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

248 {
249 if ($this->hasValidIdentifiers($element)) {
250 $this->registerIdentifiers($element);
251 }
252
253 $this->elements[] = $element;
254 }
registerIdentifiers(ilAssOrderingElement $element)
hasValidIdentifiers(ilAssOrderingElement $element)

References hasValidIdentifiers(), and registerIdentifiers().

Referenced by 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 505 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 ( int  $question_id,
array  $elements = [] 
)
static

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

843 {
844 $elementList = new self();
845
846 $elementList->setQuestionId($question_id);
847 $elementList->setElements($elements);
848
849 return $elementList;
850 }

References $elements, $question_id, and setQuestionId().

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

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

◆ buildRandomIdentifier()

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

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

599 {
600 $usedTriesCounter = 0;
601
602 do {
603 if ($usedTriesCounter >= self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES) {
604 $this->throwCouldNotBuildRandomIdentifierException(self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES);
605 }
606
607 $usedTriesCounter++;
608
611 $randomIdentifier = mt_rand($lowerBound, $upperBound);
612
613 $testElement = new ilAssOrderingElement();
614 $testElement->setRandomIdentifier($randomIdentifier);
615 } while ($this->isIdentifierRegistered($testElement, self::IDENTIFIER_TYPE_RANDOM));
616
617 return $randomIdentifier;
618 }
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 581 of file class.ilAssOrderingElementList.php.

582 {
583 $lastSolutionIdentifier = $this->getLastSolutionIdentifier();
584
585 if ($lastSolutionIdentifier === null) {
586 return 0;
587 }
588
589 $nextSolutionIdentifier = $lastSolutionIdentifier + self::SOLUTION_IDENTIFIER_VALUE_INTERVAL;
590
591 return $nextSolutionIdentifier;
592 }

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:

◆ completeContentsFromElementList()

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

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

776 {
777 foreach ($this as $thisElement) {
778 if (!$otherList->elementExistByRandomIdentifier($thisElement->getRandomIdentifier())) {
779 continue;
780 }
781
782 $otherElement = $otherList->getElementByRandomIdentifier(
783 $thisElement->getRandomIdentifier()
784 );
785
786 $thisElement->setContent($otherElement->getContent());
787 }
788 }

◆ countElements()

ilAssOrderingElementList::countElements ( )

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

106 {
107 return count($this->elements);
108 }

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

+ Here is the caller graph for this function:

◆ current()

ilAssOrderingElementList::current ( )
Returns
ilAssOrderingElement

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

794 {
795 return current($this->elements);
796 }

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

649 {
650 foreach ($this as $element) {
651 $element->setRandomIdentifier($this->buildRandomIdentifier());
652 }
653 }

References buildRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistByPosition()

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

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

274 {
275 return ($this->getElementByPosition($position) !== null);
276 }

References getElementByPosition().

+ Here is the call graph for this function:

◆ elementExistByRandomIdentifier()

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

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

297 {
298 return ($this->getElementByRandomIdentifier($randomIdentifier) !== null);
299 }

References getElementByRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistBySolutionIdentifier()

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

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

322 {
323 return ($this->getElementBySolutionIdentifier($solutionIdentifier) !== null);
324 }
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 391 of file class.ilAssOrderingElementList.php.

392 {
393 $identifier = $this->fetchIdentifier($element, $identifierType);
394
395 if (!$this->isValidIdentifier($identifierType, $identifier)) {
396 $identifier = $this->buildIdentifier($identifierType);
397 $this->populateIdentifier($element, $identifierType, $identifier);
398 $this->registerIdentifier($element, $identifierType);
399 }
400 }
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)
Parameters
ilAssOrderingElement$element

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

380 {
381 //TODO: remove!
382 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
383 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
384 return $element;
385 }
ensureValidIdentifier(ilAssOrderingElement $element, $identifierType)

References ensureValidIdentifier().

Referenced by assOrderingQuestion\setOrderingElementList().

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

◆ fetchIdentifier()

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

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

457 {
458 switch ($identifierType) {
460 case self::IDENTIFIER_TYPE_RANDOM: return $element->getRandomIdentifier();
461 }
462
463 $this->throwUnknownIdentifierTypeException($identifierType);
464 }

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

84 {
85 $that = clone $this;
86 return $that;
87 }

◆ getDifferenceElementList()

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

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

744 {
745 $differenceRandomIdentifierIndex = $this->getDifferenceRandomIdentifierIndex($otherElementList);
746
747 $differenceElementList = new self();
748 $differenceElementList->setQuestionId($this->getQuestionId());
749
750 foreach ($differenceRandomIdentifierIndex as $randomIdentifier) {
751 $element = $this->getElementByRandomIdentifier($randomIdentifier);
752 $differenceElementList->addElement($element);
753 }
754
755 return $differenceElementList;
756 }
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 762 of file class.ilAssOrderingElementList.php.

763 {
764 $differenceRandomIdentifierIndex = array_diff(
766 $otherElementList->getRandomIdentifierIndex()
767 );
768
769 return $differenceRandomIdentifierIndex;
770 }

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

261 {
262 if (isset($this->elements[$position])) {
263 return $this->elements[$position];
264 }
265
266 return null;
267 }

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

283 {
284 foreach ($this as $element) {
285 if ($element->getRandomIdentifier() === intval($randomIdentifier)) {
286 return $element;
287 }
288 }
289 return null;
290 }

Referenced by elementExistByRandomIdentifier(), and getDifferenceElementList().

+ Here is the caller graph for this function:

◆ getElementBySolutionIdentifier()

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

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

306 {
307 foreach ($this as $element) {
308 if ($element->getSolutionIdentifier() != $solutionIdentifier) {
309 continue;
310 }
311
312 return $element;
313 }
314 return null;
315 }

Referenced by elementExistBySolutionIdentifier().

+ Here is the caller graph for this function:

◆ getElements()

ilAssOrderingElementList::getElements ( )
Returns
ilAssOrderingElement[]

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

194 {
195 return $this->elements;
196 }

References $elements.

Referenced by assOrderingQuestion\setOrderingElementList(), and ILIAS\TA\Questions\Ordering\assOrderingQuestionDatabaseRepository\updateOrderingList().

+ Here is the caller graph for this function:

◆ getFallbackDefaultElement()

static ilAssOrderingElementList::getFallbackDefaultElement ( )
static
Returns
ilAssOrderingElement

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

834 {
835 $element = new ilAssOrderingElement();
836 $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
837
838 return $element;
839 }

Referenced by ilAssOrderingDefaultElementFallback\manipulateFormInputValues().

+ Here is the caller graph for this function:

◆ getHash()

ilAssOrderingElementList::getHash ( )

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

853 {
854 $items = array();
855
856 foreach ($this as $element) {
857 $items[] = implode(':', array(
858 $element->getSolutionIdentifier(),
859 $element->getRandomIdentifier(),
860 $element->getIndentation()
861 ));
862 }
863
864 return md5(serialize($items));
865 }

◆ getIndexedElements()

ilAssOrderingElementList::getIndexedElements (   $identifierType)
protected
Returns
array

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

234 {
235 $elements = array();
236
237 foreach ($this as $element) {
238 $elements[$this->fetchIdentifier($element, $identifierType)] = $element;
239 }
240
241 return $elements;
242 }

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

564 {
565 $lastSolutionIdentifier = null;
566
567 foreach ($this->getRegisteredSolutionIdentifiers() as $registeredIdentifier) {
568 if ($lastSolutionIdentifier > $registeredIdentifier) {
569 continue;
570 }
571
572 $lastSolutionIdentifier = $registeredIdentifier;
573 }
574
575 return $lastSolutionIdentifier;
576 }

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

670 {
671 if (!$this->hasSameElementSetByRandomIdentifiers($otherList)) {
672 throw new ilTestQuestionPoolException('cannot compare lists having different element sets');
673 }
674
675 $parityTrueElementList = new self();
676 $parityTrueElementList->setQuestionId($this->getQuestionId());
677
678 foreach ($this as $thisElement) {
679 $otherElement = $otherList->getElementByRandomIdentifier(
680 $thisElement->getRandomIdentifier()
681 );
682
683 if ($otherElement->getPosition() != $thisElement->getPosition()) {
684 continue;
685 }
686
687 if ($otherElement->getIndentation() != $thisElement->getIndentation()) {
688 continue;
689 }
690
691 $parityTrueElementList->addElement($thisElement);
692 }
693
694 return $parityTrueElementList;
695 }

References getQuestionId(), and hasSameElementSetByRandomIdentifiers().

+ Here is the call graph for this function:

◆ getQuestionId()

◆ getRandomIdentifierIndex()

ilAssOrderingElementList::getRandomIdentifierIndex ( )
Returns
array

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

210 {
211 return array_keys($this->getRandomIdentifierIndexedElements());
212 }

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

202 {
203 return $this->getIndexedElements(self::IDENTIFIER_TYPE_RANDOM);
204 }

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

347 {
348 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
349 return array();
350 }
351
352 return self::$identifierRegistry[$identifierType][$this->getQuestionId()];
353 }

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

338 {
339 return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_RANDOM);
340 }

References getRegisteredIdentifiers().

+ Here is the call graph for this function:

◆ getRegisteredSolutionIdentifiers()

ilAssOrderingElementList::getRegisteredSolutionIdentifiers ( )
protected
Returns
array

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

330 {
331 return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_SOLUTION);
332 }

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

226 {
227 return array_keys($this->getSolutionIdentifierIndexedElements());
228 }

References getSolutionIdentifierIndexedElements().

+ Here is the call graph for this function:

◆ getSolutionIdentifierIndexedElements()

ilAssOrderingElementList::getSolutionIdentifierIndexedElements ( )
Returns
array

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

218 {
219 return $this->getIndexedElements(self::IDENTIFIER_TYPE_SOLUTION);
220 }

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

111 {
112 return (bool) $this->countElements();
113 }

References countElements().

+ Here is the call graph for this function:

◆ hasSameElementSetByRandomIdentifiers()

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

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

658 : bool
659 {
660 $numIntersectingElements = count(array_intersect(
661 $otherList->getRandomIdentifierIndex(),
662 $this->getRandomIdentifierIndex()
663 ));
664
665 return $numIntersectingElements == $this->countElements()
666 && $numIntersectingElements == $otherList->countElements();
667 }

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

360 {
361 $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
362
363 if (!$this->isValidIdentifier(self::IDENTIFIER_TYPE_SOLUTION, $identifier)) {
364 return false;
365 }
366
367 $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
368
369 if (!$this->isValidIdentifier(self::IDENTIFIER_TYPE_RANDOM, $identifier)) {
370 return false;
371 }
372
373 return true;
374 }

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

116 {
117 return $position == 0;
118 }

◆ isIdentifierRegistered()

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

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

436 {
437 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
438 return false;
439 }
440
441 $identifier = $this->fetchIdentifier($element, $identifierType);
442
443 if (!in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
444 return false;
445 }
446
447 return true;
448 }

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

121 {
122 return $position == ($this->countElements() - 1);
123 }

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

488 {
489 switch ($identifierType) {
491 return self::isValidSolutionIdentifier($identifier);
492
494 return self::isValidRandomIdentifier($identifier);
495 }
496
497 $this->throwUnknownIdentifierTypeException($identifierType);
498 }

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

641 {
642 return self::isValidPosition($indentation); // horizontal position ^^
643 }

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

636 {
637 return self::isValidSolutionIdentifier($position); // this was the position earlier
638 }

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

627 : bool
628 {
629 return is_numeric($identifier)
630 && $identifier == (int) $identifier
631 && (int) $identifier >= self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND
632 && (int) $identifier <= self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND;
633 }

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

+ Here is the caller graph for this function:

◆ isValidSolutionIdentifier()

static ilAssOrderingElementList::isValidSolutionIdentifier (   $identifier)
static

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

620 : bool
621 {
622 return is_numeric($identifier)
623 && $identifier == (int) $identifier
624 && (int) $identifier >= 0;
625 }

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

+ Here is the caller graph for this function:

◆ key()

ilAssOrderingElementList::key ( )
Returns
integer|bool

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

810 {
811 return key($this->elements);
812 }

References key().

Referenced by key(), and valid().

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

◆ moveElementByPositions()

ilAssOrderingElementList::moveElementByPositions (   $currentPosition,
  $targetPosition 
)

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

126 {
127 $movingElement = $this->getElementByPosition($currentPosition);
128 $dodgingElement = $this->getElementByPosition($targetPosition);
129
130 $elementList = new self();
131 $elementList->setQuestionId($this->getQuestionId());
132
133 foreach ($this as $element) {
134 if ($element->getPosition() == $currentPosition) {
135 $elementList->addElement($dodgingElement);
136 continue;
137 }
138
139 if ($element->getPosition() == $targetPosition) {
140 $elementList->addElement($movingElement);
141 continue;
142 }
143
144 $elementList->addElement($element);
145 }
146
147 $dodgingElement->setPosition($currentPosition);
148 $movingElement->setPosition($targetPosition);
149
150 $this->setElements($elementList->getElements());
151 }

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

+ Here is the call graph for this function:

◆ next()

ilAssOrderingElementList::next ( )
Returns
ilAssOrderingElement

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

802 {
803 return next($this->elements);
804 }

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

473 {
474 switch ($identifierType) {
475 case self::IDENTIFIER_TYPE_SOLUTION: $element->setSolutionIdentifier($identifier); break;
476 case self::IDENTIFIER_TYPE_RANDOM: $element->setRandomIdentifier($identifier); break;
477 default: $this->throwUnknownIdentifierTypeException($identifierType);
478 }
479 }
setSolutionIdentifier($solution_identifier)
setRandomIdentifier(int $random_identifier)

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

417 {
418 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
419 self::$identifierRegistry[$identifierType][$this->getQuestionId()] = array();
420 }
421
422 $identifier = $this->fetchIdentifier($element, $identifierType);
423
424 if (!in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
425 self::$identifierRegistry[$identifierType][$this->getQuestionId()][] = $identifier;
426 }
427 }

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

406 {
407 $this->registerIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
408 $this->registerIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
409 }

References registerIdentifier().

Referenced by addElement().

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

◆ removeElement()

ilAssOrderingElementList::removeElement ( ilAssOrderingElement  $removeElement)

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

154 {
155 $elementList = new self();
156 $elementList->setQuestionId($this->getQuestionId());
157
158 $positionCounter = 0;
159
160 foreach ($this as $element) {
161 if ($element->isSameElement($removeElement)) {
162 continue;
163 }
164
165 $element->setPosition($positionCounter++);
166 $elementList->addElement($element);
167 }
168 }

References getQuestionId().

+ Here is the call graph for this function:

◆ reorderByRandomIdentifiers()

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

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

703 {
704 $positionsMap = array_flip(array_values($randomIdentifiers));
705
706 $orderedElements = array();
707
708 foreach ($this as $element) {
709 if (!isset($positionsMap[$element->getRandomIdentifier()])) {
710 $this->throwMissingReorderPositionException($element->getRandomIdentifier());
711 }
712
713 $position = $positionsMap[$element->getRandomIdentifier()];
714 unset($positionsMap[$element->getRandomIdentifier()]);
715
716 $element->setPosition($position);
717 $orderedElements[$position] = $element;
718 }
719
720 if (count($positionsMap)) {
721 $this->throwUnknownRandomIdentifiersException(array_keys($positionsMap));
722 }
723
724 ksort($orderedElements);
725
726 $this->setElements(array_values($orderedElements));
727 }
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 173 of file class.ilAssOrderingElementList.php.

174 {
175 $this->elements = array();
176 }

Referenced by 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 732 of file class.ilAssOrderingElementList.php.

733 {
734 foreach ($this as $element) {
735 $element->setIndentation(0);
736 }
737 }

◆ rewind()

ilAssOrderingElementList::rewind ( )
Returns
ilAssOrderingElement

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

826 {
827 return reset($this->elements);
828 }

◆ setElements()

ilAssOrderingElementList::setElements (   $elements)
Parameters
$elements

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

182 {
183 $this->resetElements();
184
185 foreach ($elements as $element) {
186 $this->addElement($element);
187 }
188 }
addElement(ilAssOrderingElement $element)

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 (   $question_id)
Parameters
integer$question_id

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

101 {
102 $this->question_id = $question_id;
103 }

References $question_id.

Referenced by buildInstance().

+ Here is the caller graph for this function:

◆ throwCouldNotBuildRandomIdentifierException()

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

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

531 {
533 "could not build random identifier (max tries: $maxTries)"
534 );
535 }

Referenced by buildRandomIdentifier().

+ Here is the caller graph for this function:

◆ throwMissingReorderPositionException()

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

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

542 {
544 "cannot reorder element due to missing position (random identifier: $randomIdentifier)"
545 );
546 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ throwUnknownIdentifierTypeException()

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

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

520 {
522 "unknown identifier type given (type: $identifierType)"
523 );
524 }

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

553 {
555 'cannot reorder element due to one or more unknown random identifiers ' .
556 '(' . implode(', ', $randomIdentifiers) . ')'
557 );
558 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ valid()

ilAssOrderingElementList::valid ( )
Returns
bool

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

818 {
819 return ($this->key() !== null);
820 }

References key().

+ Here is the call graph for this function:

◆ withElements()

ilAssOrderingElementList::withElements ( array  $elements)
Parameters
ilAssOrderingElement[];

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

870 : self
871 {
872 $clone = clone $this;
873 $clone->elements = $elements;
874 return $clone;
875 }

References $elements.

Referenced by assOrderingQuestion\setOrderingElementList(), and assOrderingQuestionTest\testOrderingElementListMutation().

+ Here is the caller graph for this function:

◆ withQuestionId()

ilAssOrderingElementList::withQuestionId ( int  $question_id)

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

877 : self
878 {
879 $clone = clone $this;
880 $clone->question_id = $question_id;
881 return $clone;
882 }

References $question_id.

Referenced by assOrderingQuestion\setOrderingElementList().

+ Here is the caller 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.

◆ $question_id

ilAssOrderingElementList::$question_id
protected

◆ 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: