ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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, and $question_id.

57  {
58  $this->objectInstanceId = ++self::$objectInstanceCounter;
59 
60  $this->question_id = $question_id;
61  $this->elements = $elements;
62  }

Member Function Documentation

◆ __clone()

ilAssOrderingElementList::__clone ( )

clone list by additionally cloning the element objects

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

References $elements.

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  }

◆ addElement()

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

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

References hasValidIdentifiers(), and registerIdentifiers().

Referenced by setElements().

248  {
249  if ($this->hasValidIdentifiers($element)) {
250  $this->registerIdentifiers($element);
251  }
252 
253  $this->elements[] = $element;
254  }
registerIdentifiers(ilAssOrderingElement $element)
hasValidIdentifiers(ilAssOrderingElement $element)
+ 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(), and throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier().

506  {
507  switch ($identifierType) {
508  case self::IDENTIFIER_TYPE_SOLUTION: return $this->buildSolutionIdentifier();
509  case self::IDENTIFIER_TYPE_RANDOM: return $this->buildRandomIdentifier();
510  }
511 
512  $this->throwUnknownIdentifierTypeException($identifierType);
513  }
+ 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.

References $elements, and setQuestionId().

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

843  {
844  $elementList = new self();
845 
846  $elementList->setQuestionId($question_id);
847  $elementList->setElements($elements);
848 
849  return $elementList;
850  }
+ 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.

References isIdentifierRegistered(), and throwCouldNotBuildRandomIdentifierException().

Referenced by buildIdentifier(), and distributeNewRandomIdentifiers().

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 
609  $lowerBound = self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND;
610  $upperBound = self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND;
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)
+ 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.

References getLastSolutionIdentifier().

Referenced by buildIdentifier().

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  }
+ 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.

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

106  {
107  return count($this->elements);
108  }
+ 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  }

◆ distributeNewRandomIdentifiers()

ilAssOrderingElementList::distributeNewRandomIdentifiers ( )

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

References buildRandomIdentifier().

649  {
650  foreach ($this as $element) {
651  $element->setRandomIdentifier($this->buildRandomIdentifier());
652  }
653  }
+ 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.

References getElementByPosition().

274  {
275  return ($this->getElementByPosition($position) !== null);
276  }
+ 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.

References getElementByRandomIdentifier().

297  {
298  return ($this->getElementByRandomIdentifier($randomIdentifier) !== null);
299  }
+ 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.

References getElementBySolutionIdentifier().

322  {
323  return ($this->getElementBySolutionIdentifier($solutionIdentifier) !== null);
324  }
getElementBySolutionIdentifier($solutionIdentifier)
+ 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.

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

Referenced by ensureValidIdentifiers().

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  }
isValidIdentifier($identifierType, $identifier)
populateIdentifier(ilAssOrderingElement $element, $identifierType, $identifier)
fetchIdentifier(ilAssOrderingElement $element, $identifierType)
registerIdentifier(ilAssOrderingElement $element, $identifierType)
+ 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.

References ensureValidIdentifier().

Referenced by assOrderingQuestion\setOrderingElementList().

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

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

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

457  {
458  switch ($identifierType) {
459  case self::IDENTIFIER_TYPE_SOLUTION: return $element->getSolutionIdentifier();
460  case self::IDENTIFIER_TYPE_RANDOM: return $element->getRandomIdentifier();
461  }
462 
463  $this->throwUnknownIdentifierTypeException($identifierType);
464  }
+ 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.

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

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

References getRandomIdentifierIndex().

Referenced by getDifferenceElementList().

763  {
764  $differenceRandomIdentifierIndex = array_diff(
765  $this->getRandomIdentifierIndex(),
766  $otherElementList->getRandomIdentifierIndex()
767  );
768 
769  return $differenceRandomIdentifierIndex;
770  }
+ 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.

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

261  {
262  if (isset($this->elements[$position])) {
263  return $this->elements[$position];
264  }
265 
266  return null;
267  }
+ 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.

Referenced by elementExistByRandomIdentifier(), and getDifferenceElementList().

283  {
284  foreach ($this as $element) {
285  if ($element->getRandomIdentifier() === intval($randomIdentifier)) {
286  return $element;
287  }
288  }
289  return null;
290  }
+ 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.

Referenced by elementExistBySolutionIdentifier().

306  {
307  foreach ($this as $element) {
308  if ($element->getSolutionIdentifier() != $solutionIdentifier) {
309  continue;
310  }
311 
312  return $element;
313  }
314  return null;
315  }
+ Here is the caller graph for this function:

◆ getElements()

ilAssOrderingElementList::getElements ( )

◆ getFallbackDefaultElement()

static ilAssOrderingElementList::getFallbackDefaultElement ( )
static
Returns
ilAssOrderingElement

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

Referenced by ilAssOrderingDefaultElementFallback\manipulateFormInputValues().

834  {
835  $element = new ilAssOrderingElement();
836  $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
837 
838  return $element;
839  }
+ 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.

References $elements, and fetchIdentifier().

Referenced by getRandomIdentifierIndexedElements(), and getSolutionIdentifierIndexedElements().

234  {
235  $elements = array();
236 
237  foreach ($this as $element) {
238  $elements[$this->fetchIdentifier($element, $identifierType)] = $element;
239  }
240 
241  return $elements;
242  }
fetchIdentifier(ilAssOrderingElement $element, $identifierType)
+ 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.

References getRegisteredSolutionIdentifiers().

Referenced by buildSolutionIdentifier().

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  }
+ 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.

References getQuestionId(), and hasSameElementSetByRandomIdentifiers().

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  }
+ Here is the call graph for this function:

◆ getQuestionId()

◆ getRandomIdentifierIndex()

ilAssOrderingElementList::getRandomIdentifierIndex ( )
Returns
array

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

References getRandomIdentifierIndexedElements().

Referenced by getDifferenceRandomIdentifierIndex(), and hasSameElementSetByRandomIdentifiers().

210  {
211  return array_keys($this->getRandomIdentifierIndexedElements());
212  }
+ 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.

References getIndexedElements().

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

202  {
203  return $this->getIndexedElements(self::IDENTIFIER_TYPE_RANDOM);
204  }
+ 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.

References getQuestionId().

Referenced by getRegisteredRandomIdentifiers(), and getRegisteredSolutionIdentifiers().

347  {
348  if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
349  return array();
350  }
351 
352  return self::$identifierRegistry[$identifierType][$this->getQuestionId()];
353  }
+ 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.

References getRegisteredIdentifiers().

338  {
339  return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_RANDOM);
340  }
+ Here is the call graph for this function:

◆ getRegisteredSolutionIdentifiers()

ilAssOrderingElementList::getRegisteredSolutionIdentifiers ( )
protected
Returns
array

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

References getRegisteredIdentifiers().

Referenced by getLastSolutionIdentifier().

330  {
331  return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_SOLUTION);
332  }
+ 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.

References getSolutionIdentifierIndexedElements().

226  {
227  return array_keys($this->getSolutionIdentifierIndexedElements());
228  }
+ Here is the call graph for this function:

◆ getSolutionIdentifierIndexedElements()

ilAssOrderingElementList::getSolutionIdentifierIndexedElements ( )
Returns
array

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

References getIndexedElements().

Referenced by getSolutionIdentifierIndex().

218  {
219  return $this->getIndexedElements(self::IDENTIFIER_TYPE_SOLUTION);
220  }
+ 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.

References countElements().

111  {
112  return (bool) $this->countElements();
113  }
+ 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.

References countElements(), and getRandomIdentifierIndex().

Referenced by getParityTrueElementList().

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  }
+ 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.

References fetchIdentifier(), and isValidIdentifier().

Referenced by addElement().

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  }
isValidIdentifier($identifierType, $identifier)
fetchIdentifier(ilAssOrderingElement $element, $identifierType)
+ 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.

References fetchIdentifier(), and getQuestionId().

Referenced by buildRandomIdentifier().

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  }
fetchIdentifier(ilAssOrderingElement $element, $identifierType)
+ 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.

References countElements().

121  {
122  return $position == ($this->countElements() - 1);
123  }
+ 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.

References throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier(), and hasValidIdentifiers().

488  {
489  switch ($identifierType) {
490  case self::IDENTIFIER_TYPE_SOLUTION:
491  return self::isValidSolutionIdentifier($identifier);
492 
493  case self::IDENTIFIER_TYPE_RANDOM:
494  return self::isValidRandomIdentifier($identifier);
495  }
496 
497  $this->throwUnknownIdentifierTypeException($identifierType);
498  }
+ 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.

Referenced by ilAssOrderingElement\isExportIdent().

641  {
642  return self::isValidPosition($indentation); // horizontal position ^^
643  }
+ Here is the caller graph for this function:

◆ isValidPosition()

static ilAssOrderingElementList::isValidPosition (   $position)
static

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

Referenced by ilAssOrderingElement\isExportIdent().

636  {
637  return self::isValidSolutionIdentifier($position); // this was the position earlier
638  }
+ Here is the caller graph for this function:

◆ isValidRandomIdentifier()

static ilAssOrderingElementList::isValidRandomIdentifier (   $identifier)
static

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

Referenced by ilAssOrderingElement\isExportIdent().

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  }
+ Here is the caller graph for this function:

◆ isValidSolutionIdentifier()

static ilAssOrderingElementList::isValidSolutionIdentifier (   $identifier)
static

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

Referenced by ilAssOrderingElement\isExportIdent().

620  : bool
621  {
622  return is_numeric($identifier)
623  && $identifier == (int) $identifier
624  && (int) $identifier >= 0;
625  }
+ Here is the caller graph for this function:

◆ key()

ilAssOrderingElementList::key ( )
Returns
integer|bool

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

Referenced by valid().

810  {
811  return key($this->elements);
812  }
+ Here is the caller graph for this function:

◆ moveElementByPositions()

ilAssOrderingElementList::moveElementByPositions (   $currentPosition,
  $targetPosition 
)

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

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

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  }
+ 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  }

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

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

Referenced by ensureValidIdentifier().

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  }
setRandomIdentifier(int $random_identifier)
setSolutionIdentifier($solution_identifier)
+ 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.

References fetchIdentifier(), and getQuestionId().

Referenced by ensureValidIdentifier(), and registerIdentifiers().

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  }
fetchIdentifier(ilAssOrderingElement $element, $identifierType)
+ 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.

References registerIdentifier().

Referenced by addElement().

406  {
407  $this->registerIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
408  $this->registerIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
409  }
registerIdentifier(ilAssOrderingElement $element, $identifierType)
+ 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.

References getQuestionId().

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  }
+ 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.

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

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)
+ Here is the call graph for this function:

◆ resetElements()

ilAssOrderingElementList::resetElements ( )

resets elements

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

Referenced by setElements().

174  {
175  $this->elements = array();
176  }
+ 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.

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

Referenced by moveElementByPositions(), and reorderByRandomIdentifiers().

182  {
183  $this->resetElements();
184 
185  foreach ($elements as $element) {
186  $this->addElement($element);
187  }
188  }
addElement(ilAssOrderingElement $element)
+ 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.

References $question_id.

Referenced by buildInstance().

101  {
102  $this->question_id = $question_id;
103  }
+ 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.

Referenced by buildRandomIdentifier().

531  {
532  throw new ilTestQuestionPoolException(
533  "could not build random identifier (max tries: $maxTries)"
534  );
535  }
+ 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.

Referenced by reorderByRandomIdentifiers().

542  {
543  throw new ilTestQuestionPoolException(
544  "cannot reorder element due to missing position (random identifier: $randomIdentifier)"
545  );
546  }
+ 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.

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

520  {
521  throw new ilTestQuestionPoolException(
522  "unknown identifier type given (type: $identifierType)"
523  );
524  }
+ 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.

Referenced by reorderByRandomIdentifiers().

553  {
554  throw new ilTestQuestionPoolException(
555  'cannot reorder element due to one or more unknown random identifiers ' .
556  '(' . implode(', ', $randomIdentifiers) . ')'
557  );
558  }
+ Here is the caller graph for this function:

◆ valid()

ilAssOrderingElementList::valid ( )
Returns
bool

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

References key().

818  {
819  return ($this->key() !== null);
820  }
+ Here is the call graph for this function:

◆ withElements()

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

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

References $elements.

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

870  : self
871  {
872  $clone = clone $this;
873  $clone->elements = $elements;
874  return $clone;
875  }
+ Here is the caller graph for this function:

◆ withQuestionId()

ilAssOrderingElementList::withQuestionId ( int  $question_id)

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

References $question_id.

Referenced by assOrderingQuestion\setOrderingElementList().

877  : self
878  {
879  $clone = clone $this;
880  $clone->question_id = $question_id;
881  return $clone;
882  }
+ 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.

◆ $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'

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

◆ IDENTIFIER_TYPE_SOLUTION

const ilAssOrderingElementList::IDENTIFIER_TYPE_SOLUTION = 'SolutionIds'

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

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

◆ RANDOM_IDENTIFIER_RANGE_UPPER_BOUND

const ilAssOrderingElementList::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND = 100000

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

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


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