function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
 {
     $dateTimeNode = $attributeNode->getElementsByTagName( 'date_time' )->item( 0 );
     if ( is_object( $dateTimeNode ) )
     {
         $timestamp = eZDateUtils::textToDate( $dateTimeNode->textContent );
         $objectAttribute->setAttribute( 'data_int', $timestamp );
     }
 }
Esempio n. 2
0
 function unserializeContentObjectAttribute($package, $objectAttribute, $attributeNode)
 {
     $timeNode = $attributeNode->getElementsByTagName('time')->item(0);
     if (is_object($timeNode)) {
         $timestamp = eZDateUtils::textToDate($timeNode->textContent);
         $timeOfDay = null;
         if ($timestamp >= 0) {
             $time = new eZTime($timestamp);
             $timeOfDay = $time->timeOfDay();
         }
         $objectAttribute->setAttribute('data_int', $timeOfDay);
     }
 }
    /**
     * Returns a DOM structure of the content object and it's attributes.
     *
     * Transaction unsafe. If you call several transaction unsafe methods you must enclose
     * the calls within a db transaction; thus within db->begin and db->commit.
     *
     * @param mixed $package
     * @param int|bool $specificVersion Content object version, true for current version, false for all, else array containing specific versions.
     * @param array|bool $options Package options or false
     * @param int[]|bool $contentNodeIDArray Array of allowed nodes or false
     * @param int[]|bool $topNodeIDArray Array of top nodes in current package export or false
     * @return bool|DOMElement
     */
    function serialize( $package, $specificVersion = false, $options = false, $contentNodeIDArray = false, $topNodeIDArray = false )
    {
        if ( $options &&
             $options['node_assignment'] == 'main' )
        {
            if ( !isset( $contentNodeIDArray[$this->attribute( 'main_node_id' )] ) )
            {
                return false;
            }
        }

        $dom = new DomDocument();
        $objectNode = $dom->createElementNS( 'http://ez.no/ezobject', 'ezremote:object' );

        $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:id', $this->ID );
        $objectNode->setAttribute( 'name', $this->Name );
        $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:section_id', $this->SectionID );
        $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:owner_id', $this->OwnerID );
        $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:class_id', $this->ClassID );
        $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:published', eZDateUtils::rfc1123Date( $this->attribute( 'published' ) ) );
        $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:modified', eZDateUtils::rfc1123Date( $this->attribute( 'modified' ) ) );
        if ( !$this->attribute( 'remote_id' ) )
        {
            $this->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'object' ) );
            $this->store();
        }
        $objectNode->setAttribute( 'remote_id', $this->attribute( 'remote_id' ) );
        $contentClass = $this->attribute( 'content_class' );
        $objectNode->setAttribute( 'class_remote_id', $contentClass->attribute( 'remote_id' ) );
        $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:class_identifier', $contentClass->attribute( 'identifier' ) );
        $alwaysAvailableText = '0';
        if ( (int)$this->attribute( 'language_mask' ) & 1 )
        {
            $alwaysAvailableText = '1';
        }
        $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:always_available', $alwaysAvailableText );

        $versions = array();
        $oneLanguagePerVersion = false;
        if ( $specificVersion === false )
        {
            $versions = $this->versions();
            // Since we are exporting all versions it should only contain
            // one language per version
            //$oneLanguagePerVersion = true; // uncomment to get one language per version
        }
        else if ( $specificVersion === true )
        {
            $versions[] = $this->currentVersion();
        }
        else
        {
            $versions[] = $this->version( $specificVersion );
            // Since we are exporting a specific version it should only contain
            // one language per version?
            $oneLanguagePerVersion = true;
        }

        $this->fetchClassAttributes();

        $exportedLanguages = array();

        $versionsNode = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:version-list' );
        $versionsNode->setAttribute( 'active_version', $this->CurrentVersion );
        foreach ( $versions as $version )
        {
            if ( !$version )
            {
                continue;
            }
            $options['only_initial_language'] = $oneLanguagePerVersion;
            $versionNode = $version->serialize( $package, $options, $contentNodeIDArray, $topNodeIDArray );
            if ( $versionNode )
            {
                $importedVersionNode = $dom->importNode( $versionNode, true );
                $versionsNode->appendChild( $importedVersionNode );
                foreach ( $versionNode->getElementsByTagName( 'object-translation' ) as $versionNodeChild )
                {
                    $exportedLanguage = $versionNodeChild->getAttribute( 'language' );
                    $exportedLanguages[] = $exportedLanguage;
                    $exportedLanguages = array_unique( $exportedLanguages );
                }
            }
            unset( $versionNode );
            unset( $versionNode );
        }
        $initialLanguageCode = $this->attribute( 'initial_language_code' );
        if ( in_array( $initialLanguageCode, $exportedLanguages ) )
        {
            $objectNode->setAttribute( 'initial_language', $initialLanguageCode );
        }
        $objectNode->appendChild( $versionsNode );
        return $objectNode;
    }
Esempio n. 4
0
    function serialize( $package, $options = false, $contentNodeIDArray = false, $topNodeIDArray = false )
    {
        $dom = new DOMDocument( '1.0', 'utf-8' );

        $versionNode = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:version' );
        $dom->appendChild( $versionNode );

        $versionNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:version', $this->Version );
        $versionNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:status', $this->Status );
        $versionNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:created', eZDateUtils::rfc1123Date( $this->attribute( 'created' ) ) );
        $versionNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:modified', eZDateUtils::rfc1123Date( $this->attribute( 'modified' ) ) );

        $translationList = $this->translationList( false, false );
        $contentObject   = $this->attribute( 'contentobject' );

        $db = eZDB::instance();
        $db->begin();
        $allowedLanguages = $options['language_array'];
        if ( $options['only_initial_language'] )
        {
            $initialLanguageCode = $this->initialLanguageCode();
            if ( !in_array( $initialLanguageCode, $allowedLanguages ) )
            {
                // We can only export initial language but is not in the allowed
                // language list so we return false, ie. no export of this version.
                return false;
            }
            // Make sure only the initial language is exported
            $allowedLanguages = array( $initialLanguageCode );
        }
        $exportedLanguages = array();
        foreach ( $translationList as $translationItem )
        {
            $language = $translationItem;
            if ( !in_array( $language, $allowedLanguages ) )
            {
                continue;
            }

            $translationNode = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:object-translation' );
            $translationNode->setAttribute( 'language', $language );

            // serialize object name in current version-translation
            $objectName = $contentObject->name( $this->Version, $language );
            if ( $objectName )
            {
                $translationNode->setAttribute( 'object_name', $objectName );
            }
            else
            {
                eZDebug::writeWarning( sprintf( "Name for object %s of version %s in translation %s not found",
                                                $contentObject->attribute( 'id' ),
                                                $this->Version,
                                                $language ) );
            }

            $attributes = $this->contentObjectAttributes( $language );
            foreach ( $attributes as $attribute )
            {
                $serializedAttributeNode = $attribute->serialize( $package );
                $importedSerializedAttributeNode = $dom->importNode( $serializedAttributeNode, true );
                $translationNode->appendChild( $importedSerializedAttributeNode );
            }

            $versionNode->appendChild( $translationNode );
            $exportedLanguages[] = $language;
        }

        $nodeAssignmentListNode = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:node-assignment-list' );
        $versionNode->appendChild( $nodeAssignmentListNode );

        $contentNodeArray = eZContentObjectTreeNode::fetchByContentObjectID( $this->ContentObjectID, true, $this->Version );
        foreach( $contentNodeArray as $contentNode )
        {
            $contentNodeDOMNode = $contentNode->serialize( $options, $contentNodeIDArray, $topNodeIDArray );
            if ( $contentNodeDOMNode !== false )
            {
                $importedContentDOMNode = $dom->importNode( $contentNodeDOMNode, true );
                $nodeAssignmentListNode->appendChild( $importedContentDOMNode );
            }
        }
        $initialLanguage = $this->attribute( 'initial_language' );
        $initialLanguageCode = $initialLanguage->attribute( 'locale' );
        if ( in_array( $initialLanguageCode, $exportedLanguages ) )
        {
            $versionNode->setAttribute( 'initial_language', $initialLanguageCode );
        }

        if ( $options['related_objects'] === 'selected' )
        {
            $relatedObjectArray = $contentObject->relatedContentObjectList( $this->Version, $contentObject->ID, 0, false,
                                                                             array( 'AllRelations' => eZContentObject::RELATION_COMMON ) );
            if ( count( $relatedObjectArray ) )
            {
                $relationListNode = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:object-relation-list' );

                foreach( $relatedObjectArray as $relatedObject )
                {
                    $relatedObjectRemoteID = $relatedObject->attribute( 'remote_id' );

                    $relationNode = $dom->createElement( 'related-object-remote-id' );
                    $relationNode->appendChild( $dom->createTextNode( $relatedObjectRemoteID ) );

                    $relationListNode->appendChild( $relationNode );
                }
                $versionNode->appendChild( $relationListNode );
            }
        }

        $db->commit();
        return $versionNode;
    }