public static function getLastItem($test, $component, $sections)
    {
        $currentCmp = $component;
        // $sections = null;

        while (true)
        {
            switch ($currentCmp->getQtiClassName()) {
                case "assessmentItemRef":
                    return $currentCmp;
                    break;

                case "assessmentSection":
                    $items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();

                    if (count($items) == 0) {

                        // Check for recursion

                        $sectparent = Utils::checkRecursion($currentCmp, $sections);

                        if ($sectparent != null) {
                            $prevSectPart = null;

                            foreach ($sectparent->getSectionParts() as $key => $scpt) {
                                if ($scpt == $currentCmp) {
                                    break;
                                }

                                $prevSectPart = $scpt;
                            }

                            if ($prevSectPart == null)
                            {
                                $currentCmp = $sectparent;
                            } else {
                                $currentCmp = $prevSectPart;
                            }
                        }
                        else {

                            // No recursion
                            $prevSect = null;
                            $keyFound = null;

                            foreach ($sections as $sect) {

                                if ($sect->getIdentifier() == $currentCmp->getIdentifier()) {
                                    break;
                                } else {
                                    $prevSect = $sect;
                                }
                            }

                            if ($prevSect == null) {
                                return null;
                            } else {
                                $currentCmp = $prevSect;
                            }
                        }
                    } else { // Case with sub items
                        return $items[count($items) - 1];
                    }
                    break;

                case "testPart":
                    $items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();

                    if (count($items) == 0) {

                        // First item of the next testpart

                        $prevTest = null;
                        $keyFound = null;

                        foreach ($test->getComponentsByClassName($currentCmp->getQtiClassName()) as $test) {

                            if ($test->getIdentifier() == $currentCmp->getIdentifier()) {
                                break;
                            } else {
                                $prevTest = $test;
                            }
                        }

                        if ($prevTest != null) {
                            $currentCmp = $prevTest;
                        } else {
                            return null;
                        }
                    } else {
                        return $items[count($items) - 1];
                    }
                    break;

                default:
                    return null;
            }
        }
    }
public static function getLastItem($test, $component, $sections)
    {
        $currentCmp = $component;
        // $sections = null;

        while (true)
        {
            switch ($currentCmp->getQtiClassName()) {
                case "assessmentItemRef":
                    return $currentCmp;
                    break;

                case "assessmentSection":
                    $items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();

                    if (count($items) == 0) {

                        // Check for recursion

                        $sectparent = Utils::checkRecursion($currentCmp, $sections);

                        if ($sectparent != null) {
                            $prevSectPart = null;

                            foreach ($sectparent->getSectionParts() as $key => $scpt) {
                                if ($scpt == $currentCmp) {
                                    break;
                                }

                                $prevSectPart = $scpt;
                            }

                            if ($prevSectPart == null)
                            {
                                $currentCmp = $sectparent;
                            } else {
                                $currentCmp = $prevSectPart;
                            }
                        }
                        else {

                            // No recursion
                            $prevSect = null;
                            $keyFound = null;

                            foreach ($sections as $sect) {

                                if ($sect->getIdentifier() == $currentCmp->getIdentifier()) {
                                    break;
                                } else {
                                    $prevSect = $sect;
                                }
                            }

                            if ($prevSect == null) {
                                return null;
                            } else {
                                $currentCmp = $prevSect;
                            }
                        }
                    } else { // Case with sub items
                        return $items[count($items) - 1];
                    }
                    break;

                case "testPart":
                    $items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();

                    if (count($items) == 0) {

                        // First item of the next testpart

                        $prevTest = null;
                        $keyFound = null;

                        foreach ($test->getComponentsByClassName($currentCmp->getQtiClassName()) as $test) {

                            if ($test->getIdentifier() == $currentCmp->getIdentifier()) {
                                break;
                            } else {
                                $prevTest = $test;
                            }
                        }

                        if ($prevTest != null) {
                            $currentCmp = $prevTest;
                        } else {
                            return null;
                        }
                    } else {
                        return $items[count($items) - 1];
                    }
                    break;

                default:
                    return null;
            }
        }
    }
public static function getLastItem ( $ test , $ component , $ sections ) { $ currentCmp = $ component ; // $sections = null; while ( true ) { switch ( $ currentCmp -> getQtiClassName ( ) ) { case "assessmentItemRef" : return $ currentCmp ; break ; case "assessmentSection" : $ items = $ currentCmp -> getComponentsByClassName ( "assessmentItemRef" ) -> getArrayCopy ( ) ; if ( count ( $ items ) == 0 ) { // Check for recursion $ sectparent = Utils :: checkRecursion ( $ currentCmp , $ sections ) ; if ( $ sectparent != null ) { $ prevSectPart = null ; foreach ( $ sectparent -> getSectionParts ( ) as $ key => $ scpt ) { if ( $ scpt == $ currentCmp ) { break ; } $ prevSectPart = $ scpt ; } if ( $ prevSectPart == null ) { $ currentCmp = $ sectparent ; } else { $ currentCmp = $ prevSectPart ; } } else { // No recursion $ prevSect = null ; $ keyFound = null ; foreach ( $ sections as $ sect ) { if ( $ sect -> getIdentifier ( ) == $ currentCmp -> getIdentifier ( ) ) { break ; } else { $ prevSect = $ sect ; } } if ( $ prevSect == null ) { return null ; } else { $ currentCmp = $ prevSect ; } } } else { // Case with sub items return $ items [ count ( $ items ) - 1 ] ; } break ; case "testPart" : $ items = $ currentCmp -> getComponentsByClassName ( "assessmentItemRef" ) -> getArrayCopy ( ) ; if ( count ( $ items ) == 0 ) { // First item of the next testpart $ prevTest = null ; $ keyFound = null ; foreach ( $ test -> getComponentsByClassName ( $ currentCmp -> getQtiClassName ( ) ) as $ test ) { if ( $ test -> getIdentifier ( ) == $ currentCmp -> getIdentifier ( ) ) { break ; } else { $ prevTest = $ test ; } } if ( $ prevTest != null ) { $ currentCmp = $ prevTest ; } else { return null ; } } else { return $ items [ count ( $ items ) - 1 ] ; } break ; default : return null ; } } }
Returns the last AssessmentItem that will be prompted before a BranchRule of the QtiComponent set as parameter
will be taken.

This method depends heavily of the QtiClass of the QtiComponent. Some require multiples loops where we need to
find the lastItem from another QtiComponent : this is then done iteratively.

@param $test \qtism\data\AssessmentTest The AssessmentTest where we are searching the item from where the branch
starts.
@param $component \qtism\data\QtiComponent The QtiComponent with a BranchRule.
@param $sections AssessmentSectionCollection The collection of all sections in this AssessmentTest.
@return \qtism\data\AssessmentItem|null The last AssessmentItem that will be prompted before taking a BranchRule
in the QtiComponent set as parameter. Returns null, if there are no more AssessmentItem because the begin of the
test has been reached.
Returns the last AssessmentItem that will be prompted before a BranchRule of the QtiComponent set as parameter will be taken .