ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
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, string $identifierType)
 
 populateIdentifier (ilAssOrderingElement $element, $identifierType, $identifier)
 
 isValidIdentifier ($identifierType, $identifier)
 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, and $question_id.

70  {
71  $this->objectInstanceId = ++self::$objectInstanceCounter;
72 
73  $this->question_id = $question_id;
74  $this->elements = $elements;
75  }

Member Function Documentation

◆ __clone()

ilAssOrderingElementList::__clone ( )

clone list by additionally cloning the element objects

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

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

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

◆ addElement()

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

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

References hasValidIdentifiers(), and registerIdentifiers().

Referenced by setElements().

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

References buildRandomIdentifier(), buildSolutionIdentifier(), and throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier().

509  : int
510  {
511  switch ($identifierType) {
512  case self::IDENTIFIER_TYPE_SOLUTION:
513  return $this->buildSolutionIdentifier();
514  default:
515  case self::IDENTIFIER_TYPE_RANDOM:
516  return $this->buildRandomIdentifier();
517  }
518 
519  $this->throwUnknownIdentifierTypeException($identifierType);
520  }
+ 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.

References $elements, and setQuestionId().

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

849  {
850  $elementList = new self();
851 
852  $elementList->setQuestionId($question_id);
853  $elementList->setElements($elements);
854 
855  return $elementList;
856  }
+ 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.

References isIdentifierRegistered(), and throwCouldNotBuildRandomIdentifierException().

Referenced by buildIdentifier(), and distributeNewRandomIdentifiers().

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

References getLastSolutionIdentifier().

Referenced by buildIdentifier().

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

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

118  : int
119  {
120  return count($this->elements);
121  }
+ Here is the caller graph for this function:

◆ current()

ilAssOrderingElementList::current ( )

◆ distributeNewRandomIdentifiers()

ilAssOrderingElementList::distributeNewRandomIdentifiers ( )

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

References buildRandomIdentifier().

655  : void
656  {
657  foreach ($this as $element) {
658  $element->setRandomIdentifier($this->buildRandomIdentifier());
659  }
660  }
+ 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.

References getElementByPosition().

286  : bool
287  {
288  return ($this->getElementByPosition($position) !== null);
289  }
+ 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.

References getElementByRandomIdentifier().

310  : bool
311  {
312  return ($this->getElementByRandomIdentifier($randomIdentifier) !== null);
313  }
+ 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.

References getElementBySolutionIdentifier().

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

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

Referenced by ensureValidIdentifiers().

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)
isValidIdentifier($identifierType, $identifier)
PhpInconsistentReturnPointsInspection
populateIdentifier(ilAssOrderingElement $element, $identifierType, $identifier)
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 393 of file class.ilAssOrderingElementList.php.

References ensureValidIdentifier().

Referenced by assOrderingQuestion\setOrderingElementList().

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

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

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

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

◆ getDifferenceElementList()

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

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

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

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

References getRandomIdentifierIndex().

Referenced by getDifferenceElementList().

768  : array
769  {
770  $differenceRandomIdentifierIndex = array_diff(
771  $this->getRandomIdentifierIndex(),
772  $otherElementList->getRandomIdentifierIndex()
773  );
774 
775  return $differenceRandomIdentifierIndex;
776  }
+ 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.

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

274  {
275  if (isset($this->elements[$position])) {
276  return $this->elements[$position];
277  }
278 
279  return null;
280  }
+ 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.

Referenced by elementExistByRandomIdentifier(), and getDifferenceElementList().

296  {
297  foreach ($this as $element) {
298  if ($element->getRandomIdentifier() === intval($randomIdentifier)) {
299  return $element;
300  }
301  }
302 
303  return null;
304  }
+ 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.

Referenced by elementExistBySolutionIdentifier().

320  {
321  foreach ($this as $element) {
322  if ($element->getSolutionIdentifier() != $solutionIdentifier) {
323  continue;
324  }
325 
326  return $element;
327  }
328  return null;
329  }
+ Here is the caller graph for this function:

◆ getElements()

ilAssOrderingElementList::getElements ( )

◆ getFallbackDefaultElement()

static ilAssOrderingElementList::getFallbackDefaultElement ( )
static
Returns
ilAssOrderingElement

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

Referenced by ilAssOrderingDefaultElementFallback\manipulateFormInputValues().

840  {
841  $element = new ilAssOrderingElement();
842  $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
843 
844  return $element;
845  }
+ 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.

References $elements, and fetchIdentifier().

Referenced by getRandomIdentifierIndexedElements(), and getSolutionIdentifierIndexedElements().

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  }
fetchIdentifier(ilAssOrderingElement $element, string $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 570 of file class.ilAssOrderingElementList.php.

References getRegisteredSolutionIdentifiers().

Referenced by buildSolutionIdentifier().

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

References getQuestionId(), and hasSameElementSetByRandomIdentifiers().

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

◆ getQuestionId()

◆ getRandomIdentifierIndex()

ilAssOrderingElementList::getRandomIdentifierIndex ( )
Returns
array

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

References getRandomIdentifierIndexedElements().

Referenced by getDifferenceRandomIdentifierIndex(), and hasSameElementSetByRandomIdentifiers().

222  : array
223  {
224  return array_keys($this->getRandomIdentifierIndexedElements());
225  }
+ 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.

References getIndexedElements().

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

214  : array
215  {
216  return $this->getIndexedElements(self::IDENTIFIER_TYPE_RANDOM);
217  }
+ 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.

References getQuestionId().

Referenced by getRegisteredRandomIdentifiers(), and getRegisteredSolutionIdentifiers().

360  : array
361  {
362  if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
363  return array();
364  }
365 
366  return self::$identifierRegistry[$identifierType][$this->getQuestionId()];
367  }
+ 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.

References getRegisteredIdentifiers().

351  : array
352  {
353  return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_RANDOM);
354  }
+ Here is the call graph for this function:

◆ getRegisteredSolutionIdentifiers()

ilAssOrderingElementList::getRegisteredSolutionIdentifiers ( )
protected
Returns
array

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

References getRegisteredIdentifiers().

Referenced by getLastSolutionIdentifier().

343  : array
344  {
345  return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_SOLUTION);
346  }
+ 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.

References getSolutionIdentifierIndexedElements().

238  : array
239  {
240  return array_keys($this->getSolutionIdentifierIndexedElements());
241  }
+ Here is the call graph for this function:

◆ getSolutionIdentifierIndexedElements()

ilAssOrderingElementList::getSolutionIdentifierIndexedElements ( )
Returns
array

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

References getIndexedElements().

Referenced by getSolutionIdentifierIndex().

230  : array
231  {
232  return $this->getIndexedElements(self::IDENTIFIER_TYPE_SOLUTION);
233  }
+ 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.

References countElements().

123  : bool
124  {
125  return (bool) $this->countElements();
126  }
+ 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.

References countElements(), and getRandomIdentifierIndex().

Referenced by getParityTrueElementList().

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

References fetchIdentifier(), and isValidIdentifier().

Referenced by addElement().

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

References fetchIdentifier(), and getQuestionId().

Referenced by buildRandomIdentifier().

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

References countElements().

133  : bool
134  {
135  return $position == ($this->countElements() - 1);
136  }
+ Here is the call graph for this function:

◆ isValidIdentifier()

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

PhpInconsistentReturnPointsInspection

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

References throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier(), and hasValidIdentifiers().

497  {
498  switch ($identifierType) {
499  case self::IDENTIFIER_TYPE_SOLUTION:
500  return self::isValidSolutionIdentifier($identifier);
501 
502  case self::IDENTIFIER_TYPE_RANDOM:
503  return self::isValidRandomIdentifier($identifier);
504  }
505 
506  $this->throwUnknownIdentifierTypeException($identifierType);
507  }
+ 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.

Referenced by ilAssOrderingElement\isExportIdent().

647  : bool
648  {
649  return self::isValidPosition($indentation); // horizontal position ^^
650  }
+ Here is the caller graph for this function:

◆ isValidPosition()

static ilAssOrderingElementList::isValidPosition (   $position)
static

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

Referenced by ilAssOrderingElement\isExportIdent().

642  : bool
643  {
644  return self::isValidSolutionIdentifier($position); // this was the position earlier
645  }
+ Here is the caller graph for this function:

◆ isValidRandomIdentifier()

static ilAssOrderingElementList::isValidRandomIdentifier (   $identifier)
static

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

References ILIAS\Repository\int().

Referenced by ilAssOrderingElement\isExportIdent().

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

References ILIAS\Repository\int().

Referenced by ilAssOrderingElement\isExportIdent().

627  : bool
628  {
629  return is_numeric($identifier)
630  && $identifier == (int) $identifier
631  && (int) $identifier >= 0;
632  }
+ 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.

Referenced by valid().

816  {
817  return key($this->elements);
818  }
+ Here is the caller graph for this function:

◆ moveElementByPositions()

ilAssOrderingElementList::moveElementByPositions (   $currentPosition,
  $targetPosition 
)

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

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

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

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

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

Referenced by ensureValidIdentifier().

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

References fetchIdentifier(), and getQuestionId().

Referenced by ensureValidIdentifier(), and registerIdentifiers().

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  }
fetchIdentifier(ilAssOrderingElement $element, string $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 419 of file class.ilAssOrderingElementList.php.

References registerIdentifier().

Referenced by addElement().

419  : void
420  {
421  $this->registerIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
422  $this->registerIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
423  }
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 166 of file class.ilAssOrderingElementList.php.

References getQuestionId().

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

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

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

◆ resetElements()

ilAssOrderingElementList::resetElements ( )

resets elements

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

Referenced by setElements().

186  : void
187  {
188  $this->elements = array();
189  }
+ 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.

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

Referenced by moveElementByPositions(), and reorderByRandomIdentifiers().

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

References $question_id.

Referenced by buildInstance().

113  : void
114  {
115  $this->question_id = $question_id;
116  }
+ 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.

Referenced by buildRandomIdentifier().

537  : void
538  {
539  throw new ilTestQuestionPoolException(
540  "could not build random identifier (max tries: $maxTries)"
541  );
542  }
+ 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.

Referenced by reorderByRandomIdentifiers().

548  : void
549  {
550  throw new ilTestQuestionPoolException(
551  "cannot reorder element due to missing position (random identifier: $randomIdentifier)"
552  );
553  }
+ 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.

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

526  : void
527  {
528  throw new ilTestQuestionPoolException(
529  "unknown identifier type given (type: $identifierType)"
530  );
531  }
+ 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.

Referenced by reorderByRandomIdentifiers().

559  : void
560  {
561  throw new ilTestQuestionPoolException(
562  'cannot reorder element due to one or more unknown random identifiers ' .
563  '(' . implode(', ', $randomIdentifiers) . ')'
564  );
565  }
+ Here is the caller graph for this function:

◆ valid()

ilAssOrderingElementList::valid ( )
Returns
bool

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

References key().

823  : bool
824  {
825  return ($this->key() !== null);
826  }
+ Here is the call graph for this function:

◆ withElements()

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

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

References $elements.

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

876  : self
877  {
878  $clone = clone $this;
879  $clone->elements = $elements;
880  return $clone;
881  }
+ Here is the caller graph for this function:

◆ withQuestionId()

ilAssOrderingElementList::withQuestionId ( int  $question_id)

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

References $question_id.

Referenced by assOrderingQuestion\setOrderingElementList().

883  : self
884  {
885  $clone = clone $this;
886  $clone->question_id = $question_id;
887  return $clone;
888  }
+ 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.

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

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

◆ IDENTIFIER_TYPE_SOLUTION

const ilAssOrderingElementList::IDENTIFIER_TYPE_SOLUTION = 'SolutionIds'

Definition at line 42 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 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.

◆ RANDOM_IDENTIFIER_RANGE_UPPER_BOUND

const ilAssOrderingElementList::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND = 100000

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

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


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