[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/packagehandlers/ezcontentclass/ -> ezcontentclasspackagehandler.php (source)

   1  <?php
   2  //
   3  // Definition of eZContentClassPackageHandler class
   4  //
   5  // Created on: <23-Jul-2003 16:11:42 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezcontentclasspackagehandler.php
  30  */
  31  
  32  /*!
  33    \class eZContentClassPackageHandler ezcontentclasspackagehandler.php
  34    \brief Handles content classes in the package system
  35  
  36  */
  37  
  38  include_once ( 'lib/ezxml/classes/ezxml.php' );
  39  include_once ( 'kernel/classes/ezcontentclass.php' );
  40  include_once ( 'kernel/classes/ezpackagehandler.php' );
  41  
  42  define( "EZ_PACKAGE_CONTENTCLASS_ERROR_EXISTS", 1 );
  43  define( "EZ_PACKAGE_CONTENTCLASS_ERROR_HAS_OBJECTS", 101 );
  44  
  45  define( "EZ_PACKAGE_CONTENTCLASS_REPLACE", 1 );
  46  define( "EZ_PACKAGE_CONTENTCLASS_SKIP", 2 );
  47  define( "EZ_PACKAGE_CONTENTCLASS_NEW", 3 );
  48  define( "EZ_PACKAGE_CONTENTCLASS_DELETE", 4 );
  49  
  50  class eZContentClassPackageHandler extends eZPackageHandler
  51  {
  52      /*!
  53       Constructor
  54      */
  55      function eZContentClassPackageHandler()
  56      {
  57          $this->eZPackageHandler( 'ezcontentclass',
  58                                   array( 'extract-install-content' => true ) );
  59      }
  60  
  61      /*!
  62       \reimp
  63       Returns an explanation for the content class install item.
  64      */
  65      function explainInstallItem( &$package, $installItem )
  66      {
  67          if ( $installItem['filename'] )
  68          {
  69              $filename = $installItem['filename'];
  70              $subdirectory = $installItem['sub-directory'];
  71              if ( $subdirectory )
  72                  $filepath = $subdirectory . '/' . $filename . '.xml';
  73              else
  74                  $filepath = $filename . '.xml';
  75  
  76              $filepath = $package->path() . '/' . $filepath;
  77  
  78              $dom =& $package->fetchDOMFromFile( $filepath );
  79              if ( $dom )
  80              {
  81                  $content =& $dom->root();
  82                  $className = $content->elementTextContentByName( 'name' );
  83                  $classIdentifier = $content->elementTextContentByName( 'identifier' );
  84                  return array( 'description' => ezi18n( 'kernel/package', 'Content class %classname (%classidentifier)', false,
  85                                                         array( '%classname' => $className,
  86                                                                '%classidentifier' => $classIdentifier ) ) );
  87              }
  88          }
  89      }
  90  
  91      /*!
  92       \reimp
  93       Uninstalls all previously installed content classes.
  94      */
  95      function uninstall( &$package, $installType, $parameters,
  96                        $name, $os, $filename, $subdirectory,
  97                        &$content, &$installParameters,
  98                        &$installData )
  99      {
 100          $classRemoteID = $content->elementTextContentByName( 'remote-id' );
 101  
 102          $class = eZContentClass::fetchByRemoteID( $classRemoteID );
 103  
 104          if ( $class == null )
 105          {
 106              eZDebug::writeNotice( "Class having remote id '$classRemoteID' not found.", 'eZContentClassPackageHandler::uninstall()' );
 107              return true;
 108          }
 109  
 110          if ( $class->isRemovable() )
 111          {
 112              $choosenAction = $this->errorChoosenAction( EZ_PACKAGE_CONTENTCLASS_ERROR_HAS_OBJECTS,
 113                                                          $installParameters );
 114              if ( $choosenAction == EZ_PACKAGE_CONTENTCLASS_SKIP )
 115              {
 116                  return true;
 117              }
 118              if ( $choosenAction != EZ_PACKAGE_CONTENTCLASS_DELETE )
 119              {
 120                  $objectsCount = eZContentObject::fetchSameClassListCount( $class->attribute( 'id' ) );
 121                  $name = $class->attribute( 'name' );
 122                  if ( $objectsCount )
 123                  {
 124                      $installParameters['error'] = array( 'error_code' => EZ_PACKAGE_CONTENTCLASS_ERROR_HAS_OBJECTS,
 125                                                           'element_id' => $classRemoteID,
 126                                                           'description' => ezi18n( 'kernel/package',
 127                                                                                    "Removing class '%classname' will result in the removal of %objectscount object(s) of this class and all their sub-items. Are you sure you want to uninstall it?",
 128                                                                                    false,
 129                                                                                    array( '%classname' => $name,
 130                                                                                           '%objectscount' => $objectsCount ) ),
 131                                                           'actions' => array( EZ_PACKAGE_CONTENTCLASS_DELETE => "Uninstall class and object(s)",
 132                                                                               EZ_PACKAGE_CONTENTCLASS_SKIP => 'Skip' ) );
 133                      return false;
 134                  }
 135              }
 136  
 137              eZDebug::writeNotice( sprintf( "Removing class '%s' (%d)", $class->attribute( 'name' ), $class->attribute( 'id' ) ) );
 138  
 139              include_once ( 'kernel/classes/ezcontentclassoperations.php' );
 140              eZContentClassOperations::remove( $class->attribute( 'id' ) );
 141          }
 142  
 143          return true;
 144      }
 145  
 146      /*!
 147       \reimp
 148       Creates a new contentclass as defined in the xml structure.
 149      */
 150      function install( &$package, $installType, $parameters,
 151                        $name, $os, $filename, $subdirectory,
 152                        &$content, &$installParameters,
 153                        &$installData )
 154      {
 155          $classNameList = new eZContentClassNameList( $content->elementTextContentByName( 'serialized-name-list' ) );
 156          if ( $classNameList->isEmpty() )
 157              $classNameList->initFromString( $content->elementTextContentByName( 'name' ) ); // for backward compatibility( <= 3.8 )
 158  
 159          $classIdentifier = $content->elementTextContentByName( 'identifier' );
 160          $classRemoteID = $content->elementTextContentByName( 'remote-id' );
 161          $classObjectNamePattern = $content->elementTextContentByName( 'object-name-pattern' );
 162          $classIsContainer = $content->attributeValue( 'is-container' );
 163          if ( $classIsContainer !== false )
 164              $classIsContainer = $classIsContainer == 'true' ? 1 : 0;
 165  
 166          $classRemoteNode = $content->elementByName( 'remote' );
 167          $classID = $classRemoteNode->elementTextContentByName( 'id' );
 168          $classGroupsNode = $classRemoteNode->elementByName( 'groups' );
 169          $classCreated = $classRemoteNode->elementTextContentByName( 'created' );
 170          $classModified = $classRemoteNode->elementTextContentByName( 'modified' );
 171          $classCreatorNode = $classRemoteNode->elementByName( 'creator' );
 172          $classModifierNode = $classRemoteNode->elementByName( 'modifier' );
 173  
 174          $classAttributesNode = $content->elementByName( 'attributes' );
 175  
 176          $dateTime = time();
 177          $classCreated = $dateTime;
 178          $classModified = $dateTime;
 179  
 180          $userID = false;
 181          if ( isset( $installParameters['user_id'] ) )
 182              $userID = $installParameters['user_id'];
 183  
 184          $class = eZContentClass::fetchByRemoteID( $classRemoteID );
 185  
 186          if ( $class )
 187          {
 188              $description = ezi18n( 'kernel/package', "Class '%classname' already exists.", false,
 189                                     array( '%classname' => $class->name() ) );
 190  
 191              $choosenAction = $this->errorChoosenAction( EZ_PACKAGE_CONTENTCLASS_ERROR_EXISTS,
 192                                                          $installParameters, $description );
 193              switch( $choosenAction )
 194              {
 195              case EZ_PACKAGE_NON_INTERACTIVE:
 196              case EZ_PACKAGE_CONTENTCLASS_REPLACE:
 197                  include_once ( 'kernel/classes/ezcontentclassoperations.php' );
 198                  if ( eZContentClassOperations::remove( $class->attribute( 'id' ) ) == false )
 199                      return true;
 200                  break;
 201  
 202              case EZ_PACKAGE_CONTENTCLASS_SKIP:
 203                  return true;
 204  
 205              case EZ_PACKAGE_CONTENTCLASS_NEW:
 206                  $class->setAttribute( 'remote_id', md5( (string)mt_rand() . (string)mktime() ) );
 207                  $class->store();
 208                  $classNameList->appendGroupName( " (imported)" );
 209                  break;
 210  
 211              default:
 212                  $installParameters['error'] = array( 'error_code' => EZ_PACKAGE_CONTENTCLASS_ERROR_EXISTS,
 213                                                       'element_id' => $classRemoteID,
 214                                                       'description' => $description,
 215                                                       'actions' => array() );
 216                  if ( $class->isRemovable() )
 217                  {
 218                      $errorMsg = ezi18n( 'kernel/package', "Replace existing class" );
 219                      $objectsCount = eZContentObject::fetchSameClassListCount( $class->attribute( 'id' ) );
 220                      if ( $objectsCount )
 221                          $errorMsg .= ' ' . ezi18n( 'kernel/package', "(Warning! $objectsCount content object(s) and their sub-items will be removed)" );
 222                      $installParameters['error']['actions'][EZ_PACKAGE_CONTENTCLASS_REPLACE] = $errorMsg;
 223                  }
 224                  $installParameters['error']['actions'][EZ_PACKAGE_CONTENTCLASS_SKIP] = ezi18n( 'kernel/package', 'Skip installing this class' );
 225                  $installParameters['error']['actions'][EZ_PACKAGE_CONTENTCLASS_NEW] = ezi18n( 'kernel/package', 'Keep existing and create a new one' );
 226                  return false;
 227              }
 228          }
 229  
 230          unset( $class );
 231  
 232          // Try to create a unique class identifier
 233          $currentClassIdentifier = $classIdentifier;
 234          $unique = false;
 235  
 236          while( !$unique )
 237          {
 238              $classList = eZContentClass::fetchByIdentifier( $currentClassIdentifier );
 239              if ( $classList )
 240              {
 241                  // "increment" class identifier
 242                  if ( preg_match( '/^(.*)_(\d+)$/', $currentClassIdentifier, $matches ) )
 243                      $currentClassIdentifier = $matches[1] . '_' . ( $matches[2] + 1 );
 244                  else
 245                      $currentClassIdentifier = $currentClassIdentifier . '_1';
 246              }
 247              else
 248                  $unique = true;
 249  
 250              unset( $classList );
 251          }
 252  
 253          $classIdentifier = $currentClassIdentifier;
 254  
 255          // create class
 256          $class = eZContentClass::create( $userID,
 257                                           array( 'version' => 0,
 258                                                  'serialized_name_list' => $classNameList->serializeNames(),
 259                                                  'identifier' => $classIdentifier,
 260                                                  'remote_id' => $classRemoteID,
 261                                                  'contentobject_name' => $classObjectNamePattern,
 262                                                  'is_container' => $classIsContainer,
 263                                                  'created' => $classCreated,
 264                                                  'modified' => $classModified ) );
 265          $class->store();
 266  
 267          $classID = $class->attribute( 'id' );
 268  
 269          if ( !isset( $installData['classid_list'] ) )
 270              $installData['classid_list'] = array();
 271          if ( !isset( $installData['classid_map'] ) )
 272              $installData['classid_map'] = array();
 273          $installData['classid_list'][] = $class->attribute( 'id' );
 274          $installData['classid_map'][$classID] = $class->attribute( 'id' );
 275  
 276          // create class attributes
 277          $classAttributeList = $classAttributesNode->children();
 278          foreach ( $classAttributeList as $classAttributeNode )
 279          {
 280              $isNotSupported = strtolower( $classAttributeNode->attributeValue( 'unsupported' ) ) == 'true';
 281              if ( $isNotSupported )
 282                  continue;
 283  
 284              $attributeDatatype = $classAttributeNode->attributeValue( 'datatype' );
 285              $attributeIsRequired = strtolower( $classAttributeNode->attributeValue( 'required' ) ) == 'true';
 286              $attributeIsSearchable = strtolower( $classAttributeNode->attributeValue( 'searchable' ) ) == 'true';
 287              $attributeIsInformationCollector = strtolower( $classAttributeNode->attributeValue( 'information-collector' ) ) == 'true';
 288              $attributeIsTranslatable = strtolower( $classAttributeNode->attributeValue( 'translatable' ) ) == 'true';
 289              $attributeSerializedNameList = new eZContentClassAttributeNameList( $classAttributeNode->elementTextContentByName( 'serialized-name-list' ) );
 290              if ( $attributeSerializedNameList->isEmpty() )
 291                  $attributeSerializedNameList->initFromString( $classAttributeNode->elementTextContentByName( 'name' ) ); // for backward compatibility( <= 3.8 )
 292              $attributeIdentifier = $classAttributeNode->elementTextContentByName( 'identifier' );
 293              $attributePlacement = $classAttributeNode->elementTextContentByName( 'placement' );
 294              $attributeDatatypeParameterNode = $classAttributeNode->elementByName( 'datatype-parameters' );
 295  
 296              $classAttribute =& $class->fetchAttributeByIdentifier( $attributeIdentifier );
 297              if ( !$classAttribute )
 298              {
 299                  $classAttribute = eZContentClassAttribute::create( $class->attribute( 'id' ),
 300                                                                     $attributeDatatype,
 301                                                                     array( 'version' => 0,
 302                                                                            'identifier' => $attributeIdentifier,
 303                                                                            'serialized_name_list' => $attributeSerializedNameList->serializeNames(),
 304                                                                            'is_required' => $attributeIsRequired,
 305                                                                            'is_searchable' => $attributeIsSearchable,
 306                                                                            'is_information_collector' => $attributeIsInformationCollector,
 307                                                                            'can_translate' => $attributeIsTranslatable,
 308                                                                            'placement' => $attributePlacement ) );
 309  
 310                  $dataType = $classAttribute->dataType();
 311                  $classAttribute->store();
 312                  $dataType->unserializeContentClassAttribute( $classAttribute, $classAttributeNode, $attributeDatatypeParameterNode );
 313                  $classAttribute->sync();
 314              }
 315          }
 316  
 317          // add class to a class group
 318          $classGroupsList = $classGroupsNode->children();
 319          foreach ( $classGroupsList as $classGroupNode )
 320          {
 321              $classGroupName = $classGroupNode->attributeValue( 'name' );
 322              $classGroup = eZContentClassGroup::fetchByName( $classGroupName );
 323              if ( !$classGroup )
 324              {
 325                  $classGroup = eZContentClassGroup::create();
 326                  $classGroup->setAttribute( 'name', $classGroupName );
 327                  $classGroup->store();
 328              }
 329              $classGroup->appendClass( $class );
 330          }
 331          return true;
 332      }
 333  
 334      /*!
 335       \reimp
 336      */
 337      function add( $packageType, &$package, &$cli, $parameters )
 338      {
 339          foreach ( $parameters['class-list'] as $classItem )
 340          {
 341              $classID = $classItem['id'];
 342              $classIdentifier = $classItem['identifier'];
 343              $classValue = $classItem['value'];
 344              $cli->notice( "Adding class $classValue to package" );
 345              $this->addClass( $package, $classID, $classIdentifier );
 346          }
 347      }
 348  
 349      /*!
 350       \static
 351       Adds the content class with ID \a $classID to the package.
 352       If \a $classIdentifier is \c false then it will be fetched from the class.
 353      */
 354      function addClass( &$package, $classID, $classIdentifier = false )
 355      {
 356          $class = false;
 357          if ( is_numeric( $classID ) )
 358              $class = eZContentClass::fetch( $classID );
 359          if ( !$class )
 360              return;
 361          $classNode =& eZContentClassPackageHandler::classDOMTree( $class );
 362          if ( !$classNode )
 363              return;
 364          if ( !$classIdentifier )
 365              $classIdentifier = $class->attribute( 'identifier' );
 366          $package->appendInstall( 'ezcontentclass', false, false, true,
 367                                   'class-' . $classIdentifier, 'ezcontentclass',
 368                                   array( 'content' => $classNode ) );
 369          $package->appendProvides( 'ezcontentclass', 'contentclass', $class->attribute( 'identifier' ) );
 370          $package->appendInstall( 'ezcontentclass', false, false, false,
 371                                   'class-' . $classIdentifier, 'ezcontentclass',
 372                                   array( 'content' => false ) );
 373      }
 374  
 375      /*!
 376       \reimp
 377      */
 378      function handleAddParameters( $packageType, &$package, &$cli, $arguments )
 379      {
 380          return $this->handleParameters( $packageType, $package, $cli, 'add', $arguments );
 381      }
 382  
 383      /*!
 384       \private
 385      */
 386      function handleParameters( $packageType, &$package, &$cli, $type, $arguments )
 387      {
 388          $classList = false;
 389          foreach ( $arguments as $argument )
 390          {
 391              if ( $argument[0] == '-' )
 392              {
 393                  if ( strlen( $argument ) > 1 and
 394                       $argument[1] == '-' )
 395                  {
 396                  }
 397                  else
 398                  {
 399                  }
 400              }
 401              else
 402              {
 403                  if ( $classList === false )
 404                  {
 405                      $classList = array();
 406                      $classArray = explode( ',', $argument );
 407                      $error = false;
 408                      foreach ( $classArray as $classID )
 409                      {
 410                          if ( in_array( $classID, $classList ) )
 411                          {
 412                              $cli->notice( "Content class $classID already in list" );
 413                              continue;
 414                          }
 415                          if ( is_numeric( $classID ) )
 416                          {
 417                              if ( !eZContentClass::exists( $classID, 0, false, false ) )
 418                              {
 419                                  $cli->error( "Content class with ID $classID does not exist" );
 420                                  $error = true;
 421                              }
 422                              else
 423                              {
 424                                  unset( $class );
 425                                  $class = eZContentClass::fetch( $classID );
 426                                  $classList[] = array( 'id' => $classID,
 427                                                        'identifier' => $class->attribute( 'identifier' ),
 428                                                        'value' => $classID );
 429                              }
 430                          }
 431                          else
 432                          {
 433                              $realClassID = eZContentClass::exists( $classID, 0, false, true );
 434                              if ( !$realClassID )
 435                              {
 436                                  $cli->error( "Content class with identifier $classID does not exist" );
 437                                  $error = true;
 438                              }
 439                              else
 440                              {
 441                                  unset( $class );
 442                                  $class = eZContentClass::fetch( $realClassID );
 443                                  $classList[] = array( 'id' => $realClassID,
 444                                                        'identifier' => $class->attribute( 'identifier' ),
 445                                                        'value' => $classID );
 446                              }
 447                          }
 448                      }
 449                      if ( $error )
 450                          return false;
 451                  }
 452              }
 453          }
 454          if ( $classList === false )
 455          {
 456              $cli->error( "No class ids chosen" );
 457              return false;
 458          }
 459          return array( 'class-list' => $classList );
 460      }
 461  
 462      /*!
 463       \static
 464       Creates the DOM tree for the content class \a $class and returns the root node.
 465      */
 466      function &classDOMTree( &$class )
 467      {
 468          if ( !$class )
 469          {
 470              $retValue = false;
 471              return $retValue;
 472          }
 473  
 474          $classNode = eZDOMDocument::createElementNode( 'content-class' );
 475          $classNode->appendChild( eZDOMDocument::createElementTextNode( 'serialized-name-list',
 476                                                                         $class->attribute( 'serialized_name_list' ) ) );
 477          $classNode->appendChild( eZDOMDocument::createElementTextNode( 'identifier',
 478                                                                         $class->attribute( 'identifier' ) ) );
 479          $classNode->appendChild( eZDOMDocument::createElementTextNode( 'remote-id',
 480                                                                          $class->attribute( 'remote_id' ) ) );
 481          $classNode->appendChild( eZDOMDocument::createElementTextNode( 'object-name-pattern',
 482                                                                         $class->attribute( 'contentobject_name' ) ) );
 483          $classNode->appendAttribute( eZDOMDocument::createAttributeNode( 'is-container',
 484                                                                           $class->attribute( 'is_container' ) ? 'true' : 'false' ) );
 485  
 486          // Remote data start
 487          $remoteNode = eZDOMDocument::createElementNode( 'remote' );
 488          $classNode->appendChild( $remoteNode );
 489  
 490          $ini =& eZINI::instance();
 491          $siteName = $ini->variable( 'SiteSettings', 'SiteURL' );
 492  
 493          $classURL = 'http://' . $siteName . '/class/view/' . $class->attribute( 'id' );
 494          $siteURL = 'http://' . $siteName . '/';
 495  
 496          $remoteNode->appendChild( eZDOMDocument::createElementTextNode( 'site-url',
 497                                                                          $siteURL ) );
 498          $remoteNode->appendChild( eZDOMDocument::createElementTextNode( 'url',
 499                                                                          $classURL ) );
 500  
 501          $classGroupsNode = eZDOMDocument::createElementNode( 'groups' );
 502  
 503          $classGroupList = eZContentClassClassGroup::fetchGroupList( $class->attribute( 'id' ),
 504                                                                       $class->attribute( 'version' ) );
 505          foreach ( array_keys( $classGroupList ) as $classGroupKey )
 506          {
 507              $classGroupLink =& $classGroupList[$classGroupKey];
 508              $classGroup = eZContentClassGroup::fetch( $classGroupLink->attribute( 'group_id' ) );
 509              if ( $classGroup )
 510                  $classGroupsNode->appendChild( eZDOMDocument::createElementNode( 'group',
 511                                                                                   array( 'id' => $classGroup->attribute( 'id' ),
 512                                                                                          'name' => $classGroup->attribute( 'name' ) ) ) );
 513          }
 514          $remoteNode->appendChild( $classGroupsNode );
 515  
 516          $remoteNode->appendChild( eZDOMDocument::createElementTextNode( 'id',
 517                                                                          $class->attribute( 'id' ) ) );
 518          $remoteNode->appendChild( eZDOMDocument::createElementTextNode( 'created',
 519                                                                          $class->attribute( 'created' ) ) );
 520          $remoteNode->appendChild( eZDOMDocument::createElementTextNode( 'modified',
 521                                                                          $class->attribute( 'modified' ) ) );
 522  
 523          $creatorNode = eZDOMDocument::createElementNode( 'creator' );
 524          $remoteNode->appendChild( $creatorNode );
 525          $creatorNode->appendChild( eZDOMDocument::createElementTextNode( 'user-id',
 526                                                                           $class->attribute( 'creator_id' ) ) );
 527          $creator =& $class->attribute( 'creator' );
 528          if ( $creator )
 529              $creatorNode->appendChild( eZDOMDocument::createElementTextNode( 'user-login',
 530                                                                               $creator->attribute( 'login' ) ) );
 531  
 532          $modifierNode = eZDOMDocument::createElementNode( 'modifier' );
 533          $remoteNode->appendChild( $modifierNode );
 534          $modifierNode->appendChild( eZDOMDocument::createElementTextNode( 'user-id',
 535                                                                            $class->attribute( 'modifier_id' ) ) );
 536          $modifier =& $class->attribute( 'modifier' );
 537          if ( $modifier )
 538              $modifierNode->appendChild( eZDOMDocument::createElementTextNode( 'user-login',
 539                                                                                $modifier->attribute( 'login' ) ) );
 540          // Remote data end
 541  
 542          $attributesNode = eZDOMDocument::createElementNode( 'attributes' );
 543          $attributesNode->appendAttribute( eZDOMDocument::createAttributeNode( 'ezcontentclass-attribute',
 544                                                                                'http://ezpublish/contentclassattribute',
 545                                                                                'xmlns' ) );
 546          $classNode->appendChild( $attributesNode );
 547  
 548          $attributes =& $class->fetchAttributes();
 549          for ( $i = 0; $i < count( $attributes ); ++$i )
 550          {
 551              $attribute =& $attributes[$i];
 552              unset( $attributeNode );
 553              $attributeNode = eZDOMDocument::createElementNode( 'attribute',
 554                                                                 array( 'datatype' => $attribute->attribute( 'data_type_string' ),
 555                                                                        'required' => $attribute->attribute( 'is_required' ) ? 'true' : 'false',
 556                                                                        'searchable' => $attribute->attribute( 'is_searchable' ) ? 'true' : 'false',
 557                                                                        'information-collector' => $attribute->attribute( 'is_information_collector' ) ? 'true' : 'false',
 558                                                                        'translatable' => $attribute->attribute( 'can_translate' ) ? 'true' : 'false' ) );
 559              unset( $attributeRemoteNode );
 560              $attributeRemoteNode = eZDOMDocument::createElementNode( 'remote' );
 561              $attributeNode->appendChild( $attributeRemoteNode );
 562              $attributeRemoteNode->appendChild( eZDOMDocument::createElementTextNode( 'id',
 563                                                                                       $attribute->attribute( 'id' ) ) );
 564              $attributeNode->appendChild( eZDOMDocument::createElementTextNode( 'serialized-name-list',
 565                                                                                 $attribute->attribute( 'serialized_name_list' ) ) );
 566              $attributeNode->appendChild( eZDOMDocument::createElementTextNode( 'identifier',
 567                                                                                 $attribute->attribute( 'identifier' ) ) );
 568              $attributeNode->appendChild( eZDOMDocument::createElementTextNode( 'placement',
 569                                                                                 $attribute->attribute( 'placement' ) ) );
 570              unset( $attributeParametersNode );
 571              $attributeParametersNode = eZDOMDocument::createElementNode( 'datatype-parameters' );
 572              $attributeNode->appendChild( $attributeParametersNode );
 573  
 574              $dataType = $attribute->dataType();
 575              if ( is_object( $dataType ) )
 576              {
 577                  $dataType->serializeContentClassAttribute( $attribute, $attributeNode, $attributeParametersNode );
 578              }
 579  
 580              $attributesNode->appendChild( $attributeNode );
 581          }
 582          return $classNode;
 583      }
 584  
 585      function contentclassDirectory()
 586      {
 587          return 'ezcontentclass';
 588      }
 589  
 590      /*!
 591       \reimp
 592      */
 593      /*function createInstallNode( &$package, $export, &$installNode, $installItem, $installType )
 594      {
 595          if ( $installNode->attributeValue( 'type' ) == 'ezcontentclass' )
 596          {
 597              if ( $export )
 598              {
 599                  $classFile = $installItem['filename'] . '.xml';
 600                  if ( $installItem['sub-directory'] )
 601                      $classFile = $installItem['sub-directory'] . '/' . $classFile;
 602                  $originalPath = $package->path() . '/' . $classFile;
 603                  $exportPath = $export['path'];
 604                  $installDirectory = $exportPath . '/' . eZContentClassPackageHandler::contentclassDirectory();
 605                  if ( !file_exists(  $installDirectory ) )
 606                      eZDir::mkdir( $installDirectory, eZDir::directoryPermission(), true );
 607                  eZFileHandler::copy( $originalPath, $installDirectory . '/' . $installItem['filename'] . '.xml' );
 608              }
 609          }
 610      }
 611      */
 612  }
 613  
 614  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7