public function getComponentsByClassName($classNames, $recursive = true)
    {
        if (gettype($classNames) !== 'string' && !is_array($classNames)) {
            $msg = "The QtiComponent::getComponentsByClassName method only accepts ";
            $msg.= "a string or an array as its main argument, '" . gettype($classNames) . "' given.";
            throw new InvalidArgumentException($classNames);
        }

        if (!is_array($classNames)) {
            $classNames = array($classNames);
        }

        $toIterate = ($recursive === true) ? $this->getIterator() : $this->getComponents();
        $foundComponents = new QtiComponentCollection();

        foreach ($toIterate as $component) {
            if (in_array($component->getQtiClassName(), $classNames)) {
                $foundComponents[] = $component;
            }
        }

        return $foundComponents;
    }
public function getComponentsByClassName($classNames, $recursive = true)
    {
        if (gettype($classNames) !== 'string' && !is_array($classNames)) {
            $msg = "The QtiComponent::getComponentsByClassName method only accepts ";
            $msg.= "a string or an array as its main argument, '" . gettype($classNames) . "' given.";
            throw new InvalidArgumentException($classNames);
        }

        if (!is_array($classNames)) {
            $classNames = array($classNames);
        }

        $toIterate = ($recursive === true) ? $this->getIterator() : $this->getComponents();
        $foundComponents = new QtiComponentCollection();

        foreach ($toIterate as $component) {
            if (in_array($component->getQtiClassName(), $classNames)) {
                $foundComponents[] = $component;
            }
        }

        return $foundComponents;
    }
public function getComponentsByClassName ( $ classNames , $ recursive = true ) { if ( gettype ( $ classNames ) !== 'string' && ! is_array ( $ classNames ) ) { $ msg = "The QtiComponent::getComponentsByClassName method only accepts " ; $ msg .= "a string or an array as its main argument, '" . gettype ( $ classNames ) . "' given." ; throw new InvalidArgumentException ( $ classNames ) ; } if ( ! is_array ( $ classNames ) ) { $ classNames = array ( $ classNames ) ; } $ toIterate = ( $ recursive === true ) ? $ this -> getIterator ( ) : $ this -> getComponents ( ) ; $ foundComponents = new QtiComponentCollection ( ) ; foreach ( $ toIterate as $ component ) { if ( in_array ( $ component -> getQtiClassName ( ) , $ classNames ) ) { $ foundComponents [ ] = $ component ; } } return $ foundComponents ; }
Get QtiComponents object which is contained by this one the basis of
a given QTI className. If nothing found, an empty QtiComponentCollection
object is returned.

Example where we look for all assessmentSection class instances contained
in an assessmentTest.
<code>
$search = $assessmentTest->getComponentByClassName('assessmentSection');
// $search contains a QTIComponentCollection composed of AssessmentSection objects.
</code>

@param array|string An array of strings or a string.
@param boolean $recursive Whether to search recursively in contained QtiComponent objects.
@return \qtism\data\QtiComponentCollection
@throws \InvalidArgumentException If $classNames is not an array nor a string value.
Get QtiComponents object which is contained by this one the basis of a given QTI className . If nothing found an empty QtiComponentCollection object is returned .