Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcontentobjecttrashnode.php
Go to the documentation of this file.
1 <?php
14 class eZContentObjectTrashNode extends eZContentObjectTreeNode
15 {
19 static function definition()
20 {
21 return array( 'fields' => array( 'node_id' => array( 'name' => 'NodeID',
22 'datatype' => 'integer',
23 'default' => 0,
24 'required' => true ),
25 'parent_node_id' => array( 'name' => 'ParentNodeID',
26 'datatype' => 'integer',
27 'default' => 0,
28 'required' => true ),
29 'main_node_id' => array( 'name' => 'MainNodeID',
30 'datatype' => 'integer',
31 'default' => 0,
32 'required' => true ),
33 'contentobject_id' => array( 'name' => 'ContentObjectID',
34 'datatype' => 'integer',
35 'default' => 0,
36 'required' => true,
37 'foreign_class' => 'eZContentObject',
38 'foreign_attribute' => 'id',
39 'multiplicity' => '1..*' ),
40 'contentobject_version' => array( 'name' => 'ContentObjectVersion',
41 'datatype' => 'integer',
42 'default' => 0,
43 'required' => true ),
44 'depth' => array( 'name' => 'Depth',
45 'datatype' => 'integer',
46 'default' => 0,
47 'required' => true ),
48 'sort_field' => array( 'name' => 'SortField',
49 'datatype' => 'integer',
50 'default' => 1,
51 'required' => true ),
52 'sort_order' => array( 'name' => 'SortOrder',
53 'datatype' => 'integer',
54 'default' => 1,
55 'required' => true ),
56 'priority' => array( 'name' => 'Priority',
57 'datatype' => 'integer',
58 'default' => 0,
59 'required' => true ),
60 'modified_subnode' => array( 'name' => 'ModifiedSubNode',
61 'datatype' => 'integer',
62 'default' => 0,
63 'required' => true ),
64 'path_string' => array( 'name' => 'PathString',
65 'datatype' => 'string',
66 'default' => '',
67 'required' => true ),
68 'path_identification_string' => array( 'name' => 'PathIdentificationString',
69 'datatype' => 'text',
70 'default' => '',
71 'required' => true ),
72 'remote_id' => array( 'name' => 'RemoteID',
73 'datatype' => 'string',
74 'default' => '',
75 'required' => true ),
76 'is_hidden' => array( 'name' => 'IsHidden',
77 'datatype' => 'integer',
78 'default' => 0,
79 'required' => true ),
80 'is_invisible' => array( 'name' => 'IsInvisible',
81 'datatype' => 'integer',
82 'default' => 0,
83 'required' => true ),
84 'trashed' => array( 'name' => 'Trashed',
85 'datatype' => 'integer',
86 'default' => 0,
87 'required' => true )
88 ),
89
90 'keys' => array( 'node_id' ),
91 'function_attributes' => array( // functional attributes derived from ezcontentobjecttreenode
92 'name' => 'getName',
93 'data_map' => 'dataMap',
94 'object' => 'object',
95 'contentobject_version_object' => 'contentObjectVersionObject',
96 'sort_array' => 'sortArray',
97 'can_read' => 'canRead',
98 'can_create' => 'canCreate',
99 'can_edit' => 'canEdit',
100 'can_remove' => 'canRemove',
101 'creator' => 'creator',
102 'path_array' => 'pathArray',
103 'parent' => 'fetchParent',
104 'class_identifier' => 'classIdentifier',
105 'class_name' => 'className',
106 // new functional attributes
107 'original_parent' => 'originalParent',
108 'original_parent_path_id_string' => 'originalParentPathIdentificationString'
109 ),
110 'class_name' => 'eZContentObjectTrashNode',
111 'name' => 'ezcontentobject_trash' );
112 }
113
120 static function createFromNode( $node )
121 {
122 $row = array( 'node_id' => $node->attribute( 'node_id' ),
123 'parent_node_id' => $node->attribute( 'parent_node_id' ),
124 'main_node_id' => $node->attribute( 'main_node_id' ),
125 'contentobject_id' => $node->attribute( 'contentobject_id' ),
126 'contentobject_version' => $node->attribute( 'contentobject_version' ),
127 'contentobject_is_published' => $node->attribute( 'contentobject_is_published' ),
128 'depth' => $node->attribute( 'depth' ),
129 'sort_field' => $node->attribute( 'sort_field' ),
130 'sort_order' => $node->attribute( 'sort_order' ),
131 'priority' => $node->attribute( 'priority' ),
132 'modified_subnode' => $node->attribute( 'modified_subnode' ),
133 'path_string' => $node->attribute( 'path_string' ),
134 'path_identification_string' => $node->attribute( 'path_identification_string' ),
135 'remote_id' => $node->attribute( 'remote_id' ),
136 'is_hidden' => $node->attribute( 'is_hidden' ),
137 'is_invisible' => $node->attribute( 'is_invisible' ),
138 'trashed' => time() );
139
140 $trashNode = new eZContentObjectTrashNode( $row );
141 return $trashNode;
142 }
143
151 function storeToTrash()
152 {
153 $this->store();
154
155 $db = eZDB::instance();
156 $db->begin();
157
159 $contentObject = $this->attribute( 'object' );
160 if ( $contentObject === null )
161 {
162 $db->commit();
163 return;
164 }
165 $offset = 0;
166 $limit = 20;
167 while (
168 $contentobjectAttributes = $contentObject->allContentObjectAttributes(
169 $contentObject->attribute( 'id' ), true,
170 array( 'limit' => $limit, 'offset' => $offset )
171 )
172 )
173 {
174 foreach ( $contentobjectAttributes as $contentobjectAttribute )
175 {
176 $dataType = $contentobjectAttribute->dataType();
177 if ( !$dataType )
178 continue;
179 $dataType->trashStoredObjectAttribute( $contentobjectAttribute );
180 }
181 $offset += $limit;
182 }
183
184 $db->commit();
185 }
186
193 static function purgeForObject( $contentObjectID )
194 {
195 if ( !is_numeric( $contentObjectID ) )
196 return false;
197 $db = eZDB::instance();
198 $db->begin();
199 $db->query( "DELETE FROM ezcontentobject_trash WHERE contentobject_id='$contentObjectID'" );
200 $db->commit();
201 }
202
212 static function trashList( $params = false, $asCount = false )
213 {
214 if ( $params === false )
215 {
216 $params = array( 'Offset' => false,
217 'Limit' => false,
218 'SortBy' => false,
219 'AttributeFilter' => false,
220 'Trashed' => false,
221 );
222 }
223
224 $offset = ( isset( $params['Offset'] ) && is_numeric( $params['Offset'] ) ) ? $params['Offset'] : false;
225 $limit = ( isset( $params['Limit'] ) && is_numeric( $params['Limit'] ) ) ? $params['Limit'] : false;
226 $asObject = ( isset( $params['AsObject'] ) ) ? $params['AsObject'] : true;
227 $objectNameFilter = ( isset( $params['ObjectNameFilter'] ) ) ? $params['ObjectNameFilter'] : false;
228 $sortBy = ( isset( $params['SortBy'] ) && is_array( $params['SortBy'] ) ) ? $params['SortBy'] : array( array( 'name' ) );
229 $trashed = ( isset( $params['Trashed'] ) && is_int( $params['Trashed'] ) ) ? " AND trashed <= {$params['Trashed']}" : '';
230
231 if ( $asCount )
232 {
233 $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( false );
234 }
235 else
236 {
237 $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $sortBy, 'ezcot' );
238 }
239
240 $attributeFilter = eZContentObjectTreeNode::createAttributeFilterSQLStrings( $params['AttributeFilter'], $sortingInfo );
241 if ( $attributeFilter === false )
242 {
243 return null;
244 }
245
246 $objectNameFilterSQL = eZContentObjectTreeNode::createObjectNameFilterConditionSQLString( $objectNameFilter );
247
248 $limitation = ( isset( $params['Limitation'] ) && is_array( $params['Limitation'] ) ) ? $params['Limitation']: false;
249 $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation );
250 $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList, 'ezcontentobject_trash', 'ezcot' );
251
252 if ( $asCount )
253 {
254 $query = "SELECT count(*) as count ";
255 }
256 else
257 {
258 $query = "SELECT
259 ezcontentobject.*,
260 ezcot.*,
261 ezcontentclass.serialized_name_list as class_serialized_name_list,
262 ezcontentclass.identifier as class_identifier,
263 ezcontentobject_name.name as name,
264 ezcontentobject_name.real_translation
265 $sortingInfo[attributeTargetSQL] ";
266 }
267 $query .= "FROM
268 ezcontentobject_trash ezcot
269 INNER JOIN ezcontentobject ON ezcot.contentobject_id = ezcontentobject.id
270 INNER JOIN ezcontentclass ON ezcontentclass.version = 0 AND ezcontentclass.id = ezcontentobject.contentclass_id
271 INNER JOIN ezcontentobject_name ON (
272 ezcot.contentobject_id = ezcontentobject_name.contentobject_id AND
273 ezcot.contentobject_version = ezcontentobject_name.content_version
274 )
275 $sortingInfo[attributeFromSQL]
276 $attributeFilter[from]
277 $sqlPermissionChecking[from]
278 WHERE
279 $sortingInfo[attributeWhereSQL]
280 $attributeFilter[where]
281 " . eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' ) . "
282 $sqlPermissionChecking[where]
283 $objectNameFilterSQL
284 AND " . eZContentLanguage::languagesSQLFilter( 'ezcontentobject' )
285 . $trashed;
286
287 if ( !$asCount && $sortingInfo['sortingFields'] && strlen( $sortingInfo['sortingFields'] ) > 5 )
288 $query .= " ORDER BY $sortingInfo[sortingFields]";
289
290 $db = eZDB::instance();
291 if ( !$offset && !$limit )
292 $trashRowsArray = $db->arrayQuery( $query );
293 else
294 $trashRowsArray = $db->arrayQuery( $query, array( 'offset' => $offset,
295 'limit' => $limit ) );
296
297 // cleanup temp tables
298 $db->dropTempTableList( $sqlPermissionChecking['temp_tables'] );
299
300 if ( $asCount )
301 {
302 return $trashRowsArray[0]['count'];
303 }
304 else if ( $asObject )
305 {
306 $retTrashNodes = array();
307 foreach ( array_keys( $trashRowsArray ) as $key )
308 {
309 $trashRow =& $trashRowsArray[ $key ];
310 $retTrashNodes[] = new eZContentObjectTrashNode( $trashRow );
311 }
312 return $retTrashNodes;
313 }
314 else
315 {
316 return $trashRowsArray;
317 }
318 }
319
326 static function trashListCount( $params = false )
327 {
328 return eZContentObjectTrashNode::trashList( $params, true );
329 }
330
337 function originalParent()
338 {
339 if ( $this->originalNodeParent === 0 )
340 {
341 $this->originalNodeParent = eZContentObjectTreeNode::fetch( $this->attribute( 'parent_node_id' ) );
342 if ( $this->originalNodeParent === null )
343 return false;
344 }
345
346 if ( $this->pathArray === 0 && $this->originalNodeParent instanceof eZContentObjectTreeNode )
347 $this->pathArray = $this->attribute( 'path_array' );
348
349 if ( $this->pathArray && count( $this->pathArray ) > 0 )
350 {
351 $realParentPathArray = $this->originalNodeParent->attribute( 'path_array' );
352 $realParentPath = implode( '/', $realParentPathArray );
353
354 $thisParentPathArray = array_slice( $this->pathArray, 0, -1 );
355 $thisParentPath = implode( '/', $thisParentPathArray );
356
357 if ( $thisParentPath == $realParentPath )
358 {
359 // original parent exists at the same placement
360 return $this->originalNodeParent;
361 }
362 }
363 // original parent was moved or deleted
364 return null;
365 }
366
374 function originalParentPathIdentificationString()
375 {
376 $originalParent = $this->originalParent();
377 if ( $originalParent )
378 {
379 return $originalParent->attribute( 'path_identification_string' );
380 }
381 // original parent was moved or does not exist, return original parent path
382 $path = $this->attribute( 'path_identification_string' );
383 $path = substr( $path, 0, strrpos( $path, '/') );
384 return $path;
385 }
386
395 public static function fetchByContentObjectID( $contentObjectID, $asObject = true, $contentObjectVersion = false )
396 {
397 $conds = array( 'contentobject_id' => $contentObjectID );
398 if ( $contentObjectVersion !== false )
399 {
400 $conds['contentobject_version'] = $contentObjectVersion;
401 }
402
403 return self::fetchObject(
404 self::definition(),
405 null,
406 $conds,
407 $asObject
408 );
409 }
410
414 protected $originalNodeParent = 0;
415
419 protected $pathArray = 0;
420 }
421
422 ?>
eZContentLanguage\sqlFilter
static sqlFilter( $languageTable, $languageListTable=null, $languageAttributeName='language_id', $languageListAttributeName='language_mask', $lang=false)
Definition: ezcontentlanguage.php:692
eZContentLanguage\languagesSQLFilter
static languagesSQLFilter( $languageListTable, $languageListAttributeName='language_mask')
Definition: ezcontentlanguage.php:659
eZContentObjectTrashNode
Definition: ezcontentobjecttrashnode.php:15
eZContentObjectTrashNode\purgeForObject
static purgeForObject( $contentObjectID)
Definition: ezcontentobjecttrashnode.php:193
eZContentObjectTrashNode\definition
static definition()
Definition: ezcontentobjecttrashnode.php:19
eZContentObjectTrashNode\createFromNode
static createFromNode( $node)
Definition: ezcontentobjecttrashnode.php:120
eZContentObjectTrashNode\$originalNodeParent
$originalNodeParent
Definition: ezcontentobjecttrashnode.php:414
eZContentObjectTrashNode\originalParent
originalParent()
Definition: ezcontentobjecttrashnode.php:337
eZContentObjectTrashNode\trashListCount
static trashListCount( $params=false)
Definition: ezcontentobjecttrashnode.php:326
eZContentObjectTrashNode\originalParentPathIdentificationString
originalParentPathIdentificationString()
Definition: ezcontentobjecttrashnode.php:374
eZContentObjectTrashNode\trashList
static trashList( $params=false, $asCount=false)
Definition: ezcontentobjecttrashnode.php:212
eZContentObjectTrashNode\fetchByContentObjectID
static fetchByContentObjectID( $contentObjectID, $asObject=true, $contentObjectVersion=false)
Definition: ezcontentobjecttrashnode.php:395
eZContentObjectTrashNode\$pathArray
$pathArray
Definition: ezcontentobjecttrashnode.php:419
eZContentObjectTreeNode
Definition: ezcontentobjecttreenode.php:17
eZContentObjectTreeNode\store
store( $fieldFilters=null)
Definition: ezcontentobjecttreenode.php:5737
eZContentObjectTreeNode\createSortingSQLStrings
static createSortingSQLStrings( $sortList, $treeTableName='ezcontentobject_tree', $allowCustomColumns=false)
Definition: ezcontentobjecttreenode.php:560
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
eZContentObjectTreeNode\createObjectNameFilterConditionSQLString
static createObjectNameFilterConditionSQLString( $filter)
Definition: ezcontentobjecttreenode.php:945
eZContentObjectTreeNode\getLimitationList
static getLimitationList(&$limitation)
Definition: ezcontentobjecttreenode.php:1895
eZContentObjectTreeNode\createPermissionCheckingSQL
static createPermissionCheckingSQL( $limitationList, $treeTableName='ezcontentobject_tree', $tableAliasName='ezcontentobject_tree')
Definition: ezcontentobjecttreenode.php:1662
eZContentObjectTreeNode\createAttributeFilterSQLStrings
static createAttributeFilterSQLStrings(&$attributeFilter, &$sortingInfo=array( 'sortCount'=> 0, 'attributeJoinCount'=> 0), $language=false)
Definition: ezcontentobjecttreenode.php:973
eZContentObjectTreeNode\pathArray
pathArray()
Definition: ezcontentobjecttreenode.php:3207
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.