ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilAssOrderingElementList Class Reference
+ Inheritance diagram for ilAssOrderingElementList:
+ Collaboration diagram for ilAssOrderingElementList:

Public Member Functions

 __construct ()
 ilAssOrderingElementList constructor. More...
 
 __clone ()
 clone list by additionally cloning the element objects More...
 
 getClone ()
 
 getQuestionId ()
 
 setQuestionId ($questionId)
 
 loadFromDb ()
 load elements from database More...
 
 clearElementContents ()
 clears the contents of all elements More...
 
 countElements ()
 
 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)
 
 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 ()
 

Static Public Member Functions

static isValidSolutionIdentifier ($identifier)
 
static isValidRandomIdentifier ($identifier)
 
static isValidPosition ($position)
 
static isValidIndentation ($indentation)
 
static getFallbackDefaultElement ()
 
static buildInstance ($questionId, $orderingElements=array())
 

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)
 
 ensureValidIdentifiers (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

 $questionId
 
 $elements
 

Static Protected Attributes

static $identifierRegistry
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilAssOrderingElementList::__construct ( )

ilAssOrderingElementList constructor.

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

References resetElements().

54  {
55  $this->objectInstanceId = ++self::$objectInstanceCounter;
56 
57  $this->questionId = null;
58  $this->resetElements();
59  }
+ Here is the call graph for this function:

Member Function Documentation

◆ __clone()

ilAssOrderingElementList::__clone ( )

clone list by additionally cloning the element objects

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

References $elements, $key, and array.

65  {
66  $this->objectInstanceId = ++self::$objectInstanceCounter;
67 
68  $elements = array();
69 
70  foreach ($this as $key => $element) {
71  $elements[$key] = clone $element;
72  }
73 
74  $this->elements = $elements;
75  }
Create styles array
The data for the language used.
$key
Definition: croninfo.php:18

◆ addElement()

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

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

References hasValidIdentifiers(), and registerIdentifiers().

Referenced by loadFromDb(), and setElements().

309  {
310  if ($this->hasValidIdentifiers($element)) {
311  $this->registerIdentifiers($element);
312  }
313 
314  $this->elements[] = $element;
315  }
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 567 of file class.ilAssOrderingElementList.php.

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

Referenced by ensureValidIdentifier().

568  {
569  switch ($identifierType) {
570  case self::IDENTIFIER_TYPE_SOLUTION: return $this->buildSolutionIdentifier();
571  case self::IDENTIFIER_TYPE_RANDOM: return $this->buildRandomIdentifier();
572  }
573 
574  $this->throwUnknownIdentifierTypeException($identifierType);
575  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildInstance()

static ilAssOrderingElementList::buildInstance (   $questionId,
  $orderingElements = array() 
)
static
Parameters
integer$questionId
array[ilAssOrderingElement]$orderingElements
Returns
ilAssOrderingElementList

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

References $questionId.

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

960  {
961  $elementList = new self();
962 
963  $elementList->setQuestionId($questionId);
964  $elementList->setElements($orderingElements);
965 
966  return $elementList;
967  }
+ Here is the caller graph for this function:

◆ buildRandomIdentifier()

ilAssOrderingElementList::buildRandomIdentifier ( )
protected
Returns
int $randomIdentifier
Exceptions
ilTestQuestionPoolException

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

References isIdentifierRegistered(), and throwCouldNotBuildRandomIdentifierException().

Referenced by buildIdentifier(), and distributeNewRandomIdentifiers().

661  {
662  $usedTriesCounter = 0;
663 
664  do {
665  if ($usedTriesCounter >= self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES) {
666  $this->throwCouldNotBuildRandomIdentifierException(self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES);
667  }
668 
669  $usedTriesCounter++;
670 
671  $lowerBound = self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND;
672  $upperBound = self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND;
673  $randomIdentifier = mt_rand($lowerBound, $upperBound);
674 
675  $testElement = new ilAssOrderingElement();
676  $testElement->setRandomIdentifier($randomIdentifier);
677  } while ($this->isIdentifierRegistered($testElement, self::IDENTIFIER_TYPE_RANDOM));
678 
679  return $randomIdentifier;
680  }
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 643 of file class.ilAssOrderingElementList.php.

References getLastSolutionIdentifier().

Referenced by buildIdentifier().

644  {
645  $lastSolutionIdentifier = $this->getLastSolutionIdentifier();
646 
647  if ($lastSolutionIdentifier === null) {
648  return 0;
649  }
650 
651  $nextSolutionIdentifier = $lastSolutionIdentifier + self::SOLUTION_IDENTIFIER_VALUE_INTERVAL;
652 
653  return $nextSolutionIdentifier;
654  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearElementContents()

ilAssOrderingElementList::clearElementContents ( )

clears the contents of all elements

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

165  {
166  foreach ($this as $orderingElement) {
167  $orderingElement->setContent('');
168  }
169  }

◆ completeContentsFromElementList()

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

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

889  {
890  foreach ($this as $thisElement) {
891  if (!$otherList->elementExistByRandomIdentifier($thisElement->getRandomIdentifier())) {
892  continue;
893  }
894 
895  $otherElement = $otherList->getElementByRandomIdentifier(
896  $thisElement->getRandomIdentifier()
897  );
898 
899  $thisElement->setContent($otherElement->getContent());
900  }
901  }

◆ countElements()

ilAssOrderingElementList::countElements ( )

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

Referenced by hasSameElementSetByRandomIdentifiers(), and isLastElementPosition().

172  {
173  return count($this->elements);
174  }
+ Here is the caller graph for this function:

◆ current()

ilAssOrderingElementList::current ( )
Returns
ilAssOrderingElement

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

907  {
908  return current($this->elements);
909  }

◆ distributeNewRandomIdentifiers()

ilAssOrderingElementList::distributeNewRandomIdentifiers ( )

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

References buildRandomIdentifier().

734  {
735  foreach ($this as $element) {
736  $element->setRandomIdentifier($this->buildRandomIdentifier());
737  }
738  }
+ Here is the call graph for this function:

◆ elementExistByPosition()

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

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

References getElementByPosition().

335  {
336  return ($this->getElementByPosition($position) !== null);
337  }
+ Here is the call graph for this function:

◆ elementExistByRandomIdentifier()

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

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

References getElementByRandomIdentifier().

361  {
362  return ($this->getElementByRandomIdentifier($randomIdentifier) !== null);
363  }
+ Here is the call graph for this function:

◆ elementExistBySolutionIdentifier()

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

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

References getElementBySolutionIdentifier().

386  {
387  return ($this->getElementBySolutionIdentifier($solutionIdentifier) !== null);
388  }
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 453 of file class.ilAssOrderingElementList.php.

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

Referenced by ensureValidIdentifiers().

454  {
455  $identifier = $this->fetchIdentifier($element, $identifierType);
456 
457  if (!$this->isValidIdentifier($identifierType, $identifier)) {
458  $identifier = $this->buildIdentifier($identifierType);
459  $this->populateIdentifier($element, $identifierType, $identifier);
460  $this->registerIdentifier($element, $identifierType);
461  }
462  }
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)
protected
Parameters
ilAssOrderingElement$element

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

References ensureValidIdentifier().

Referenced by loadFromDb().

444  {
445  $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
446  $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
447  }
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 518 of file class.ilAssOrderingElementList.php.

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

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

519  {
520  switch ($identifierType) {
521  case self::IDENTIFIER_TYPE_SOLUTION: return $element->getSolutionIdentifier();
522  case self::IDENTIFIER_TYPE_RANDOM: return $element->getRandomIdentifier();
523  }
524 
525  $this->throwUnknownIdentifierTypeException($identifierType);
526  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getClone()

ilAssOrderingElementList::getClone ( )
Returns
ilAssOrderingElementList

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

81  {
82  $that = clone $this;
83  return $that;
84  }

◆ getDifferenceElementList()

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

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

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

857  {
858  $differenceRandomIdentifierIndex = $this->getDifferenceRandomIdentifierIndex($otherElementList);
859 
860  $differenceElementList = new self();
861  $differenceElementList->setQuestionId($this->getQuestionId());
862 
863  foreach ($differenceRandomIdentifierIndex as $randomIdentifier) {
864  $element = $this->getElementByRandomIdentifier($randomIdentifier);
865  $differenceElementList->addElement($element);
866  }
867 
868  return $differenceElementList;
869  }
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 875 of file class.ilAssOrderingElementList.php.

References getRandomIdentifierIndex().

Referenced by getDifferenceElementList().

876  {
877  $differenceRandomIdentifierIndex = array_diff(
878  $this->getRandomIdentifierIndex(),
879  $otherElementList->getRandomIdentifierIndex()
880  );
881 
882  return $differenceRandomIdentifierIndex;
883  }
+ 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 321 of file class.ilAssOrderingElementList.php.

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

322  {
323  if (isset($this->elements[$position])) {
324  return $this->elements[$position];
325  }
326 
327  return null;
328  }
+ Here is the caller graph for this function:

◆ getElementByRandomIdentifier()

ilAssOrderingElementList::getElementByRandomIdentifier (   $randomIdentifier)
Parameters
$randomIdentifier
Returns
ilAssOrderingElement

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

Referenced by elementExistByRandomIdentifier(), and getDifferenceElementList().

344  {
345  foreach ($this as $element) {
346  if ($element->getRandomIdentifier() != $randomIdentifier) {
347  continue;
348  }
349 
350  return $element;
351  }
352 
353  return null;
354  }
+ Here is the caller graph for this function:

◆ getElementBySolutionIdentifier()

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

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

Referenced by elementExistBySolutionIdentifier().

370  {
371  foreach ($this as $element) {
372  if ($element->getSolutionIdentifier() != $solutionIdentifier) {
373  continue;
374  }
375 
376  return $element;
377  }
378  return null;
379  }
+ Here is the caller graph for this function:

◆ getElements()

ilAssOrderingElementList::getElements ( )
Returns
array[ilAssOrderingElement]

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

References $elements.

◆ getFallbackDefaultElement()

static ilAssOrderingElementList::getFallbackDefaultElement ( )
static
Returns
ilAssOrderingElement

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

Referenced by ilAssOrderingDefaultElementFallback\manipulateFormInputValues().

947  {
948  $element = new ilAssOrderingElement();
949  $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
950 
951  return $element;
952  }
+ Here is the caller graph for this function:

◆ getIndexedElements()

ilAssOrderingElementList::getIndexedElements (   $identifierType)
protected
Returns
array

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

References $elements, array, and fetchIdentifier().

Referenced by getRandomIdentifierIndexedElements(), and getSolutionIdentifierIndexedElements().

295  {
296  $elements = array();
297 
298  foreach ($this as $element) {
299  $elements[$this->fetchIdentifier($element, $identifierType)] = $element;
300  }
301 
302  return $elements;
303  }
Create styles array
The data for the language used.
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 625 of file class.ilAssOrderingElementList.php.

References getRegisteredSolutionIdentifiers().

Referenced by buildSolutionIdentifier().

626  {
627  $lastSolutionIdentifier = null;
628 
629  foreach ($this->getRegisteredSolutionIdentifiers() as $registeredIdentifier) {
630  if ($lastSolutionIdentifier > $registeredIdentifier) {
631  continue;
632  }
633 
634  $lastSolutionIdentifier = $registeredIdentifier;
635  }
636 
637  return $lastSolutionIdentifier;
638  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParityTrueElementList()

ilAssOrderingElementList::getParityTrueElementList ( self  $otherList)

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

References getQuestionId(), and hasSameElementSetByRandomIdentifiers().

783  {
784  if (!$this->hasSameElementSetByRandomIdentifiers($otherList)) {
785  throw new ilTestQuestionPoolException('cannot compare lists having different element sets');
786  }
787 
788  $parityTrueElementList = new self();
789  $parityTrueElementList->setQuestionId($this->getQuestionId());
790 
791  foreach ($this as $thisElement) {
792  $otherElement = $otherList->getElementByRandomIdentifier(
793  $thisElement->getRandomIdentifier()
794  );
795 
796  if ($otherElement->getPosition() != $thisElement->getPosition()) {
797  continue;
798  }
799 
800  if ($otherElement->getIndentation() != $thisElement->getIndentation()) {
801  continue;
802  }
803 
804  $parityTrueElementList->addElement($thisElement);
805  }
806 
807  return $parityTrueElementList;
808  }
+ Here is the call graph for this function:

◆ getQuestionId()

ilAssOrderingElementList::getQuestionId ( )

◆ getRandomIdentifierIndex()

ilAssOrderingElementList::getRandomIdentifierIndex ( )
Returns
array

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

References getRandomIdentifierIndexedElements().

Referenced by getDifferenceRandomIdentifierIndex(), and hasSameElementSetByRandomIdentifiers().

271  {
272  return array_keys($this->getRandomIdentifierIndexedElements());
273  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRandomIdentifierIndexedElements()

ilAssOrderingElementList::getRandomIdentifierIndexedElements ( )
Returns
array

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

References getIndexedElements().

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

263  {
264  return $this->getIndexedElements(self::IDENTIFIER_TYPE_RANDOM);
265  }
+ 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 410 of file class.ilAssOrderingElementList.php.

References array, and getQuestionId().

Referenced by getRegisteredRandomIdentifiers(), and getRegisteredSolutionIdentifiers().

411  {
412  if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
413  return array();
414  }
415 
416  return self::$identifierRegistry[$identifierType][$this->getQuestionId()];
417  }
Create styles array
The data for the language used.
+ 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 401 of file class.ilAssOrderingElementList.php.

References getRegisteredIdentifiers().

402  {
403  return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_RANDOM);
404  }
+ Here is the call graph for this function:

◆ getRegisteredSolutionIdentifiers()

ilAssOrderingElementList::getRegisteredSolutionIdentifiers ( )
protected
Returns
array

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

References getRegisteredIdentifiers().

Referenced by getLastSolutionIdentifier().

394  {
395  return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_SOLUTION);
396  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSolutionIdentifierIndex()

ilAssOrderingElementList::getSolutionIdentifierIndex ( )
Returns
array

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

References getSolutionIdentifierIndexedElements().

287  {
288  return array_keys($this->getSolutionIdentifierIndexedElements());
289  }
+ Here is the call graph for this function:

◆ getSolutionIdentifierIndexedElements()

ilAssOrderingElementList::getSolutionIdentifierIndexedElements ( )
Returns
array

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

References getIndexedElements().

Referenced by getSolutionIdentifierIndex().

279  {
280  return $this->getIndexedElements(self::IDENTIFIER_TYPE_SOLUTION);
281  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasSameElementSetByRandomIdentifiers()

ilAssOrderingElementList::hasSameElementSetByRandomIdentifiers ( self  $otherList)
Parameters
ilAssOrderingElementList$otherList
Returns
bool $hasSameElements

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

References countElements(), and getRandomIdentifierIndex().

Referenced by getParityTrueElementList().

745  {
746  $numIntersectingElements = count(array_intersect(
747  $otherList->getRandomIdentifierIndex(),
748  $this->getRandomIdentifierIndex()
749  ));
750 
751  if ($numIntersectingElements != $this->countElements()) {
752  return false;
753  }
754 
755  if ($numIntersectingElements != $otherList->countElements()) {
756  return false;
757  }
758 
759  return true; // faster ;-)
760 
761  $otherListRandomIdentifierIndex = $otherList->getRandomIdentifierIndex();
762 
763  foreach ($this as $orderingElement) {
764  if (!in_array($orderingElement->getRandomIdentifier(), $otherListRandomIdentifierIndex)) {
765  return false;
766  }
767 
768  $randomIdentifierIndexMatchingsCount = count(array_keys(
769  $otherListRandomIdentifierIndex,
770  $orderingElement->getRandomIdentifier(),
771  false
772  ));
773 
774  if ($randomIdentifierIndexMatchingsCount != 1) {
775  return false;
776  }
777  }
778 
779  return $this->countElements() == $otherList->countElements();
780  }
+ 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 423 of file class.ilAssOrderingElementList.php.

References fetchIdentifier(), and isValidIdentifier().

Referenced by addElement().

424  {
425  $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
426 
427  if (!$this->isValidIdentifier(self::IDENTIFIER_TYPE_SOLUTION, $identifier)) {
428  return false;
429  }
430 
431  $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
432 
433  if (!$this->isValidIdentifier(self::IDENTIFIER_TYPE_RANDOM, $identifier)) {
434  return false;
435  }
436 
437  return true;
438  }
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 176 of file class.ilAssOrderingElementList.php.

177  {
178  return $position == 0;
179  }

◆ isIdentifierRegistered()

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

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

References fetchIdentifier(), and getQuestionId().

Referenced by buildRandomIdentifier().

498  {
499  if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
500  return false;
501  }
502 
503  $identifier = $this->fetchIdentifier($element, $identifierType);
504 
505  if (!in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
506  return false;
507  }
508 
509  return true;
510  }
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 181 of file class.ilAssOrderingElementList.php.

References countElements().

182  {
183  return $position == ($this->countElements() - 1);
184  }
+ 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 549 of file class.ilAssOrderingElementList.php.

References throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier(), and hasValidIdentifiers().

550  {
551  switch ($identifierType) {
552  case self::IDENTIFIER_TYPE_SOLUTION:
553  return self::isValidSolutionIdentifier($identifier);
554 
555  case self::IDENTIFIER_TYPE_RANDOM:
556  return self::isValidRandomIdentifier($identifier);
557  }
558 
559  $this->throwUnknownIdentifierTypeException($identifierType);
560  }
+ 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 725 of file class.ilAssOrderingElementList.php.

Referenced by ilAssOrderingElement\isExportIdent().

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

◆ isValidPosition()

static ilAssOrderingElementList::isValidPosition (   $position)
static

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

Referenced by ilAssOrderingElement\isExportIdent().

721  {
722  return self::isValidSolutionIdentifier($position); // this was the position earlier
723  }
+ Here is the caller graph for this function:

◆ isValidRandomIdentifier()

static ilAssOrderingElementList::isValidRandomIdentifier (   $identifier)
static

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

Referenced by ilAssOrderingElement\isExportIdent().

700  {
701  if (!is_numeric($identifier)) {
702  return false;
703  }
704 
705  if ($identifier != (int) $identifier) {
706  return false;
707  }
708 
709  if ($identifier < self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND) {
710  return false;
711  }
712 
713  if ($identifier > self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND) {
714  return false;
715  }
716 
717  return true;
718  }
+ Here is the caller graph for this function:

◆ isValidSolutionIdentifier()

static ilAssOrderingElementList::isValidSolutionIdentifier (   $identifier)
static

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

Referenced by ilAssOrderingElement\isExportIdent().

683  {
684  if (!is_numeric($identifier)) {
685  return false;
686  }
687 
688  if ($identifier != (int) $identifier) {
689  return false;
690  }
691 
692  if ($identifier < 0) {
693  return false;
694  }
695 
696  return true;
697  }
+ Here is the caller graph for this function:

◆ key()

ilAssOrderingElementList::key ( )
Returns
integer|bool

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

Referenced by valid().

923  {
924  return key($this->elements);
925  }
+ Here is the caller graph for this function:

◆ loadFromDb()

ilAssOrderingElementList::loadFromDb ( )

load elements from database

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

References $GLOBALS, $ilDB, $result, $row, addElement(), array, ensureValidIdentifiers(), getQuestionId(), registerIdentifiers(), and time.

106  {
107  $ilDB = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['ilDB'] : $GLOBALS['ilDB'];
108 
109  $result = $ilDB->queryF(
110  "SELECT * FROM qpl_a_ordering WHERE question_fi = %s ORDER BY position ASC",
111  array('integer'),
112  array($this->getQuestionId())
113  );
114 
115  while ($row = $ilDB->fetchAssoc($result)) {
116  $element = new ilAssOrderingElement();
117 
118  $element->setRandomIdentifier($row['random_id']);
119  $element->setSolutionIdentifier($row['solution_key']);
120 
121  $element->setPosition($row['position']);
122  $element->setIndentation($row["depth"]);
123 
124  $element->setContent($row['answertext']);
125 
126  $this->addElement($element);
127  $this->registerIdentifiers($element);
128  }
129  }
registerIdentifiers(ilAssOrderingElement $element)
$result
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
addElement(ilAssOrderingElement $element)
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:

◆ moveElementByPositions()

ilAssOrderingElementList::moveElementByPositions (   $currentPosition,
  $targetPosition 
)

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

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

187  {
188  $movingElement = $this->getElementByPosition($currentPosition);
189  $dodgingElement = $this->getElementByPosition($targetPosition);
190 
191  $elementList = new self();
192  $elementList->setQuestionId($this->getQuestionId());
193 
194  foreach ($this as $element) {
195  if ($element->getPosition() == $currentPosition) {
196  $elementList->addElement($dodgingElement);
197  continue;
198  }
199 
200  if ($element->getPosition() == $targetPosition) {
201  $elementList->addElement($movingElement);
202  continue;
203  }
204 
205  $elementList->addElement($element);
206  }
207 
208  $dodgingElement->setPosition($currentPosition);
209  $movingElement->setPosition($targetPosition);
210 
211  $this->setElements($elementList->getElements());
212  }
+ Here is the call graph for this function:

◆ next()

ilAssOrderingElementList::next ( )
Returns
ilAssOrderingElement

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

915  {
916  return next($this->elements);
917  }

◆ populateIdentifier()

ilAssOrderingElementList::populateIdentifier ( ilAssOrderingElement  $element,
  $identifierType,
  $identifier 
)
protected
Parameters
ilAssOrderingElement$element
string$identifierType
$identifier
Exceptions
ilTestQuestionPoolException

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

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

Referenced by ensureValidIdentifier().

535  {
536  switch ($identifierType) {
537  case self::IDENTIFIER_TYPE_SOLUTION: $element->setSolutionIdentifier($identifier); break;
538  case self::IDENTIFIER_TYPE_RANDOM: $element->setRandomIdentifier($identifier); break;
539  default: $this->throwUnknownIdentifierTypeException($identifierType);
540  }
541  }
setSolutionIdentifier($solutionIdentifier)
setRandomIdentifier($randomIdentifier)
+ 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 478 of file class.ilAssOrderingElementList.php.

References array, fetchIdentifier(), and getQuestionId().

Referenced by ensureValidIdentifier(), and registerIdentifiers().

479  {
480  if (!isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
481  self::$identifierRegistry[$identifierType][$this->getQuestionId()] = array();
482  }
483 
484  $identifier = $this->fetchIdentifier($element, $identifierType);
485 
486  if (!in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()])) {
487  self::$identifierRegistry[$identifierType][$this->getQuestionId()][] = $identifier;
488  }
489  }
Create styles array
The data for the language used.
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 467 of file class.ilAssOrderingElementList.php.

References registerIdentifier().

Referenced by addElement(), and loadFromDb().

468  {
469  $this->registerIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
470  $this->registerIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
471  }
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 214 of file class.ilAssOrderingElementList.php.

References getQuestionId().

215  {
216  $elementList = new self();
217  $elementList->setQuestionId($this->getQuestionId());
218 
219  $positionCounter = 0;
220 
221  foreach ($this as $element) {
222  if ($element->isSameElement($removeElement)) {
223  continue;
224  }
225 
226  $element->setPosition($positionCounter++);
227  $elementList->addElement($element);
228  }
229  }
+ Here is the call graph for this function:

◆ reorderByRandomIdentifiers()

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

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

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

816  {
817  $positionsMap = array_flip(array_values($randomIdentifiers));
818 
819  $orderedElements = array();
820 
821  foreach ($this as $element) {
822  if (!isset($positionsMap[$element->getRandomIdentifier()])) {
823  $this->throwMissingReorderPositionException($element->getRandomIdentifier());
824  }
825 
826  $position = $positionsMap[$element->getRandomIdentifier()];
827  unset($positionsMap[$element->getRandomIdentifier()]);
828 
829  $element->setPosition($position);
830  $orderedElements[$position] = $element;
831  }
832 
833  if (count($positionsMap)) {
834  $this->throwUnknownRandomIdentifiersException(array_keys($positionsMap));
835  }
836 
837  ksort($orderedElements);
838 
839  $this->setElements(array_values($orderedElements));
840  }
throwMissingReorderPositionException($randomIdentifier)
throwUnknownRandomIdentifiersException($randomIdentifiers)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ resetElements()

ilAssOrderingElementList::resetElements ( )

resets elements

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

References array.

Referenced by __construct(), and setElements().

235  {
236  $this->elements = array();
237  }
Create styles array
The data for the language used.
+ 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 845 of file class.ilAssOrderingElementList.php.

846  {
847  foreach ($this as $element) {
848  $element->setIndentation(0);
849  }
850  }

◆ rewind()

ilAssOrderingElementList::rewind ( )
Returns
ilAssOrderingElement

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

939  {
940  return reset($this->elements);
941  }

◆ setElements()

ilAssOrderingElementList::setElements (   $elements)
Parameters
$elements

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

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

Referenced by moveElementByPositions(), and reorderByRandomIdentifiers().

243  {
244  $this->resetElements();
245 
246  foreach ($elements as $element) {
247  $this->addElement($element);
248  }
249  }
addElement(ilAssOrderingElement $element)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setQuestionId()

ilAssOrderingElementList::setQuestionId (   $questionId)
Parameters
integer$questionId

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

References $questionId.

98  {
99  $this->questionId = $questionId;
100  }

◆ throwCouldNotBuildRandomIdentifierException()

ilAssOrderingElementList::throwCouldNotBuildRandomIdentifierException (   $maxTries)
protected
Parameters
string$identifierType
Exceptions
ilTestQuestionPoolException

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

Referenced by buildRandomIdentifier().

593  {
594  throw new ilTestQuestionPoolException(
595  "could not build random identifier (max tries: $maxTries)"
596  );
597  }
+ Here is the caller graph for this function:

◆ throwMissingReorderPositionException()

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

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

Referenced by reorderByRandomIdentifiers().

604  {
605  throw new ilTestQuestionPoolException(
606  "cannot reorder element due to missing position (random identifier: $randomIdentifier)"
607  );
608  }
+ Here is the caller graph for this function:

◆ throwUnknownIdentifierTypeException()

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

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

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

582  {
583  throw new ilTestQuestionPoolException(
584  "unknown identifier type given (type: $identifierType)"
585  );
586  }
+ Here is the caller graph for this function:

◆ throwUnknownRandomIdentifiersException()

ilAssOrderingElementList::throwUnknownRandomIdentifiersException (   $randomIdentifiers)
protected
Parameters
array$randomIdentifiers
Exceptions
ilTestQuestionPoolException

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

Referenced by reorderByRandomIdentifiers().

615  {
616  throw new ilTestQuestionPoolException(
617  'cannot reorder element due to one or more unknown random identifiers ' .
618  '(' . implode(', ', $randomIdentifiers) . ')'
619  );
620  }
+ Here is the caller graph for this function:

◆ valid()

ilAssOrderingElementList::valid ( )
Returns
bool

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

References key().

931  {
932  return ($this->key() !== null);
933  }
+ Here is the call graph for this function:

Field Documentation

◆ $elements

ilAssOrderingElementList::$elements
protected

◆ $identifierRegistry

ilAssOrderingElementList::$identifierRegistry
staticprotected
Initial value:
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.

◆ $questionId

ilAssOrderingElementList::$questionId
protected

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

Referenced by buildInstance(), getQuestionId(), and setQuestionId().

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