Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcontentfunctions.php
Go to the documentation of this file.
1 <?php
11 class eZContentFunctions
12 {
88 static function createAndPublishObject( $params )
89 {
90 $parentNodeID = $params['parent_node_id'];
91 $classIdentifier = $params['class_identifier'];
92 $creatorID = isset( $params['creator_id'] ) ? $params['creator_id'] : false;
93 $attributesData = isset( $params['attributes'] ) ? $params['attributes'] : false;
94 $storageDir = isset( $params['storage_dir'] ) ? $params['storage_dir'] : '';
95
96 $contentObject = false;
97
98 $parentNode = eZContentObjectTreeNode::fetch( $parentNodeID, false, false );
99
100 if ( is_array( $parentNode ) )
101 {
102 $contentClass = eZContentClass::fetchByIdentifier( $classIdentifier );
103 if ( $contentClass instanceof eZContentClass )
104 {
105 $db = eZDB::instance();
106 $db->begin();
107
108 $languageCode = isset( $params['language'] ) ? $params['language'] : false;
109 $sectionID = isset( $params['section_id'] ) ? $params['section_id'] : 0;
110 $contentObject = $contentClass->instantiate( $creatorID , $sectionID, false, $languageCode );
111
112 if ( array_key_exists( 'remote_id', $params ) )
113 $contentObject->setAttribute( 'remote_id', $params['remote_id'] );
114
115 $contentObject->store();
116
117 $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObject->attribute( 'id' ),
118 'contentobject_version' => $contentObject->attribute( 'current_version' ),
119 'parent_node' => $parentNodeID,
120 'is_main' => 1,
121 'sort_field' => $contentClass->attribute( 'sort_field' ),
122 'sort_order' => $contentClass->attribute( 'sort_order' ) ) );
123 $nodeAssignment->store();
124
125 $version = $contentObject->version( 1 );
126 $version->setAttribute( 'modified', eZDateTime::currentTimeStamp() );
127 $version->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT );
128 $version->store();
129
130 if ( is_array( $attributesData ) && !empty( $attributesData ) )
131 {
132 $attributes = $contentObject->attribute( 'contentobject_attributes' );
133
134 foreach( $attributes as $attribute )
135 {
136 $attributeIdentifier = $attribute->attribute( 'contentclass_attribute_identifier' );
137 if ( isset( $attributesData[$attributeIdentifier] ) )
138 {
139 $dataString = $attributesData[$attributeIdentifier];
140 switch ( $datatypeString = $attribute->attribute( 'data_type_string' ) )
141 {
142 case 'ezimage':
143 case 'ezbinaryfile':
144 case 'ezmedia':
145 {
146 $dataString = $storageDir . $dataString;
147 break;
148 }
149 default:
150 }
151
152 $attribute->fromString( $dataString );
153 $attribute->store();
154 }
155 }
156 }
157
158 $db->commit();
159
160 $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ),
161 'version' => 1 ) );
162 }
163 else
164 {
165 eZDebug::writeError( "Content class with identifier '$classIdentifier' doesn't exist.", __METHOD__ );
166 }
167 }
168 else
169 {
170 eZDebug::writeError( "Node with id '$parentNodeID' doesn't exist.", __METHOD__ );
171 }
172
173 return $contentObject;
174 }
175
227 public static function updateAndPublishObject( eZContentObject $object, array $params )
228 {
229 if ( !array_key_exists( 'attributes', $params ) and !is_array( $params['attributes'] ) and count( $params['attributes'] ) > 0 )
230 {
231 eZDebug::writeError( 'No attributes specified for object' . $object->attribute( 'id' ), __METHOD__ );
232 return false;
233 }
234
235 $storageDir = '';
236 $languageCode = false;
237 $mustStore = false;
238
239 if ( array_key_exists( 'remote_id', $params ) )
240 {
241 $object->setAttribute( 'remote_id', $params['remote_id'] );
242 $mustStore = true;
243 }
244
245 if ( array_key_exists( 'section_id', $params ) )
246 {
247 $object->setAttribute( 'section_id', $params['section_id'] );
248 $mustStore = true;
249 }
250
251 if ( $mustStore )
252 $object->store();
253
254 if ( array_key_exists( 'storage_dir', $params ) )
255 $storageDir = $params['storage_dir'];
256
257 if ( array_key_exists( 'language', $params ) and $params['language'] != false )
258 {
259 $languageCode = $params['language'];
260 }
261 else
262 {
263 $initialLanguageID = $object->attribute( 'initial_language_id' );
264 $language = eZContentLanguage::fetch( $initialLanguageID );
265 $languageCode = $language->attribute( 'locale' );
266 }
267
268 $db = eZDB::instance();
269 $db->begin();
270
271 $newVersion = $object->createNewVersion( false, true, $languageCode );
272
273 if ( !$newVersion instanceof eZContentObjectVersion )
274 {
275 eZDebug::writeError( 'Unable to create a new version for object ' . $object->attribute( 'id' ), __METHOD__ );
276
277 $db->rollback();
278
279 return false;
280 }
281
282 $newVersion->setAttribute( 'modified', time() );
283 $newVersion->store();
284
285 $attributeList = $newVersion->attribute( 'contentobject_attributes' );
286
287 $attributesData = $params['attributes'];
288
289 foreach( $attributeList as $attribute )
290 {
291 $attributeIdentifier = $attribute->attribute( 'contentclass_attribute_identifier' );
292 if ( array_key_exists( $attributeIdentifier, $attributesData ) )
293 {
294 $dataString = $attributesData[$attributeIdentifier];
295 switch ( $datatypeString = $attribute->attribute( 'data_type_string' ) )
296 {
297 case 'ezimage':
298 case 'ezbinaryfile':
299 case 'ezmedia':
300 {
301 $dataString = $storageDir . $dataString;
302 break;
303 }
304 default:
305 }
306
307 $attribute->fromString( $dataString );
308 $attribute->store();
309 }
310 }
311
312 $db->commit();
313
314 $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $newVersion->attribute( 'contentobject_id' ),
315 'version' => $newVersion->attribute( 'version' ) ) );
316
317 if( $operationResult['status'] == eZModuleOperationInfo::STATUS_CONTINUE )
318 return true;
319
320 return false;
321 }
322 }
323
324 ?>
eZContentClass
Handles eZ Publish content classes.
Definition: ezcontentclass.php:20
eZContentClass\fetchByIdentifier
static fetchByIdentifier( $identifier, $asObject=true, $version=eZContentClass::VERSION_STATUS_DEFINED, $user_id=false, $parent_id=null)
Definition: ezcontentclass.php:1203
eZContentFunctions
Definition: ezcontentfunctions.php:12
eZContentFunctions\updateAndPublishObject
static updateAndPublishObject(eZContentObject $object, array $params)
Definition: ezcontentfunctions.php:227
eZContentFunctions\createAndPublishObject
static createAndPublishObject( $params)
Definition: ezcontentfunctions.php:88
eZContentLanguage\fetch
static fetch( $id)
Definition: ezcontentlanguage.php:251
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
eZContentObjectVersion
The class eZContentObjectVersion handles different versions of an content object.
Definition: ezcontentobjectversion.php:19
eZContentObjectVersion\STATUS_DRAFT
const STATUS_DRAFT
Definition: ezcontentobjectversion.php:29
eZContentObject
Definition: ezcontentobject.php:17
eZContentObject\store
store( $fieldFilters=null)
Definition: ezcontentobject.php:260
eZContentObject\createNewVersion
createNewVersion( $copyFromVersion=false, $versionCheck=true, $languageCode=false, $copyFromLanguageCode=false, $status=eZContentObjectVersion::STATUS_DRAFT)
Definition: ezcontentobject.php:1427
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDateTime\currentTimeStamp
static currentTimeStamp()
Definition: ezdatetime.php:203
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZModuleOperationInfo\STATUS_CONTINUE
const STATUS_CONTINUE
Definition: ezmoduleoperationinfo.php:25
eZNodeAssignment\create
static create( $parameters=array())
Definition: eznodeassignment.php:193
eZOperationHandler\execute
static execute( $moduleName, $operationName, $operationParameters, $lastTriggerName=null, $useTriggers=true)
Definition: ezoperationhandler.php:42
eZPersistentObject\setAttribute
setAttribute( $attr, $val)
Definition: ezpersistentobject.php:1374
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.