/**
     * Initialize contentobject attribute content
     *
     * @param eZContentObjectAttribute $contentObjectAttribute
     * @param integer $currentVersion
     * @param eZContentObjectAttribute $originalContentObjectAttribute
     */
    function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
    {
        if ( $currentVersion != false )
        {
            $contentObjectID = $contentObjectAttribute->attribute( 'contentobject_id' );
            $originalContentObjectID = $originalContentObjectAttribute->attribute( 'contentobject_id' );
            $languageMask = $contentObjectAttribute->attribute( 'language_id' ) & ~1;
            $originalLanguageMask = $originalContentObjectAttribute->attribute( 'language_id' ) & ~1;

            // Case when content object was copied or when new translation has been added to the existing one
            if ( ( $contentObjectID != $originalContentObjectID )
                    || ( ( $contentObjectID == $originalContentObjectID )
                       && ( $languageMask != $originalLanguageMask )
                            && ( $contentObjectAttribute->attribute( 'can_translate' ) ) ) )
            {
                $page = $originalContentObjectAttribute->content();
                $clonedPage = clone $page;
                $contentObjectAttribute->setContent( $clonedPage );
                $contentObjectAttribute->store();
            }
            else
            {
                $dataText = $originalContentObjectAttribute->attribute( 'data_text' );
                $contentObjectAttribute->setAttribute( 'data_text', $dataText );
            }
        }
        else
        {
            $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
            $defaultLayout = $contentClassAttribute->attribute( self::DEFAULT_ZONE_LAYOUT_FIELD );
            $zoneINI = eZINI::instance( 'zone.ini' );
            $page = new eZPage();
            $zones = array();
            if ( $defaultLayout !== '' )
            {
                if ( $zoneINI->hasVariable( $defaultLayout, 'Zones' ) )
                    $zones = $zoneINI->variable( $defaultLayout, 'Zones' );

                $page->setAttribute( 'zone_layout', $defaultLayout );
                foreach ( $zones as $zoneIdentifier )
                {
                    $newZone = $page->addZone( new eZPageZone() );
                    $newZone->setAttribute( 'id', md5( mt_rand() . microtime() . $page->getZoneCount() ) );
                    $newZone->setAttribute( 'zone_identifier', $zoneIdentifier );
                    $newZone->setAttribute( 'action', 'add' );
                }
            }
            else
            {
                $allowedZones = array();
                if ( $zoneINI->hasGroup( 'General' ) && $zoneINI->hasVariable( 'General', 'AllowedTypes' ) )
                    $allowedZones = $zoneINI->variable( 'General', 'AllowedTypes' );

                $class = eZContentClass::fetch( $contentClassAttribute->attribute( 'contentclass_id' ) );

                foreach ( $allowedZones as $allowedZone )
                {
                    $availableForClasses = array();
                    if ( $zoneINI->hasVariable( $allowedZone, 'AvailableForClasses' ) )
                        $availableForClasses = $zoneINI->variable( $allowedZone, 'AvailableForClasses' );

                    if ( in_array( $class->attribute( 'identifier' ), $availableForClasses ) )
                    {
                        if ( $zoneINI->hasVariable( $allowedZone, 'Zones' ) )
                            $zones = $zoneINI->variable( $allowedZone, 'Zones' );

                        $page->setAttribute( 'zone_layout', $allowedZone );
                        foreach ( $zones as $zoneIdentifier )
                        {
                            $newZone = $page->addZone( new eZPageZone() );
                            $newZone->setAttribute( 'id', md5( mt_rand() . microtime() . $page->getZoneCount() ) );
                            $newZone->setAttribute( 'zone_identifier', $zoneIdentifier );
                            $newZone->setAttribute( 'action', 'add' );
                        }

                        break;
                    }
                    else
                        continue;
                }
            }
            $contentObjectAttribute->setContent( $page );
        }
    }
 /**
  * Initialize contentobject attribute content
  *
  * @param eZContentObjectAttribute $contentObjectAttribute
  * @param integer $currentVersion
  * @param eZContentObjectAttribute $originalContentObjectAttribute
  */
 function initializeObjectAttribute($contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
 {
     if ($currentVersion != false) {
         $contentObjectID = $contentObjectAttribute->attribute('contentobject_id');
         $originalContentObjectID = $originalContentObjectAttribute->attribute('contentobject_id');
         if ($contentObjectID != $originalContentObjectID) {
             $page = $originalContentObjectAttribute->content();
             $clonedPage = clone $page;
             $contentObjectAttribute->setContent($clonedPage);
             $contentObjectAttribute->store();
         } else {
             $dataText = $originalContentObjectAttribute->attribute('data_text');
             $contentObjectAttribute->setAttribute('data_text', $dataText);
         }
     } else {
         $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
         $defaultLayout = $contentClassAttribute->attribute("data_text1");
         $zoneINI = eZINI::instance('zone.ini');
         $page = new eZPage();
         $zones = array();
         if ($defaultLayout !== '') {
             if ($zoneINI->hasVariable($defaultLayout, 'Zones')) {
                 $zones = $zoneINI->variable($defaultLayout, 'Zones');
             }
             $page->setAttribute('zone_layout', $defaultLayout);
             foreach ($zones as $zoneIdentifier) {
                 $newZone = $page->addZone(new eZPageZone());
                 $newZone->setAttribute('id', md5(mt_rand() . microtime() . $page->getZoneCount()));
                 $newZone->setAttribute('zone_identifier', $zoneIdentifier);
                 $newZone->setAttribute('action', 'add');
             }
         } else {
             $allowedZones = array();
             if ($zoneINI->hasGroup('General') && $zoneINI->hasVariable('General', 'AllowedTypes')) {
                 $allowedZones = $zoneINI->variable('General', 'AllowedTypes');
             }
             $class = eZContentClass::fetch($contentClassAttribute->attribute('contentclass_id'));
             foreach ($allowedZones as $allowedZone) {
                 $availableForClasses = array();
                 if ($zoneINI->hasVariable($allowedZone, 'AvailableForClasses')) {
                     $availableForClasses = $zoneINI->variable($allowedZone, 'AvailableForClasses');
                 }
                 if (in_array($class->attribute('identifier'), $availableForClasses)) {
                     if ($zoneINI->hasVariable($allowedZone, 'Zones')) {
                         $zones = $zoneINI->variable($allowedZone, 'Zones');
                     }
                     $page->setAttribute('zone_layout', $allowedZone);
                     foreach ($zones as $zoneIdentifier) {
                         $newZone = $page->addZone(new eZPageZone());
                         $newZone->setAttribute('id', md5(mt_rand() . microtime() . $page->getZoneCount()));
                         $newZone->setAttribute('zone_identifier', $zoneIdentifier);
                         $newZone->setAttribute('action', 'add');
                     }
                     break;
                 } else {
                     continue;
                 }
             }
         }
         $contentObjectAttribute->setContent($page);
     }
 }
示例#3
0
 /**
  * Creates object structure from given XML type string
  *
  * @static
  * @param string $source
  * @return eZPage
  */
 public static function createFromXML($source)
 {
     $newObj = new eZPage();
     if ($source) {
         $dom = new DOMDocument('1.0', 'utf-8');
         $success = $dom->loadXML($source);
         $root = $dom->documentElement;
         foreach ($root->childNodes as $node) {
             if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'zone') {
                 $zoneNode = eZPageZone::createFromXML($node);
                 $newObj->addZone($zoneNode);
             } elseif ($node->nodeType == XML_ELEMENT_NODE) {
                 $newObj->setAttribute($node->nodeName, $node->nodeValue);
             }
         }
         if ($root->hasAttributes()) {
             foreach ($root->attributes as $attr) {
                 $newObj->setAttribute($attr->name, $attr->value);
             }
         }
     }
     $zoneINI = eZINI::instance('zone.ini');
     $layoutName = $newObj->attribute('zone_layout');
     if ($zoneINI->hasVariable($layoutName, 'Zones')) {
         foreach ($zoneINI->variable($layoutName, 'Zones') as $zoneIdentifier) {
             foreach ($newObj->attribute('zones') as $inObjectZone) {
                 if ($inObjectZone->attribute('zone_identifier') === $zoneIdentifier) {
                     continue 2;
                 }
             }
             $newZone = $newObj->addZone(new eZPageZone());
             $newZone->setAttribute('id', md5(mt_rand() . microtime() . $newObj->getZoneCount()));
             $newZone->setAttribute('zone_identifier', $zoneIdentifier);
             $newZone->setAttribute('action', 'add');
         }
     }
     return $newObj;
 }