ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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 (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)
 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, 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.

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  }

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

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

Referenced by ensureValidIdentifier().

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

References $elements, and setQuestionId().

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

834  {
835  $elementList = new self();
836 
837  $elementList->setQuestionId($question_id);
838  $elementList->setElements($elements);
839 
840  return $elementList;
841  }
+ 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.

References isIdentifierRegistered(), and throwCouldNotBuildRandomIdentifierException().

Referenced by buildIdentifier(), and distributeNewRandomIdentifiers().

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

References getLastSolutionIdentifier(), and null.

Referenced by buildIdentifier().

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  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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.

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

References buildRandomIdentifier().

643  : void
644  {
645  foreach ($this as $element) {
646  $element->setRandomIdentifier($this->buildRandomIdentifier());
647  }
648  }
+ Here is the call graph for this function:

◆ elementExistByPosition()

ilAssOrderingElementList::elementExistByPosition ( int  $position)

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

References getElementByPosition(), and null.

278  : bool
279  {
280  return ($this->getElementByPosition($position) !== null);
281  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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.

References getElementByRandomIdentifier(), and null.

298  : bool
299  {
300  return ($this->getElementByRandomIdentifier($randomIdentifier) !== null);
301  }
getElementByRandomIdentifier(int $random_identifier)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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.

References getElementBySolutionIdentifier(), and null.

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

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

Referenced by ensureValidIdentifiers().

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

References ensureValidIdentifier().

Referenced by assOrderingQuestion\setOrderingElementList().

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

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

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

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

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

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  }
getElementByRandomIdentifier(int $random_identifier)
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 756 of file class.ilAssOrderingElementList.php.

References getRandomIdentifierIndex().

Referenced by getDifferenceElementList().

756  : array
757  {
758  $differenceRandomIdentifierIndex = array_diff(
759  $this->getRandomIdentifierIndex(),
760  $otherElementList->getRandomIdentifierIndex()
761  );
762 
763  return $differenceRandomIdentifierIndex;
764  }
+ 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.

References null.

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

270  {
271  if (isset($this->elements[$position])) {
272  return $this->elements[$position];
273  }
274 
275  return null;
276  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ getElementByRandomIdentifier()

ilAssOrderingElementList::getElementByRandomIdentifier ( int  $random_identifier)

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

References null.

Referenced by elementExistByRandomIdentifier(), and getDifferenceElementList().

284  {
285  foreach ($this as $element) {
286  if ($element->getRandomIdentifier() === intval($random_identifier)) {
287  return $element;
288  }
289  }
290 
291  return null;
292  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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.

References null.

Referenced by elementExistBySolutionIdentifier().

308  {
309  foreach ($this as $element) {
310  if ($element->getSolutionIdentifier() != $solutionIdentifier) {
311  continue;
312  }
313 
314  return $element;
315  }
316  return null;
317  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ getElements()

ilAssOrderingElementList::getElements ( )
Returns
array<ilAssOrderingElement>

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

References $elements.

Referenced by assOrderingQuestion\setOrderingElementList(), and ILIAS\TestQuestionPool\Questions\Ordering\OrderingQuestionDatabaseRepository\updateOrderingList().

206  : array
207  {
208  return $this->elements;
209  }
+ Here is the caller graph for this function:

◆ getFallbackDefaultElement()

static ilAssOrderingElementList::getFallbackDefaultElement ( )
static
Returns
ilAssOrderingElement

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

Referenced by ilAssOrderingDefaultElementFallback\manipulateFormInputValues().

825  {
826  $element = new ilAssOrderingElement();
827  $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
828 
829  return $element;
830  }
+ 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.

References $elements, and fetchIdentifier().

Referenced by getRandomIdentifierIndexedElements(), and getSolutionIdentifierIndexedElements().

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

References getRegisteredSolutionIdentifiers(), and null.

Referenced by buildSolutionIdentifier().

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  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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.

References getQuestionId(), and hasSameElementSetByRandomIdentifiers().

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  }
+ 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(), ilAssOrderingTextsInputGUI\setElementList(), ilAssOrderingImagesInputGUI\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 348 of file class.ilAssOrderingElementList.php.

References getQuestionId().

Referenced by getRegisteredRandomIdentifiers(), and getRegisteredSolutionIdentifiers().

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

References getRegisteredIdentifiers().

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

◆ getRegisteredSolutionIdentifiers()

ilAssOrderingElementList::getRegisteredSolutionIdentifiers ( )
protected
Returns
array

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

References getRegisteredIdentifiers().

Referenced by getLastSolutionIdentifier().

331  : array
332  {
333  return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_SOLUTION);
334  }
+ 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 653 of file class.ilAssOrderingElementList.php.

References countElements(), and getRandomIdentifierIndex().

Referenced by getParityTrueElementList().

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

References fetchIdentifier(), and isValidIdentifier().

Referenced by addElement().

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

References fetchIdentifier(), and getQuestionId().

Referenced by buildRandomIdentifier().

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

References throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier(), and hasValidIdentifiers().

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

Referenced by ilAssOrderingElement\isExportIdent().

635  : bool
636  {
637  return self::isValidPosition($indentation); // horizontal position ^^
638  }
+ Here is the caller graph for this function:

◆ isValidPosition()

static ilAssOrderingElementList::isValidPosition (   $position)
static

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

Referenced by ilAssOrderingElement\isExportIdent().

630  : bool
631  {
632  return self::isValidSolutionIdentifier($position); // this was the position earlier
633  }
+ Here is the caller graph for this function:

◆ isValidRandomIdentifier()

static ilAssOrderingElementList::isValidRandomIdentifier (   $identifier)
static

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

References ILIAS\Repository\int().

Referenced by ilAssOrderingElement\isExportIdent().

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

References ILIAS\Repository\int().

Referenced by ilAssOrderingElement\isExportIdent().

615  : bool
616  {
617  return is_numeric($identifier)
618  && $identifier == (int) $identifier
619  && (int) $identifier >= 0;
620  }
+ 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.

Referenced by valid().

803  : ?int
804  {
805  return key($this->elements);
806  }
+ 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 795 of file class.ilAssOrderingElementList.php.

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

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

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

References fetchIdentifier(), and getQuestionId().

Referenced by ensureValidIdentifier(), and registerIdentifiers().

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

References registerIdentifier().

Referenced by addElement().

407  : void
408  {
409  $this->registerIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
410  $this->registerIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
411  }
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 696 of file class.ilAssOrderingElementList.php.

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

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)
+ 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 = [];
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 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.

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

Referenced by buildRandomIdentifier().

525  : void
526  {
527  throw new ilTestQuestionPoolException(
528  "could not build random identifier (max tries: $maxTries)"
529  );
530  }
+ 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.

Referenced by reorderByRandomIdentifiers().

536  : void
537  {
538  throw new ilTestQuestionPoolException(
539  "cannot reorder element due to missing position (random identifier: $randomIdentifier)"
540  );
541  }
+ 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.

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

514  : void
515  {
516  throw new ilTestQuestionPoolException(
517  "unknown identifier type given (type: $identifierType)"
518  );
519  }
+ 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.

Referenced by reorderByRandomIdentifiers().

547  : void
548  {
549  throw new ilTestQuestionPoolException(
550  'cannot reorder element due to one or more unknown random identifiers ' .
551  '(' . implode(', ', $randomIdentifiers) . ')'
552  );
553  }
+ Here is the caller graph for this function:

◆ valid()

ilAssOrderingElementList::valid ( )
Returns
bool

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

References key(), and null.

811  : bool
812  {
813  return ($this->key() !== null);
814  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ withElements()

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

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

References $elements.

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

861  : self
862  {
863  $clone = clone $this;
864  $clone->elements = $elements;
865  return $clone;
866  }
+ Here is the caller graph for this function:

◆ withQuestionId()

ilAssOrderingElementList::withQuestionId ( int  $question_id)

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

References $question_id.

Referenced by assOrderingQuestion\setOrderingElementList().

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

Field Documentation

◆ $elements

ilAssOrderingElementList::$elements = []
protected

◆ $identifierRegistry

ilAssOrderingElementList::$identifierRegistry
staticprotected
Initial value:
= [
self::IDENTIFIER_TYPE_SOLUTION => []

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: