ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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.

54 {
55 $this->objectInstanceId = ++self::$objectInstanceCounter;
56
57 $this->questionId = null;
58 $this->resetElements();
59 }

References $objectInstanceCounter, and resetElements().

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

65 {
66 $this->objectInstanceId = ++self::$objectInstanceCounter;
67
68 $elements = array();
69
70 foreach($this as $key => $element)
71 {
72 $elements[$key] = clone $element;
73 }
74
75 $this->elements = $elements;
76 }

References $elements, and $objectInstanceCounter.

◆ addElement()

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

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

318 {
319 if( $this->hasValidIdentifiers($element) )
320 {
321 $this->registerIdentifiers($element);
322 }
323
324 $this->elements[] = $element;
325 }
registerIdentifiers(ilAssOrderingElement $element)
hasValidIdentifiers(ilAssOrderingElement $element)

References hasValidIdentifiers(), and registerIdentifiers().

Referenced by loadFromDb(), and setElements().

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

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

Referenced by ensureValidIdentifier().

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

◆ buildInstance()

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

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

998 {
999 $elementList = new self();
1000
1001 $elementList->setQuestionId($questionId);
1002 $elementList->setElements($orderingElements);
1003
1004 return $elementList;
1005 }

References $questionId.

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

+ Here is the caller graph for this function:

◆ buildRandomIdentifier()

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

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

691 {
692 $usedTriesCounter = 0;
693
694 do
695 {
696 if( $usedTriesCounter >= self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES )
697 {
698 $this->throwCouldNotBuildRandomIdentifierException(self::RANDOM_IDENTIFIER_BUILD_MAX_TRIES);
699 }
700
701 $usedTriesCounter++;
702
705 $randomIdentifier = mt_rand($lowerBound, $upperBound);
706
707 $testElement = new ilAssOrderingElement();
708 $testElement->setRandomIdentifier($randomIdentifier);
709 }
710 while( $this->isIdentifierRegistered($testElement, self::IDENTIFIER_TYPE_RANDOM) );
711
712 return $randomIdentifier;
713 }
isIdentifierRegistered(ilAssOrderingElement $element, $identifierType)

References isIdentifierRegistered(), RANDOM_IDENTIFIER_RANGE_LOWER_BOUND, RANDOM_IDENTIFIER_RANGE_UPPER_BOUND, and throwCouldNotBuildRandomIdentifierException().

Referenced by buildIdentifier(), and distributeNewRandomIdentifiers().

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

◆ buildSolutionIdentifier()

ilAssOrderingElementList::buildSolutionIdentifier ( )
protected
Returns
integer|null $nextSolutionIdentifier

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

673 {
674 $lastSolutionIdentifier = $this->getLastSolutionIdentifier();
675
676 if( $lastSolutionIdentifier === null )
677 {
678 return 0;
679 }
680
681 $nextSolutionIdentifier = $lastSolutionIdentifier + self::SOLUTION_IDENTIFIER_VALUE_INTERVAL;
682
683 return $nextSolutionIdentifier;
684 }

References getLastSolutionIdentifier(), and SOLUTION_IDENTIFIER_VALUE_INTERVAL.

Referenced by buildIdentifier().

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

◆ clearElementContents()

ilAssOrderingElementList::clearElementContents ( )

clears the contents of all elements

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

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

◆ completeContentsFromElementList()

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

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

940 {
941 foreach($this as $thisElement)
942 {
943 if( !$otherList->elementExistByRandomIdentifier($thisElement->getRandomIdentifier()) )
944 {
945 continue;
946 }
947
948 $otherElement = $otherList->getElementByRandomIdentifier(
949 $thisElement->getRandomIdentifier()
950 );
951
952 $thisElement->setContent( $otherElement->getContent() );
953 }
954 }

◆ countElements()

ilAssOrderingElementList::countElements ( )

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

174 {
175 return count($this->elements);
176 }

Referenced by hasSameElementSetByRandomIdentifiers(), and isLastElementPosition().

+ Here is the caller graph for this function:

◆ current()

ilAssOrderingElementList::current ( )
Returns
ilAssOrderingElement

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

959{ return current($this->elements); }

References current().

Referenced by current().

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

◆ distributeNewRandomIdentifiers()

ilAssOrderingElementList::distributeNewRandomIdentifiers ( )

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

774 {
775 foreach($this as $element)
776 {
777 $element->setRandomIdentifier( $this->buildRandomIdentifier() );
778 }
779 }

References buildRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistByPosition()

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

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

346 {
347 return ( $this->getElementByPosition($position) !== null );
348 }

References getElementByPosition().

+ Here is the call graph for this function:

◆ elementExistByRandomIdentifier()

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

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

374 {
375 return ( $this->getElementByRandomIdentifier($randomIdentifier) !== null );
376 }

References getElementByRandomIdentifier().

+ Here is the call graph for this function:

◆ elementExistBySolutionIdentifier()

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

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

401 {
402 return ( $this->getElementBySolutionIdentifier($solutionIdentifier) !== null );
403 }
getElementBySolutionIdentifier($solutionIdentifier)

References getElementBySolutionIdentifier().

+ Here is the call graph for this function:

◆ ensureValidIdentifier()

ilAssOrderingElementList::ensureValidIdentifier ( ilAssOrderingElement  $element,
  $identifierType 
)
protected
Parameters
ilAssOrderingElement$element
string$identifierType

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

472 {
473 $identifier = $this->fetchIdentifier($element, $identifierType);
474
475 if( !$this->isValidIdentifier($identifierType, $identifier) )
476 {
477 $identifier = $this->buildIdentifier($identifierType);
478 $this->populateIdentifier($element, $identifierType, $identifier);
479 $this->registerIdentifier($element, $identifierType);
480 }
481 }
registerIdentifier(ilAssOrderingElement $element, $identifierType)
populateIdentifier(ilAssOrderingElement $element, $identifierType, $identifier)
isValidIdentifier($identifierType, $identifier)
fetchIdentifier(ilAssOrderingElement $element, $identifierType)

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

Referenced by ensureValidIdentifiers().

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

◆ ensureValidIdentifiers()

ilAssOrderingElementList::ensureValidIdentifiers ( ilAssOrderingElement  $element)
protected
Parameters
ilAssOrderingElement$element

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

462 {
463 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
464 $this->ensureValidIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
465 }
ensureValidIdentifier(ilAssOrderingElement $element, $identifierType)

References ensureValidIdentifier().

+ Here is the call graph for this function:

◆ fetchIdentifier()

ilAssOrderingElementList::fetchIdentifier ( ilAssOrderingElement  $element,
  $identifierType 
)
protected
Parameters
ilAssOrderingElement$element
string$identifierType
Returns
int
Exceptions
ilTestQuestionPoolException

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

542 {
543 switch($identifierType)
544 {
546 case self::IDENTIFIER_TYPE_RANDOM: return $element->getRandomIdentifier();
547 }
548
549 $this->throwUnknownIdentifierTypeException($identifierType);
550 }

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

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

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

◆ getClone()

ilAssOrderingElementList::getClone ( )
Returns
ilAssOrderingElementList

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

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

◆ getDifferenceElementList()

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

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

908 {
909 $differenceRandomIdentifierIndex = $this->getDifferenceRandomIdentifierIndex($otherElementList);
910
911 $differenceElementList = new self();
912 $differenceElementList->setQuestionId($this->getQuestionId());
913
914 foreach($differenceRandomIdentifierIndex as $randomIdentifier)
915 {
916 $element = $this->getElementByRandomIdentifier($randomIdentifier);
917 $differenceElementList->addElement($element);
918 }
919
920 return $differenceElementList;
921 }
getDifferenceRandomIdentifierIndex(self $otherElementList)

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

+ Here is the call graph for this function:

◆ getDifferenceRandomIdentifierIndex()

ilAssOrderingElementList::getDifferenceRandomIdentifierIndex ( self  $otherElementList)
protected
Parameters
ilAssOrderingElementList$other
Returns
array

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

928 {
929 $differenceRandomIdentifierIndex = array_diff(
930 $this->getRandomIdentifierIndex(), $otherElementList->getRandomIdentifierIndex()
931 );
932
933 return $differenceRandomIdentifierIndex;
934 }

References getRandomIdentifierIndex().

Referenced by getDifferenceElementList().

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

332 {
333 if( isset($this->elements[$position]) )
334 {
335 return $this->elements[$position];
336 }
337
338 return null;
339 }

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

+ Here is the caller graph for this function:

◆ getElementByRandomIdentifier()

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

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

355 {
356 foreach($this as $element)
357 {
358 if( $element->getRandomIdentifier() != $randomIdentifier )
359 {
360 continue;
361 }
362
363 return $element;
364 }
365
366 return null;
367 }

Referenced by elementExistByRandomIdentifier(), and getDifferenceElementList().

+ Here is the caller graph for this function:

◆ getElementBySolutionIdentifier()

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

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

383 {
384 foreach($this as $element)
385 {
386 if( $element->getSolutionIdentifier() != $solutionIdentifier )
387 {
388 continue;
389 }
390
391 return $element;
392 }
393 return null;
394 }

Referenced by elementExistBySolutionIdentifier().

+ Here is the caller graph for this function:

◆ getElements()

ilAssOrderingElementList::getElements ( )
Returns
array[ilAssOrderingElement]

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

263 {
264 return $this->elements;
265 }

References $elements.

◆ getFallbackDefaultElement()

static ilAssOrderingElementList::getFallbackDefaultElement ( )
static
Returns
ilAssOrderingElement

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

985 {
986 $element = new ilAssOrderingElement();
987 $element->setRandomIdentifier(self::FALLBACK_DEFAULT_ELEMENT_RANDOM_IDENTIFIER);
988
989 return $element;
990 }

Referenced by ilAssOrderingDefaultElementFallback\manipulateFormInputValues().

+ Here is the caller graph for this function:

◆ getIndexedElements()

ilAssOrderingElementList::getIndexedElements (   $identifierType)
protected
Returns
array

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

303 {
304 $elements = array();
305
306 foreach($this as $element)
307 {
308 $elements[$this->fetchIdentifier($element, $identifierType)] = $element;
309 }
310
311 return $elements;
312 }

References $elements, and fetchIdentifier().

Referenced by getRandomIdentifierIndexedElements(), and getSolutionIdentifierIndexedElements().

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

◆ getLastSolutionIdentifier()

ilAssOrderingElementList::getLastSolutionIdentifier ( )
protected
Returns
integer|null $lastSolutionIdentifier

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

653 {
654 $lastSolutionIdentifier = null;
655
656 foreach( $this->getRegisteredSolutionIdentifiers() as $registeredIdentifier)
657 {
658 if( $lastSolutionIdentifier > $registeredIdentifier )
659 {
660 continue;
661 }
662
663 $lastSolutionIdentifier = $registeredIdentifier;
664 }
665
666 return $lastSolutionIdentifier;
667 }

References getRegisteredSolutionIdentifiers().

Referenced by buildSolutionIdentifier().

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

◆ getParityTrueElementList()

ilAssOrderingElementList::getParityTrueElementList ( self  $otherList)

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

826 {
827 if( !$this->hasSameElementSetByRandomIdentifiers($otherList) )
828 {
829 throw new ilTestQuestionPoolException('cannot compare lists having different element sets');
830 }
831
832 $parityTrueElementList = new self();
833 $parityTrueElementList->setQuestionId($this->getQuestionId());
834
835 foreach($this as $thisElement)
836 {
837 $otherElement = $otherList->getElementByRandomIdentifier(
838 $thisElement->getRandomIdentifier()
839 );
840
841 if( $otherElement->getPosition() != $thisElement->getPosition() )
842 {
843 continue;
844 }
845
846 if( $otherElement->getIndentation() != $thisElement->getIndentation() )
847 {
848 continue;
849 }
850
851 $parityTrueElementList->addElement($thisElement);
852 }
853
854 return $parityTrueElementList;
855 }

References getQuestionId(), and hasSameElementSetByRandomIdentifiers().

+ Here is the call graph for this function:

◆ getQuestionId()

ilAssOrderingElementList::getQuestionId ( )
Returns
integer

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

91 {
92 return $this->questionId;
93 }

References $questionId.

Referenced by getDifferenceElementList(), getParityTrueElementList(), getRegisteredIdentifiers(), isIdentifierRegistered(), loadFromDb(), moveElementByPositions(), registerIdentifier(), and removeElement().

+ Here is the caller graph for this function:

◆ getRandomIdentifierIndex()

ilAssOrderingElementList::getRandomIdentifierIndex ( )
Returns
array

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

279 {
280 return array_keys($this->getRandomIdentifierIndexedElements());
281 }

References getRandomIdentifierIndexedElements().

Referenced by getDifferenceRandomIdentifierIndex().

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

◆ getRandomIdentifierIndexedElements()

ilAssOrderingElementList::getRandomIdentifierIndexedElements ( )
Returns
array

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

271 {
272 return $this->getIndexedElements(self::IDENTIFIER_TYPE_RANDOM);
273 }

References getIndexedElements().

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

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

◆ getRegisteredIdentifiers()

ilAssOrderingElementList::getRegisteredIdentifiers (   $identifierType)
protected
Parameters
string$identifierType
Returns
array

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

426 {
427 if( !isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()]) )
428 {
429 return array();
430 }
431
432 return self::$identifierRegistry[$identifierType][$this->getQuestionId()];
433 }

References getQuestionId().

Referenced by getRegisteredRandomIdentifiers(), and getRegisteredSolutionIdentifiers().

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

◆ getRegisteredRandomIdentifiers()

ilAssOrderingElementList::getRegisteredRandomIdentifiers ( )
protected
Returns
array

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

417 {
418 return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_RANDOM);
419 }

References getRegisteredIdentifiers().

+ Here is the call graph for this function:

◆ getRegisteredSolutionIdentifiers()

ilAssOrderingElementList::getRegisteredSolutionIdentifiers ( )
protected
Returns
array

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

409 {
410 return $this->getRegisteredIdentifiers(self::IDENTIFIER_TYPE_SOLUTION);
411 }

References getRegisteredIdentifiers().

Referenced by getLastSolutionIdentifier().

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

◆ getSolutionIdentifierIndex()

ilAssOrderingElementList::getSolutionIdentifierIndex ( )
Returns
array

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

295 {
296 return array_keys($this->getSolutionIdentifierIndexedElements());
297 }

References getSolutionIdentifierIndexedElements().

+ Here is the call graph for this function:

◆ getSolutionIdentifierIndexedElements()

ilAssOrderingElementList::getSolutionIdentifierIndexedElements ( )
Returns
array

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

287 {
288 return $this->getIndexedElements(self::IDENTIFIER_TYPE_SOLUTION);
289 }

References getIndexedElements().

Referenced by getSolutionIdentifierIndex().

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

786 {
787 $numIntersectingElements = count(array_intersect(
788 $otherList->getRandomIdentifierIndex(), $this->getRandomIdentifierIndex()
789 ));
790
791 if( $numIntersectingElements != $this->countElements() )
792 {
793 return false;
794 }
795
796 if( $numIntersectingElements != $otherList->countElements() )
797 {
798 return false;
799 }
800
801 return true; // faster ;-)
802
803 $otherListRandomIdentifierIndex = $otherList->getRandomIdentifierIndex();
804
805 foreach($this as $orderingElement)
806 {
807 if( !in_array($orderingElement->getRandomIdentifier(), $otherListRandomIdentifierIndex) )
808 {
809 return false;
810 }
811
812 $randomIdentifierIndexMatchingsCount = count( array_keys(
813 $otherListRandomIdentifierIndex, $orderingElement->getRandomIdentifier(), false
814 ));
815
816 if( $randomIdentifierIndexMatchingsCount != 1 )
817 {
818 return false;
819 }
820 }
821
822 return $this->countElements() == $otherList->countElements();
823 }

References countElements().

Referenced by getParityTrueElementList().

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

◆ hasValidIdentifiers()

ilAssOrderingElementList::hasValidIdentifiers ( ilAssOrderingElement  $element)
protected
Parameters
ilAssOrderingElement$element
Returns
bool

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

440 {
441 $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
442
443 if( !$this->isValidIdentifier(self::IDENTIFIER_TYPE_SOLUTION, $identifier) )
444 {
445 return false;
446 }
447
448 $identifier = $this->fetchIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
449
450 if( !$this->isValidIdentifier(self::IDENTIFIER_TYPE_RANDOM, $identifier) )
451 {
452 return false;
453 }
454
455 return true;
456 }

References fetchIdentifier(), and isValidIdentifier().

Referenced by addElement().

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

◆ isFirstElementPosition()

ilAssOrderingElementList::isFirstElementPosition (   $position)

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

179 {
180 return $position == 0;
181 }

◆ isIdentifierRegistered()

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

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

519 {
520 if( !isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()]) )
521 {
522 return false;
523 }
524
525 $identifier = $this->fetchIdentifier($element, $identifierType);
526
527 if( !in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()]) )
528 {
529 return false;
530 }
531
532 return true;
533 }

References fetchIdentifier(), and getQuestionId().

Referenced by buildRandomIdentifier().

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

◆ isLastElementPosition()

ilAssOrderingElementList::isLastElementPosition (   $position)

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

184 {
185 return $position == ($this->countElements() - 1);
186 }

References countElements().

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

575 {
576 switch($identifierType)
577 {
579 return self::isValidSolutionIdentifier($identifier);
580
582 return self::isValidRandomIdentifier($identifier);
583 }
584
585 $this->throwUnknownIdentifierTypeException($identifierType);
586 }

References IDENTIFIER_TYPE_RANDOM, IDENTIFIER_TYPE_SOLUTION, isValidRandomIdentifier(), isValidSolutionIdentifier(), and throwUnknownIdentifierTypeException().

Referenced by ensureValidIdentifier(), and hasValidIdentifiers().

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

◆ isValidIndentation()

static ilAssOrderingElementList::isValidIndentation (   $indentation)
static

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

766 {
767 return self::isValidPosition($indentation); // horizontal position ^^
768 }

References isValidPosition().

Referenced by ilAssOrderingElement\isExportIdent().

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

◆ isValidPosition()

static ilAssOrderingElementList::isValidPosition (   $position)
static

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

761 {
762 return self::isValidSolutionIdentifier($position); // this was the position earlier
763 }

References isValidSolutionIdentifier().

Referenced by ilAssOrderingElement\isExportIdent(), and isValidIndentation().

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

◆ isValidRandomIdentifier()

static ilAssOrderingElementList::isValidRandomIdentifier (   $identifier)
static

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

736 {
737 if( !is_numeric($identifier) )
738 {
739 return false;
740 }
741
742 if( $identifier != (int)$identifier )
743 {
744 return false;
745 }
746
747 if( $identifier < self::RANDOM_IDENTIFIER_RANGE_LOWER_BOUND )
748 {
749 return false;
750 }
751
752 if( $identifier > self::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND )
753 {
754 return false;
755 }
756
757 return true;
758 }

Referenced by ilAssOrderingElement\isExportIdent(), and isValidIdentifier().

+ Here is the caller graph for this function:

◆ isValidSolutionIdentifier()

static ilAssOrderingElementList::isValidSolutionIdentifier (   $identifier)
static

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

716 {
717 if( !is_numeric($identifier) )
718 {
719 return false;
720 }
721
722 if( $identifier != (int)$identifier )
723 {
724 return false;
725 }
726
727 if( $identifier < 0 )
728 {
729 return false;
730 }
731
732 return true;
733 }

Referenced by ilAssOrderingElement\isExportIdent(), isValidIdentifier(), and isValidPosition().

+ Here is the caller graph for this function:

◆ key()

ilAssOrderingElementList::key ( )
Returns
integer|bool

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

969{ return key($this->elements); }

References key().

Referenced by key(), and valid().

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

◆ loadFromDb()

ilAssOrderingElementList::loadFromDb ( )

load elements from database

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

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

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

+ Here is the call graph for this function:

◆ moveElementByPositions()

ilAssOrderingElementList::moveElementByPositions (   $currentPosition,
  $targetPosition 
)

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

189 {
190 $movingElement = $this->getElementByPosition($currentPosition);
191 $dodgingElement = $this->getElementByPosition($targetPosition);
192
193 $elementList = new self();
194 $elementList->setQuestionId($this->getQuestionId());
195
196 foreach($this as $element)
197 {
198 if( $element->getPosition() == $currentPosition )
199 {
200 $elementList->addElement($dodgingElement);
201 continue;
202 }
203
204 if( $element->getPosition() == $targetPosition )
205 {
206 $elementList->addElement($movingElement);
207 continue;
208 }
209
210 $elementList->addElement($element);
211 }
212
213 $dodgingElement->setPosition($currentPosition);
214 $movingElement->setPosition($targetPosition);
215
216 $this->setElements( $elementList->getElements() );
217 }

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

+ Here is the call graph for this function:

◆ next()

ilAssOrderingElementList::next ( )
Returns
ilAssOrderingElement

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

964{ return next($this->elements); }

References next().

Referenced by next().

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

◆ populateIdentifier()

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

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

559 {
560 switch($identifierType)
561 {
562 case self::IDENTIFIER_TYPE_SOLUTION: $element->setSolutionIdentifier($identifier); break;
563 case self::IDENTIFIER_TYPE_RANDOM: $element->setRandomIdentifier($identifier); break;
564 default: $this->throwUnknownIdentifierTypeException($identifierType);
565 }
566 }
setRandomIdentifier($randomIdentifier)
setSolutionIdentifier($solutionIdentifier)

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

Referenced by ensureValidIdentifier().

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

◆ registerIdentifier()

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

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

498 {
499 if( !isset(self::$identifierRegistry[$identifierType][$this->getQuestionId()]) )
500 {
501 self::$identifierRegistry[$identifierType][$this->getQuestionId()] = array();
502 }
503
504 $identifier = $this->fetchIdentifier($element, $identifierType);
505
506 if( !in_array($identifier, self::$identifierRegistry[$identifierType][$this->getQuestionId()]) )
507 {
508 self::$identifierRegistry[$identifierType][$this->getQuestionId()][] = $identifier;
509 }
510 }

References fetchIdentifier(), and getQuestionId().

Referenced by ensureValidIdentifier(), and registerIdentifiers().

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

◆ registerIdentifiers()

ilAssOrderingElementList::registerIdentifiers ( ilAssOrderingElement  $element)
protected
Parameters
ilAssOrderingElement$element

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

487 {
488 $this->registerIdentifier($element, self::IDENTIFIER_TYPE_SOLUTION);
489 $this->registerIdentifier($element, self::IDENTIFIER_TYPE_RANDOM);
490 }

References registerIdentifier().

Referenced by addElement(), and loadFromDb().

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

◆ removeElement()

ilAssOrderingElementList::removeElement ( ilAssOrderingElement  $removeElement)

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

220 {
221 $elementList = new self();
222 $elementList->setQuestionId($this->getQuestionId());
223
224 $positionCounter = 0;
225
226 foreach($this as $element)
227 {
228 if( $element->isSameElement($removeElement) )
229 {
230 continue;
231 }
232
233 $element->setPosition($positionCounter++);
234 $elementList->addElement($element);
235 }
236 }

References getQuestionId().

+ Here is the call graph for this function:

◆ reorderByRandomIdentifiers()

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

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

863 {
864 $positionsMap = array_flip( array_values($randomIdentifiers) );
865
866 $orderedElements = array();
867
868 foreach($this as $element)
869 {
870 if( !isset($positionsMap[$element->getRandomIdentifier()]) )
871 {
872 $this->throwMissingReorderPositionException($element->getRandomIdentifier());
873 }
874
875 $position = $positionsMap[$element->getRandomIdentifier()];
876 unset($positionsMap[$element->getRandomIdentifier()]);
877
878 $element->setPosition($position);
879 $orderedElements[$position] = $element;
880 }
881
882 if( count($positionsMap) )
883 {
884 $this->throwUnknownRandomIdentifiersException( array_keys($positionsMap) );
885 }
886
887 ksort($orderedElements);
888
889 $this->setElements( array_values($orderedElements) );
890 }
throwMissingReorderPositionException($randomIdentifier)
throwUnknownRandomIdentifiersException($randomIdentifiers)

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

+ Here is the call graph for this function:

◆ resetElements()

ilAssOrderingElementList::resetElements ( )

resets elements

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

242 {
243 $this->elements = array();
244 }

Referenced by __construct(), and setElements().

+ Here is the caller graph for this function:

◆ resetElementsIndentations()

ilAssOrderingElementList::resetElementsIndentations ( )

resets the indentation to level 0 for all elements in list

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

896 {
897 foreach($this as $element)
898 {
899 $element->setIndentation(0);
900 }
901 }

◆ rewind()

ilAssOrderingElementList::rewind ( )
Returns
ilAssOrderingElement

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

979{ return reset($this->elements); }

◆ setElements()

ilAssOrderingElementList::setElements (   $elements)
Parameters
$elements

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

250 {
251 $this->resetElements();
252
253 foreach($elements as $element)
254 {
255 $this->addElement($element);
256 }
257 }

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

Referenced by moveElementByPositions(), and reorderByRandomIdentifiers().

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

◆ setQuestionId()

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

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

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

References $questionId.

◆ throwCouldNotBuildRandomIdentifierException()

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

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

620 {
622 "could not build random identifier (max tries: $maxTries)"
623 );
624 }

Referenced by buildRandomIdentifier().

+ Here is the caller graph for this function:

◆ throwMissingReorderPositionException()

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

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

631 {
633 "cannot reorder element due to missing position (random identifier: $randomIdentifier)"
634 );
635 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ throwUnknownIdentifierTypeException()

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

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

609 {
611 "unknown identifier type given (type: $identifierType)"
612 );
613 }

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

+ Here is the caller graph for this function:

◆ throwUnknownRandomIdentifiersException()

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

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

642 {
644 'cannot reorder element due to one or more unknown random identifiers '.
645 '(' . implode(', ', $randomIdentifiers) . ')'
646 );
647 }

Referenced by reorderByRandomIdentifiers().

+ Here is the caller graph for this function:

◆ valid()

ilAssOrderingElementList::valid ( )
Returns
bool

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

974{ return ($this->key() !== null); }

References key().

+ Here is the call graph for this function:

Field Documentation

◆ $elements

ilAssOrderingElementList::$elements
protected

◆ $identifierRegistry

ilAssOrderingElementList::$identifierRegistry
staticprotected
Initial value:
= array(
self::IDENTIFIER_TYPE_SOLUTION => array(),
self::IDENTIFIER_TYPE_RANDOM => array()
)

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

◆ $objectInstanceCounter

ilAssOrderingElementList::$objectInstanceCounter = 0
static

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

Referenced by __clone(), and __construct().

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

◆ IDENTIFIER_TYPE_SOLUTION

const ilAssOrderingElementList::IDENTIFIER_TYPE_SOLUTION = 'SolutionIds'

◆ JS_ADDED_ELEMENTS_RANDOM_IDENTIFIER_START_VALUE

const ilAssOrderingElementList::JS_ADDED_ELEMENTS_RANDOM_IDENTIFIER_START_VALUE = -1

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

Referenced by buildRandomIdentifier().

◆ RANDOM_IDENTIFIER_RANGE_UPPER_BOUND

const ilAssOrderingElementList::RANDOM_IDENTIFIER_RANGE_UPPER_BOUND = 100000

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

Referenced by buildRandomIdentifier().

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

Referenced by buildSolutionIdentifier().


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