Marshall a ResponseValidityConstraint object to its XML counterpart.

@param \qtism\data\QtiComponent $component
@return \DOMElement
162156
public function marshall(QtiComponent $component)
    {
        $element = self::getDOMCradle()->createElement('responseValidityConstraint');
        $this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
        $this->setDOMElementAttribute($element, 'minConstraint', $component->getMinConstraint());
        $this->setDOMElementAttribute($element, 'maxConstraint', $component->getMaxConstraint());
        
        if (($patternMask = $component->getPatternMask()) !== '') {
            $this->setDOMElementAttribute($element, 'patternMask', $patternMask);
        }
        
        foreach ($component->getAssociationValidityConstraints() as $associationValidityConstraint) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($associationValidityConstraint);
            $element->appendChild($marshaller->marshall($associationValidityConstraint));
        }

        return $element;
    }
503289
public function getChildrenRenderings(QtiComponent $component)
    {
        $returnValue = array();

        foreach (array_reverse($component->getComponents()->getArrayCopy()) as $c) {

            if (count($this->getRenderingStack()) > 0) {
                list($renderedComponent, $rendering) = $this->getRenderingStack()->pop();

                if ($c === $renderedComponent) {
                    array_unshift($returnValue, $rendering);
                } else {
                    // repush...
                    $this->storeRendering($renderedComponent, $rendering);
                }
            }
        }

        return $returnValue;
    }
1186804
protected function marshall(QtiComponent $component)
    {
        $element = $this->createElement($component);
        $version = $this->getVersion();
        
        $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
        $this->setDOMElementAttribute($element, 'base', $component->getBase());
        
        if (Version::compare($version, '2.1.0', '>=') === true) {
            $this->setDOMElementAttribute($element, 'powerForm', $component->mustPowerForm());
            $this->setDOMElementAttribute($element, 'delimiter', $component->getDelimiter());
            $this->setDOMElementAttribute($element, 'mappingIndicator', $component->getMappingIndicator());
        }

        if ($component->hasFormat() === true) {
            $this->setDOMElementAttribute($element, 'format', $component->getFormat());
        }

        if ($component->hasIndex() === true) {
            $this->setDOMElementAttribute($element, 'index', $component->getIndex());
        }

        if ($component->hasField() === true) {
            $this->setDOMElementAttribute($element, 'field', $component->getField());
        }

        if ($component->hasXmlBase() === true) {
            self::setXmlBase($element, $component->getXmlBase());
        }

        $this->fillElement($element, $component);

        return $element;
    }
43461
protected function marshall(QtiComponent $component)
    {
        $element = self::getDOMCradle()->createElement('col');

        if ($component->getSpan() !== 1) {
            $this->setDOMElementAttribute($element, 'span', $component->getSpan());
        }

        $this->fillElement($element, $component);

        return $element;
    }
7756
protected function addComponent($component, $value)
    {
        $this->validateComponentExists($component);

        // We need to make sure the value we're given isn't empty before adding it into our components.
        if (! empty($value)) {
            $this->components[$component][] = $value;
        }
    }
211108
protected function marshall(QtiComponent $component)
    {
        $element = parent::marshall($component);

        $this->setDOMElementAttribute($element, 'href', $component->getHref());

        // Deal with categories.
        $categories = $component->getCategories();
        if (count($categories) > 0) {
            $this->setDOMElementAttribute($element, 'category', implode("\x20", $categories->getArrayCopy()));
        }

        // Deal with variableMappings.
        $variableMappings = $component->getVariableMappings();
        foreach ($variableMappings as $mapping) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($mapping);
            $element->appendChild($marshaller->marshall($mapping));
        }

        // Deal with weights.
        $weights = $component->getWeights();
        foreach ($weights as $weight) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($weight);
            $element->appendChild($marshaller->marshall($weight));
        }

        // Deal with templateDefaults.
        $templateDefaults = $component->getTemplateDefaults();
        foreach ($templateDefaults as $default) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($default);
            $element->appendChild($marshaller->marshall($default));
        }

        return $element;
    }
889888
protected function marshall(QtiComponent $component)
    {
        $element = static::getDOMCradle()->createElement($component->getQtiClassName());

        $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
        $this->setDOMElementAttribute($element, 'cardinality', Cardinality::getNameByConstant($component->getCardinality()));

        if ($component->getBaseType() != -1) {
            $this->setDOMElementAttribute($element, 'baseType', BaseType::getNameByConstant($component->getBaseType()));
        }

        // deal with default value.
        if ($component->getDefaultValue() != null) {
            $defaultValue = $component->getDefaultValue();
            $defaultValueMarshaller = $this->getMarshallerFactory()->createMarshaller($defaultValue, array($component->getBaseType()));
            $element->appendChild($defaultValueMarshaller->marshall($defaultValue));
        }

        return $element;
    }
697636
protected function marshall(QtiComponent $component)
    {
        $element = parent::marshall($component);
        $version = $this->getVersion();

        // deal with views.
        // !!! If $arrayViews contain all possible views, it means that the treated
        // !!! outcome is relevant to all views, as per QTI 2.1 spec.
        if (Version::compare($version, '2.1.0', '>=') === true && !in_array($component->getViews()->getArrayCopy(), View::asArray())) {
            $arrayViews = array();
            foreach ($component->getViews() as $view) {
                $arrayViews[] = View::getNameByConstant($view);
            }

            if (count($arrayViews) > 0) {
                $this->setDOMElementAttribute($element, 'view', implode("\x20", $arrayViews));
            }
        }

        // deal with interpretation.
        if ($component->getInterpretation() != '') {
            $this->setDOMElementAttribute($element, 'interpretation', $component->getInterpretation());
        }

        // deal with long interpretation.
        if ($component->getLongInterpretation() != '') {
            $this->setDOMElementAttribute($element, 'longInterpretation', $component->getLongInterpretation());
        }

        // Deal with normal maximum.
        if ($component->getNormalMaximum() !== false) {
            $this->setDOMElementAttribute($element, 'normalMaximum', $component->getNormalMaximum());
        }

        // Deal with normal minimum.
        if (Version::compare($version, '2.1.0', '>=') === true && $component->getNormalMinimum() !== false) {
            $this->setDOMElementAttribute($element, 'normalMinimum', $component->getNormalMinimum());
        }

        // Deal with mastery value.
        if (Version::compare($version, '2.1.0', '>=') === true && $component->getMasteryValue() !== false) {
            $this->setDOMElementAttribute($element, 'masteryValue', $component->getMasteryValue());
        }

        // Deal with lookup table.
        if ($component->getLookupTable() != null) {
            $lookupTableMarshaller = $this->getMarshallerFactory()->createMarshaller($component->getLookupTable(), array($component->getBaseType()));
            $element->appendChild($lookupTableMarshaller->marshall($component->geTLookupTable()));
        }

        return $element;
    }
554148
protected function marshall(QtiComponent $component)
    {
        $element = static::getDOMCradle()->createElement($component->getQtiClassName());

        $this->setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());

        $expr = $component->getExpression();
        $exprMarshaller = $this->getMarshallerFactory()->createMarshaller($expr);
        $exprElt = $exprMarshaller->marshall($expr);

        $element->appendChild($exprElt);

        return $element;
    }
539073
public function unmarshall(DOMElement $element)
    {
        if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
            
            if (($minConstraint = $this->getDOMElementAttributeAs($element, 'minConstraint', 'integer')) !== null) {
                
                if (($maxConstraint = $this->getDOMElementAttributeAs($element, 'maxConstraint', 'integer')) !== null) {
                    
                    if (($patternMask = $this->getDOMElementAttributeAs($element, 'patternMask')) === null) {
                        $patternMask = '';
                    }
                    try {
                        $component = new ResponseValidityConstraint($responseIdentifier, $minConstraint, $maxConstraint, $patternMask);
                    
                        // Find child associationValidityConstraint elements if any.
                        $associationValidityConstraintElts = $this->getChildElementsByTagName($element, 'associationValidityConstraint');
                            
                        foreach ($associationValidityConstraintElts as $associationValidityConstraintElt) {
                            $marshaller = $this->getMarshallerFactory()->createMarshaller($associationValidityConstraintElt);
                            $component->addAssociationValidityConstraint($marshaller->unmarshall($associationValidityConstraintElt));
                        }
                        
                        return $component;
                    } catch (InvalidArgumentException $e) {
                        throw new UnmarshallingException(
                            "An error occured while unmarshalling a 'responseValidityConstraint'. See chained exceptions for more information.",
                            $element,
                            $e
                        );
                    }
                    
                } else {
                    throw new UnmarshallingException(
                        "The mandatory 'maxConstraint' attribute is missing from element 'responseValididtyConstraint'.",
                        $element
                    );
                }
            } else {
                throw new UnmarshallingException(
                    "The mandatory 'minConstraint' attribute is missing from element 'responseValididtyConstraint'.",
                    $element
                );
            }
        } else {
            throw new UnmarshallingException(
                "The mandatory 'responseIdentifier' attribute is missing from element 'responseValididtyConstraint'.",
                $element
            );
        }
    }
52262
public function callComponent($componentName)
    {
        if (!isset($this->components[$componentName])) {
            $requiredInterface = isset(static::$defaultComponents[$componentName][1])
                ? static::$defaultComponents[$componentName][1]
                : null;
            $componentConfig = isset(static::$defaultComponents[$componentName][2])
                ? static::$defaultComponents[$componentName][2]
                : [];
            if (isset($this->config['components'][$componentName])){
                $componentConfig = array_merge($componentConfig, $this->config['components'][$componentName]);
            }
            if (isset($componentConfig['class'])) {
                $componentClassName = $componentConfig['class'];
            } else {
                $componentClassName = isset(static::$defaultComponents[$componentName][0])
                    ? static::$defaultComponents[$componentName][0]
                    : null;
            }
            unset($this->config['components'][$componentName]);
            if (isset($componentConfig['class']))
            unset($componentConfig['class']);
            if ($componentClassName) {
                $instance = new $componentClassName($componentConfig, $this);
                if (null === $requiredInterface || ($instance instanceof $requiredInterface)) {
                    $this->components[$componentName] = $instance;
                } else {
                    throw new InvalidInterfaceException([$componentName, $componentClassName, $requiredInterface]);
                }
            } else {
                throw new UnknownComponentException($componentName);
            }
        }
        return $this->components[$componentName];
    }
1374251
public function add(HtmlComponent $component)
    {
        if (isset($this->components[$component->id])) {
            throw new ZE(sprintf(ERROR_COMPONENT_ALREADY_EXISTS, $component->id, $this->id));
        }
        if (property_exists($this, $component->id)) {
            $id = strlen($this->id) > 0 ? $this->id : get_class($this);
            throw new ZE(sprintf(ERROR_COMPONENT_AS_PROPERTY, $component->id, $id));
        }

        $this->components[$component->id] = $component;
        $component->setOwner($this);
        $component->onAdded();
        return $component;
    }
871082
protected function marshall(QtiComponent $component)
    {
        $element = self::getDOMCradle()->createElement('table');

        if ($component->hasSummary() === true) {
            $this->setDOMElementAttribute($element, 'summary', $component->getSummary());
        }

        if ($component->hasXmlBase() === true) {
            self::setXmlBase($element, $component->getXmlBase());
        }

        if ($component->hasCaption() === true) {
            $caption = $component->getCaption();
            $marshaller = $this->getMarshallerFactory()->createMarshaller($caption);
            $element->appendChild($marshaller->marshall($caption));
        }

        $cols = $component->getCols();
        if (count($cols) > 0) {
            foreach ($cols as $c) {
                $marshaller = $this->getMarshallerFactory()->createMarshaller($c);
                $element->appendChild($marshaller->marshall($c));
            }
        }

        $colgroups = $component->getColgroups();
        if (count($colgroups) > 0) {
            foreach ($colgroups as $c) {
                $marshaller = $this->getMarshallerFactory()->createMarshaller($c);
                $element->appendChild($marshaller->marshall($c));
            }
        }

        if ($component->hasThead() === true) {
            $thead = $component->getThead();
            $marshaller = $this->getMarshallerFactory()->createMarshaller($thead);
            $element->appendChild($marshaller->marshall($thead));
        }

        if ($component->hasTfoot() === true) {
            $tfoot = $component->getTfoot();
            $marshaller = $this->getMarshallerFactory()->createMarshaller($tfoot);
            $element->appendChild($marshaller->marshall($tfoot));
        }

        foreach ($component->getTbodies() as $tbody) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($tbody);
            $element->appendChild($marshaller->marshall($tbody));
        }

        $this->fillElement($element, $component);

        return $element;
    }
1229411
public function checkConstraint($constraint)
    {
        if (!$constraint instanceof ConstraintContract && !$constraint instanceof ConstraintGroupContract) {
            throw new InvalidArgumentException("Constraint has to be Constraint or ConstraintGroup, not " . Type::of($constraint));
        }
        if ($this->allowedOperators && $constraint instanceof Constraint) {
            $constraint->allowOperators($this->allowedOperators);
        }
        return $constraint;
    }
1030474
protected function marshallChildrenKnown(QtiComponent $component, array $elements)
    {
        $element = self::getDOMCradle()->createElement($component->getQtiClassName());

        $this->setDOMElementAttribute($element, 'figures', $component->getFigures());
        $this->setDOMElementAttribute($element, 'roundingMode', RoundingMode::getNameByConstant($component->getRoundingMode()));

        foreach ($elements as $elt) {
            $element->appendChild($elt);
        }

        return $element;
    }
729981
public function prepend(FormComponentDriver $component)
    {
        $field = $component->getField();
        if (!isset($this->components[$field]))
            array_unshift($this->fields, $field);
        $this->components[$field] = $component;
        $this->checkLoadData($component);
        return $this;
    }
978818
public function setRequired(bool $required) : Component
    {
        if ($required) {
            $this->getTag()->setAttribute('required', 'required');
        } else {
            $this->getTag()->removeAttribute('required');
        }

        return parent::setRequired($required);
    }