public function setAttribute($name, $value){

        $returnValue = false;

        if(is_null($value)){
            return $returnValue;
        }

        if(isset($this->attributes[$name])){

            $datatypeClass = $this->attributes[$name]->getType();
            // check if the attribute needs an element level validation
            if(is_subclass_of($datatypeClass, 'oat\\taoQtiItem\\model\\qti\\datatype\\Identifier')){

                if($value instanceof IdentifiedElement){
                    if($this->validateAttribute($name, $value)){
                        $this->attributes[$name]->setValue($value);
                        $returnValue = true;
                    }else{
                        $vr = print_r($value, true);
                        common_Logger::w($vr);
                        throw new InvalidArgumentException('Invalid identifier attribute value');
                    }
                }elseif(is_string($value)){
                    // try converting to string identifier and search the identified object:
                    $identifier = (string) $value;
                    $elt = $this->getIdentifiedElement($identifier, $datatypeClass::getAllowedClasses());
                    if(!is_null($elt)){
                        // ok, found among allowed classes
                        $this->attributes[$name]->setValue($elt);
                        $returnValue = true;
                    }else{
                        throw new QtiModelException('No QTI element with the identifier has been found: '.$identifier);
                    }
                }
            }else{
                $this->attributes[$name]->setValue($value);
                $returnValue = true;
            }
        }else{
            $this->attributes[$name] = new Generic($value);
            $returnValue = true;
        }

        return $returnValue;
    }
public function setAttribute($name, $value){

        $returnValue = false;

        if(is_null($value)){
            return $returnValue;
        }

        if(isset($this->attributes[$name])){

            $datatypeClass = $this->attributes[$name]->getType();
            // check if the attribute needs an element level validation
            if(is_subclass_of($datatypeClass, 'oat\\taoQtiItem\\model\\qti\\datatype\\Identifier')){

                if($value instanceof IdentifiedElement){
                    if($this->validateAttribute($name, $value)){
                        $this->attributes[$name]->setValue($value);
                        $returnValue = true;
                    }else{
                        $vr = print_r($value, true);
                        common_Logger::w($vr);
                        throw new InvalidArgumentException('Invalid identifier attribute value');
                    }
                }elseif(is_string($value)){
                    // try converting to string identifier and search the identified object:
                    $identifier = (string) $value;
                    $elt = $this->getIdentifiedElement($identifier, $datatypeClass::getAllowedClasses());
                    if(!is_null($elt)){
                        // ok, found among allowed classes
                        $this->attributes[$name]->setValue($elt);
                        $returnValue = true;
                    }else{
                        throw new QtiModelException('No QTI element with the identifier has been found: '.$identifier);
                    }
                }
            }else{
                $this->attributes[$name]->setValue($value);
                $returnValue = true;
            }
        }else{
            $this->attributes[$name] = new Generic($value);
            $returnValue = true;
        }

        return $returnValue;
    }
public function setAttribute ( $ name , $ value ) { $ returnValue = false ; if ( is_null ( $ value ) ) { return $ returnValue ; } if ( isset ( $ this -> attributes [ $ name ] ) ) { $ datatypeClass = $ this -> attributes [ $ name ] -> getType ( ) ; // check if the attribute needs an element level validation if ( is_subclass_of ( $ datatypeClass , 'oat\\taoQtiItem\\model\\qti\\datatype\\Identifier' ) ) { if ( $ value instanceof IdentifiedElement ) { if ( $ this -> validateAttribute ( $ name , $ value ) ) { $ this -> attributes [ $ name ] -> setValue ( $ value ) ; $ returnValue = true ; } else { $ vr = print_r ( $ value , true ) ; common_Logger :: w ( $ vr ) ; throw new InvalidArgumentException ( 'Invalid identifier attribute value' ) ; } } elseif ( is_string ( $ value ) ) { // try converting to string identifier and search the identified object: $ identifier = ( string ) $ value ; $ elt = $ this -> getIdentifiedElement ( $ identifier , $ datatypeClass :: getAllowedClasses ( ) ) ; if ( ! is_null ( $ elt ) ) { // ok, found among allowed classes $ this -> attributes [ $ name ] -> setValue ( $ elt ) ; $ returnValue = true ; } else { throw new QtiModelException ( 'No QTI element with the identifier has been found: ' . $ identifier ) ; } } } else { $ this -> attributes [ $ name ] -> setValue ( $ value ) ; $ returnValue = true ; } } else { $ this -> attributes [ $ name ] = new Generic ( $ value ) ; $ returnValue = true ; } return $ returnValue ; }
Set the value of an attribute

@param string $name
@param mixed $value
@return boolean
@throws InvalidArgumentException
@throws \oat\taoQtiItem\model\qti\exception\QtiModelException
Set the value of an attribute