ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 (int $position)
 
 elementExistByPosition (int $position)
 
 getElementByRandomIdentifier (int $random_identifier)
 
 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 = []
 

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 = [];
85
86 foreach ($this as $key => $element) {
87 $elements[$key] = clone $element;
88 }
89
90 $this->elements = $elements;
91 }

References $elements, 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 497 of file class.ilAssOrderingElementList.php.

497 : int
498 {
499 switch ($identifierType) {
501 return $this->buildSolutionIdentifier();
502 default:
504 return $this->buildRandomIdentifier();
505 }
506
507 $this->throwUnknownIdentifierTypeException($identifierType);
508 }

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

834 {
835 $elementList = new self();
836
837 $elementList->setQuestionId($question_id);
838 $elementList->setElements($elements);
839
840 return $elementList;
841 }

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

Referenced by assOrderingQuestion\fetchSolutionListFromFormSubmissionData(), ilAssOrderingImagesInputGUI\getElementList(), ilAssOrderingTextsInputGUI\getElementList(), and ilAssNestedOrderingElementsInputGUI\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 593 of file class.ilAssOrderingElementList.php.

593 : int
594 {
595 $usedTriesCounter = 0;
596
597 do {
598 if ($usedTriesCounter >= self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES) {
599 $this->throwCouldNotBuildRandomIdentifierException(self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES);
600 }
601
602 $usedTriesCounter++;
603
606 $randomIdentifier = mt_rand($lowerBound, $upperBound);
607
608 $testElement = new ilAssOrderingElement();
609 $testElement->setRandomIdentifier($randomIdentifier);
610 } while ($this->isIdentifierRegistered($testElement, self::IDENTIFIER_TYPE_RANDOM));
611
612 return $randomIdentifier;
613 }
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 576 of file class.ilAssOrderingElementList.php.

576 : ?int
577 {
578 $lastSolutionIdentifier = $this->getLastSolutionIdentifier();
579
580 if ($lastSolutionIdentifier === null) {
581 return 0;
582 }
583
584 $nextSolutionIdentifier = $lastSolutionIdentifier + self::SOLUTION_IDENTIFIER_VALUE_INTERVAL;
585
586 return $nextSolutionIdentifier;
587 }

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

769 : void
770 {
771 foreach ($this as $thisElement) {
772 if (!$otherList->elementExistByRandomIdentifier($thisElement->getRandomIdentifier())) {
773 continue;
774 }
775
776 $otherElement = $otherList->getElementByRandomIdentifier(
777 $thisElement->getRandomIdentifier()
778 );
779
780 $thisElement->setContent($otherElement->getContent());
781 }
782 }

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

788 {
789 return current($this->elements);
790 }

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

643 : void
644 {
645 foreach ($this as $element) {
646 $element->setRandomIdentifier($this->buildRandomIdentifier());
647 }
648 }

References buildRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistByPosition()

ilAssOrderingElementList::elementExistByPosition ( int  $position)

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

278 : bool
279 {
280 return ($this->getElementByPosition($position) !== null);
281 }

References getElementByPosition().

+ Here is the call graph for this function:

◆ elementExistByRandomIdentifier()

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

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

298 : bool
299 {
300 return ($this->getElementByRandomIdentifier($randomIdentifier) !== null);
301 }
getElementByRandomIdentifier(int $random_identifier)

References getElementByRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistBySolutionIdentifier()

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

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

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

393 : void
394 {
395 $identifier = $this->fetchIdentifier($element, $identifierType);
396
397 if (!$this->isValidIdentifier($identifierType, $identifier)) {
398 $identifier = $this->buildIdentifier($identifierType);
399 $this->populateIdentifier($element, $identifierType, $identifier);
400 $this->registerIdentifier($element, $identifierType);
401 }
402 }
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 381 of file class.ilAssOrderingElementList.php.

382 {
383 //TODO: remove!
384 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
385 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
386 return $element;
387 }
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 455 of file class.ilAssOrderingElementList.php.

455 : ?int
456 {
457 if ($identifierType == self::IDENTIFIER_TYPE_SOLUTION) {
458 return $element->getSolutionIdentifier();
459 } else {
460 return $element->getRandomIdentifier();
461 }
462
463 $this->throwUnknownIdentifierTypeException($identifierType);
464 }

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

738 {
739 $differenceRandomIdentifierIndex = $this->getDifferenceRandomIdentifierIndex($otherElementList);
740
741 $differenceElementList = new self();
742 $differenceElementList->setQuestionId($this->getQuestionId());
743
744 foreach ($differenceRandomIdentifierIndex as $randomIdentifier) {
745 $element = $this->getElementByRandomIdentifier($randomIdentifier);
746 $differenceElementList->addElement($element);
747 }
748
749 return $differenceElementList;
750 }
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 756 of file class.ilAssOrderingElementList.php.

756 : array
757 {
758 $differenceRandomIdentifierIndex = array_diff(
760 $otherElementList->getRandomIdentifierIndex()
761 );
762
763 return $differenceRandomIdentifierIndex;
764 }

References getRandomIdentifierIndex().

Referenced by getDifferenceElementList().

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

◆ getElementByPosition()

ilAssOrderingElementList::getElementByPosition ( int  $position)

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

270 {
271 if (isset($this->elements[$position])) {
272 return $this->elements[$position];
273 }
274
275 return null;
276 }

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

+ Here is the caller graph for this function:

◆ getElementByRandomIdentifier()

ilAssOrderingElementList::getElementByRandomIdentifier ( int  $random_identifier)

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

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

Referenced by elementExistByRandomIdentifier(), and getDifferenceElementList().

+ Here is the caller graph for this function:

◆ getElementBySolutionIdentifier()

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

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

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

Referenced by elementExistBySolutionIdentifier().

+ Here is the caller graph for this function:

◆ getElements()

ilAssOrderingElementList::getElements ( )
Returns
array<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\TestQuestionPool\Questions\Ordering\OrderingQuestionDatabaseRepository\updateOrderingList().

+ Here is the caller graph for this function:

◆ getFallbackDefaultElement()

static ilAssOrderingElementList::getFallbackDefaultElement ( )
static
Returns
ilAssOrderingElement

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

825 {
826 $element = new ilAssOrderingElement();
827 $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
828
829 return $element;
830 }

Referenced by ilAssOrderingDefaultElementFallback\manipulateFormInputValues().

+ Here is the caller graph for this function:

◆ getHash()

ilAssOrderingElementList::getHash ( )

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

843 : string
844 {
845 $items = [];
846
847 foreach ($this as $element) {
848 $items[] = implode(':', [
849 $element->getSolutionIdentifier(),
850 $element->getRandomIdentifier(),
851 $element->getIndentation()
852 ]);
853 }
854
855 return md5(serialize($items));
856 }

◆ getIndexedElements()

ilAssOrderingElementList::getIndexedElements (   $identifierType)
protected
Returns
array

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

246 : array
247 {
248 $elements = [];
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 558 of file class.ilAssOrderingElementList.php.

558 : ?int
559 {
560 $lastSolutionIdentifier = null;
561
562 foreach ($this->getRegisteredSolutionIdentifiers() as $registeredIdentifier) {
563 if ($lastSolutionIdentifier > $registeredIdentifier) {
564 continue;
565 }
566
567 $lastSolutionIdentifier = $registeredIdentifier;
568 }
569
570 return $lastSolutionIdentifier;
571 }

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

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

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

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

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

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

References getRegisteredIdentifiers().

+ Here is the call graph for this function:

◆ getRegisteredSolutionIdentifiers()

ilAssOrderingElementList::getRegisteredSolutionIdentifiers ( )
protected
Returns
array

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

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

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

653 : bool
654 {
655 $numIntersectingElements = count(array_intersect(
656 $otherList->getRandomIdentifierIndex(),
657 $this->getRandomIdentifierIndex()
658 ));
659
660 return $numIntersectingElements == $this->countElements()
661 && $numIntersectingElements == $otherList->countElements();
662 }

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

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

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

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

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

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

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

635 : bool
636 {
637 return self::isValidPosition($indentation); // horizontal position ^^
638 }

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

630 : bool
631 {
632 return self::isValidSolutionIdentifier($position); // this was the position earlier
633 }

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

622 : bool
623 {
624 return is_numeric($identifier)
625 && $identifier == (int) $identifier
626 && (int) $identifier >= self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND
627 && (int) $identifier <= self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND;
628 }

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

615 : bool
616 {
617 return is_numeric($identifier)
618 && $identifier == (int) $identifier
619 && (int) $identifier >= 0;
620 }

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

803 : ?int
804 {
805 return key($this->elements);
806 }

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

795 : void
796 {
797 next($this->elements);
798 }

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.

472 : void
473 {
474 switch ($identifierType) {
475 case self::IDENTIFIER_TYPE_SOLUTION: $element->setSolutionIdentifier($identifier);
476 break;
477 case self::IDENTIFIER_TYPE_RANDOM: $element->setRandomIdentifier($identifier);
478 break;
479 default: $this->throwUnknownIdentifierTypeException($identifierType);
480 }
481 }
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 418 of file class.ilAssOrderingElementList.php.

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

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

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

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

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

726 : void
727 {
728 foreach ($this as $element) {
729 $element->setIndentation(0);
730 }
731 }

◆ rewind()

ilAssOrderingElementList::rewind ( )

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

816 : void
817 {
818 reset($this->elements);
819 }

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

525 : void
526 {
528 "could not build random identifier (max tries: $maxTries)"
529 );
530 }

Referenced by buildRandomIdentifier().

+ Here is the caller graph for this function:

◆ throwMissingReorderPositionException()

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

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

536 : void
537 {
539 "cannot reorder element due to missing position (random identifier: $randomIdentifier)"
540 );
541 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ throwUnknownIdentifierTypeException()

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

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

514 : void
515 {
517 "unknown identifier type given (type: $identifierType)"
518 );
519 }

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

547 : void
548 {
550 'cannot reorder element due to one or more unknown random identifiers ' .
551 '(' . implode(', ', $randomIdentifiers) . ')'
552 );
553 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ valid()

ilAssOrderingElementList::valid ( )
Returns
bool

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

811 : bool
812 {
813 return ($this->key() !== null);
814 }

References key().

+ Here is the call graph for this function:

◆ withElements()

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

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

861 : self
862 {
863 $clone = clone $this;
864 $clone->elements = $elements;
865 return $clone;
866 }

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

868 : self
869 {
870 $clone = clone $this;
871 $clone->question_id = $question_id;
872 return $clone;
873 }

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:
= [
self::IDENTIFIER_TYPE_SOLUTION => [],
self::IDENTIFIER_TYPE_RANDOM => []
]

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: