ILIAS  release_8 Revision v8.24
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, string $identifierType)
 
 populateIdentifier (ilAssOrderingElement $element, $identifierType, $identifier)
 
 isValidIdentifier ($identifierType, $identifier)
 @noinspection PhpInconsistentReturnPointsInspection More...
 
 buildIdentifier ($identifierType)
 
 throwUnknownIdentifierTypeException ($identifierType)
 
 throwCouldNotBuildRandomIdentifierException ($maxTries)
 
 throwMissingReorderPositionException ($randomIdentifier)
 
 throwUnknownRandomIdentifiersException ($randomIdentifiers)
 
 getLastSolutionIdentifier ()
 
 buildSolutionIdentifier ()
 
 buildRandomIdentifier ()
 
 getDifferenceRandomIdentifierIndex (self $otherElementList)
 

Protected Attributes

 $question_id
 
 $elements = array()
 

Static Protected Attributes

static $identifierRegistry
 

Detailed Description

Definition at line 25 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 67 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 80 of file class.ilAssOrderingElementList.php.

81 {
82 $this->objectInstanceId = ++self::$objectInstanceCounter;
83
84 $elements = array();
85
86 foreach ($this as $key => $element) {
87 $elements[$key] = clone $element;
88 }
89
90 $this->elements = $elements;
91 }
string $key
Consumer key/client ID value.
Definition: System.php:193

References $elements, ILIAS\LTI\ToolProvider\$key, and $objectInstanceCounter.

◆ addElement()

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

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

260 : void
261 {
262 if ($this->hasValidIdentifiers($element)) {
263 $this->registerIdentifiers($element);
264 }
265
266 $this->elements[] = $element;
267 }
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

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

509 : int
510 {
511 switch ($identifierType) {
513 return $this->buildSolutionIdentifier();
514 default:
516 return $this->buildRandomIdentifier();
517 }
518
519 $this->throwUnknownIdentifierTypeException($identifierType);
520 }

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

849 {
850 $elementList = new self();
851
852 $elementList->setQuestionId($question_id);
853 $elementList->setElements($elements);
854
855 return $elementList;
856 }

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

605 : int
606 {
607 $usedTriesCounter = 0;
608
609 do {
610 if ($usedTriesCounter >= self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES) {
611 $this->throwCouldNotBuildRandomIdentifierException(self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES);
612 }
613
614 $usedTriesCounter++;
615
618 $randomIdentifier = mt_rand($lowerBound, $upperBound);
619
620 $testElement = new ilAssOrderingElement();
621 $testElement->setRandomIdentifier($randomIdentifier);
622 } while ($this->isIdentifierRegistered($testElement, self::IDENTIFIER_TYPE_RANDOM));
623
624 return $randomIdentifier;
625 }
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 588 of file class.ilAssOrderingElementList.php.

588 : ?int
589 {
590 $lastSolutionIdentifier = $this->getLastSolutionIdentifier();
591
592 if ($lastSolutionIdentifier === null) {
593 return 0;
594 }
595
596 $nextSolutionIdentifier = $lastSolutionIdentifier + self::SOLUTION_IDENTIFIER_VALUE_INTERVAL;
597
598 return $nextSolutionIdentifier;
599 }

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

781 : void
782 {
783 foreach ($this as $thisElement) {
784 if (!$otherList->elementExistByRandomIdentifier($thisElement->getRandomIdentifier())) {
785 continue;
786 }
787
788 $otherElement = $otherList->getElementByRandomIdentifier(
789 $thisElement->getRandomIdentifier()
790 );
791
792 $thisElement->setContent($otherElement->getContent());
793 }
794 }

◆ countElements()

ilAssOrderingElementList::countElements ( )

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

118 : int
119 {
120 return count($this->elements);
121 }

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

+ Here is the caller graph for this function:

◆ current()

ilAssOrderingElementList::current ( )
Returns
ilAssOrderingElement

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

800 {
801 return current($this->elements);
802 }

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

655 : void
656 {
657 foreach ($this as $element) {
658 $element->setRandomIdentifier($this->buildRandomIdentifier());
659 }
660 }

References buildRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistByPosition()

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

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

286 : bool
287 {
288 return ($this->getElementByPosition($position) !== null);
289 }

References getElementByPosition().

+ Here is the call graph for this function:

◆ elementExistByRandomIdentifier()

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

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

310 : bool
311 {
312 return ($this->getElementByRandomIdentifier($randomIdentifier) !== null);
313 }

References getElementByRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistBySolutionIdentifier()

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

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

335 : bool
336 {
337 return ($this->getElementBySolutionIdentifier($solutionIdentifier) !== null);
338 }
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 405 of file class.ilAssOrderingElementList.php.

405 : void
406 {
407 $identifier = $this->fetchIdentifier($element, $identifierType);
408
409 if (!$this->isValidIdentifier($identifierType, $identifier)) {
410 $identifier = $this->buildIdentifier($identifierType);
411 $this->populateIdentifier($element, $identifierType, $identifier);
412 $this->registerIdentifier($element, $identifierType);
413 }
414 }
fetchIdentifier(ilAssOrderingElement $element, string $identifierType)
registerIdentifier(ilAssOrderingElement $element, $identifierType)
populateIdentifier(ilAssOrderingElement $element, $identifierType, $identifier)
isValidIdentifier($identifierType, $identifier)
@noinspection PhpInconsistentReturnPointsInspection

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

394 {
395 //TODO: remove!
396 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
397 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
398 return $element;
399 }
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,
string  $identifierType 
)
protected
Exceptions
ilTestQuestionPoolException

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

467 : ?int
468 {
469 if ($identifierType == self::IDENTIFIER_TYPE_SOLUTION) {
470 return $element->getSolutionIdentifier();
471 } else {
472 return $element->getRandomIdentifier();
473 }
474
475 $this->throwUnknownIdentifierTypeException($identifierType);
476 }

References ilAssOrderingElement\getRandomIdentifier(), ilAssOrderingElement\getSolutionIdentifier(), 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 96 of file class.ilAssOrderingElementList.php.

97 {
98 $that = clone $this;
99 return $that;
100 }

Referenced by assOrderingQuestion\getShuffledOrderingElementList().

+ Here is the caller graph for this function:

◆ getDifferenceElementList()

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

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

750 {
751 $differenceRandomIdentifierIndex = $this->getDifferenceRandomIdentifierIndex($otherElementList);
752
753 $differenceElementList = new self();
754 $differenceElementList->setQuestionId($this->getQuestionId());
755
756 foreach ($differenceRandomIdentifierIndex as $randomIdentifier) {
757 $element = $this->getElementByRandomIdentifier($randomIdentifier);
758 $differenceElementList->addElement($element);
759 }
760
761 return $differenceElementList;
762 }
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 768 of file class.ilAssOrderingElementList.php.

768 : array
769 {
770 $differenceRandomIdentifierIndex = array_diff(
772 $otherElementList->getRandomIdentifierIndex()
773 );
774
775 return $differenceRandomIdentifierIndex;
776 }

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

274 {
275 if (isset($this->elements[$position])) {
276 return $this->elements[$position];
277 }
278
279 return null;
280 }

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

296 {
297 foreach ($this as $element) {
298 if ($element->getRandomIdentifier() === intval($randomIdentifier)) {
299 return $element;
300 }
301 }
302
303 return null;
304 }

Referenced by elementExistByRandomIdentifier(), and getDifferenceElementList().

+ Here is the caller graph for this function:

◆ getElementBySolutionIdentifier()

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

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

320 {
321 foreach ($this as $element) {
322 if ($element->getSolutionIdentifier() != $solutionIdentifier) {
323 continue;
324 }
325
326 return $element;
327 }
328 return null;
329 }

Referenced by elementExistBySolutionIdentifier().

+ Here is the caller graph for this function:

◆ getElements()

ilAssOrderingElementList::getElements ( )
Returns
ilAssOrderingElement[]

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

206 : array
207 {
208 return $this->elements;
209 }

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

840 {
841 $element = new ilAssOrderingElement();
842 $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
843
844 return $element;
845 }

Referenced by ilAssOrderingDefaultElementFallback\manipulateFormInputValues().

+ Here is the caller graph for this function:

◆ getHash()

ilAssOrderingElementList::getHash ( )

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

858 : string
859 {
860 $items = array();
861
862 foreach ($this as $element) {
863 $items[] = implode(':', array(
864 $element->getSolutionIdentifier(),
865 $element->getRandomIdentifier(),
866 $element->getIndentation()
867 ));
868 }
869
870 return md5(serialize($items));
871 }

◆ getIndexedElements()

ilAssOrderingElementList::getIndexedElements (   $identifierType)
protected
Returns
array

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

246 : array
247 {
248 $elements = array();
249
250 foreach ($this as $element) {
251 $elements[$this->fetchIdentifier($element, $identifierType)] = $element;
252 }
253
254 return $elements;
255 }

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

570 : ?int
571 {
572 $lastSolutionIdentifier = null;
573
574 foreach ($this->getRegisteredSolutionIdentifiers() as $registeredIdentifier) {
575 if ($lastSolutionIdentifier > $registeredIdentifier) {
576 continue;
577 }
578
579 $lastSolutionIdentifier = $registeredIdentifier;
580 }
581
582 return $lastSolutionIdentifier;
583 }

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

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

References getQuestionId(), and hasSameElementSetByRandomIdentifiers().

+ Here is the call graph for this function:

◆ getQuestionId()

ilAssOrderingElementList::getQuestionId ( )

◆ getRandomIdentifierIndex()

ilAssOrderingElementList::getRandomIdentifierIndex ( )
Returns
array

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

222 : array
223 {
224 return array_keys($this->getRandomIdentifierIndexedElements());
225 }

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

214 : array
215 {
216 return $this->getIndexedElements(self::IDENTIFIER_TYPE_RANDOM);
217 }

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

360 : array
361 {
362 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
363 return array();
364 }
365
366 return self::$identifierRegistry[$identifierType][$this->getQuestionId()];
367 }

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

351 : array
352 {
353 return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_RANDOM);
354 }

References getRegisteredIdentifiers().

+ Here is the call graph for this function:

◆ getRegisteredSolutionIdentifiers()

ilAssOrderingElementList::getRegisteredSolutionIdentifiers ( )
protected
Returns
array

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

343 : array
344 {
345 return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_SOLUTION);
346 }

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

238 : array
239 {
240 return array_keys($this->getSolutionIdentifierIndexedElements());
241 }

References getSolutionIdentifierIndexedElements().

+ Here is the call graph for this function:

◆ getSolutionIdentifierIndexedElements()

ilAssOrderingElementList::getSolutionIdentifierIndexedElements ( )
Returns
array

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

230 : array
231 {
232 return $this->getIndexedElements(self::IDENTIFIER_TYPE_SOLUTION);
233 }

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

123 : bool
124 {
125 return (bool) $this->countElements();
126 }

References countElements().

+ Here is the call graph for this function:

◆ hasSameElementSetByRandomIdentifiers()

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

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

665 : bool
666 {
667 $numIntersectingElements = count(array_intersect(
668 $otherList->getRandomIdentifierIndex(),
669 $this->getRandomIdentifierIndex()
670 ));
671
672 return $numIntersectingElements == $this->countElements()
673 && $numIntersectingElements == $otherList->countElements();
674 }

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

373 : bool
374 {
375 $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
376
377 if (!$this->isValidIdentifier(self::IDENTIFIER_TYPE_SOLUTION, $identifier)) {
378 return false;
379 }
380
381 $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
382
383 if (!$this->isValidIdentifier(self::IDENTIFIER_TYPE_RANDOM, $identifier)) {
384 return false;
385 }
386
387 return true;
388 }

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

128 : bool
129 {
130 return $position == 0;
131 }

◆ isIdentifierRegistered()

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

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

449 : bool
450 {
451 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
452 return false;
453 }
454
455 $identifier = $this->fetchIdentifier($element, $identifierType);
456
457 if (!in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
458 return false;
459 }
460
461 return true;
462 }

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

133 : bool
134 {
135 return $position == ($this->countElements() - 1);
136 }

References countElements().

+ Here is the call graph for this function:

◆ isValidIdentifier()

ilAssOrderingElementList::isValidIdentifier (   $identifierType,
  $identifier 
)
protected

@noinspection PhpInconsistentReturnPointsInspection

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

497 {
498 switch ($identifierType) {
500 return self::isValidSolutionIdentifier($identifier);
501
503 return self::isValidRandomIdentifier($identifier);
504 }
505
506 $this->throwUnknownIdentifierTypeException($identifierType);
507 }

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

647 : bool
648 {
649 return self::isValidPosition($indentation); // horizontal position ^^
650 }

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

642 : bool
643 {
644 return self::isValidSolutionIdentifier($position); // this was the position earlier
645 }

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

634 : bool
635 {
636 return is_numeric($identifier)
637 && $identifier == (int) $identifier
638 && (int) $identifier >= self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND
639 && (int) $identifier <= self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND;
640 }

References ILIAS\Repository\int().

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

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

◆ isValidSolutionIdentifier()

static ilAssOrderingElementList::isValidSolutionIdentifier (   $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 >= 0;
632 }

References ILIAS\Repository\int().

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

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

◆ key()

ilAssOrderingElementList::key ( )
Returns
integer|bool

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

816 {
817 return key($this->elements);
818 }

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

138 : void
139 {
140 $movingElement = $this->getElementByPosition($currentPosition);
141 $dodgingElement = $this->getElementByPosition($targetPosition);
142
143 $elementList = new self();
144 $elementList->setQuestionId($this->getQuestionId());
145
146 foreach ($this as $element) {
147 if ($element->getPosition() == $currentPosition) {
148 $elementList->addElement($dodgingElement);
149 continue;
150 }
151
152 if ($element->getPosition() == $targetPosition) {
153 $elementList->addElement($movingElement);
154 continue;
155 }
156
157 $elementList->addElement($element);
158 }
159
160 $dodgingElement->setPosition($currentPosition);
161 $movingElement->setPosition($targetPosition);
162
163 $this->setElements($elementList->getElements());
164 }

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

+ Here is the call graph for this function:

◆ next()

ilAssOrderingElementList::next ( )
Returns
ilAssOrderingElement|false

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

808 {
809 return next($this->elements);
810 }

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

484 : void
485 {
486 switch ($identifierType) {
487 case self::IDENTIFIER_TYPE_SOLUTION: $element->setSolutionIdentifier($identifier);
488 break;
489 case self::IDENTIFIER_TYPE_RANDOM: $element->setRandomIdentifier($identifier);
490 break;
491 default: $this->throwUnknownIdentifierTypeException($identifierType);
492 }
493 }
setRandomIdentifier(int $random_identifier)
setSolutionIdentifier(int $solution_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 430 of file class.ilAssOrderingElementList.php.

430 : void
431 {
432 if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
433 self::$identifierRegistry[$identifierType][$this->getQuestionId()] = array();
434 }
435
436 $identifier = $this->fetchIdentifier($element, $identifierType);
437
438 if (!in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
439 self::$identifierRegistry[$identifierType][$this->getQuestionId()][] = $identifier;
440 }
441 }

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

419 : void
420 {
421 $this->registerIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
422 $this->registerIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
423 }

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

166 : void
167 {
168 $elementList = new self();
169 $elementList->setQuestionId($this->getQuestionId());
170
171 $positionCounter = 0;
172
173 foreach ($this as $element) {
174 if ($element->isSameElement($removeElement)) {
175 continue;
176 }
177
178 $element->setPosition($positionCounter++);
179 $elementList->addElement($element);
180 }
181 }

References getQuestionId().

+ Here is the call graph for this function:

◆ reorderByRandomIdentifiers()

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

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

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

186 : void
187 {
188 $this->elements = array();
189 }

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

738 : void
739 {
740 foreach ($this as $element) {
741 $element->setIndentation(0);
742 }
743 }

◆ rewind()

ilAssOrderingElementList::rewind ( )
Returns
ilAssOrderingElement|false

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

832 {
833 return reset($this->elements);
834 }

◆ setElements()

ilAssOrderingElementList::setElements (   $elements)
Parameters
$elements

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

194 : void
195 {
196 $this->resetElements();
197
198 foreach ($elements as $element) {
199 $this->addElement($element);
200 }
201 }
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 113 of file class.ilAssOrderingElementList.php.

113 : void
114 {
115 $this->question_id = $question_id;
116 }

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

537 : void
538 {
540 "could not build random identifier (max tries: $maxTries)"
541 );
542 }

Referenced by buildRandomIdentifier().

+ Here is the caller graph for this function:

◆ throwMissingReorderPositionException()

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

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

548 : void
549 {
551 "cannot reorder element due to missing position (random identifier: $randomIdentifier)"
552 );
553 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ throwUnknownIdentifierTypeException()

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

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

526 : void
527 {
529 "unknown identifier type given (type: $identifierType)"
530 );
531 }

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

559 : void
560 {
562 'cannot reorder element due to one or more unknown random identifiers ' .
563 '(' . implode(', ', $randomIdentifiers) . ')'
564 );
565 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ valid()

ilAssOrderingElementList::valid ( )
Returns
bool

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

823 : bool
824 {
825 return ($this->key() !== null);
826 }

References key().

+ Here is the call graph for this function:

◆ withElements()

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

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

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

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

883 : self
884 {
885 $clone = clone $this;
886 $clone->question_id = $question_id;
887 return $clone;
888 }

References $question_id.

Referenced by assOrderingQuestion\setOrderingElementList().

+ Here is the caller graph for this function:

Field Documentation

◆ $elements

ilAssOrderingElementList::$elements = array()
protected

◆ $identifierRegistry

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

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

◆ $objectInstanceCounter

ilAssOrderingElementList::$objectInstanceCounter = 0
static

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

Referenced by __clone(), and __construct().

◆ $objectInstanceId

ilAssOrderingElementList::$objectInstanceId

Definition at line 28 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 38 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 39 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 40 of file class.ilAssOrderingElementList.php.

◆ RANDOM_IDENTIFIER_BUILD_MAX_TRIES

const ilAssOrderingElementList::RANDOM_IDENTIFIER_BUILD_MAX_TRIES = 1000

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

◆ RANDOM_IDENTIFIER_RANGE_LOWER_BOUND

const ilAssOrderingElementList::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND = 1

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

Referenced by buildRandomIdentifier().

◆ RANDOM_IDENTIFIER_RANGE_UPPER_BOUND

const ilAssOrderingElementList::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND = 100000

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

Referenced by buildRandomIdentifier().

◆ SOLUTION_IDENTIFIER_BUILD_MAX_TRIES

const ilAssOrderingElementList::SOLUTION_IDENTIFIER_BUILD_MAX_TRIES = 1000

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

◆ SOLUTION_IDENTIFIER_START_VALUE

const ilAssOrderingElementList::SOLUTION_IDENTIFIER_START_VALUE = 0

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

◆ SOLUTION_IDENTIFIER_VALUE_INTERVAL

const ilAssOrderingElementList::SOLUTION_IDENTIFIER_VALUE_INTERVAL = 1

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

Referenced by buildSolutionIdentifier().


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