[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/classes/ -> ezcontentfunctions.php (source)

   1  <?php
   2  
   3  //
   4  // Created on: <13-Nov-2006 15:00:00 dl>
   5  //
   6  // SOFTWARE NAME: eZ publish
   7  // SOFTWARE RELEASE: 3.9.0
   8  // BUILD VERSION: 17785
   9  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  10  // SOFTWARE LICENSE: GNU General Public License v2.0
  11  // NOTICE: >
  12  //   This program is free software; you can redistribute it and/or
  13  //   modify it under the terms of version 2.0  of the GNU General
  14  //   Public License as published by the Free Software Foundation.
  15  //
  16  //   This program is distributed in the hope that it will be useful,
  17  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  //   GNU General Public License for more details.
  20  //
  21  //   You should have received a copy of version 2.0 of the GNU General
  22  //   Public License along with this program; if not, write to the Free
  23  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24  //   MA 02110-1301, USA.
  25  //
  26  //
  27  
  28  class eZContentFunctions
  29  {
  30      function createAndPublishObject( $params )
  31      {
  32          include_once ( 'kernel/classes/ezcontentobject.php' );
  33          include_once ( 'kernel/classes/ezcontentobjecttreenode.php' );
  34          include_once ( 'lib/ezlocale/classes/ezdatetime.php' );
  35  
  36          $parentNodeID = $params['parent_node_id'];
  37          $classIdentifier = $params['class_identifier'];
  38          $creatorID = isset( $params['creator_id'] ) ? $params['creator_id'] : false;
  39          $attributesData = isset( $params['attributes'] ) ? $params['attributes'] : false;
  40          $storageDir = isset( $params['storage_dir'] ) ? $params['storage_dir'] : '';
  41  
  42          $contentObject = false;
  43  
  44          $parentNode = eZContentObjectTreeNode::fetch( $parentNodeID );
  45  
  46          if ( is_object( $parentNode ) )
  47          {
  48              $contentClass = eZContentClass::fetchByIdentifier( $classIdentifier );
  49              if ( is_object( $contentClass ) )
  50              {
  51                  $db =& eZDB::instance();
  52                  $db->begin();
  53  
  54                  $contentObject = $contentClass->instantiate( $creatorID );
  55                  $contentObject->store();
  56  
  57                  $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObject->attribute( 'id' ),
  58                                                                     'contentobject_version' => $contentObject->attribute( 'current_version' ),
  59                                                                     'parent_node' => $parentNode->attribute( 'node_id' ),
  60                                                                     'is_main' => 1 ) );
  61                  $nodeAssignment->store();
  62  
  63                  $version =& $contentObject->version( 1 );
  64                  $version->setAttribute( 'modified', eZDateTime::currentTimeStamp() );
  65                  $version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
  66                  $version->store();
  67  
  68                  if ( is_array( $attributesData ) && count( $attributesData ) > 0 )
  69                  {
  70                      $attributes = $contentObject->attribute( 'contentobject_attributes' );
  71  
  72                      foreach( $attributes as $attribute )
  73                      {
  74                          $attributeIdentifier = $attribute->attribute( 'contentclass_attribute_identifier' );
  75                          if ( isset( $attributesData[$attributeIdentifier] ) )
  76                          {
  77                              $dataString = $attributesData[$attributeIdentifier];
  78                              switch ( $datatypeString = $attribute->attribute( 'data_type_string' ) )
  79                              {
  80                                  case 'ezimage':
  81                                  case 'ezbinaryfile':
  82                                  case 'ezmedia':
  83                                  {
  84                                      $dataString = $storageDir . $dataString;
  85                                      break;
  86                                  }
  87                                  default:
  88                              }
  89  
  90                              $attribute->fromString( $dataString );
  91                              $attribute->store();
  92                          }
  93                      }
  94                  }
  95  
  96                  $db->commit();
  97  
  98                  include_once ( 'lib/ezutils/classes/ezoperationhandler.php' );
  99                  $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ),
 100                                                                                               'version' => 1 ) );
 101              }
 102              else
 103              {
 104                  eZDebug::writeError( "Content class with identifier '$classIdentifier' doesn't exist.", 'eZContentFunctions::createAndPublishObject' );
 105              }
 106          }
 107          else
 108          {
 109              eZDebug::writeError( "Node with id 'parentNodeID' doesn't exist.", 'eZContentFunctions::createAndPublishObject' );
 110          }
 111  
 112          return $contentObject;
 113      }
 114  }
 115  
 116  ?>


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