Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcontentobject.php
Go to the documentation of this file.
1 <?php
16 class eZContentObject extends eZPersistentObject
17 {
18 public $ContentObjectAttributeArray;
19 const STATUS_DRAFT = 0;
20 const STATUS_PUBLISHED = 1;
21 const STATUS_ARCHIVED = 2;
22
23 const PACKAGE_ERROR_NO_CLASS = 1;
24 const PACKAGE_ERROR_EXISTS = 2;
25 const PACKAGE_ERROR_NODE_EXISTS = 3;
26 const PACKAGE_ERROR_MODIFIED = 101;
27 const PACKAGE_ERROR_HAS_CHILDREN = 102;
28
29 const PACKAGE_REPLACE = 1;
30 const PACKAGE_SKIP = 2;
31 const PACKAGE_NEW = 3;
32 const PACKAGE_UPDATE = 6;
33
34 const PACKAGE_DELETE = 4;
35 const PACKAGE_KEEP = 5;
36
37 const RELATION_COMMON = 1;
38 const RELATION_EMBED = 2;
39 const RELATION_LINK = 4;
40 const RELATION_ATTRIBUTE = 8;
41
49 public function __construct( $row )
50 {
51 parent::__construct( $row );
52 $this->ClassIdentifier = false;
53 if ( isset( $row['contentclass_identifier'] ) )
54 $this->ClassIdentifier = $row['contentclass_identifier'];
55 if ( isset( $row['class_identifier'] ) )
56 $this->ClassIdentifier = $row['class_identifier'];
57 $this->ClassName = false;
58 // Depending on how the information is retrieved, the "serialized_name_list" is sometimes available in "class_serialized_name_list" key
59 if ( isset( $row['class_serialized_name_list'] ) )
60 $row['serialized_name_list'] = $row['class_serialized_name_list'];
61 // Depending on how the information is retrieved, the "contentclass_name" is sometimes available in "class_name" key
62 if ( isset( $row['class_name'] ) )
63 $row['contentclass_name'] = $row['class_name'];
64 if ( isset( $row['contentclass_name'] ) )
65 $this->ClassName = $row['contentclass_name'];
66 if ( isset( $row['serialized_name_list'] ) )
67 $this->ClassName = eZContentClass::nameFromSerializedString( $row['serialized_name_list'] );
68
69 $this->CurrentLanguage = false;
70 if ( isset( $row['content_translation'] ) )
71 {
72 $this->CurrentLanguage = $row['content_translation'];
73 }
74 else if ( isset( $row['real_translation'] ) )
75 {
76 $this->CurrentLanguage = $row['real_translation'];
77 }
78 else if ( isset( $row['language_mask'] ) )
79 {
80 $topPriorityLanguage = eZContentLanguage::topPriorityLanguageByMask( $row['language_mask'] );
81 if ( $topPriorityLanguage )
82 {
83 $this->CurrentLanguage = $topPriorityLanguage->attribute( 'locale' );
84 }
85 }
86
87 // Initialize the permission array cache
88 $this->Permissions = array();
89 }
90
95 function eZContentObject( $row )
96 {
97 self::__construct( $row );
98 }
99
100 static function definition()
101 {
102 static $definition = array( "fields" => array( "id" => array( 'name' => 'ID',
103 'datatype' => 'integer',
104 'default' => 0,
105 'required' => true ),
106 "section_id" => array( 'name' => "SectionID",
107 'datatype' => 'integer',
108 'default' => 0,
109 'required' => true,
110 'foreign_class' => 'eZSection',
111 'foreign_attribute' => 'id',
112 'multiplicity' => '1..*' ),
113 "owner_id" => array( 'name' => "OwnerID",
114 'datatype' => 'integer',
115 'default' => 0,
116 'required' => true,
117 'foreign_class' => 'eZUser',
118 'foreign_attribute' => 'contentobject_id',
119 'multiplicity' => '1..*'),
120 "contentclass_id" => array( 'name' => "ClassID",
121 'datatype' => 'integer',
122 'default' => 0,
123 'required' => true,
124 'foreign_class' => 'eZContentClass',
125 'foreign_attribute' => 'id',
126 'multiplicity' => '1..*' ),
127 "name" => array( 'name' => "Name",
128 'datatype' => 'string',
129 'default' => '',
130 'required' => true ),
131 "published" => array( 'name' => "Published",
132 'datatype' => 'integer',
133 'default' => 0,
134 'required' => true ),
135 "modified" => array( 'name' => "Modified",
136 'datatype' => 'integer',
137 'default' => 0,
138 'required' => true ),
139 "current_version" => array( 'name' => "CurrentVersion",
140 'datatype' => 'integer',
141 'default' => 0,
142 'required' => true ),
143 "status" => array( 'name' => "Status",
144 'datatype' => 'integer',
145 'default' => 0,
146 'required' => true ),
147 'remote_id' => array( 'name' => "RemoteID",
148 'datatype' => 'string',
149 'default' => '',
150 'required' => true ),
151 'language_mask' => array( 'name' => 'LanguageMask',
152 'datatype' => 'integer',
153 'default' => 0,
154 'required' => true ),
155 'initial_language_id' => array( 'name' => 'InitialLanguageID',
156 'datatype' => 'integer',
157 'default' => 0,
158 'required' => true,
159 'foreign_class' => 'eZContentLanguage',
160 'foreign_attribute' => 'id',
161 'multiplicity' => '1..*' ) ),
162 "keys" => array( "id" ),
163 "function_attributes" => array( "current" => "currentVersion",
164 "published_version" => "publishedVersion",
165 'versions' => 'versions',
166 'author_array' => 'authorArray',
167 "class_name" => "className",
168 "content_class" => "contentClass",
169 "contentobject_attributes" => "contentObjectAttributes",
170 "owner" => "owner",
171 "related_contentobject_array" => "relatedContentObjectList",
172 "related_contentobject_count" => "relatedContentObjectCount",
173 'reverse_related_contentobject_array' => 'reverseRelatedObjectList',
174 'reverse_related_contentobject_count' => 'reverseRelatedObjectCount',
175 "linked_contentobject_array" => "linkedContentObjectList",
176 "linked_contentobject_count" => "linkedContentObjectCount",
177 'reverse_linked_contentobject_array' => 'reverseLinkedObjectList',
178 'reverse_linked_contentobject_count' => 'reverseLinkedObjectCount',
179 "embedded_contentobject_array" => "embeddedContentObjectList",
180 "embedded_contentobject_count" => "embeddedContentObjectCount",
181 'reverse_embedded_contentobject_array' => 'reverseEmbeddedObjectList',
182 'reverse_embedded_contentobject_count' => 'reverseEmbeddedObjectCount',
183 "can_read" => "canRead",
184 "can_pdf" => "canPdf",
185 "can_diff" => "canDiff",
186 "can_create" => "canCreate",
187 "can_create_class_list" => "canCreateClassList",
188 "can_edit" => "canEdit",
189 "can_translate" => "canTranslate",
190 "can_remove" => "canRemove",
191 "can_move" => "canMoveFrom",
192 "can_move_from" => "canMoveFrom",
193 'can_view_embed' => 'canViewEmbed',
194 "data_map" => "dataMap",
195 "grouped_data_map" => "groupedDataMap",
196 "main_parent_node_id" => "mainParentNodeID",
197 "assigned_nodes" => "assignedNodes",
198 "visible_nodes" => "visibleNodes",
199 "has_visible_node" => "hasVisibleNode",
200 "parent_nodes" => "parentNodeIDArray",
201 "main_node_id" => "mainNodeID",
202 "main_node" => "mainNode",
203 "default_language" => "defaultLanguage",
204 "content_action_list" => "contentActionList",
205 "class_identifier" => "contentClassIdentifier",
206 'class_group_id_list' => 'contentClassGroupIDList',
207 'name' => 'name',
208 'match_ingroup_id_list' => 'matchIngroupIDList',
209 'remote_id' => 'remoteID',
210 'current_language' => 'currentLanguage',
211 'current_language_object' => 'currentLanguageObject',
212 'initial_language' => 'initialLanguage',
213 'initial_language_code' => 'initialLanguageCode',
214 'available_languages' => 'availableLanguages',
215 'language_codes' => 'availableLanguages',
216 'language_js_array' => 'availableLanguagesJsArray',
217 'languages' => 'languages',
218 'all_languages' => 'allLanguages',
219 'can_edit_languages' => 'canEditLanguages',
220 'can_create_languages' => 'canCreateLanguages',
221 'always_available' => 'isAlwaysAvailable',
222 'allowed_assign_section_list' => 'allowedAssignSectionList',
223 'allowed_assign_state_id_list' => 'allowedAssignStateIDList',
224 'allowed_assign_state_list' => 'allowedAssignStateList',
225 'state_id_array' => 'stateIDArray',
226 'state_identifier_array' => 'stateIdentifierArray',
227 'section_identifier' => 'sectionIdentifier' ),
228 "increment_key" => "id",
229 "class_name" => "eZContentObject",
230 "sort" => array( "id" => "asc" ),
231 "name" => "ezcontentobject" );
232 return $definition;
233 }
234
240 function matchIngroupIDList()
241 {
242 $contentINI = eZINI::instance( 'content.ini' );
243 $inList = false;
244 if( $contentINI->variable( 'ContentOverrideSettings', 'EnableClassGroupOverride' ) == 'true' )
245 {
246 $contentClass = $this->contentClass();
247 $inList = $contentClass->attribute( 'ingroup_id_list' );
248 }
249 return $inList;
250 }
251
260 function store( $fieldFilters = null )
261 {
262 // Unset the cache
263 global $eZContentObjectContentObjectCache;
264 unset( $eZContentObjectContentObjectCache[$this->ID] );
265 global $eZContentObjectDataMapCache;
266 unset( $eZContentObjectDataMapCache[$this->ID] );
267 global $eZContentObjectVersionCache;
268 unset( $eZContentObjectVersionCache[$this->ID] );
269
270 $db = eZDB::instance();
271 $db->begin();
272 $this->storeNodeModified();
273 parent::store( $fieldFilters );
274 $db->commit();
275 }
276
284 static function clearCache( $idArray = array() )
285 {
286 if ( is_numeric( $idArray ) )
287 $idArray = array( $idArray );
288
289 // clear in-memory cache for all objects
290 if ( count( $idArray ) == 0 )
291 {
292 unset( $GLOBALS['eZContentObjectContentObjectCache'] );
293 unset( $GLOBALS['eZContentObjectDataMapCache'] );
294 unset( $GLOBALS['eZContentObjectVersionCache'] );
295
296 return;
297 }
298
299 // clear in-memory cache for specified object(s)
300 global $eZContentObjectContentObjectCache;
301 global $eZContentObjectDataMapCache;
302 global $eZContentObjectVersionCache;
303 foreach ( $idArray as $objectID )
304 {
305 unset( $eZContentObjectContentObjectCache[$objectID] );
306 unset( $eZContentObjectDataMapCache[$objectID] );
307 unset( $eZContentObjectVersionCache[$objectID] );
308 }
309 }
310
317 function storeNodeModified()
318 {
319 if ( is_numeric( $this->ID ) )
320 {
321 $nodeArray = $this->assignedNodes();
322
323 $db = eZDB::instance();
324 $db->begin();
325 foreach ( array_keys( $nodeArray ) as $key )
326 {
327 $nodeArray[$key]->updateAndStoreModified();
328 }
329 $db->commit();
330 }
331 }
332
340 function name( $version = false , $lang = false )
341 {
342 // if the object id is null, we can't read data from the database
343 // and return the locally known name
344 if ( $this->attribute( 'id' ) === null )
345 {
346 return $this->Name;
347 }
348 if ( !$version )
349 {
350 $version = $this->attribute( 'current_version' );
351 }
352 if ( !$lang && $this->CurrentLanguage )
353 {
354 $lang = $this->CurrentLanguage;
355 }
356
357 return $this->versionLanguageName( $version, $lang );
358 }
359
365 function names()
366 {
367 $version = $this->attribute( 'current_version' );
368 $id = $this->attribute( 'id' );
369
370 $db = eZDB::instance();
371 $rows = $db->arrayQuery( "SELECT name, real_translation FROM ezcontentobject_name WHERE contentobject_id = '$id' AND content_version='$version'" );
372 $names = array();
373 foreach ( $rows as $row )
374 {
375 $names[$row['real_translation']] = $row['name'];
376 }
377
378 return $names;
379 }
380
388 function versionLanguageName( $version, $lang = false )
389 {
390 $name = false;
391 if ( !$version > 0 )
392 {
393 eZDebug::writeNotice( "There is no object name for version($version) of the content object ($contentObjectID) in language($lang)", __METHOD__ );
394 return $name;
395 }
396 $db = eZDB::instance();
397 $contentObjectID = $this->attribute( 'id' );
398 if ( !$lang )
399 {
400 // If $lang not given we will use the initial language of the object
401 $query = "SELECT initial_language_id FROM ezcontentobject WHERE id='$contentObjectID'";
402 $rows = $db->arrayQuery( $query );
403 if ( $rows )
404 {
405 $languageID = $rows[0]['initial_language_id'];
406 $language = eZContentLanguage::fetch( $languageID );
407 if ( $language )
408 {
409 $lang = $language->attribute( 'locale' );
410 }
411 else
412 {
413 return $name;
414 }
415 }
416 else
417 {
418 return $name;
419 }
420 }
421 $lang = $db->escapeString( $lang );
422 $version = (int) $version;
423
424 $languageID = $this->attribute( 'initial_language_id' );
425 if ( $this->attribute( 'always_available' ) )
426 {
427 $languageID = (int) $languageID | 1;
428 }
429
430 $query= "SELECT name, content_translation
431 FROM ezcontentobject_name
432 WHERE contentobject_id = '$contentObjectID'
433 AND content_version = '$version'
434 AND ( content_translation = '$lang' OR language_id = '$languageID' )";
435 $result = $db->arrayQuery( $query );
436
437 $resCount = count( $result );
438 if( $resCount < 1 )
439 {
440 eZDebug::writeNotice( "There is no object name for version($version) of the content object ($contentObjectID) in language($lang)", __METHOD__ );
441 }
442 else if( $resCount > 1 )
443 {
444 // we have name in requested language => find and return it
445 foreach( $result as $row )
446 {
447 if( $row['content_translation'] == $lang )
448 {
449 $name = $row['name'];
450 break;
451 }
452 }
453 }
454 else
455 {
456 // we don't have name in requested language(or requested language is the same as initial language) => use name in initial language
457 $name = $result[0]['name'];
458 }
459
460 return $name;
461 }
462
468 function setCachedName( $name )
469 {
470 $this->Name = $name;
471 }
472
483 function setName( $objectName, $versionNum = false, $languageCode = false )
484 {
485 $initialLanguageCode = false;
486 if ( $initialLanguage = $this->initialLanguage() )
487 {
488 $initialLanguageCode = $initialLanguage->attribute( 'locale' );
489 }
490 $db = eZDB::instance();
491
492 if ( $languageCode == false )
493 {
494 $languageCode = $initialLanguageCode;
495 }
496 $languageCode = $db->escapeString( $languageCode );
497 if ( $languageCode == $initialLanguageCode )
498 {
499 $this->Name = $objectName;
500 }
501
502 if ( !$versionNum )
503 {
504 $versionNum = $this->attribute( 'current_version' );
505 }
506 $objectID =(int) $this->attribute( 'id' );
507 $versionNum =(int) $versionNum;
508
509 $languageID =(int) eZContentLanguage::idByLocale( $languageCode );
510
511 $objectName = $db->escapeString( $objectName );
512
513 $db->begin();
514
515 // Check if name is already set before setting/changing it.
516 // This helps to avoid deadlocks in mysql: a pair of DELETE/INSERT might cause deadlock here
517 // in case of concurrent execution.
518 $rows = $db->arrayQuery( "SELECT COUNT(*) AS count FROM ezcontentobject_name WHERE contentobject_id = '$objectID'
519 AND content_version = '$versionNum' AND content_translation ='$languageCode'" );
520 if ( $rows[0]['count'] )
521 {
522 $db->query( "UPDATE ezcontentobject_name SET name='$objectName'
523 WHERE
524 contentobject_id = '$objectID' AND
525 content_version = '$versionNum' AND
526 content_translation ='$languageCode'" );
527 }
528 else
529 {
530 $db->query( "INSERT INTO ezcontentobject_name( contentobject_id,
531 name,
532 content_version,
533 content_translation,
534 real_translation,
535 language_id )
536 VALUES( '$objectID',
537 '$objectName',
538 '$versionNum',
539 '$languageCode',
540 '$languageCode',
541 '$languageID' )" );
542 }
543
544 $db->commit();
545 }
546
552 function dataMap()
553 {
554 return $this->fetchDataMap();
555 }
556
565 public function groupedDataMap()
566 {
567 return self::createGroupedDataMap( $this->fetchDataMap() );
568 }
569
579 public static function createGroupedDataMap( $contentObjectAttributes )
580 {
581 $groupedDataMap = array();
582 $contentINI = eZINI::instance( 'content.ini' );
583 $categorys = $contentINI->variable( 'ClassAttributeSettings', 'CategoryList' );
584 $defaultCategory = $contentINI->variable( 'ClassAttributeSettings', 'DefaultCategory' );
585 foreach( $contentObjectAttributes as $attribute )
586 {
587 $classAttribute = $attribute->contentClassAttribute();
588 $attributeCategory = $classAttribute->attribute('category');
589 $attributeIdentifier = $classAttribute->attribute( 'identifier' );
590 if ( !isset( $categorys[ $attributeCategory ] ) || !$attributeCategory )
591 $attributeCategory = $defaultCategory;
592
593 if ( !isset( $groupedDataMap[ $attributeCategory ] ) )
594 $groupedDataMap[ $attributeCategory ] = array();
595
596 $groupedDataMap[ $attributeCategory ][$attributeIdentifier] = $attribute;
597
598 }
599 return $groupedDataMap;
600 }
601
609 function fetchDataMap( $version = false, $language = false )
610 {
611 // Global variable to cache datamaps
612 global $eZContentObjectDataMapCache;
613
614 if ( $version == false )
615 $version = $this->attribute( 'current_version' );
616
617 if ( $language == false )
618 {
619 $language = $this->CurrentLanguage;
620 }
621
622 if ( !$language || !isset( $eZContentObjectDataMapCache[$this->ID][$version][$language] ) )
623 {
624 $data = $this->contentObjectAttributes( true, $version, $language );
625
626 if ( !$language )
627 {
628 $language = $this->CurrentLanguage;
629 }
630
631 // Store the attributes for later use
632 $this->ContentObjectAttributeArray[$version][$language] = $data;
633 $eZContentObjectDataMapCache[$this->ID][$version][$language] = $data;
634 }
635 else
636 {
637 $data = $eZContentObjectDataMapCache[$this->ID][$version][$language];
638 }
639
640 if ( !isset( $this->DataMap[$version][$language] ) )
641 {
642 $ret = array();
643 /* @var eZContentObjectAttribute[] $data */
644 foreach( $data as $key => $item )
645 {
646 $identifier = $item->contentClassAttributeIdentifier();
647 $ret[$identifier] = $data[$key];
648 }
649 $this->DataMap[$version][$language] = $ret;
650 }
651 else
652 {
653 $ret = $this->DataMap[$version][$language];
654 }
655 return $ret;
656 }
657
663 function resetDataMap()
664 {
665 $this->ContentObjectAttributeArray = array();
666 $this->ContentObjectAttributes = array();
667 $this->DataMap = array();
668 return $this->DataMap;
669 }
670
681 function fetchAttributesByIdentifier( $identifierArray, $version = false, $languageArray = false, $asObject = true )
682 {
683 if ( count( $identifierArray ) === 0 )
684 {
685 return null;
686 }
687
688 $db = eZDB::instance();
689
690 $identifierQuotedString = array();
691 foreach ( $identifierArray as $identifier )
692 {
693 $identifierQuotedString[] = "'$identifier'";
694 }
695
696 if ( !$version or !is_numeric( $version ) )
697 {
698 $version = $this->CurrentVersion;
699 }
700
701 if ( is_array( $languageArray ) )
702 {
703 $langCodeQuotedString = array();
704 foreach ( $languageArray as $langCode )
705 {
706 if ( is_string( $langCode ) )
707 $langCodeQuotedString[] = "'$langCode'";
708 }
709
710 if ( !empty( $langCodeQuotedString ) )
711 {
712 $languageText = "AND ";
713 $languageText .= $db->generateSQLINStatement( $langCodeQuotedString, 'ezcontentobject_attribute.language_code' );
714 }
715 }
716
717 if ( !isset( $languageText ) )
718 {
719 $languageText = "AND " . eZContentLanguage::sqlFilter( 'ezcontentobject_attribute', 'ezcontentobject_version' );
720 }
721
722 $versionText = "AND ezcontentobject_attribute.version = '$version'";
723
724 $query = "SELECT ezcontentobject_attribute.*, ezcontentclass_attribute.identifier as identifier
725 FROM ezcontentobject_attribute, ezcontentclass_attribute, ezcontentobject_version
726 WHERE
727 ezcontentclass_attribute.version = ". eZContentClass::VERSION_STATUS_DEFINED . " AND
728 ezcontentclass_attribute.id = ezcontentobject_attribute.contentclassattribute_id AND
729 ezcontentobject_version.contentobject_id = {$this->ID} AND
730 ezcontentobject_version.version = {$version} AND
731 ezcontentobject_attribute.contentobject_id = {$this->ID}
732
733 {$languageText}
734
735 {$versionText}
736
737 AND
738 ";
739
740 $query .= $db->generateSQLINStatement( $identifierQuotedString, 'identifier' );
741
742 $rows = $db->arrayQuery( $query );
743
744 if ( count( $rows ) > 0 )
745 {
746 if ( $asObject )
747 {
748 $returnArray = array();
749 foreach( $rows as $row )
750 {
751 $returnArray[$row['id']] = new eZContentObjectAttribute( $row );
752 }
753 return $returnArray;
754 }
755 else
756 {
757 return $rows;
758 }
759 }
760 return null;
761 }
762
768 function owner()
769 {
770 if ( $this->OwnerID != 0 )
771 {
772 return eZContentObject::fetch( $this->OwnerID );
773 }
774 return null;
775 }
776
782 function contentClassGroupIDList()
783 {
784 $contentClass = $this->contentClass();
785 return $contentClass->attribute( 'ingroup_id_list' );
786 }
787
795 function contentClassIdentifier()
796 {
797 if ( !is_numeric( $this->ClassID ) )
798 {
799 $retValue = null;
800 return $retValue;
801 }
802
803 if ( $this->ClassIdentifier !== false )
804 return $this->ClassIdentifier;
805
806 $this->ClassIdentifier = eZContentClass::classIdentifierByID( $this->ClassID );
807
808 return $this->ClassIdentifier;
809 }
810
816 function contentClass()
817 {
818 if ( !is_numeric( $this->ClassID ) )
819 {
820 $retValue = null;
821 return $retValue;
822 }
823
824 return eZContentClass::fetch( $this->ClassID );
825 }
826
832 function remoteID()
833 {
834 $remoteID = $this->attribute( 'remote_id', true );
835
836 if ( !$remoteID )
837 {
838 $this->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'object' ) );
839 if ( $this->attribute( 'id' ) !== null )
840 $this->sync( array( 'remote_id' ) );
841 $remoteID = $this->attribute( 'remote_id', true );
842 }
843
844 return $remoteID;
845 }
846
852 function mainParentNodeID()
853 {
854 $list = eZContentObjectTreeNode::getParentNodeIdListByContentObjectID( $this->ID, false, true );
855 return isset( $list[0] ) ? $list[0] : null;
856 }
857
865 static function fetchByRemoteID( $remoteID, $asObject = true )
866 {
867 $db = eZDB::instance();
868 $remoteID =$db->escapeString( $remoteID );
869 $resultArray = $db->arrayQuery( 'SELECT id FROM ezcontentobject WHERE remote_id=\'' . $remoteID . '\'' );
870 if ( count( $resultArray ) != 1 )
871 $object = null;
872 else
873 $object = eZContentObject::fetch( $resultArray[0]['id'], $asObject );
874 return $object;
875 }
876
885 static function fetch( $id, $asObject = true )
886 {
887 if ( is_array( $id ) )
888 {
889 $id = '';
890 }
891
892 global $eZContentObjectContentObjectCache;
893
894 // If the object given by its id is not cached or should be returned as array
895 // then we fetch it from the DB (objects are always cached as arrays).
896 if ( !isset( $eZContentObjectContentObjectCache[$id] ) or $asObject === false )
897 {
898 $db = eZDB::instance();
899
900 $resArray = $db->arrayQuery( eZContentObject::createFetchSQLString( $id ) );
901
902 $objectArray = array();
903 if ( count( $resArray ) == 1 && $resArray !== false )
904 {
905 $objectArray = $resArray[0];
906 }
907 else
908 {
909 eZDebug::writeError( "Object not found ($id)", __METHOD__ );
910 $retValue = null;
911 return $retValue;
912 }
913
914 if ( $asObject )
915 {
916 $obj = new eZContentObject( $objectArray );
917 $eZContentObjectContentObjectCache[$id] = $obj;
918 }
919 else
920 {
921 return $objectArray;
922 }
923
924 return $obj;
925 }
926 else
927 {
928 return $eZContentObjectContentObjectCache[$id];
929 }
930 }
931
943 static function fetchForUpdate( $id, $asObject = true )
944 {
945 global $eZContentObjectContentObjectCache;
946
947 $db = eZDB::instance();
948 $id = (int) $id;
949
950 if ( $db->DatabaseName() === 'sqlite' )
951 {
952 // Select for update, to lock the row
953 $resArray = $db->arrayQuery( "SELECT * FROM ezcontentobject WHERE id='$id'" );
954 }
955 else
956 {
957 // Select for update, to lock the row
958 $resArray = $db->arrayQuery( "SELECT * FROM ezcontentobject WHERE id='$id' FOR UPDATE" );
959 }
960
961 if ( !is_array( $resArray ) || count( $resArray ) !== 1 )
962 {
963 eZDebug::writeError( "Object not found ($id)", __METHOD__ );
964 return null;
965 }
966
967 $objectArray = $resArray[0];
968 $classId = $objectArray['contentclass_id'];
969 $contentClassResArray = $db->arrayQuery(
970 "SELECT
971 ezcontentclass.serialized_name_list as serialized_name_list,
972 ezcontentclass.identifier as contentclass_identifier,
973 ezcontentclass.is_container as is_container
974 FROM
975 ezcontentclass
976 WHERE
977 ezcontentclass.id='$classId' AND
978 ezcontentclass.version=0"
979 );
980 $objectArray = array_merge($objectArray, $contentClassResArray[0]);
981
982 if ( !$asObject )
983 {
984 return $objectArray;
985 }
986
987 $obj = new eZContentObject( $objectArray );
988 $eZContentObjectContentObjectCache[$id] = $obj;
989
990 return $obj;
991 }
992
999 static function exists( $id )
1000 {
1001 global $eZContentObjectContentObjectCache;
1002
1003 // Check the global cache
1004 if ( isset( $eZContentObjectContentObjectCache[$id] ) )
1005 return true;
1006
1007 // If the object is not cached we need to check the DB
1008 $db = eZDB::instance();
1009
1010 $resArray = $db->arrayQuery( eZContentObject::createFetchSQLString( $id ) );
1011
1012 if ( $resArray !== false and count( $resArray ) == 1 )
1013 {
1014 return true;
1015 }
1016
1017 return false;
1018
1019 }
1020
1027 static function createFetchSQLString( $id )
1028 {
1029 $id = (int) $id;
1030
1031 $fetchSQLString = "SELECT ezcontentobject.*,
1032 ezcontentclass.serialized_name_list as serialized_name_list,
1033 ezcontentclass.identifier as contentclass_identifier,
1034 ezcontentclass.is_container as is_container
1035 FROM
1036 ezcontentobject,
1037 ezcontentclass
1038 WHERE
1039 ezcontentobject.id='$id' AND
1040 ezcontentclass.id = ezcontentobject.contentclass_id AND
1041 ezcontentclass.version=0";
1042
1043 return $fetchSQLString;
1044 }
1045
1055 static function createFilterByVisibilitySQLString( $IgnoreVisibility = false, $ezcontentobjectTable = 'ezcontentobject' )
1056 {
1057 if ( $IgnoreVisibility )
1058 return '';
1059 return " AND ( SELECT MIN( ezct.is_invisible ) FROM ezcontentobject_tree ezct WHERE ezct.contentobject_id = $ezcontentobjectTable.id ) = 0 ";
1060 }
1061
1072 static function fetchByNodeID( $nodeID, $asObject = true )
1073 {
1074 global $eZContentObjectContentObjectCache;
1075 $resultAsArray = is_array( $nodeID );
1076 $nodeID = (array)$nodeID;
1077
1078 $db = eZDB::instance();
1079
1080 $resArray = $db->arrayQuery(
1081 "SELECT co.*, con.name as name, con.real_translation, cot.node_id
1082 FROM ezcontentobject co
1083 JOIN ezcontentobject_tree cot ON co.id = cot.contentobject_id AND co.current_version = cot.contentobject_version
1084 JOIN ezcontentobject_name con ON co.id = con.contentobject_id AND co.current_version = con.content_version
1085 WHERE " .
1086 $db->generateSQLINStatement( $nodeID, 'cot.node_id', false, true, 'int' ) . " AND " .
1087 eZContentLanguage::sqlFilter( 'con', 'co' )
1088 );
1089
1090 if ( $resArray === false || empty( $resArray ) )
1091 {
1092 eZDebug::writeError( 'A problem occured while fetching objects with following NodeIDs : ' . implode( ', ', $nodeID ), __METHOD__ );
1093 return $resultAsArray ? array() : null;
1094 }
1095
1096 $objectArray = array();
1097 if ( $asObject )
1098 {
1099 foreach ( $resArray as $res )
1100 {
1101 $objectArray[$res['node_id']] = $eZContentObjectContentObjectCache[$res['id']] = new self( $res );
1102 }
1103 }
1104 else
1105 {
1106 foreach ( $resArray as $res )
1107 {
1108 $objectArray[$res['node_id']] = $res;
1109 }
1110 }
1111
1112 if ( !$resultAsArray )
1113 return $objectArray[$res['node_id']];
1114
1115 return $objectArray;
1116 }
1117
1132 static function fetchIDArray( $idArray, $asObject = true , $lang = false )
1133 {
1134 global $eZContentObjectContentObjectCache;
1135
1136 $db = eZDB::instance();
1137
1138 $resRowArray = $db->arrayQuery(
1139 "SELECT ezcontentclass.serialized_name_list as class_serialized_name_list, ezcontentobject.*, ezcontentobject_name.name as name, ezcontentobject_name.real_translation
1140 FROM
1141 ezcontentclass,
1142 ezcontentobject,
1143 ezcontentobject_name
1144 WHERE
1145 ezcontentclass.id=ezcontentobject.contentclass_id AND " .
1146 // All elements from $idArray should be casted to (int)
1147 $db->generateSQLINStatement( $idArray, 'ezcontentobject.id', false, true, 'int' ) . " AND
1148 ezcontentobject.id = ezcontentobject_name.contentobject_id AND
1149 ezcontentobject.current_version = ezcontentobject_name.content_version AND " .
1150 eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject', 'language_id', 'language_mask', $lang )
1151 );
1152
1153 $objectRetArray = array();
1154 foreach ( $resRowArray as $resRow )
1155 {
1156 $objectID = $resRow['id'];
1157 $resRow['class_name'] = eZContentClass::nameFromSerializedString( $resRow['class_serialized_name_list'] );
1158 if ( $asObject )
1159 {
1160 $obj = new eZContentObject( $resRow );
1161 $obj->ClassName = $resRow['class_name'];
1162 if ( $lang !== false )
1163 {
1164 $eZContentObjectContentObjectCache[$objectID] = $obj;
1165 }
1166 $objectRetArray[$objectID] = $obj;
1167 }
1168 else
1169 {
1170 $objectRetArray[$objectID] = $resRow;
1171 }
1172 }
1173 return $objectRetArray;
1174 }
1175
1185 static function fetchList( $asObject = true, $conditions = null, $offset = false, $limit = false )
1186 {
1187 $limitation = null;
1188 if ( $offset !== false or
1189 $limit !== false )
1190 $limitation = array( 'offset' => $offset,
1191 'length' => $limit );
1192 return eZPersistentObject::fetchObjectList( eZContentObject::definition(),
1193 null,
1194 $conditions, null, $limitation,
1195 $asObject );
1196 }
1197
1207 static function fetchFilteredList( $conditions = null, $offset = false, $limit = false, $asObject = true )
1208 {
1209 $limits = null;
1210 if ( $offset or $limit )
1211 $limits = array( 'offset' => $offset,
1212 'length' => $limit );
1213 return eZPersistentObject::fetchObjectList( eZContentObject::definition(),
1214 null,
1215 $conditions, null, $limits,
1216 $asObject );
1217 }
1218
1224 static function fetchListCount( $conditions = null )
1225 {
1226 $rows = eZPersistentObject::fetchObjectList( eZContentObject::definition(),
1227 array(),
1228 $conditions,
1229 false/* we don't want any sorting when counting. Sorting leads to error on postgresql 8.x */,
1230 null,
1231 false, false,
1232 array( array( 'operation' => 'count( * )',
1233 'name' => 'count' ) ) );
1234 return $rows[0]['count'];
1235 }
1236
1247 static function fetchSameClassList( $contentClassID, $asObject = true, $offset = false, $limit = false )
1248 {
1249 $conditions = array( 'contentclass_id' => $contentClassID );
1250 return eZContentObject::fetchFilteredList( $conditions, $offset, $limit, $asObject );
1251 }
1252
1259 static function fetchSameClassListCount( $contentClassID )
1260 {
1261 $result = eZPersistentObject::fetchObjectList( eZContentObject::definition(),
1262 array(),
1263 array( "contentclass_id" => $contentClassID ),
1264 false, null,
1265 false, false,
1266 array( array( 'operation' => 'count( * )',
1267 'name' => 'count' ) ) );
1268 return $result[0]['count'];
1269 }
1270
1277 function currentVersion( $asObject = true )
1278 {
1279 return eZContentObjectVersion::fetchVersion( $this->attribute( "current_version" ), $this->ID, $asObject );
1280 }
1281
1287 public function publishedVersion()
1288 {
1289 $params = array(
1290 'conditions' => array(
1291 'status' => eZContentObjectVersion::STATUS_PUBLISHED
1292 )
1293 );
1294 $versions = $this->versions( false, $params );
1295
1296 if ( !empty( $versions ) )
1297 {
1298 return $versions[0]['version'];
1299 }
1300 return null;
1301 }
1302
1310 function version( $version, $asObject = true )
1311 {
1312 if ( $asObject )
1313 {
1314 global $eZContentObjectVersionCache;
1315
1316 if ( !isset( $eZContentObjectVersionCache ) ) // prevent PHP warning below
1317 $eZContentObjectVersionCache = array();
1318
1319 if ( isset( $eZContentObjectVersionCache[$this->ID][$version] ) )
1320 {
1321 return $eZContentObjectVersionCache[$this->ID][$version];
1322 }
1323 else
1324 {
1325 $eZContentObjectVersionCache[$this->ID][$version] = eZContentObjectVersion::fetchVersion( $version, $this->ID, $asObject );
1326 return $eZContentObjectVersionCache[$this->ID][$version];
1327 }
1328 }
1329 else
1330 {
1331 return eZContentObjectVersion::fetchVersion( $version, $this->ID, $asObject );
1332 }
1333 }
1334
1342 function versions( $asObject = true, $parameters = array() )
1343 {
1344 $conditions = array( "contentobject_id" => $this->ID );
1345 if ( isset( $parameters['conditions'] ) )
1346 {
1347 if ( isset( $parameters['conditions']['status'] ) )
1348 $conditions['status'] = $parameters['conditions']['status'];
1349 if ( isset( $parameters['conditions']['creator_id'] ) )
1350 $conditions['creator_id'] = $parameters['conditions']['creator_id'];
1351 if ( isset( $parameters['conditions']['language_code'] ) )
1352 {
1353 $conditions['initial_language_id'] = eZContentLanguage::idByLocale( $parameters['conditions']['language_code'] );
1354 }
1355 if ( isset( $parameters['conditions']['initial_language_id'] ) )
1356 {
1357 $conditions['initial_language_id'] = $parameters['conditions']['initial_language_id'];
1358 }
1359 }
1360 $sort = isset( $parameters['sort'] ) ? $parameters['sort'] : null;
1361 $limit = isset( $parameters['limit'] ) ? $parameters['limit'] : null;
1362
1363 return eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),
1364 null, $conditions,
1365 $sort, $limit,
1366 $asObject );
1367 }
1368
1374 function hasRemainingVersions()
1375 {
1376 $remainingVersions = $this->versions( false );
1377 if ( !is_array( $remainingVersions ) or
1378 count( $remainingVersions ) == 0 )
1379 {
1380 return false;
1381 }
1382 return true;
1383 }
1384
1392 function createInitialVersion( $userID, $initialLanguageCode = false )
1393 {
1394 return eZContentObjectVersion::create( $this->attribute( "id" ), $userID, 1, $initialLanguageCode );
1395 }
1396
1408 function createNewVersionIn( $languageCode, $copyFromLanguageCode = false, $copyFromVersion = false, $versionCheck = true, $status = eZContentObjectVersion::STATUS_DRAFT )
1409 {
1410 return $this->createNewVersion( $copyFromVersion, $versionCheck, $languageCode, $copyFromLanguageCode, $status );
1411 }
1412
1427 function createNewVersion( $copyFromVersion = false, $versionCheck = true, $languageCode = false, $copyFromLanguageCode = false, $status = eZContentObjectVersion::STATUS_DRAFT )
1428 {
1429 $db = eZDB::instance();
1430 $db->begin();
1431
1432 // get the next available version number
1433 $nextVersionNumber = $this->nextVersion();
1434
1435 if ( $copyFromVersion == false )
1436 {
1437 $version = $this->currentVersion();
1438 }
1439 else
1440 {
1441 $version = $this->version( $copyFromVersion );
1442 }
1443
1444 if ( !$languageCode )
1445 {
1446 $initialLanguage = $version->initialLanguage();
1447 if ( !$initialLanguage )
1448 {
1449 $initialLanguage = $this->initialLanguage();
1450 }
1451
1452 if ( $initialLanguage )
1453 {
1454 $languageCode = $initialLanguage->attribute( 'locale' );
1455 }
1456 }
1457
1458 $copiedVersion = $this->copyVersion( $this, $version, $nextVersionNumber, false, $status, $languageCode, $copyFromLanguageCode );
1459
1460 // We need to make sure the copied version contains node-assignment for the existing nodes.
1461 // This is required for BC since scripts might traverse the node-assignments and mark
1462 // some of them for removal.
1463 $parentMap = array();
1464 $copiedNodeAssignmentList = $copiedVersion->attribute( 'node_assignments' );
1465 foreach ( $copiedNodeAssignmentList as $copiedNodeAssignment )
1466 {
1467 $parentMap[$copiedNodeAssignment->attribute( 'parent_node' )] = $copiedNodeAssignment;
1468 }
1469 $nodes = $this->assignedNodes();
1470 foreach ( $nodes as $node )
1471 {
1472 $remoteID = 0;
1473 // Remove assignments which conflicts with existing nodes, but keep remote_id
1474 if ( isset( $parentMap[$node->attribute( 'parent_node_id' )] ) )
1475 {
1476 $copiedNodeAssignment = $parentMap[$node->attribute( 'parent_node_id' )];
1477 $remoteID = $copiedNodeAssignment->attribute( 'remote_id' );
1478 $copiedNodeAssignment->purge();
1479 }
1480 $newNodeAssignment = $copiedVersion->assignToNode( $node->attribute( 'parent_node_id' ), $node->attribute( 'is_main' ), 0,
1481 $node->attribute( 'sort_field' ), $node->attribute( 'sort_order' ),
1482 $remoteID, $node->attribute( 'remote_id' ) );
1483 // Reset execution bit
1484 $newNodeAssignment->setAttribute( 'op_code', $newNodeAssignment->attribute( 'op_code' ) & ~1 );
1485 $newNodeAssignment->store();
1486 }
1487
1488 // Removing last item if we don't have enough space in version list
1489 if ( $versionCheck )
1490 {
1491 $versionlimit = eZContentClass::versionHistoryLimit( $this->attribute( 'contentclass_id' ) );
1492 $versionCount = $this->getVersionCount();
1493 if ( $versionCount > $versionlimit )
1494 {
1495 // Remove oldest archived version
1496 $params = array( 'conditions'=> array( 'status' => eZContentObjectVersion::STATUS_ARCHIVED ) );
1497 $versions = $this->versions( true, $params );
1498 if ( count( $versions ) > 0 )
1499 {
1500 $modified = $versions[0]->attribute( 'modified' );
1501 $removeVersion = $versions[0];
1502 foreach ( $versions as $version )
1503 {
1504 $currentModified = $version->attribute( 'modified' );
1505 if ( $currentModified < $modified )
1506 {
1507 $modified = $currentModified;
1508 $removeVersion = $version;
1509 }
1510 }
1511 $removeVersion->removeThis();
1512 }
1513 }
1514 }
1515
1516 $db->commit();
1517 return $copiedVersion;
1518 }
1519
1538 function copyVersion( &$newObject, &$version, $newVersionNumber, $contentObjectID = false, $status = eZContentObjectVersion::STATUS_DRAFT, $languageCode = false, $copyFromLanguageCode = false )
1539 {
1540 $user = eZUser::currentUser();
1541 $userID = $user->attribute( 'contentobject_id' );
1542
1543 $nodeAssignmentList = $version->attribute( 'node_assignments' );
1544
1545 $db = eZDB::instance();
1546 $db->begin();
1547
1548 // This is part of the new 3.8 code.
1549 foreach ( $nodeAssignmentList as $nodeAssignment )
1550 {
1551 // Only copy assignments which has a remote_id since it will be used in template code.
1552 if ( $nodeAssignment->attribute( 'remote_id' ) == 0 )
1553 {
1554 continue;
1555 }
1556 $clonedAssignment = $nodeAssignment->cloneNodeAssignment( $newVersionNumber, $contentObjectID );
1557 $clonedAssignment->setAttribute( 'op_code', eZNodeAssignment::OP_CODE_SET ); // Make sure op_code is marked to 'set' the data.
1558 $clonedAssignment->store();
1559 }
1560
1561 $currentVersionNumber = $version->attribute( "version" );
1562 $contentObjectTranslations = $version->translations();
1563
1564 $clonedVersion = $version->cloneVersion( $newVersionNumber, $userID, $contentObjectID, $status );
1565
1566 if ( $contentObjectID != false )
1567 {
1568 if ( $clonedVersion->attribute( 'status' ) == eZContentObjectVersion::STATUS_PUBLISHED )
1569 $clonedVersion->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT );
1570 }
1571
1572 $clonedVersion->store();
1573
1574 // We copy related objects before the attributes, this means that the related objects
1575 // are available once the datatype code is run.
1576 $this->copyContentObjectRelations( $currentVersionNumber, $newVersionNumber, $contentObjectID );
1577
1578 $languageCodeToCopy = false;
1579 if ( $languageCode && in_array( $languageCode, $this->availableLanguages() ) )
1580 {
1581 $languageCodeToCopy = $languageCode;
1582 }
1583 if ( $copyFromLanguageCode && in_array( $copyFromLanguageCode, $this->availableLanguages() ) )
1584 {
1585 $languageCodeToCopy = $copyFromLanguageCode;
1586 }
1587
1588 $haveCopied = false;
1589 if ( !$languageCode || $languageCodeToCopy )
1590 {
1591 foreach ( $contentObjectTranslations as $contentObjectTranslation )
1592 {
1593 if ( $languageCode != false && $contentObjectTranslation->attribute( 'language_code' ) != $languageCodeToCopy )
1594 {
1595 continue;
1596 }
1597
1598 $contentObjectAttributes = $contentObjectTranslation->objectAttributes();
1599
1600 foreach ( $contentObjectAttributes as $attribute )
1601 {
1602 $clonedAttribute = $attribute->cloneContentObjectAttribute( $newVersionNumber, $currentVersionNumber, $contentObjectID, $languageCode );
1603 $clonedAttribute->sync();
1604 eZDebugSetting::writeDebug( 'kernel-content-object-copy', $clonedAttribute, 'copyVersion:cloned attribute' );
1605 }
1606
1607 $haveCopied = true;
1608 }
1609 }
1610
1611 if ( !$haveCopied && $languageCode )
1612 {
1613 $class = $this->contentClass();
1614 $classAttributes = $class->fetchAttributes();
1615 foreach ( $classAttributes as $classAttribute )
1616 {
1617 if ( $classAttribute->attribute( 'can_translate' ) == 1 )
1618 {
1619 $classAttribute->instantiate( $contentObjectID? $contentObjectID: $this->attribute( 'id' ), $languageCode, $newVersionNumber );
1620 }
1621 else
1622 {
1623 // If attribute is NOT Translatable we should check isAlwaysAvailable(),
1624 // For example,
1625 // if initial_language_id is 4 and the attribute is always available
1626 // language_id will be 5 in ezcontentobject_version/ezcontentobject_attribute,
1627 // this means it uses language ID 4 but also has the bit 0 set to 1 (a reservered bit),
1628 // You can read about this in the document in doc/features/3.8/.
1629 $initialLangID = !$this->isAlwaysAvailable() ? $this->attribute( 'initial_language_id' ) : $this->attribute( 'initial_language_id' ) | 1;
1630 $contentAttribute = eZContentObjectAttribute::fetchByClassAttributeID( $classAttribute->attribute( 'id' ),
1631 $this->attribute( 'id' ),
1632 $this->attribute( 'current_version' ),
1633 $initialLangID );
1634 if ( $contentAttribute )
1635 {
1636 $newAttribute = $contentAttribute->cloneContentObjectAttribute( $newVersionNumber, $currentVersionNumber, $contentObjectID, $languageCode );
1637 $newAttribute->sync();
1638 }
1639 else
1640 {
1641 $classAttribute->instantiate( $contentObjectID? $contentObjectID: $this->attribute( 'id' ), $languageCode, $newVersionNumber );
1642 }
1643 }
1644 }
1645 }
1646
1647 if ( $languageCode )
1648 {
1649 $clonedVersion->setAttribute( 'initial_language_id', eZContentLanguage::idByLocale( $languageCode ) );
1650 $clonedVersion->updateLanguageMask();
1651 }
1652
1653 $db->commit();
1654
1655 return $clonedVersion;
1656 }
1657
1669 static function create( $name, $contentclassID, $userID, $sectionID = 1, $version = 1, $languageCode = false )
1670 {
1671 if ( $languageCode == false )
1672 {
1673 $languageCode = eZContentObject::defaultLanguage();
1674 }
1675
1676 $languageID = eZContentLanguage::idByLocale( $languageCode );
1677
1678 $row = array(
1679 "name" => $name,
1680 "current_version" => $version,
1681 'initial_language_id' => $languageID,
1682 'language_mask' => $languageID,
1683 "contentclass_id" => $contentclassID,
1684 "permission_id" => 1,
1685 "parent_id" => 0,
1686 "main_node_id" => 0,
1687 "owner_id" => $userID,
1688 "section_id" => $sectionID,
1689 'remote_id' => eZRemoteIdUtility::generate( 'object' ) );
1690
1691 return new eZContentObject( $row );
1692 }
1693
1697 function __clone()
1698 {
1699 $this->setAttribute( 'id', null );
1700 $this->setAttribute( 'published', time() );
1701 $this->setAttribute( 'modified', time() );
1702 $this->resetDataMap();
1703 }
1704
1714 function copy( $allVersions = true )
1715 {
1716 eZDebugSetting::writeDebug( 'kernel-content-object-copy', 'Copy start, all versions=' . ( $allVersions ? 'true' : 'false' ), 'copy' );
1717 $user = eZUser::currentUser();
1718 $userID = $user->attribute( 'contentobject_id' );
1719
1720 $contentObject = clone $this;
1721 $contentObject->setAttribute( 'current_version', 1 );
1722 $contentObject->setAttribute( 'owner_id', $userID );
1723
1724 $contentObject->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'object' ) );
1725
1726 $db = eZDB::instance();
1727 $db->begin();
1728 $contentObject->store();
1729
1730 $originalObjectID = $this->attribute( 'id' );
1731 $contentObjectID = $contentObject->attribute( 'id' );
1732
1733 $db->query( "INSERT INTO ezcobj_state_link (contentobject_state_id, contentobject_id)
1734 SELECT contentobject_state_id, $contentObjectID FROM ezcobj_state_link WHERE contentobject_id = $originalObjectID" );
1735
1736 $contentObject->setName( $this->attribute('name') );
1737 eZDebugSetting::writeDebug( 'kernel-content-object-copy', $contentObject, 'contentObject' );
1738
1739
1740 $versionList = array();
1741 if ( $allVersions )
1742 {
1743 $versions = $this->versions();
1744 foreach( $versions as $version )
1745 {
1746 $versionList[$version->attribute( 'version' )] = $version;
1747 }
1748 }
1749 else
1750 {
1751 $versionList[1] = $this->currentVersion();
1752 }
1753
1754 foreach ( $versionList as $versionNumber => $currentContentObjectVersion )
1755 {
1756 $currentVersionNumber = $currentContentObjectVersion->attribute( 'version' );
1757 $contentObject->setName( $currentContentObjectVersion->name(), $versionNumber );
1758 foreach( $contentObject->translationStringList() as $languageCode )
1759 {
1760 $contentObject->setName( $currentContentObjectVersion->name( false, $languageCode ), $versionNumber, $languageCode );
1761 }
1762
1763 $contentObjectVersion = $this->copyVersion( $contentObject, $currentContentObjectVersion,
1764 $versionNumber, $contentObject->attribute( 'id' ),
1765 false );
1766
1767 if ( $currentVersionNumber == $this->attribute( 'current_version' ) )
1768 {
1769 $parentMap = array();
1770 $copiedNodeAssignmentList = $contentObjectVersion->attribute( 'node_assignments' );
1771 foreach ( $copiedNodeAssignmentList as $copiedNodeAssignment )
1772 {
1773 $parentMap[$copiedNodeAssignment->attribute( 'parent_node' )] = $copiedNodeAssignment;
1774 }
1775 // Create node-assignment from all current published nodes
1776 $nodes = $this->assignedNodes();
1777 foreach( $nodes as $node )
1778 {
1779 $remoteID = eZRemoteIdUtility::generate( 'object' );
1780 // Remove assignments which conflicts with existing nodes, but keep remote_id
1781 if ( isset( $parentMap[$node->attribute( 'parent_node_id' )] ) )
1782 {
1783 $copiedNodeAssignment = $parentMap[$node->attribute( 'parent_node_id' )];
1784 unset( $parentMap[$node->attribute( 'parent_node_id' )] );
1785 $remoteID = $copiedNodeAssignment->attribute( 'remote_id' );
1786 $copiedNodeAssignment->purge();
1787 }
1788 $contentObjectVersion->assignToNode(
1789 $node->attribute( 'parent_node_id' ),
1790 $node->attribute( 'is_main' ),
1791 0,
1792 $node->attribute( 'sort_field' ),
1793 $node->attribute( 'sort_order' ),
1794 $remoteID
1795 );
1796 }
1797 }
1798
1799 eZDebugSetting::writeDebug( 'kernel-content-object-copy', $contentObjectVersion, 'Copied version' );
1800 }
1801
1802 // Set version number
1803 if ( $allVersions )
1804 $contentObject->setAttribute( 'current_version', $this->attribute( 'current_version' ) );
1805
1806 $contentObject->setAttribute( 'status', eZContentObject::STATUS_DRAFT );
1807
1808 $contentObject->store();
1809
1810 $db->commit();
1811
1812 eZDebugSetting::writeDebug( 'kernel-content-object-copy', 'Copy done', 'copy' );
1813 return $contentObject;
1814 }
1815
1827 function copyRevertTo( $version, $language = false )
1828 {
1829 $versionObject = $this->createNewVersionIn( $language, false, $version );
1830
1831 return $versionObject->attribute( 'version' );
1832 }
1833
1843 static function fixReverseRelations( $objectID, $mode = false, $clearCacheIfEnabled = true )
1844 {
1845 $db = eZDB::instance();
1846 $objectID = (int) $objectID;
1847
1848 // Finds all the attributes that store relations to the given object.
1849 $result = $db->arrayQuery( "SELECT attr.*
1850 FROM ezcontentobject_link link,
1851 ezcontentobject_attribute attr
1852 WHERE link.from_contentobject_id=attr.contentobject_id AND
1853 link.from_contentobject_version=attr.version AND
1854 link.contentclassattribute_id=attr.contentclassattribute_id AND
1855 link.to_contentobject_id=$objectID" );
1856 if ( count( $result ) > 0 )
1857 {
1858 $objectIDList = array();
1859 foreach( $result as $row )
1860 {
1861 $attr = new eZContentObjectAttribute( $row );
1862 $dataType = $attr->dataType();
1863 $dataType->fixRelatedObjectItem( $attr, $objectID, $mode );
1864 $objectIDList[] = $attr->attribute( 'contentobject_id' );
1865 }
1866 if ( $clearCacheIfEnabled && eZINI::instance()->variable( 'ContentSettings', 'ViewCaching' ) === 'enabled' )
1867 eZContentCacheManager::clearObjectViewCacheArray( $objectIDList );
1868 }
1869 }
1870
1877 function purge()
1878 {
1879 $delID = $this->ID;
1880 // Who deletes which content should be logged.
1881 eZAudit::writeAudit( 'content-delete', array( 'Object ID' => $delID, 'Content Name' => $this->attribute( 'name' ),
1882 'Comment' => 'Purged the current object: eZContentObject::purge()' ) );
1883
1884 $db = eZDB::instance();
1885
1886 $db->begin();
1887
1888 $attrOffset = 0;
1889 $attrLimit = 20;
1890 while (
1891 $contentobjectAttributes = $this->allContentObjectAttributes(
1892 $delID, true, array( 'limit' => $attrLimit, 'offset' => $attrOffset )
1893 )
1894 )
1895 {
1896 foreach ( $contentobjectAttributes as $contentobjectAttribute )
1897 {
1898 $dataType = $contentobjectAttribute->dataType();
1899 if ( !$dataType )
1900 continue;
1901 $dataType->deleteStoredObjectAttribute( $contentobjectAttribute );
1902 }
1903 $attrOffset += $attrLimit;
1904 }
1905
1906 eZInformationCollection::removeContentObject( $delID );
1907
1908 eZContentObjectTrashNode::purgeForObject( $delID );
1909
1910 $db->query( "DELETE FROM ezcontentobject_tree
1911 WHERE contentobject_id='$delID'" );
1912
1913 $db->query( "DELETE FROM ezcontentobject_attribute
1914 WHERE contentobject_id='$delID'" );
1915
1916 $db->query( "DELETE FROM ezcontentobject_version
1917 WHERE contentobject_id='$delID'" );
1918
1919 $db->query( "DELETE FROM ezcontentobject_name
1920 WHERE contentobject_id='$delID'" );
1921
1922 $db->query( "DELETE FROM ezcobj_state_link WHERE contentobject_id=$delID" );
1923
1924 $db->query( "DELETE FROM ezcontentobject
1925 WHERE id='$delID'" );
1926
1927 $db->query( "DELETE FROM eznode_assignment
1928 WHERE contentobject_id = '$delID'" );
1929
1930 $db->query( "DELETE FROM ezuser_role
1931 WHERE contentobject_id = '$delID'" );
1932
1933 $db->query( "DELETE FROM ezuser_discountrule
1934 WHERE contentobject_id = '$delID'" );
1935
1936 eZContentObject::fixReverseRelations( $delID, 'remove' );
1937
1938 eZSearch::removeObjectById( $delID );
1939
1940 // Check if deleted object is in basket/wishlist
1941 $sql = 'SELECT DISTINCT ezproductcollection_item.productcollection_id
1942 FROM ezbasket, ezwishlist, ezproductcollection_item
1943 WHERE ( ezproductcollection_item.productcollection_id=ezbasket.productcollection_id OR
1944 ezproductcollection_item.productcollection_id=ezwishlist.productcollection_id ) AND
1945 ezproductcollection_item.contentobject_id=' . $delID;
1946 $rows = $db->arrayQuery( $sql );
1947 if ( count( $rows ) > 0 )
1948 {
1949 $countElements = 50;
1950 $deletedArray = array();
1951 // Create array of productCollectionID will be removed from ezwishlist and ezproductcollection_item
1952 foreach ( $rows as $row )
1953 {
1954 $deletedArray[] = $row['productcollection_id'];
1955 }
1956 // Split $deletedArray into several arrays with $countElements values
1957 $splitted = array_chunk( $deletedArray, $countElements );
1958 // Remove eZProductCollectionItem and eZWishList
1959 foreach ( $splitted as $value )
1960 {
1961 eZPersistentObject::removeObject( eZProductCollectionItem::definition(), array( 'productcollection_id' => array( $value, '' ) ) );
1962 eZPersistentObject::removeObject( eZWishList::definition(), array( 'productcollection_id' => array( $value, '' ) ) );
1963 }
1964 }
1965 $db->query( 'UPDATE ezproductcollection_item
1966 SET contentobject_id = 0
1967 WHERE contentobject_id = ' . $delID );
1968
1969 // Cleanup relations in two steps to avoid locking table for to long
1970 $db->query( "DELETE FROM ezcontentobject_link
1971 WHERE from_contentobject_id = '$delID'" );
1972
1973 $db->query( "DELETE FROM ezcontentobject_link
1974 WHERE to_contentobject_id = '$delID'" );
1975
1976 // Cleanup properties: LastVisit, Creator, Owner
1977 $db->query( "DELETE FROM ezuservisit
1978 WHERE user_id = '$delID'" );
1979
1980 $db->query( "UPDATE ezcontentobject_version
1981 SET creator_id = 0
1982 WHERE creator_id = '$delID'" );
1983
1984 $db->query( "UPDATE ezcontentobject
1985 SET owner_id = 0
1986 WHERE owner_id = '$delID'" );
1987
1988 if ( isset( $GLOBALS["eZWorkflowTypeObjects"] ) and is_array( $GLOBALS["eZWorkflowTypeObjects"] ) )
1989 {
1990 $registeredTypes =& $GLOBALS["eZWorkflowTypeObjects"];
1991 }
1992 else
1993 {
1994 $registeredTypes = eZWorkflowType::fetchRegisteredTypes();
1995 }
1996
1997 // Cleanup ezworkflow_event etc...
1998 foreach ( array_keys( $registeredTypes ) as $registeredTypeKey )
1999 {
2000 $registeredType = $registeredTypes[$registeredTypeKey];
2001 $registeredType->cleanupAfterRemoving( array( 'DeleteContentObject' => $delID ) );
2002 }
2003
2004 $db->commit();
2005 }
2006
2015 function removeThis( $nodeID = null )
2016 {
2017 $delID = $this->ID;
2018
2019 // Who deletes which content should be logged.
2020 eZAudit::writeAudit( 'content-delete', array( 'Object ID' => $delID, 'Content Name' => $this->attribute( 'name' ),
2021 'Comment' => 'Setted archived status for the current object: eZContentObject::remove()' ) );
2022
2023 $nodes = $this->attribute( 'assigned_nodes' );
2024
2025 if ( $nodeID === null or count( $nodes ) <= 1 )
2026 {
2027 $db = eZDB::instance();
2028 $db->begin();
2029 $mainNodeKey = false;
2030 foreach ( $nodes as $key => $node )
2031 {
2032 if ( $node->attribute( 'main_node_id' ) == $node->attribute( 'node_id' ) )
2033 {
2034 $mainNodeKey = $key;
2035 }
2036 else
2037 {
2038 $node->removeThis();
2039 }
2040 }
2041
2042 if ( $mainNodeKey !== false )
2043 {
2044 $nodes[$mainNodeKey]->removeNodeFromTree( true );
2045 }
2046
2047
2048 $this->setAttribute( 'status', eZContentObject::STATUS_ARCHIVED );
2049 eZSearch::removeObjectById( $delID );
2050 $this->store();
2051 eZContentObject::fixReverseRelations( $delID, 'trash' );
2052 // Delete stored attribute from other tables
2053 $db->commit();
2054
2055 }
2056 else if ( $nodeID !== null )
2057 {
2058 $node = eZContentObjectTreeNode::fetch( $nodeID , false );
2059 if ( is_object( $node ) )
2060 {
2061 if ( $node->attribute( 'main_node_id' ) == $nodeID )
2062 {
2063 $db = eZDB::instance();
2064 $db->begin();
2065 foreach ( $nodes as $additionalNode )
2066 {
2067 if ( $additionalNode->attribute( 'node_id' ) != $node->attribute( 'main_node_id' ) )
2068 {
2069 $additionalNode->remove();
2070 }
2071 }
2072
2073 $node->removeNodeFromTree( true );
2074 $this->setAttribute( 'status', eZContentObject::STATUS_ARCHIVED );
2075 eZSearch::removeObjectById( $delID );
2076 $this->store();
2077 eZContentObject::fixReverseRelations( $delID, 'trash' );
2078 $db->commit();
2079 }
2080 else
2081 {
2082 eZContentObjectTreeNode::removeNode( $nodeID );
2083 }
2084 }
2085 }
2086 else
2087 {
2088 eZContentObjectTreeNode::removeNode( $nodeID );
2089 }
2090 }
2091
2098 function cleanupInternalDrafts( $userID = false, $timeDuration = 86400 )
2099 {
2100 if ( !is_numeric( $timeDuration ) ||
2101 $timeDuration < 0 )
2102 {
2103 eZDebug::writeError( "The time duration must be a positive numeric value (timeDuration = $timeDuration)", __METHOD__ );
2104 return;
2105 }
2106
2107 if ( $userID === false )
2108 {
2109 $userID = eZUser::currentUserID();
2110 }
2111 // Fetch all draft/temporary versions by specified user
2112 $parameters = array( 'conditions' => array( 'status' => eZContentObjectVersion::STATUS_INTERNAL_DRAFT,
2113 'creator_id' => $userID ) );
2114 // Remove temporary drafts which are old.
2115 $expiryTime = time() - $timeDuration; // only remove drafts older than time duration (default is 1 day)
2116 foreach ( $this->versions( true, $parameters ) as $possibleVersion )
2117 {
2118 if ( $possibleVersion->attribute( 'modified' ) < $expiryTime )
2119 {
2120 $possibleVersion->removeThis();
2121 }
2122 }
2123 }
2124
2131 static function cleanupAllInternalDrafts( $userID = false, $timeDuration = 86400 ) //
2132 {
2133 if ( !is_numeric( $timeDuration ) ||
2134 $timeDuration < 0 )
2135 {
2136 eZDebug::writeError( "The time duration must be a positive numeric value (timeDuration = $timeDuration)", __METHOD__ );
2137 return;
2138 }
2139
2140
2141 if ( $userID === false )
2142 {
2143 $userID = eZUser::currentUserID();
2144 }
2145 // Remove all internal drafts
2146 $untouchedDrafts = eZContentObjectVersion::fetchForUser( $userID, eZContentObjectVersion::STATUS_INTERNAL_DRAFT );
2147
2148 $expiryTime = time() - $timeDuration; // only remove drafts older than time duration (default is 1 day)
2149 foreach ( $untouchedDrafts as $untouchedDraft )
2150 {
2151 if ( $untouchedDraft->attribute( 'modified' ) < $expiryTime )
2152 {
2153 $untouchedDraft->removeThis();
2154 }
2155 }
2156 }
2157
2166 function allContentObjectAttributes( $contentObjectID, $asObject = true, $limit = null )
2167 {
2168 return eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
2169 null,
2170 array("contentobject_id" => $contentObjectID ),
2171 null,
2172 $limit,
2173 $asObject );
2174 }
2175
2190 function contentObjectAttributes( $asObject = true, $version = false, $language = false, $contentObjectAttributeID = false, $distinctItemsOnly = false )
2191 {
2192 $db = eZDB::instance();
2193 if ( $version == false )
2194 {
2195 $version = $this->CurrentVersion;
2196 }
2197 else
2198 {
2199 $version = (int) $version;
2200 }
2201
2202 if ( $language === false )
2203 {
2204 $language = $this->CurrentLanguage;
2205 }
2206
2207 if ( is_string( $language ) )
2208 $language = $db->escapeString( $language );
2209
2210 if ( $contentObjectAttributeID !== false )
2211 $contentObjectAttributeID =(int) $contentObjectAttributeID;
2212
2213 if ( !$language || !isset( $this->ContentObjectAttributes[$version][$language] ) )
2214 {
2215 $versionText = "AND ezcontentobject_attribute.version = '$version'";
2216 if ( $language )
2217 {
2218 $languageText = "AND ezcontentobject_attribute.language_code = '$language'";
2219 }
2220 else
2221 {
2222 $languageText = "AND ".eZContentLanguage::sqlFilter( 'ezcontentobject_attribute', 'ezcontentobject_version' );
2223 }
2224 $attributeIDText = false;
2225 if ( $contentObjectAttributeID )
2226 $attributeIDText = "AND ezcontentobject_attribute.id = '$contentObjectAttributeID'";
2227 $distinctText = false;
2228 if ( $distinctItemsOnly )
2229 $distinctText = "GROUP BY ezcontentobject_attribute.id";
2230 $query = "SELECT ezcontentobject_attribute.*, ezcontentclass_attribute.identifier as identifier FROM
2231 ezcontentobject_attribute, ezcontentclass_attribute, ezcontentobject_version
2232 WHERE
2233 ezcontentclass_attribute.version = '0' AND
2234 ezcontentclass_attribute.id = ezcontentobject_attribute.contentclassattribute_id AND
2235 ezcontentobject_version.contentobject_id = '$this->ID' AND
2236 ezcontentobject_version.version = '$version' AND
2237 ezcontentobject_attribute.contentobject_id = '$this->ID' $versionText $languageText $attributeIDText
2238 $distinctText
2239 ORDER BY
2240 ezcontentclass_attribute.placement ASC,
2241 ezcontentobject_attribute.language_code ASC";
2242
2243 $attributeArray = $db->arrayQuery( $query );
2244
2245 if ( !$language && $attributeArray )
2246 {
2247 $language = $attributeArray[0]['language_code'];
2248 $this->CurrentLanguage = $language;
2249 }
2250
2251 $returnAttributeArray = array();
2252 foreach ( $attributeArray as $attribute )
2253 {
2254 $attr = new eZContentObjectAttribute( $attribute );
2255 $attr->setContentClassAttributeIdentifier( $attribute['identifier'] );
2256 $returnAttributeArray[] = $attr;
2257 }
2258
2259 if ( $language !== null and $version !== null )
2260 {
2261 $this->ContentObjectAttributes[$version][$language] = $returnAttributeArray;
2262 }
2263 }
2264 else
2265 {
2266 $returnAttributeArray = $this->ContentObjectAttributes[$version][$language];
2267 }
2268
2269 return $returnAttributeArray;
2270 }
2271
2279 function setContentObjectAttributes( &$attributes, $version, $language )
2280 {
2281 $this->ContentObjectAttributes[$version][$language] = $attributes;
2282 }
2283
2290 static function fillNodeListAttributes( $objList, $asObject = true )
2291 {
2292 $db = eZDB::instance();
2293
2294 if ( count( $objList ) > 0 )
2295 {
2296 $objectArray = array();
2297 $tmpLanguageObjectList = array();
2298 $whereSQL = '';
2299 $count = count( $objList );
2300 $i = 0;
2301 foreach ( $objList as $obj )
2302 {
2303 if ( $obj instanceOf eZContentObject )
2304 $object = $obj;
2305 else
2306 $object = $obj->attribute( 'object' );
2307
2308 $language = $object->currentLanguage();
2309 $tmpLanguageObjectList[$object->attribute( 'id' )] = $language;
2310 $objectArray = array( 'id' => $object->attribute( 'id' ),
2311 'language' => $language,
2312 'version' => $object->attribute( 'current_version' ) );
2313
2314 $whereSQL .= "( ezcontentobject_attribute.version = '" . $object->attribute( 'current_version' ) . "' AND
2315 ezcontentobject_attribute.contentobject_id = '" . $object->attribute( 'id' ) . "' AND
2316 ezcontentobject_attribute.language_code = '" . $language . "' ) ";
2317
2318 $i++;
2319 if ( $i < $count )
2320 $whereSQL .= ' OR ';
2321 }
2322
2323 $query = "SELECT ezcontentobject_attribute.*, ezcontentclass_attribute.identifier as identifier FROM
2324 ezcontentobject_attribute, ezcontentclass_attribute
2325 WHERE
2326 ezcontentclass_attribute.version = '0' AND
2327 ezcontentclass_attribute.id = ezcontentobject_attribute.contentclassattribute_id AND
2328 ( $whereSQL )
2329 ORDER BY
2330 ezcontentobject_attribute.contentobject_id, ezcontentclass_attribute.placement ASC";
2331
2332 $attributeArray = $db->arrayQuery( $query );
2333
2334 $tmpAttributeObjectList = array();
2335 $returnAttributeArray = array();
2336 foreach ( $attributeArray as $attribute )
2337 {
2338 $attr = new eZContentObjectAttribute( $attribute );
2339 $attr->setContentClassAttributeIdentifier( $attribute['identifier'] );
2340
2341 $tmpAttributeObjectList[$attr->attribute( 'contentobject_id' )][] = $attr;
2342 }
2343
2344 foreach ( $objList as $obj )
2345 {
2346 if ( $obj instanceOf eZContentObject )
2347 {
2348 $obj->setContentObjectAttributes( $tmpAttributeObjectList[$obj->attribute( 'id' )],
2349 $obj->attribute( 'current_version' ),
2350 $tmpLanguageObjectList[$obj->attribute( 'id' )] );
2351 }
2352 else
2353 {
2354 $object = $obj->attribute( 'object' );
2355 $object->setContentObjectAttributes( $tmpAttributeObjectList[$object->attribute( 'id' )],
2356 $object->attribute( 'current_version' ),
2357 $tmpLanguageObjectList[$object->attribute( 'id' )] );
2358 $obj->setContentObject( $object );
2359 }
2360 }
2361 }
2362 }
2363
2367 function resetInputRelationList()
2368 {
2369 $this->InputRelationList = array( eZContentObject::RELATION_EMBED => array(),
2370 eZContentObject::RELATION_LINK => array() );
2371 }
2372
2377 function appendInputRelationList( $addingIDList, $relationType )
2378 {
2379 if ( !is_array( $addingIDList ) )
2380 {
2381 $addingIDList = array( ( int ) $addingIDList );
2382 }
2383 elseif ( !count( $addingIDList ) )
2384 {
2385 return;
2386 }
2387 $relationType = ( int ) $relationType;
2388 if ( !$this->InputRelationList )
2389 {
2390 $this->resetInputRelationList();
2391 }
2392
2393 foreach ( array_keys( $this->InputRelationList ) as $inputRelationType )
2394 {
2395 if ( $inputRelationType & $relationType )
2396 {
2397 $this->InputRelationList[$inputRelationType] = array_merge( $this->InputRelationList[$inputRelationType], $addingIDList );
2398 }
2399 }
2400 }
2401
2406 function commitInputRelations( $editVersion )
2407 {
2408 foreach ( $this->InputRelationList as $relationType => $relatedObjectIDArray )
2409 {
2410 $oldRelatedObjectArray = $this->relatedObjects( $editVersion, false, 0, false, array( 'AllRelations' => $relationType ) );
2411
2412 foreach ( $oldRelatedObjectArray as $oldRelatedObject )
2413 {
2414 $oldRelatedObjectID = $oldRelatedObject->ID;
2415 if ( !in_array( $oldRelatedObjectID, $relatedObjectIDArray ) )
2416 {
2417 $this->removeContentObjectRelation( $oldRelatedObjectID, $editVersion, 0, $relationType );
2418 }
2419 $relatedObjectIDArray = array_diff( $relatedObjectIDArray, array( $oldRelatedObjectID ) );
2420 }
2421
2422 foreach ( $relatedObjectIDArray as $relatedObjectID )
2423 {
2424 $this->addContentObjectRelation( $relatedObjectID, $editVersion, 0, $relationType );
2425 }
2426 }
2427 return true;
2428 }
2429
2437 function validateInput( $contentObjectAttributes, $attributeDataBaseName,
2438 $inputParameters = false, $parameters = array() )
2439 {
2440 $result = array( 'unvalidated-attributes' => array(),
2441 'validated-attributes' => array(),
2442 'status-map' => array(),
2443 'require-fixup' => false,
2444 'input-validated' => true );
2445 $parameters = array_merge( array( 'prefix-name' => false ),
2446 $parameters );
2447 if ( $inputParameters )
2448 {
2449 $result['unvalidated-attributes'] =& $inputParameters['unvalidated-attributes'];
2450 $result['validated-attributes'] =& $inputParameters['validated-attributes'];
2451 }
2452 $unvalidatedAttributes =& $result['unvalidated-attributes'];
2453 $validatedAttributes =& $result['validated-attributes'];
2454 $statusMap =& $result['status-map'];
2455 if ( !$inputParameters )
2456 $inputParameters = array( 'unvalidated-attributes' => &$unvalidatedAttributes,
2457 'validated-attributes' => &$validatedAttributes );
2458 $requireFixup =& $result['require-fixup'];
2459 $inputValidated =& $result['input-validated'];
2460 $http = eZHTTPTool::instance();
2461
2462 $this->resetInputRelationList();
2463
2464 $editVersion = null;
2465 $defaultLanguage = $this->initialLanguageCode();
2466 foreach( $contentObjectAttributes as $contentObjectAttribute )
2467 {
2468 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
2469 $editVersion = $contentObjectAttribute->attribute('version');
2470
2471 // Check if this is a translation
2472 $currentLanguage = $contentObjectAttribute->attribute( 'language_code' );
2473
2474 $isTranslation = false;
2475 if ( $currentLanguage != $defaultLanguage )
2476 $isTranslation = true;
2477
2478 // If current attribute is a translation
2479 // Check if this attribute can be translated
2480 // If not do not validate, since the input will be copyed from the original
2481 $doNotValidate = false;
2482 if ( $isTranslation )
2483 {
2484 if ( !$contentClassAttribute->attribute( 'can_translate' ) )
2485 $doNotValidate = true;
2486 }
2487
2488 if ( $doNotValidate == true )
2489 {
2490 $status = eZInputValidator::STATE_ACCEPTED;
2491 }
2492 else
2493 {
2494 $status = $contentObjectAttribute->validateInput( $http, $attributeDataBaseName,
2495 $inputParameters, $parameters );
2496 }
2497 $statusMap[$contentObjectAttribute->attribute( 'id' )] = array( 'value' => $status,
2498 'attribute' => $contentObjectAttribute );
2499
2500 if ( $status == eZInputValidator::STATE_INTERMEDIATE )
2501 $requireFixup = true;
2502 else if ( $status == eZInputValidator::STATE_INVALID )
2503 {
2504 $inputValidated = false;
2505 $dataType = $contentObjectAttribute->dataType();
2506 $attributeName = $dataType->attribute( 'information' );
2507 $attributeName = $attributeName['name'];
2508 $description = $contentObjectAttribute->attribute( 'validation_error' );
2509 $validationNameArray[] = $contentClassAttribute->attribute( 'name' );
2510 $validationName = implode( '->', $validationNameArray );
2511 $hasValidationError = $contentObjectAttribute->attribute( 'has_validation_error' );
2512 if ( $hasValidationError )
2513 {
2514 if ( !$description )
2515 $description = false;
2516 $validationNameArray = array();
2517 if ( $parameters['prefix-name'] )
2518 $validationNameArray = $parameters['prefix-name'];
2519 }
2520 else
2521 {
2522 if ( !$description )
2523 $description = 'unknown error';
2524 }
2525 $unvalidatedAttributes[] = array( 'id' => $contentObjectAttribute->attribute( 'id' ),
2526 'identifier' => $contentClassAttribute->attribute( 'identifier' ),
2527 'name' => $validationName,
2528 'description' => $description );
2529 }
2530 else if ( $status == eZInputValidator::STATE_ACCEPTED )
2531 {
2532 $dataType = $contentObjectAttribute->dataType();
2533 $attributeName = $dataType->attribute( 'information' );
2534 $attributeName = $attributeName['name'];
2535 if ( $contentObjectAttribute->attribute( 'validation_log' ) != null )
2536 {
2537 $description = $contentObjectAttribute->attribute( 'validation_log' );
2538 if ( !$description )
2539 $description = false;
2540 $validationName = $contentClassAttribute->attribute( 'name' );
2541 if ( $parameters['prefix-name'] )
2542 $validationName = $parameters['prefix-name'] . '->' . $validationName;
2543 $validatedAttributes[] = array( 'id' => $contentObjectAttribute->attribute( 'id' ),
2544 'identifier' => $contentClassAttribute->attribute( 'identifier' ),
2545 'name' => $validationName,
2546 'description' => $description );
2547 }
2548 }
2549 }
2550
2551 if ( $editVersion !== null )
2552 {
2553 $this->commitInputRelations( $editVersion );
2554 }
2555 $this->resetInputRelationList();
2556
2557 return $result;
2558 }
2559
2564 function fixupInput( $contentObjectAttributes, $attributeDataBaseName )
2565 {
2566 $http = eZHTTPTool::instance();
2567 foreach ( $contentObjectAttributes as $contentObjectAttribute )
2568 {
2569 $contentObjectAttribute->fixupInput( $http, $attributeDataBaseName );
2570 }
2571 }
2572
2580 function fetchInput( $contentObjectAttributes, $attributeDataBaseName,
2581 $customActionAttributeArray, $customActionParameters )
2582 {
2583 // Global variable to cache datamaps
2584 global $eZContentObjectDataMapCache;
2585
2586 $result = array( 'attribute-input-map' => array() );
2587 $attributeInputMap =& $result['attribute-input-map'];
2588 $http = eZHTTPTool::instance();
2589
2590 $defaultLanguage = $this->initialLanguageCode();
2591
2592 $this->fetchDataMap();
2593 foreach ( $contentObjectAttributes as $contentObjectAttribute )
2594 {
2595 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
2596
2597 // Check if this is a translation
2598 $currentLanguage = $contentObjectAttribute->attribute( 'language_code' );
2599
2600 $isTranslation = false;
2601 if ( $currentLanguage != $defaultLanguage )
2602 $isTranslation = true;
2603
2604 // If current attribute is an un-translateable translation, input should not be fetched
2605 $fetchInput = true;
2606 if ( $isTranslation == true )
2607 {
2608 if ( !$contentClassAttribute->attribute( 'can_translate' ) )
2609 {
2610 $fetchInput = false;
2611 }
2612 }
2613
2614 // Do not handle input for non-translateable attributes.
2615 // Input will be copyed from the std. translation on storage
2616 if ( $fetchInput )
2617 {
2618 if ( $contentObjectAttribute->fetchInput( $http, $attributeDataBaseName ) )
2619 {
2620 $attributeInputMap[$contentObjectAttribute->attribute('id')] = true;
2621
2622 // we fill the internal data map cache for the current version here with the attributes of the new version
2623 // this will make the data map cache inconsistent, but this is required to make it possible to use $object.data_map
2624 // in content/edit templates
2625 $attributeIdentifier = $contentObjectAttribute->attribute( 'contentclass_attribute_identifier' );
2626 $eZContentObjectDataMapCache[$this->ID][$this->CurrentVersion][$currentLanguage][$attributeIdentifier] = $contentObjectAttribute;
2627 $this->DataMap[$this->CurrentVersion][$currentLanguage][$attributeIdentifier] = $contentObjectAttribute;
2628 }
2629
2630 // Custom Action Code
2631 $this->handleCustomHTTPActions( $contentObjectAttribute, $attributeDataBaseName,
2632 $customActionAttributeArray, $customActionParameters );
2633 }
2634
2635 }
2636 return $result;
2637 }
2638
2645 function handleCustomHTTPActions( $contentObjectAttribute, $attributeDataBaseName,
2646 $customActionAttributeArray, $customActionParameters )
2647 {
2648 $http = eZHTTPTool::instance();
2649 $customActionParameters['base_name'] = $attributeDataBaseName;
2650 if ( isset( $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )] ) )
2651 {
2652 $customActionAttributeID = $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )]['id'];
2653 $customAction = $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )]['value'];
2654 $contentObjectAttribute->customHTTPAction( $http, $customAction, $customActionParameters );
2655 }
2656
2657 $contentObjectAttribute->handleCustomHTTPActions( $http, $attributeDataBaseName,
2658 $customActionAttributeArray, $customActionParameters );
2659 }
2660
2667 function handleAllCustomHTTPActions( $attributeDataBaseName,
2668 $customActionAttributeArray, $customActionParameters,
2669 $objectVersion = false )
2670 {
2671 $http = eZHTTPTool::instance();
2672 $contentObjectAttributes = $this->contentObjectAttributes( true, $objectVersion );
2673 $oldAttributeDataBaseName = $customActionParameters['base_name'];
2674 $customActionParameters['base_name'] = $attributeDataBaseName;
2675 foreach( $contentObjectAttributes as $contentObjectAttribute )
2676 {
2677 if ( isset( $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )] ) )
2678 {
2679 $customActionAttributeID = $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )]['id'];
2680 $customAction = $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )]['value'];
2681 $contentObjectAttribute->customHTTPAction( $http, $customAction, $customActionParameters );
2682 }
2683
2684 $contentObjectAttribute->handleCustomHTTPActions( $http, $attributeDataBaseName,
2685 $customActionAttributeArray, $customActionParameters );
2686 }
2687 $customActionParameters['base_name'] = $oldAttributeDataBaseName;
2688 }
2689
2693 static function recursionProtectionStart()
2694 {
2695 $GLOBALS["ez_content_object_recursion_protect"] = array();
2696 }
2697
2702 static function recursionProtect( $id )
2703 {
2704 if ( isset( $GLOBALS["ez_content_object_recursion_protect"][$id] ) )
2705 {
2706 return false;
2707 }
2708 else
2709 {
2710 $GLOBALS["ez_content_object_recursion_protect"][$id] = true;
2711 return true;
2712 }
2713 }
2714
2718 static function recursionProtectionEnd()
2719 {
2720 unset( $GLOBALS["ez_content_object_recursion_protect"] );
2721 }
2722
2730 function storeInput( $contentObjectAttributes,
2731 $attributeInputMap )
2732 {
2733 $db = eZDB::instance();
2734 $db->begin();
2735 foreach ( $contentObjectAttributes as $contentObjectAttribute )
2736 {
2737 if ( isset( $attributeInputMap[$contentObjectAttribute->attribute('id')] ) )
2738 {
2739 $contentObjectAttribute->store();
2740 }
2741 }
2742 $db->commit();
2743 unset( $this->ContentObjectAttributes );
2744 }
2745
2751 function nextVersion()
2752 {
2753 $db = eZDB::instance();
2754 $versions = $db->arrayQuery( "SELECT ( MAX( version ) + 1 ) AS next_id FROM ezcontentobject_version
2755 WHERE contentobject_id='$this->ID'" );
2756 return $versions[0]["next_id"];
2757
2758 }
2759
2765 function previousVersion()
2766 {
2767 $db = eZDB::instance();
2768 $versions = $db->arrayQuery( "SELECT version FROM ezcontentobject_version
2769 WHERE contentobject_id='$this->ID'
2770 ORDER BY version DESC", array( 'limit' => 2 ) );
2771 if ( count( $versions ) > 1 and isset( $versions[1]['version'] ) )
2772 {
2773 return $versions[1]['version'];
2774 }
2775 else
2776 {
2777 return false;
2778 }
2779 }
2780
2786 function getVersionCount()
2787 {
2788 $db = eZDB::instance();
2789 $versionCount = $db->arrayQuery( "SELECT ( COUNT( version ) ) AS version_count FROM ezcontentobject_version
2790 WHERE contentobject_id='$this->ID'" );
2791 return $versionCount[0]["version_count"];
2792
2793 }
2794
2800 function currentLanguage()
2801 {
2802 return $this->CurrentLanguage;
2803 }
2804
2810 function currentLanguageObject()
2811 {
2812 if ( $this->CurrentLanguage )
2813 {
2814 $language = eZContentLanguage::fetchByLocale( $this->CurrentLanguage );
2815 }
2816 else
2817 {
2818 $language = false;
2819 }
2820
2821 return $language;
2822 }
2823
2829 function setCurrentLanguage( $lang )
2830 {
2831 $this->CurrentLanguage = $lang;
2832 $this->Name = null;
2833 }
2834
2840 function initialLanguage()
2841 {
2842 return isset( $this->InitialLanguageID ) ? eZContentLanguage::fetch( $this->InitialLanguageID ) : false;
2843 }
2844
2850 function initialLanguageCode()
2851 {
2852 $initialLanguage = $this->initialLanguage();
2853 // If current contentobject is "Top Level Nodes" than it doesn't have "initial Language" and "locale".
2854 return ( $initialLanguage !== false ) ? $initialLanguage->attribute( 'locale' ) : false;
2855 }
2856
2868 function addLocation( $parentNodeID, $asObject = false )
2869 {
2870 $node = eZContentObjectTreeNode::addChildTo( $this->ID, $parentNodeID, true, $this->CurrentVersion );
2871
2872 $data = array( 'contentobject_id' => $this->ID,
2873 'contentobject_version' => $this->attribute( 'current_version' ),
2874 'parent_node' => $parentNodeID,
2875 // parent_remote_id in node assignment holds remote id of the added location,
2876 // not of the parent location or of the node assignment itself
2877 'parent_remote_id' => $node->attribute( 'remote_id' ),
2878 'is_main' => 0 );
2879 $nodeAssignment = eZNodeAssignment::create( $data );
2880 $nodeAssignment->setAttribute( 'op_code', eZNodeAssignment::OP_CODE_CREATE_NOP );
2881 $nodeAssignment->store();
2882
2883 if ( $asObject )
2884 {
2885 return $node;
2886 }
2887 else
2888 {
2889 return $node->attribute( 'node_id' );
2890 }
2891 }
2892
2905 function addContentObjectRelation( $toObjectID,
2906 $fromObjectVersion = false,
2907 $attributeID = 0,
2908 $relationType = eZContentObject::RELATION_COMMON )
2909 {
2910 if ( $attributeID !== 0 )
2911 {
2912 $relationType = eZContentObject::RELATION_ATTRIBUTE;
2913 }
2914
2915 $relationType =(int) $relationType;
2916 if ( ( $relationType & eZContentObject::RELATION_ATTRIBUTE ) != 0 &&
2917 $relationType != eZContentObject::RELATION_ATTRIBUTE )
2918 {
2919 eZDebug::writeWarning( "Object relation type conflict", __METHOD__ );
2920 }
2921
2922 $db = eZDB::instance();
2923
2924 if ( !$fromObjectVersion )
2925 $fromObjectVersion = $this->CurrentVersion;
2926
2927 $fromObjectID = $this->ID;
2928
2929 if ( !is_numeric( $toObjectID ) )
2930 {
2931 eZDebug::writeError( "Related object ID (toObjectID): '$toObjectID', is not a numeric value.", __METHOD__ );
2932 return false;
2933 }
2934
2935 if ( !eZContentObject::exists( $toObjectID ) )
2936 {
2937 eZDebug::writeError( "Related object ID (toObjectID): '$toObjectID', does not refer to any existing object.", __METHOD__ );
2938 return false;
2939 }
2940
2941 $fromObjectID =(int) $fromObjectID;
2942 $attributeID =(int) $attributeID;
2943 $fromObjectVersion =(int) $fromObjectVersion;
2944 $relationBaseType = ( $relationType & eZContentObject::RELATION_ATTRIBUTE ) ?
2945 eZContentObject::RELATION_ATTRIBUTE :
2946 eZContentObject::RELATION_COMMON | eZContentObject::RELATION_EMBED | eZContentObject::RELATION_LINK;
2947 $relationTypeMatch = $db->bitAnd( 'relation_type', $relationBaseType );
2948 $query = "SELECT count(*) AS count
2949 FROM ezcontentobject_link
2950 WHERE from_contentobject_id=$fromObjectID AND
2951 from_contentobject_version=$fromObjectVersion AND
2952 to_contentobject_id=$toObjectID AND
2953 $relationTypeMatch >= 0 AND
2954 contentclassattribute_id=$attributeID";
2955 $count = $db->arrayQuery( $query );
2956 // if current relation does not exist
2957 if ( !isset( $count[0]['count'] ) || $count[0]['count'] == '0' )
2958 {
2959 $db->begin();
2960 $db->query( "INSERT INTO ezcontentobject_link ( from_contentobject_id, from_contentobject_version, to_contentobject_id, contentclassattribute_id, relation_type )
2961 VALUES ( $fromObjectID, $fromObjectVersion, $toObjectID, $attributeID, $relationType )" );
2962 $db->commit();
2963 }
2964 elseif ( isset( $count[0]['count'] ) &&
2965 $count[0]['count'] != '0' &&
2966 $attributeID == 0 &&
2967 (eZContentObject::RELATION_ATTRIBUTE & $relationType) == 0 )
2968 {
2969 $db->begin();
2970 $newRelationType = $db->bitOr( 'relation_type', $relationType );
2971 $db->query( "UPDATE ezcontentobject_link
2972 SET relation_type = $newRelationType
2973 WHERE from_contentobject_id=$fromObjectID AND
2974 from_contentobject_version=$fromObjectVersion AND
2975 to_contentobject_id=$toObjectID AND
2976 contentclassattribute_id=$attributeID" );
2977 $db->commit();
2978 }
2979 }
2980
2996 function removeContentObjectRelation( $toObjectID = false, $fromObjectVersion = false, $attributeID = 0, $relationType = eZContentObject::RELATION_COMMON )
2997 {
2998 $db = eZDB::instance();
2999
3000 if ( !$fromObjectVersion )
3001 $fromObjectVersion = $this->CurrentVersion;
3002 $fromObjectVersion = (int) $fromObjectVersion;
3003 $fromObjectID = $this->ID;
3004
3005 if ( $toObjectID !== false )
3006 {
3007 $toObjectID =(int) $toObjectID;
3008 $toObjectCondition = "AND to_contentobject_id=$toObjectID";
3009 }
3010 else
3011 $toObjectCondition = '';
3012
3013 if ( $attributeID !== false )
3014 {
3015 $attributeID =(int) $attributeID;
3016 $classAttributeCondition = "AND contentclassattribute_id=$attributeID";
3017 }
3018 else
3019 $classAttributeCondition = '';
3020
3021 $lastRelationType = 0;
3022 $db->begin();
3023 if ( !$attributeID && ( $fromObjectVersion != $this->CurrentVersion || $this->CurrentVersion == 1 ) )
3024 {
3025 // Querying only for object level relations.
3026 $rows = $db->arrayQuery( "SELECT * FROM ezcontentobject_link
3027 WHERE from_contentobject_id=$fromObjectID
3028 AND from_contentobject_version=$fromObjectVersion
3029 AND contentclassattribute_id='0'
3030 $toObjectCondition" );
3031 if ( !empty( $rows ) )
3032 {
3033 $lastRow = end( $rows );
3034 // Remember type in order to later compare with given $relationType and determine if it is composite.
3035 $lastRelationType = (int) $lastRow['relation_type'];
3036 }
3037 }
3038
3039 if ( 0 !== ( eZContentObject::RELATION_ATTRIBUTE & $relationType ) ||
3040 0 != $attributeID ||
3041 $relationType == $lastRelationType )
3042 {
3043 $db->query( "DELETE FROM ezcontentobject_link
3044 WHERE from_contentobject_id=$fromObjectID AND
3045 from_contentobject_version=$fromObjectVersion $classAttributeCondition $toObjectCondition" );
3046 }
3047 else
3048 {
3049 if ( $db->databaseName() == 'oracle' )
3050 {
3051 $notRelationType = - ( $relationType + 1 );
3052 $db->query( "UPDATE ezcontentobject_link
3053 SET relation_type = " . $db->bitAnd( 'relation_type', $notRelationType ) . "
3054 WHERE from_contentobject_id=$fromObjectID AND
3055 from_contentobject_version=$fromObjectVersion $classAttributeCondition $toObjectCondition" );
3056 }
3057 else
3058 {
3059 $db->query( "UPDATE ezcontentobject_link
3060 SET relation_type = ( relation_type & ".(~$relationType)." )
3061 WHERE from_contentobject_id=$fromObjectID AND
3062 from_contentobject_version=$fromObjectVersion $classAttributeCondition $toObjectCondition" );
3063 }
3064 }
3065
3066 $db->commit();
3067 }
3068
3074 function copyContentObjectRelations( $currentVersion, $newVersion, $newObjectID = false )
3075 {
3076 $objectID = $this->ID;
3077 if ( !$newObjectID )
3078 {
3079 $newObjectID = $objectID;
3080 }
3081
3082 $db = eZDB::instance();
3083 $db->begin();
3084
3085 $relations = $db->arrayQuery( "SELECT to_contentobject_id, relation_type FROM ezcontentobject_link
3086 WHERE contentclassattribute_id='0'
3087 AND from_contentobject_id='$objectID'
3088 AND from_contentobject_version='$currentVersion'" );
3089 foreach ( $relations as $relation )
3090 {
3091 $toContentObjectID = $relation['to_contentobject_id'];
3092 $relationType = $relation['relation_type'];
3093 $db->query( "INSERT INTO ezcontentobject_link( contentclassattribute_id,
3094 from_contentobject_id,
3095 from_contentobject_version,
3096 to_contentobject_id,
3097 relation_type )
3098 VALUES ( '0', '$newObjectID', '$newVersion', '$toContentObjectID', '$relationType' )" );
3099 }
3100
3101 $db->commit();
3102 }
3103
3107 static function isObjectRelationTyped()
3108 {
3109 $siteIni = eZINI::instance( 'site.ini' );
3110 if ( $siteIni->hasVariable( 'BackwardCompatibilitySettings', 'ObjectRelationTyped' ) )
3111 {
3112 if ( 'enabled' == $siteIni->variable( 'BackwardCompatibilitySettings', 'ObjectRelationTyped' ) )
3113 {
3114 return true;
3115 }
3116 }
3117 return false;
3118 }
3119
3124 static function relationTypeMask( $allRelations = false )
3125 {
3126 $relationTypeMask = eZContentObject::RELATION_COMMON |
3127 eZContentObject::RELATION_EMBED;
3128
3129 if ( eZContentObject::isObjectRelationTyped() )
3130 {
3131 $relationTypeMask |= eZContentObject::RELATION_LINK;
3132 }
3133
3134 if ( $allRelations )
3135 {
3136 $relationTypeMask |= eZContentObject::RELATION_ATTRIBUTE;
3137 }
3138
3139 return $relationTypeMask;
3140 }
3141
3180 function relatedObjects( $fromObjectVersion = false,
3181 $objectID = false,
3182 $attributeID = 0,
3183 $groupByAttribute = false,
3184 $params = false,
3185 $reverseRelatedObjects = false )
3186 {
3187 if ( $fromObjectVersion == false )
3188 $fromObjectVersion = isset( $this->CurrentVersion ) ? $this->CurrentVersion : false;
3189 $fromObjectVersion =(int) $fromObjectVersion;
3190 if( !$objectID )
3191 $objectID = $this->ID;
3192 $objectID =(int) $objectID;
3193
3194 $limit = ( isset( $params['Limit'] ) && is_numeric( $params['Limit'] ) ) ? $params['Limit'] : false;
3195 $offset = ( isset( $params['Offset'] ) && is_numeric( $params['Offset'] ) ) ? $params['Offset'] : false;
3196 $asObject = ( isset( $params['AsObject'] ) ) ? $params['AsObject'] : true;
3197 $loadDataMap = ( isset( $params['LoadDataMap'] ) ) ? $params['LoadDataMap'] : false;
3198
3199
3200 $db = eZDB::instance();
3201 $sortingString = '';
3202 $sortingInfo = array( 'attributeFromSQL' => '',
3203 'attributeWhereSQL' => '',
3204 'attributeTargetSQL' => '' );
3205 $relatedClassIdentifiersSQL = '';
3206 $showInvisibleNodesCond = '';
3207 // process params (only SortBy and IgnoreVisibility currently supported):
3208 // Supported sort_by modes:
3209 // class_identifier, class_name, modified, name, published, section
3210 if ( is_array( $params ) )
3211 {
3212 if ( isset( $params['SortBy'] ) )
3213 {
3214 $validSortBy = array( 'class_identifier', 'class_name', 'modified', 'name', 'published', 'section' );
3215 $sortByParam = array();
3216 if ( is_array( $params['SortBy'] ) )
3217 {
3218 // only one SortBy, as a simple array
3219 if ( !is_array( $params['SortBy'][0] ) )
3220 {
3221 if ( !in_array( $params['SortBy'][0], $validSortBy ) )
3222 eZDebug::writeWarning( "Unsupported sort_by parameter {$params['SortBy'][0]}; check the online documentation for the list of supported sort types", __METHOD__ );
3223 else
3224 $sortByParam[] = $params['SortBy'];
3225 }
3226 // multiple SortBy, check each of them one by one, and keep valid ones
3227 else
3228 {
3229 $invalidSortBy = array();
3230 foreach( $params['SortBy'] as $sortByTuple )
3231 {
3232 if ( !in_array( $sortByTuple[0], $validSortBy ) )
3233 $invalidSortBy[] = $sortByTuple[0];
3234 else
3235 $sortByParam[] = $sortByTuple;
3236 }
3237 if ( count( $invalidSortBy ) > 0 )
3238 {
3239 eZDebug::writeWarning( "Unsupported sort_by parameter(s) " . implode( ', ', $invalidSortBy ) . "; check the online documentation for the list of supported sort types", __METHOD__ );
3240 }
3241 }
3242 }
3243 if ( count( $sortByParam ) > 0 )
3244 {
3245 $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $sortByParam );
3246 $sortingString = ' ORDER BY ' . $sortingInfo['sortingFields'];
3247 }
3248 }
3249 if ( isset( $params['IgnoreVisibility'] ) )
3250 {
3251 $showInvisibleNodesCond = self::createFilterByVisibilitySQLString( $params['IgnoreVisibility'] );
3252 }
3253
3254 // related class identifier filter
3255 $relatedClassIdentifiersSQL = '';
3256 if ( isset( $params['RelatedClassIdentifiers'] ) && is_array( $params['RelatedClassIdentifiers'] ) )
3257 {
3258 $relatedClassIdentifiers = array();
3259 foreach( $params['RelatedClassIdentifiers'] as $classIdentifier )
3260 {
3261 $relatedClassIdentifiers[] = "'" . $db->escapeString( $classIdentifier ) . "'";
3262 }
3263 $relatedClassIdentifiersSQL = $db->generateSQLINStatement( $relatedClassIdentifiers, 'ezcontentclass.identifier', false, true, 'string' ). " AND";
3264 unset( $classIdentifier, $relatedClassIdentifiers );
3265 }
3266 }
3267
3268 $relationTypeMasking = '';
3269 $relationTypeMask = isset( $params['AllRelations'] ) ? $params['AllRelations'] : ( $attributeID === false );
3270 if ( $attributeID && ( $relationTypeMask === false || $relationTypeMask === eZContentObject::RELATION_ATTRIBUTE ) )
3271 {
3272 $attributeID =(int) $attributeID;
3273 $relationTypeMasking .= " contentclassattribute_id=$attributeID AND ";
3274 $relationTypeMask = eZContentObject::RELATION_ATTRIBUTE;
3275 }
3276 elseif ( is_bool( $relationTypeMask ) )
3277 {
3278 $relationTypeMask = eZContentObject::relationTypeMask( $relationTypeMask );
3279 }
3280
3281 if ( $db->databaseName() == 'oracle' )
3282 {
3283 $relationTypeMasking .= " bitand( relation_type, $relationTypeMask ) <> 0 ";
3284 }
3285 else
3286 {
3287 $relationTypeMasking .= " ( relation_type & $relationTypeMask ) <> 0 ";
3288 }
3289
3290 // Create SQL
3291 $fromOrToContentObjectID = $reverseRelatedObjects == false ? " AND ezcontentobject.id=ezcontentobject_link.to_contentobject_id AND
3292 ezcontentobject_link.from_contentobject_id='$objectID' AND
3293 ezcontentobject_link.from_contentobject_version='$fromObjectVersion' "
3294 : " AND ezcontentobject.id=ezcontentobject_link.from_contentobject_id AND
3295 ezcontentobject_link.to_contentobject_id=$objectID AND
3296 ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version ";
3297 $query = "SELECT ";
3298
3299 if ( $groupByAttribute )
3300 {
3301 $query .= "ezcontentobject_link.contentclassattribute_id, ";
3302 }
3303 $query .= "
3304 ezcontentclass.serialized_name_list AS class_serialized_name_list,
3305 ezcontentclass.identifier as contentclass_identifier,
3306 ezcontentclass.is_container as is_container,
3307 ezcontentobject.*, ezcontentobject_name.name as name, ezcontentobject_name.real_translation
3308 $sortingInfo[attributeTargetSQL]
3309 FROM
3310 ezcontentclass,
3311 ezcontentobject,
3312 ezcontentobject_link,
3313 ezcontentobject_name
3314 $sortingInfo[attributeFromSQL]
3315 WHERE
3316 ezcontentclass.id=ezcontentobject.contentclass_id AND
3317 ezcontentclass.version=0 AND
3318 ezcontentobject.status=" . eZContentObject::STATUS_PUBLISHED . " AND
3319 $sortingInfo[attributeWhereSQL]
3320 $relatedClassIdentifiersSQL
3321 $relationTypeMasking
3322 $fromOrToContentObjectID
3323 $showInvisibleNodesCond AND
3324 ezcontentobject.id = ezcontentobject_name.contentobject_id AND
3325 ezcontentobject.current_version = ezcontentobject_name.content_version AND
3326 " . eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' ) . "
3327 $sortingString";
3328 if ( !$offset && !$limit )
3329 {
3330 $relatedObjects = $db->arrayQuery( $query );
3331 }
3332 else
3333 {
3334 $relatedObjects = $db->arrayQuery( $query, array( 'offset' => $offset,
3335 'limit' => $limit ) );
3336 }
3337
3338 $ret = array();
3339 $tmp = array();
3340 foreach ( $relatedObjects as $object )
3341 {
3342 if ( $asObject )
3343 {
3344 $obj = new eZContentObject( $object );
3345 $obj->ClassName = eZContentClass::nameFromSerializedString( $object['class_serialized_name_list'] );
3346 }
3347 else
3348 {
3349 $obj = $object;
3350 }
3351
3352 $tmp[] = $obj;
3353
3354 if ( !$groupByAttribute )
3355 {
3356 $ret[] = $obj;
3357 }
3358 else
3359 {
3360 $classAttrID = $object['contentclassattribute_id'];
3361
3362 if ( !isset( $ret[$classAttrID] ) )
3363 $ret[$classAttrID] = array();
3364
3365 $ret[$classAttrID][] = $obj;
3366 }
3367 }
3368 if ( $loadDataMap && $asObject )
3369 eZContentObject::fillNodeListAttributes( $tmp );
3370 return $ret;
3371 }
3372
3385 function relatedContentObjectList( $fromObjectVersion = false,
3386 $fromObjectID = false,
3387 $attributeID = 0,
3388 $groupByAttribute = false,
3389 $params = false )
3390 {
3391 eZDebugSetting::writeDebug( 'kernel-content-object-related-objects', $fromObjectID, "objectID" );
3392 return $this->relatedObjects( $fromObjectVersion, $fromObjectID, $attributeID, $groupByAttribute, $params );
3393 }
3394
3404 function linkedContentObjectList( $fromObjectVersion = false, $fromObjectID = false )
3405 {
3406 return $this->relatedObjects( $fromObjectVersion,
3407 $fromObjectID,
3408 0,
3409 false,
3410 array( 'AllRelations' => eZContentObject::RELATION_LINK ) );
3411 }
3412
3422 function embeddedContentObjectList( $fromObjectVersion = false, $fromObjectID = false )
3423 {
3424 return $this->relatedObjects( $fromObjectVersion,
3425 $fromObjectID,
3426 0,
3427 false,
3428 array( 'AllRelations' => eZContentObject::RELATION_EMBED ) );
3429 }
3430
3440 function reverseLinkedObjectList( $fromObjectVersion = false, $fromObjectID = false )
3441 {
3442 return $this->relatedObjects( $fromObjectVersion,
3443 $fromObjectID,
3444 0,
3445 false,
3446 array( 'AllRelations' => eZContentObject::RELATION_LINK ),
3447 true );
3448 }
3449
3459 function reverseEmbeddedObjectList( $fromObjectVersion = false, $fromObjectID = false )
3460 {
3461 return $this->relatedObjects( $fromObjectVersion,
3462 $fromObjectID,
3463 0,
3464 false,
3465 array( 'AllRelations' => eZContentObject::RELATION_EMBED ),
3466 true );
3467 }
3468
3481 function relatedContentObjectArray( $fromObjectVersion = false,
3482 $fromObjectID = false,
3483 $attributeID = 0,
3484 $params = false )
3485 {
3486 return eZContentObject::relatedContentObjectList( $fromObjectVersion,
3487 $fromObjectID,
3488 $attributeID,
3489 false,
3490 $params );
3491 }
3492
3503 function relatedContentObjectCount( $fromObjectVersion = false,
3504 $attributeID = 0,
3505 $params = false )
3506 {
3507 eZDebugSetting::writeDebug( 'kernel-content-object-related-objects', $this->ID, "relatedContentObjectCount::objectID" );
3508 return $this->relatedObjectCount( $fromObjectVersion,
3509 $attributeID,
3510 false,
3511 $params );
3512 }
3513
3525 function reverseRelatedObjectList( $version = false,
3526 $attributeID = 0,
3527 $groupByAttribute = false,
3528 $params = false )
3529 {
3530 return $this->relatedObjects( $version, $this->ID, $attributeID, $groupByAttribute, $params, true );
3531 }
3532
3541 function linkedContentObjectCount( $fromObjectVersion = false )
3542 {
3543 return $this->relatedObjectCount( $fromObjectVersion,
3544 0,
3545 false,
3546 array( 'AllRelations' => eZContentObject::RELATION_LINK ) );
3547 }
3548
3557 function embeddedContentObjectCount( $fromObjectVersion = false )
3558 {
3559 return $this->relatedObjectCount( $fromObjectVersion,
3560 0,
3561 false,
3562 array( 'AllRelations' => eZContentObject::RELATION_EMBED ) );
3563 }
3564
3573 function reverseLinkedObjectCount( $fromObjectVersion = false )
3574 {
3575 return $this->relatedObjectCount( $fromObjectVersion,
3576 0,
3577 true,
3578 array( 'AllRelations' => eZContentObject::RELATION_LINK ) );
3579 }
3580
3589 function reverseEmbeddedObjectCount( $fromObjectVersion = false )
3590 {
3591 return $this->relatedObjectCount( $fromObjectVersion,
3592 0,
3593 true,
3594 array( 'AllRelations' => eZContentObject::RELATION_EMBED ) );
3595 }
3596
3624 function relatedObjectCount( $version = false, $attributeID = 0, $reverseRelatedObjects = false, $params = false )
3625 {
3626 $objectID = $this->ID;
3627 if ( $version == false )
3628 $version = isset( $this->CurrentVersion ) ? $this->CurrentVersion : false;
3629 $version = (int) $version;
3630
3631 $db = eZDB::instance();
3632 $showInvisibleNodesCond = '';
3633
3634 // process params (only IgnoreVisibility currently supported):
3635 if ( is_array( $params ) )
3636 {
3637 if ( isset( $params['IgnoreVisibility'] ) )
3638 {
3639 $showInvisibleNodesCond = self::createFilterByVisibilitySQLString(
3640 $params['IgnoreVisibility'],
3641 // inner_object represents the source of relation while outer_object represents the target
3642 $reverseRelatedObjects ? 'inner_object' : 'outer_object'
3643 );
3644 }
3645 }
3646
3647 $relationTypeMasking = '';
3648 $relationTypeMask = isset( $params['AllRelations'] ) ? $params['AllRelations'] : ( $attributeID === false );
3649 if ( $attributeID && ( $relationTypeMask === false || $relationTypeMask === eZContentObject::RELATION_ATTRIBUTE ) )
3650 {
3651 $attributeID =(int) $attributeID;
3652 $relationTypeMasking .= " AND inner_link.contentclassattribute_id = $attributeID ";
3653 $relationTypeMask = eZContentObject::RELATION_ATTRIBUTE;
3654 }
3655 elseif ( is_bool( $relationTypeMask ) )
3656 {
3657 $relationTypeMask = eZContentObject::relationTypeMask( $relationTypeMask );
3658 }
3659
3660 if ( $db->databaseName() == 'oracle' )
3661 {
3662 $relationTypeMasking .= " AND bitand( inner_link.relation_type, $relationTypeMask ) <> 0 ";
3663 }
3664 else
3665 {
3666 $relationTypeMasking .= " AND ( inner_link.relation_type & $relationTypeMask ) <> 0 ";
3667 }
3668
3669 if ( $reverseRelatedObjects )
3670 {
3671 $outerObjectIDSQL = 'outer_object.id = outer_link.from_contentobject_id';
3672 if ( is_array( $objectID ) )
3673 {
3674 if ( count( $objectID ) > 0 )
3675 {
3676 $objectIDSQL = ' AND ' . $db->generateSQLINStatement( $objectID, 'inner_link.to_contentobject_id', false, false, 'int' ) . ' AND
3677 inner_link.from_contentobject_version = inner_object.current_version';
3678 }
3679 else
3680 {
3681 $objectIDSQL = '';
3682 }
3683 }
3684 else
3685 {
3686 $objectID = (int) $objectID;
3687 $objectIDSQL = " AND inner_link.to_contentobject_id = $objectID
3688 AND inner_link.from_contentobject_version = inner_object.current_version";
3689 }
3690 }
3691 else
3692 {
3693 $outerObjectIDSQL = 'outer_object.id = outer_link.to_contentobject_id';
3694 $objectIDSQL = " AND inner_link.from_contentobject_id = $objectID
3695 AND inner_link.from_contentobject_version = $version";
3696 }
3697
3698 $query = "SELECT
3699 COUNT( outer_object.id ) AS count
3700 FROM
3701 ezcontentobject outer_object, ezcontentobject inner_object, ezcontentobject_link outer_link
3702 INNER JOIN
3703 ezcontentobject_link inner_link ON outer_link.id = inner_link.id
3704 WHERE
3705 $outerObjectIDSQL
3706 AND outer_object.status = " . eZContentObject::STATUS_PUBLISHED . "
3707 AND inner_object.id = inner_link.from_contentobject_id
3708 AND inner_object.status = " . eZContentObject::STATUS_PUBLISHED . "
3709 $objectIDSQL
3710 $relationTypeMasking
3711 $showInvisibleNodesCond";
3712
3713 $rows = $db->arrayQuery( $query );
3714 return $rows[0]['count'];
3715 }
3716
3727 function reverseRelatedObjectCount( $version = false, $attributeID = 0, $params = false )
3728 {
3729 return $this->relatedObjectCount( $version, $attributeID, true, $params );
3730 }
3731
3741 function contentObjectListRelatingThis( $version = false )
3742 {
3743 return $this->reverseRelatedObjectList( $version );
3744 }
3745
3751 function parentNodeIDArray()
3752 {
3753 return $this->parentNodes( true, false );
3754 }
3755
3763 function parentNodes( $version = false, $asObject = true )
3764 {
3765 // We no longer use node-assignment table to find the parents but uses
3766 // the 'published' tree structure.
3767 $retNodes = array();
3768
3769 $parentNodeIDs = eZContentObjectTreeNode::getParentNodeIdListByContentObjectID( $this->ID );
3770 if ( !$parentNodeIDs )
3771 {
3772 return $retNodes;
3773 }
3774 if ( $asObject )
3775 {
3776 $retNodes = eZContentObjectTreeNode::fetch( $parentNodeIDs );
3777 if ( !is_array( $retNodes ) )
3778 {
3779 $retNodes = array( $retNodes );
3780 }
3781 }
3782 else
3783 {
3784 $retNodes = $parentNodeIDs;
3785 }
3786
3787 return $retNodes;
3788 }
3789
3805 function createNodeAssignment( $parentNodeID, $isMain, $remoteID = false, $sortField = eZContentObjectTreeNode::SORT_FIELD_PUBLISHED, $sortOrder = eZContentObjectTreeNode::SORT_ORDER_DESC )
3806 {
3807 $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $this->attribute( 'id' ),
3808 'contentobject_version' => $this->attribute( 'current_version' ),
3809 'parent_node' => $parentNodeID,
3810 'is_main' => ( $isMain ? 1 : 0 ),
3811 'sort_field' => $sortField,
3812 'sort_order' => $sortOrder ) );
3813 if ( $remoteID !== false )
3814 {
3815 $nodeAssignment->setAttribute( 'remote_id', $remoteID );
3816 }
3817 $nodeAssignment->store();
3818 return $nodeAssignment;
3819 }
3820
3831 static function createWithNodeAssignment( $parentNode, $contentClassID, $languageCode, $remoteID = false )
3832 {
3833 $class = eZContentClass::fetch( $contentClassID );
3834 $parentObject = $parentNode->attribute( 'object' );
3835
3836 // Check if the user has access to create a folder here
3837 if ( $class instanceof eZContentClass and
3838 $parentObject->checkAccess( 'create', $contentClassID, false, false, $languageCode ) == '1' )
3839 {
3840 // Set section of the newly created object to the section's value of it's parent object
3841 $sectionID = $parentObject->attribute( 'section_id' );
3842
3843 $db = eZDB::instance();
3844 $db->begin();
3845 $contentObject = $class->instantiateIn( $languageCode, false, $sectionID, false, eZContentObjectVersion::STATUS_INTERNAL_DRAFT );
3846 $nodeAssignment = $contentObject->createNodeAssignment( $parentNode->attribute( 'node_id' ),
3847 true, $remoteID,
3848 $class->attribute( 'sort_field' ),
3849 $class->attribute( 'sort_order' ) );
3850 $db->commit();
3851 return $contentObject;
3852 }
3853 return null;
3854 }
3855
3867 function visibleNodes()
3868 {
3869 $result = array();
3870 foreach ( $this->assignedNodes( true, true ) as $node )
3871 {
3872 if ( $node->attribute( 'node_id' ) == $this->attribute( 'main_node_id' ) )
3873 {
3874 array_unshift( $result, $node );
3875 }
3876 else
3877 {
3878 $result[] = $node;
3879 }
3880 }
3881 return $result;
3882 }
3883
3893 function hasVisibleNode()
3894 {
3895 $contentobjectID = $this->attribute( 'id' );
3896 if ( $contentobjectID == null )
3897 {
3898 return false;
3899 }
3900 $visibilitySQL = '';
3901 if ( eZINI::instance()->variable( 'SiteAccessSettings', 'ShowHiddenNodes' ) !== 'true' )
3902 {
3903 $visibilitySQL = "AND ezcontentobject_tree.is_invisible = 0 ";
3904 }
3905 $rows = eZDB::instance()->arrayQuery(
3906 "SELECT COUNT(ezcontentobject_tree.node_id) AS node_count " .
3907 "FROM ezcontentobject_tree " .
3908 "INNER JOIN ezcontentobject ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id) " .
3909 "WHERE contentobject_id = $contentobjectID " . $visibilitySQL
3910 );
3911 return ( $rows[0]['node_count'] > 0 );
3912 }
3913
3922 function assignedNodes( $asObject = true, $checkVisibility = false )
3923 {
3924 $contentobjectID = $this->attribute( 'id' );
3925 if ( $contentobjectID == null )
3926 {
3927 return array();
3928 }
3929 $visibilitySQL = '';
3930 if (
3931 $checkVisibility === true
3932 && eZINI::instance()->variable( 'SiteAccessSettings', 'ShowHiddenNodes' ) !== 'true'
3933 )
3934 {
3935 $visibilitySQL = "AND ezcontentobject_tree.is_invisible = 0 ";
3936 }
3937 $nodesListArray = eZDB::instance()->arrayQuery(
3938 "SELECT " .
3939 "ezcontentobject.contentclass_id, ezcontentobject.current_version, ezcontentobject.initial_language_id, ezcontentobject.language_mask, " .
3940 "ezcontentobject.modified, ezcontentobject.name, ezcontentobject.owner_id, ezcontentobject.published, ezcontentobject.remote_id AS object_remote_id, ezcontentobject.section_id, " .
3941 "ezcontentobject.status, ezcontentobject_tree.contentobject_is_published, ezcontentobject_tree.contentobject_version, ezcontentobject_tree.depth, " .
3942 "ezcontentobject_tree.is_hidden, ezcontentobject_tree.is_invisible, ezcontentobject_tree.main_node_id, ezcontentobject_tree.modified_subnode, ezcontentobject_tree.node_id, " .
3943 "ezcontentobject_tree.parent_node_id, ezcontentobject_tree.path_identification_string, ezcontentobject_tree.path_string, ezcontentobject_tree.priority, ezcontentobject_tree.remote_id, " .
3944 "ezcontentobject_tree.sort_field, ezcontentobject_tree.sort_order, ezcontentclass.serialized_name_list as class_serialized_name_list, " .
3945 "ezcontentclass.identifier as class_identifier, " .
3946 "ezcontentclass.is_container as is_container " .
3947 "FROM ezcontentobject_tree " .
3948 "INNER JOIN ezcontentobject ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id) " .
3949 "INNER JOIN ezcontentclass ON (ezcontentclass.version = 0 AND ezcontentclass.id = ezcontentobject.contentclass_id) " .
3950 "WHERE contentobject_id = $contentobjectID " .
3951 $visibilitySQL .
3952 "ORDER BY path_string"
3953 );
3954 if ( $asObject == true )
3955 {
3956 return eZContentObjectTreeNode::makeObjectsArray( $nodesListArray, true, array( "id" => $contentobjectID ) );
3957 }
3958 else
3959 return $nodesListArray;
3960 }
3961
3967 function mainNodeID()
3968 {
3969 if ( !is_numeric( $this->MainNodeID ) )
3970 {
3971 $mainNodeID = eZContentObjectTreeNode::findMainNode( $this->attribute( 'id' ) );
3972 $this->MainNodeID = $mainNodeID;
3973 }
3974 return $this->MainNodeID;
3975 }
3976
3982 function mainNode()
3983 {
3984 return eZContentObjectTreeNode::findMainNode( $this->attribute( 'id' ), true );
3985 }
3986
3992 function setPermissions( $permissionArray )
3993 {
3994 $this->Permissions =& $permissionArray;
3995 }
3996
4002 function permissions( )
4003 {
4004 return $this->Permissions;
4005 }
4006
4012 function canEditLanguages()
4013 {
4014 $availableLanguages = $this->availableLanguages();
4015 $languages = array();
4016
4017 foreach ( eZContentLanguage::prioritizedLanguages() as $language )
4018 {
4019 $languageCode = $language->attribute( 'locale' );
4020 if ( in_array( $languageCode, $availableLanguages ) &&
4021 $this->canEdit( false, false, false, $languageCode ) )
4022 {
4023 $languages[] = $language;
4024 }
4025 }
4026
4027 return $languages;
4028 }
4029
4035 function canCreateLanguages()
4036 {
4037 $availableLanguages = $this->availableLanguages();
4038 $languages = array();
4039 foreach ( eZContentLanguage::prioritizedLanguages() as $language )
4040 {
4041 $languageCode = $language->attribute( 'locale' );
4042 if ( !in_array( $languageCode, $availableLanguages ) &&
4043 $this->checkAccess( 'edit', false, false, false, $languageCode ) )
4044 {
4045 $languages[] = $language;
4046 }
4047 }
4048
4049 return $languages;
4050 }
4051
4058 function checkGroupLimitationAccess( $limitationValueList, $userID, $contentObjectID = false )
4059 {
4060 $access = 'denied';
4061
4062 if ( is_array( $limitationValueList ) && is_numeric( $userID ) )
4063 {
4064 if ( $contentObjectID !== false )
4065 {
4066 $contentObject = eZContentObject::fetch( $contentObjectID );
4067 }
4068 else
4069 {
4070 $contentObject = $this;
4071 }
4072
4073 if ( is_object( $contentObject ) )
4074 {
4075 // limitation value == 1, means "self group"
4076 if ( in_array( 1, $limitationValueList ) )
4077 {
4078 // no need to check groups if user ownes this object
4079 $ownerID = $contentObject->attribute( 'owner_id' );
4080 if ( $ownerID == $userID || $contentObject->attribute( 'id' ) == $userID )
4081 {
4082 $access = 'allowed';
4083 }
4084 else
4085 {
4086 // get parent node ids for 'user' and 'owner'
4087 $groupList = eZContentObjectTreeNode::getParentNodeIdListByContentObjectID( array( $userID, $ownerID ), true );
4088
4089 // find group(s) which is common for 'user' and 'owner'
4090 $commonGroup = array_intersect( $groupList[$userID], $groupList[$ownerID] );
4091
4092 if ( count( $commonGroup ) > 0 )
4093 {
4094 // ok, we have at least 1 common group
4095 $access = 'allowed';
4096 }
4097 }
4098 }
4099 }
4100 }
4101
4102 return $access;
4103 }
4104
4115 function checkAccess( $functionName, $originalClassID = false, $parentClassID = false, $returnAccessList = false, $language = false )
4116 {
4117 $classID = $originalClassID;
4118 $user = eZUser::currentUser();
4119 $userID = $user->attribute( 'contentobject_id' );
4120 $origFunctionName = $functionName;
4121
4122 // Fetch the ID of the language if we get a string with a language code
4123 // e.g. 'eng-GB'
4124 $originalLanguage = $language;
4125 if ( is_string( $language ) && strlen( $language ) > 0 )
4126 {
4127 $language = eZContentLanguage::idByLocale( $language );
4128 }
4129 else
4130 {
4131 $language = false;
4132 }
4133
4134 // This will be filled in with the available languages of the object
4135 // if a Language check is performed.
4136 $languageList = false;
4137
4138 // The 'move' function simply reuses 'edit' for generic access
4139 // but adds another top-level check below
4140 // The original function is still available in $origFunctionName
4141 if ( $functionName == 'move' )
4142 $functionName = 'edit';
4143
4144 $accessResult = $user->hasAccessTo( 'content' , $functionName );
4145 $accessWord = $accessResult['accessWord'];
4146
4147 /*
4148 // Uncomment this part if 'create' permissions should become implied 'edit'.
4149 // Merges in 'create' policies with 'edit'
4150 if ( $functionName == 'edit' &&
4151 !in_array( $accessWord, array( 'yes', 'no' ) ) )
4152 {
4153 // Add in create policies.
4154 $accessExtraResult = $user->hasAccessTo( 'content', 'create' );
4155 if ( $accessExtraResult['accessWord'] != 'no' )
4156 {
4157 $accessWord = $accessExtraResult['accessWord'];
4158 if ( isset( $accessExtraResult['policies'] ) )
4159 {
4160 $accessResult['policies'] = array_merge( $accessResult['policies'],
4161 $accessExtraResult['policies'] );
4162 }
4163 if ( isset( $accessExtraResult['accessList'] ) )
4164 {
4165 $accessResult['accessList'] = array_merge( $accessResult['accessList'],
4166 $accessExtraResult['accessList'] );
4167 }
4168 }
4169 }
4170 */
4171
4172 if ( $origFunctionName == 'remove' or
4173 $origFunctionName == 'move' )
4174 {
4175 $mainNode = $this->attribute( 'main_node' );
4176 // We do not allow these actions on objects placed at top-level
4177 // - remove
4178 // - move
4179 if ( $mainNode and $mainNode->attribute( 'parent_node_id' ) <= 1 )
4180 {
4181 return 0;
4182 }
4183 }
4184
4185 if ( $classID === false )
4186 {
4187 $classID = $this->attribute( 'contentclass_id' );
4188 }
4189 if ( $accessWord == 'yes' )
4190 {
4191 return 1;
4192 }
4193 else if ( $accessWord == 'no' )
4194 {
4195 if ( $functionName == 'edit' )
4196 {
4197 // Check if we have 'create' access under the main parent
4198 if ( $this->attribute( 'current_version' ) == 1 && !$this->attribute( 'status' ) )
4199 {
4200 $mainNode = eZNodeAssignment::fetchForObject( $this->attribute( 'id' ), $this->attribute( 'current_version' ) );
4201 $parentObj = $mainNode[0]->attribute( 'parent_contentobject' );
4202 if ( $parentObj instanceof eZContentObject )
4203 {
4204 $result = $parentObj->checkAccess( 'create', $this->attribute( 'contentclass_id' ),
4205 $parentObj->attribute( 'contentclass_id' ), false, $originalLanguage );
4206 return $result;
4207 }
4208 else
4209 {
4210 eZDebug::writeError( "Error retrieving parent object of main node for object id: " . $this->attribute( 'id' ), __METHOD__ );
4211 }
4212 }
4213
4214 return 0;
4215 }
4216
4217 if ( $returnAccessList === false )
4218 {
4219 return 0;
4220 }
4221 else
4222 {
4223 return $accessResult['accessList'];
4224 }
4225 }
4226 else
4227 {
4228 $policies =& $accessResult['policies'];
4229 $access = 'denied';
4230 foreach ( array_keys( $policies ) as $pkey )
4231 {
4232 $limitationArray =& $policies[ $pkey ];
4233 if ( $access == 'allowed' )
4234 {
4235 break;
4236 }
4237
4238 $limitationList = array();
4239 if ( isset( $limitationArray['Subtree' ] ) )
4240 {
4241 $checkedSubtree = false;
4242 }
4243 else
4244 {
4245 $checkedSubtree = true;
4246 $accessSubtree = false;
4247 }
4248 if ( isset( $limitationArray['Node'] ) )
4249 {
4250 $checkedNode = false;
4251 }
4252 else
4253 {
4254 $checkedNode = true;
4255 $accessNode = false;
4256 }
4257 foreach ( array_keys( $limitationArray ) as $key )
4258 {
4259 $access = 'denied';
4260 switch( $key )
4261 {
4262 case 'Class':
4263 {
4264 if ( $functionName == 'create' and
4265 !$originalClassID )
4266 {
4267 $access = 'allowed';
4268 }
4269 else if ( $functionName == 'create' and
4270 in_array( $classID, $limitationArray[$key] ) )
4271 {
4272 $access = 'allowed';
4273 }
4274 else if ( $functionName != 'create' and
4275 in_array( $this->attribute( 'contentclass_id' ), $limitationArray[$key] ) )
4276 {
4277 $access = 'allowed';
4278 }
4279 else
4280 {
4281 $access = 'denied';
4282 $limitationList = array( 'Limitation' => $key,
4283 'Required' => $limitationArray[$key] );
4284 }
4285 } break;
4286
4287 case 'ParentClass':
4288 {
4289
4290 if ( in_array( $this->attribute( 'contentclass_id' ), $limitationArray[$key] ) )
4291 {
4292 $access = 'allowed';
4293 }
4294 else
4295 {
4296 $access = 'denied';
4297 $limitationList = array( 'Limitation' => $key,
4298 'Required' => $limitationArray[$key] );
4299 }
4300 } break;
4301
4302 case 'ParentDepth':
4303 {
4304 $assignedNodes = $this->attribute( 'assigned_nodes' );
4305 if ( count( $assignedNodes ) > 0 )
4306 {
4307 foreach ( $assignedNodes as $assignedNode )
4308 {
4309 $depth = $assignedNode->attribute( 'depth' );
4310 if ( in_array( $depth, $limitationArray[$key] ) )
4311 {
4312 $access = 'allowed';
4313 break;
4314 }
4315 }
4316 }
4317
4318 if ( $access != 'allowed' )
4319 {
4320 $access = 'denied';
4321 $limitationList = array( 'Limitation' => $key,
4322 'Required' => $limitationArray[$key] );
4323 }
4324 } break;
4325
4326 case 'Section':
4327 case 'User_Section':
4328 {
4329 if ( in_array( $this->attribute( 'section_id' ), $limitationArray[$key] ) )
4330 {
4331 $access = 'allowed';
4332 }
4333 else
4334 {
4335 $access = 'denied';
4336 $limitationList = array( 'Limitation' => $key,
4337 'Required' => $limitationArray[$key] );
4338 }
4339 } break;
4340
4341 case 'Language':
4342 {
4343 $languageMask = 0;
4344 // If we don't have a language list yet we need to fetch it
4345 // and optionally filter out based on $language.
4346
4347 if ( $functionName == 'create' )
4348 {
4349 // If the function is 'create' we do not use the language_mask for matching.
4350 if ( $language !== false )
4351 {
4352 $languageMask = $language;
4353 }
4354 else
4355 {
4356 // If the create is used and no language specified then
4357 // we need to match against all possible languages (which
4358 // is all bits set, ie. -1).
4359 $languageMask = -1;
4360 }
4361 }
4362 else
4363 {
4364 if ( $language !== false )
4365 {
4366 if ( $languageList === false )
4367 {
4368 $languageMask = (int)$this->attribute( 'language_mask' );
4369 // We are restricting language check to just one language
4370 $languageMask &= (int)$language;
4371 // If the resulting mask is 0 it means that the user is trying to
4372 // edit a language which does not exist, ie. translating.
4373 // The mask will then become the language trying to edit.
4374 if ( $languageMask == 0 )
4375 {
4376 $languageMask = $language;
4377 }
4378 }
4379 }
4380 else
4381 {
4382 $languageMask = -1;
4383 }
4384 }
4385 // Fetch limit mask for limitation list
4386 $limitMask = eZContentLanguage::maskByLocale( $limitationArray[$key] );
4387 if ( ( $languageMask & $limitMask ) != 0 )
4388 {
4389 $access = 'allowed';
4390 }
4391 else
4392 {
4393 $access = 'denied';
4394 $limitationList = array( 'Limitation' => $key,
4395 'Required' => $limitationArray[$key] );
4396 }
4397 } break;
4398
4399 case 'Owner':
4400 case 'ParentOwner':
4401 {
4402 // if limitation value == 2, anonymous limited to current session.
4403 if ( in_array( 2, $limitationArray[$key] ) &&
4404 $user->isAnonymous() )
4405 {
4406 $createdObjectIDList = eZPreferences::value( 'ObjectCreationIDList' );
4407 if ( $createdObjectIDList &&
4408 in_array( $this->ID, unserialize( $createdObjectIDList ) ) )
4409 {
4410 $access = 'allowed';
4411 }
4412 }
4413 else if ( $this->attribute( 'owner_id' ) == $userID || $this->ID == $userID )
4414 {
4415 $access = 'allowed';
4416 }
4417 if ( $access != 'allowed' )
4418 {
4419 $access = 'denied';
4420 $limitationList = array ( 'Limitation' => $key, 'Required' => $limitationArray[$key] );
4421 }
4422 } break;
4423
4424 case 'Group':
4425 case 'ParentGroup':
4426 {
4427 $access = $this->checkGroupLimitationAccess( $limitationArray[$key], $userID );
4428
4429 if ( $access != 'allowed' )
4430 {
4431 $access = 'denied';
4432 $limitationList = array ( 'Limitation' => $key,
4433 'Required' => $limitationArray[$key] );
4434 }
4435 } break;
4436
4437 case 'State':
4438 {
4439 if ( count( array_intersect( $limitationArray[$key], $this->attribute( 'state_id_array' ) ) ) == 0 )
4440 {
4441 $access = 'denied';
4442 $limitationList = array ( 'Limitation' => $key,
4443 'Required' => $limitationArray[$key] );
4444 }
4445 else
4446 {
4447 $access = 'allowed';
4448 }
4449 } break;
4450
4451 case 'Node':
4452 {
4453 $accessNode = false;
4454 $mainNodeID = $this->attribute( 'main_node_id' );
4455 foreach ( $limitationArray[$key] as $nodeID )
4456 {
4457 $node = eZContentObjectTreeNode::fetch( $nodeID, false, false );
4458 $limitationNodeID = $node['main_node_id'];
4459 if ( $mainNodeID == $limitationNodeID )
4460 {
4461 $access = 'allowed';
4462 $accessNode = true;
4463 break;
4464 }
4465 }
4466 if ( $access != 'allowed' && $checkedSubtree && !$accessSubtree )
4467 {
4468 $access = 'denied';
4469 // ??? TODO: if there is a limitation on Subtree, return two limitations?
4470 $limitationList = array( 'Limitation' => $key,
4471 'Required' => $limitationArray[$key] );
4472 }
4473 else
4474 {
4475 $access = 'allowed';
4476 }
4477 $checkedNode = true;
4478 } break;
4479
4480 case 'Subtree':
4481 {
4482 $accessSubtree = false;
4483 $assignedNodes = $this->attribute( 'assigned_nodes' );
4484 if ( count( $assignedNodes ) != 0 )
4485 {
4486 foreach ( $assignedNodes as $assignedNode )
4487 {
4488 $path = $assignedNode->attribute( 'path_string' );
4489 $subtreeArray = $limitationArray[$key];
4490 foreach ( $subtreeArray as $subtreeString )
4491 {
4492 if ( strstr( $path, $subtreeString ) )
4493 {
4494 $access = 'allowed';
4495 $accessSubtree = true;
4496 break;
4497 }
4498 }
4499 }
4500 }
4501 else
4502 {
4503 $parentNodes = $this->attribute( 'parent_nodes' );
4504 if ( count( $parentNodes ) == 0 )
4505 {
4506 if ( $this->attribute( 'owner_id' ) == $userID || $this->ID == $userID )
4507 {
4508 $access = 'allowed';
4509 $accessSubtree = true;
4510 }
4511 }
4512 else
4513 {
4514 foreach ( $parentNodes as $parentNode )
4515 {
4516 $parentNode = eZContentObjectTreeNode::fetch( $parentNode, false, false );
4517 $path = $parentNode['path_string'];
4518
4519 $subtreeArray = $limitationArray[$key];
4520 foreach ( $subtreeArray as $subtreeString )
4521 {
4522 if ( strstr( $path, $subtreeString ) )
4523 {
4524 $access = 'allowed';
4525 $accessSubtree = true;
4526 break;
4527 }
4528 }
4529 }
4530 }
4531 }
4532 if ( $access != 'allowed' && $checkedNode && !$accessNode )
4533 {
4534 $access = 'denied';
4535 // ??? TODO: if there is a limitation on Node, return two limitations?
4536 $limitationList = array( 'Limitation' => $key,
4537 'Required' => $limitationArray[$key] );
4538 }
4539 else
4540 {
4541 $access = 'allowed';
4542 }
4543 $checkedSubtree = true;
4544 } break;
4545
4546 case 'User_Subtree':
4547 {
4548 $assignedNodes = $this->attribute( 'assigned_nodes' );
4549 if ( count( $assignedNodes ) != 0 )
4550 {
4551 foreach ( $assignedNodes as $assignedNode )
4552 {
4553 $path = $assignedNode->attribute( 'path_string' );
4554 $subtreeArray = $limitationArray[$key];
4555 foreach ( $subtreeArray as $subtreeString )
4556 {
4557 if ( strstr( $path, $subtreeString ) )
4558 {
4559 $access = 'allowed';
4560 }
4561 }
4562 }
4563 }
4564 else
4565 {
4566 $parentNodes = $this->attribute( 'parent_nodes' );
4567 if ( count( $parentNodes ) == 0 )
4568 {
4569 if ( $this->attribute( 'owner_id' ) == $userID || $this->ID == $userID )
4570 {
4571 $access = 'allowed';
4572 }
4573 }
4574 else
4575 {
4576 foreach ( $parentNodes as $parentNode )
4577 {
4578 $parentNode = eZContentObjectTreeNode::fetch( $parentNode, false, false );
4579 $path = $parentNode['path_string'];
4580
4581 $subtreeArray = $limitationArray[$key];
4582 foreach ( $subtreeArray as $subtreeString )
4583 {
4584 if ( strstr( $path, $subtreeString ) )
4585 {
4586 $access = 'allowed';
4587 break;
4588 }
4589 }
4590 }
4591 }
4592 }
4593 if ( $access != 'allowed' )
4594 {
4595 $access = 'denied';
4596 $limitationList = array( 'Limitation' => $key,
4597 'Required' => $limitationArray[$key] );
4598 }
4599 } break;
4600
4601 default:
4602 {
4603 if ( strncmp( $key, 'StateGroup_', 11 ) === 0 )
4604 {
4605 if ( count( array_intersect( $limitationArray[$key],
4606 $this->attribute( 'state_id_array' ) ) ) == 0 )
4607 {
4608 $access = 'denied';
4609 $limitationList = array ( 'Limitation' => $key,
4610 'Required' => $limitationArray[$key] );
4611 }
4612 else
4613 {
4614 $access = 'allowed';
4615 }
4616 }
4617 }
4618 }
4619 if ( $access == 'denied' )
4620 {
4621 break;
4622 }
4623 }
4624
4625 $policyList[] = array( 'PolicyID' => $pkey,
4626 'LimitationList' => $limitationList );
4627 }
4628
4629 if ( $access == 'denied' )
4630 {
4631 if ( $functionName == 'edit' )
4632 {
4633 // Check if we have 'create' access under the main parent
4634 if ( $this->attribute( 'current_version' ) == 1 && !$this->attribute( 'status' ) )
4635 {
4636 $mainNode = eZNodeAssignment::fetchForObject( $this->attribute( 'id' ), $this->attribute( 'current_version' ) );
4637 $parentObj = $mainNode[0]->attribute( 'parent_contentobject' );
4638
4639 if ( $parentObj instanceof eZContentObject )
4640 {
4641 $result = $parentObj->checkAccess( 'create', $this->attribute( 'contentclass_id' ),
4642 $parentObj->attribute( 'contentclass_id' ), false, $originalLanguage );
4643 }
4644 else
4645 {
4646 eZDebug::writeError( "Error retrieving parent object of main node for object id: " . $this->attribute( 'id' ), __METHOD__ );
4647 $result = 0;
4648 }
4649
4650 if ( $result )
4651 {
4652 $access = 'allowed';
4653 }
4654 return $result;
4655 }
4656 }
4657 }
4658
4659 if ( $access == 'denied' )
4660 {
4661 if ( $returnAccessList === false )
4662 {
4663 return 0;
4664 }
4665 else
4666 {
4667 return array( 'FunctionRequired' => array ( 'Module' => 'content',
4668 'Function' => $origFunctionName,
4669 'ClassID' => $classID,
4670 'MainNodeID' => $this->attribute( 'main_node_id' ) ),
4671 'PolicyList' => $policyList );
4672 }
4673 }
4674 else
4675 {
4676 return 1;
4677 }
4678 }
4679 }
4680
4681 // code-template::create-block: class-list-from-policy, is-object
4682 // code-template::auto-generated:START class-list-from-policy
4683 // This code is automatically generated from templates/classlistfrompolicy.ctpl
4684 // DO NOT EDIT THIS CODE DIRECTLY, CHANGE THE TEMPLATE FILE INSTEAD
4685
4693 function classListFromPolicy( $policy, $allowedLanguageCodes = false )
4694 {
4695 $canCreateClassIDListPart = array();
4696 $hasClassIDLimitation = false;
4697 $user = eZUser::currentUser();
4698 $userID = $user->attribute( 'contentobject_id' );
4699
4700 if ( isset( $policy['ParentOwner'] ) )
4701 {
4702 // if limitation value == 2, anonymous limited to current session.
4703 if ( in_array( 2, $policy['ParentOwner'] ) && $user->isAnonymous() )
4704 {
4705 $createdObjectIDList = eZPreferences::value( 'ObjectCreationIDList' );
4706 if ( !$createdObjectIDList ||
4707 !in_array( $this->ID, unserialize( $createdObjectIDList ) ) )
4708 {
4709 return array();
4710 }
4711 }
4712 else if ( $this->attribute( 'owner_id' ) != $userID &&
4713 $this->ID != $userID )
4714 {
4715 return array();
4716 }
4717 }
4718
4719 if ( isset( $policy['ParentGroup'] ) )
4720 {
4721 $access = $this->checkGroupLimitationAccess( $policy['ParentGroup'], $userID );
4722 if ( $access !== 'allowed' )
4723 {
4724 return array();
4725 }
4726 }
4727
4728 if ( isset( $policy['Class'] ) )
4729 {
4730 $canCreateClassIDListPart = $policy['Class'];
4731 $hasClassIDLimitation = true;
4732 }
4733
4734 if ( isset( $policy['User_Section'] ) )
4735 {
4736 if ( !in_array( $this->attribute( 'section_id' ), $policy['User_Section'] ) )
4737 {
4738 return array();
4739 }
4740 }
4741
4742 if ( isset( $policy['User_Subtree'] ) )
4743 {
4744 $allowed = false;
4745 $assignedNodes = $this->attribute( 'assigned_nodes' );
4746 foreach ( $assignedNodes as $assignedNode )
4747 {
4748 $path = $assignedNode->attribute( 'path_string' );
4749 foreach ( $policy['User_Subtree'] as $subtreeString )
4750 {
4751 if ( strstr( $path, $subtreeString ) )
4752 {
4753 $allowed = true;
4754 break;
4755 }
4756 }
4757 }
4758 if( !$allowed )
4759 {
4760 return array();
4761 }
4762 }
4763
4764 if ( isset( $policy['Section'] ) )
4765 {
4766 if ( !in_array( $this->attribute( 'section_id' ), $policy['Section'] ) )
4767 {
4768 return array();
4769 }
4770 }
4771
4772 if ( isset( $policy['ParentClass'] ) )
4773 {
4774 if ( !in_array( $this->attribute( 'contentclass_id' ), $policy['ParentClass'] ) )
4775 {
4776 return array();
4777 }
4778 }
4779
4780 if ( isset( $policy['Assigned'] ) )
4781 {
4782 if ( $this->attribute( 'owner_id' ) != $userID )
4783 {
4784 return array();
4785 }
4786 }
4787
4788 $allowedNode = false;
4789 if ( isset( $policy['Node'] ) )
4790 {
4791 $allowed = false;
4792 foreach( $policy['Node'] as $nodeID )
4793 {
4794 $mainNodeID = $this->attribute( 'main_node_id' );
4795 $node = eZContentObjectTreeNode::fetch( $nodeID, false, false );
4796 if ( $mainNodeID == $node['main_node_id'] )
4797 {
4798 $allowed = true;
4799 $allowedNode = true;
4800 break;
4801 }
4802 }
4803 if ( !$allowed && !isset( $policy['Subtree'] ) )
4804 {
4805 return array();
4806 }
4807 }
4808
4809 if ( isset( $policy['Subtree'] ) )
4810 {
4811 $allowed = false;
4812 $assignedNodes = $this->attribute( 'assigned_nodes' );
4813 foreach ( $assignedNodes as $assignedNode )
4814 {
4815 $path = $assignedNode->attribute( 'path_string' );
4816 foreach ( $policy['Subtree'] as $subtreeString )
4817 {
4818 if ( strstr( $path, $subtreeString ) )
4819 {
4820 $allowed = true;
4821 break;
4822 }
4823 }
4824 }
4825 if ( !$allowed && !$allowedNode )
4826 {
4827 return array();
4828 }
4829 }
4830
4831 if ( isset( $policy['Language'] ) )
4832 {
4833 if ( $allowedLanguageCodes )
4834 {
4835 $allowedLanguageCodes = array_intersect( $allowedLanguageCodes, $policy['Language'] );
4836 }
4837 else
4838 {
4839 $allowedLanguageCodes = $policy['Language'];
4840 }
4841 }
4842
4843 if ( $hasClassIDLimitation )
4844 {
4845 return array( 'classes' => $canCreateClassIDListPart, 'language_codes' => $allowedLanguageCodes );
4846 }
4847 return array( 'classes' => '*', 'language_codes' => $allowedLanguageCodes );
4848 }
4849
4850 // This code is automatically generated from templates/classlistfrompolicy.ctpl
4851 // code-template::auto-generated:END class-list-from-policy
4852
4853 // code-template::create-block: can-instantiate-class-list, group-filter, object-policy-list, name-create, object-creation, object-sql-creation
4854 // code-template::auto-generated:START can-instantiate-class-list
4855 // This code is automatically generated from templates/classcreatelist.ctpl
4856 // DO NOT EDIT THIS CODE DIRECTLY, CHANGE THE TEMPLATE FILE INSTEAD
4857
4868 function canCreateClassList( $asObject = false, $includeFilter = true, $groupList = false, $fetchID = false )
4869 {
4870 $ini = eZINI::instance();
4871 $groupArray = array();
4872 $languageCodeList = eZContentLanguage::fetchLocaleList();
4873 $allowedLanguages = array( '*' => array() );
4874
4875 $user = eZUser::currentUser();
4876 $accessResult = $user->hasAccessTo( 'content' , 'create' );
4877 $accessWord = $accessResult['accessWord'];
4878
4879 $classIDArray = array();
4880 $classList = array();
4881 $fetchAll = false;
4882 if ( $accessWord == 'yes' )
4883 {
4884 $fetchAll = true;
4885 $allowedLanguages['*'] = $languageCodeList;
4886 }
4887 else if ( $accessWord == 'no' )
4888 {
4889 // Cannot create any objects, return empty list.
4890 return $classList;
4891 }
4892 else
4893 {
4894 $policies = $accessResult['policies'];
4895 foreach ( $policies as $policyKey => $policy )
4896 {
4897 $policyArray = $this->classListFromPolicy( $policy, $languageCodeList );
4898 if ( empty( $policyArray ) )
4899 {
4900 continue;
4901 }
4902 $classIDArrayPart = $policyArray['classes'];
4903 $languageCodeArrayPart = $policyArray['language_codes'];
4904 // No class limitation for this policy AND no previous limitation(s)
4905 if ( $classIDArrayPart == '*' && empty( $classIDArray ) )
4906 {
4907 $fetchAll = true;
4908 $allowedLanguages['*'] = array_unique( array_merge( $allowedLanguages['*'], $languageCodeArrayPart ) );
4909 }
4910 else if ( is_array( $classIDArrayPart ) )
4911 {
4912 $fetchAll = false;
4913 foreach( $classIDArrayPart as $class )
4914 {
4915 if ( isset( $allowedLanguages[$class] ) )
4916 {
4917 $allowedLanguages[$class] = array_unique( array_merge( $allowedLanguages[$class], $languageCodeArrayPart ) );
4918 }
4919 else
4920 {
4921 $allowedLanguages[$class] = $languageCodeArrayPart;
4922 }
4923 }
4924 $classIDArray = array_merge( $classIDArray, array_diff( $classIDArrayPart, $classIDArray ) );
4925 }
4926 }
4927 }
4928
4929 $db = eZDB::instance();
4930
4931 $filterTableSQL = '';
4932 $filterSQL = '';
4933 // Create extra SQL statements for the class group filters.
4934 if ( is_array( $groupList ) )
4935 {
4936 if ( count( $groupList ) == 0 )
4937 {
4938 return $classList;
4939 }
4940
4941 $filterTableSQL = ', ezcontentclass_classgroup ccg';
4942 $filterSQL = ( " AND" .
4943 " cc.id = ccg.contentclass_id AND" .
4944 " " );
4945 $filterSQL .= $db->generateSQLINStatement( $groupList, 'ccg.group_id', !$includeFilter, true, 'int' );
4946 }
4947
4948 $classNameFilter = eZContentClassName::sqlFilter( 'cc' );
4949
4950 if ( $fetchAll )
4951 {
4952 // If $asObject is true we fetch all fields in class
4953 $fields = $asObject ? "cc.*, $classNameFilter[nameField]" : "cc.id, $classNameFilter[nameField]";
4954 $rows = $db->arrayQuery( "SELECT DISTINCT $fields " .
4955 "FROM ezcontentclass cc$filterTableSQL, $classNameFilter[from] " .
4956 "WHERE cc.version = " . eZContentClass::VERSION_STATUS_DEFINED . " $filterSQL AND $classNameFilter[where] " .
4957 "ORDER BY $classNameFilter[nameField] ASC" );
4958 $classList = eZPersistentObject::handleRows( $rows, 'eZContentClass', $asObject );
4959 }
4960 else
4961 {
4962 // If the constrained class list is empty we are not allowed to create any class
4963 if ( count( $classIDArray ) == 0 )
4964 {
4965 return $classList;
4966 }
4967
4968 $classIDCondition = $db->generateSQLINStatement( $classIDArray, 'cc.id' );
4969 // If $asObject is true we fetch all fields in class
4970 $fields = $asObject ? "cc.*, $classNameFilter[nameField]" : "cc.id, $classNameFilter[nameField]";
4971 $rows = $db->arrayQuery( "SELECT DISTINCT $fields " .
4972 "FROM ezcontentclass cc$filterTableSQL, $classNameFilter[from] " .
4973 "WHERE $classIDCondition AND" .
4974 " cc.version = " . eZContentClass::VERSION_STATUS_DEFINED . " $filterSQL AND $classNameFilter[where] " .
4975 "ORDER BY $classNameFilter[nameField] ASC" );
4976 $classList = eZPersistentObject::handleRows( $rows, 'eZContentClass', $asObject );
4977 }
4978
4979 if ( $asObject )
4980 {
4981 foreach ( $classList as $key => $class )
4982 {
4983 $id = $class->attribute( 'id' );
4984 if ( isset( $allowedLanguages[$id] ) )
4985 {
4986 $languageCodes = array_unique( array_merge( $allowedLanguages['*'], $allowedLanguages[$id] ) );
4987 }
4988 else
4989 {
4990 $languageCodes = $allowedLanguages['*'];
4991 }
4992 $classList[$key]->setCanInstantiateLanguages( $languageCodes );
4993 }
4994 }
4995
4996 eZDebugSetting::writeDebug( 'kernel-content-class', $classList, "class list fetched from db" );
4997 return $classList;
4998 }
4999
5000 // This code is automatically generated from templates/classcreatelist.ctpl
5001 // code-template::auto-generated:END can-instantiate-class-list
5002
5009 function accessList( $function )
5010 {
5011 switch( $function )
5012 {
5013 case 'read':
5014 {
5015 return $this->checkAccess( 'read', false, false, true );
5016 } break;
5017
5018 case 'edit':
5019 {
5020 return $this->checkAccess( 'edit', false, false, true );
5021 } break;
5022 }
5023 return 0;
5024 }
5025
5031 function canRead( )
5032 {
5033 if ( !isset( $this->Permissions["can_read"] ) )
5034 {
5035 $this->Permissions["can_read"] = $this->checkAccess( 'read' );
5036 }
5037 return ( $this->Permissions["can_read"] == 1 );
5038 }
5039
5045 function canPdf( )
5046 {
5047 if ( !isset( $this->Permissions["can_pdf"] ) )
5048 {
5049 $this->Permissions["can_pdf"] = $this->checkAccess( 'pdf' );
5050 }
5051 return ( $this->Permissions["can_pdf"] == 1 );
5052 }
5053
5059 function canViewEmbed( )
5060 {
5061 if ( !isset( $this->Permissions["can_view_embed"] ) )
5062 {
5063 $this->Permissions["can_view_embed"] = $this->checkAccess( 'view_embed' );
5064 }
5065 return ( $this->Permissions["can_view_embed"] == 1 );
5066 }
5067
5073 function canDiff( )
5074 {
5075 if ( !isset( $this->Permissions["can_diff"] ) )
5076 {
5077 $this->Permissions["can_diff"] = $this->checkAccess( 'diff' );
5078 }
5079 return ( $this->Permissions["can_diff"] == 1 );
5080 }
5081
5087 function canCreate( )
5088 {
5089 if ( !isset( $this->Permissions["can_create"] ) )
5090 {
5091 $this->Permissions["can_create"] = $this->checkAccess( 'create' );
5092 }
5093 return ( $this->Permissions["can_create"] == 1 );
5094 }
5095
5105 function canEdit( $originalClassID = false, $parentClassID = false, $returnAccessList = false, $language = false )
5106 {
5107 $isCalledClean = ( func_num_args() == 0 );
5108 if ( isset( $this->Permissions["can_edit"] ) && $isCalledClean )
5109 {
5110 $canEdit = $this->Permissions["can_edit"];
5111 }
5112 else
5113 {
5114 $canEdit = $this->checkAccess( 'edit', $originalClassID, $parentClassID, $returnAccessList, $language );
5115 if ( $canEdit != 1 )
5116 {
5117 $user = eZUser::currentUser();
5118 if ( $user->attribute( 'contentobject_id' ) === $this->attribute( 'id' ) )
5119 {
5120 $access = $user->hasAccessTo( 'user', 'selfedit' );
5121 if ( $access['accessWord'] == 'yes' )
5122 {
5123 $canEdit = 1;
5124 }
5125 }
5126 }
5127
5128 if ( $isCalledClean )
5129 {
5130 $this->Permissions["can_edit"] = $canEdit;
5131 }
5132 }
5133 return ( $canEdit == 1 );
5134 }
5135
5141 function canTranslate( )
5142 {
5143 if ( !isset( $this->Permissions["can_translate"] ) )
5144 {
5145 $this->Permissions["can_translate"] = $this->checkAccess( 'translate' );
5146 if ( $this->Permissions["can_translate"] != 1 )
5147 {
5148 $user = eZUser::currentUser();
5149 if ( $user->id() == $this->attribute( 'id' ) )
5150 {
5151 $access = $user->hasAccessTo( 'user', 'selfedit' );
5152 if ( $access['accessWord'] == 'yes' )
5153 {
5154 $this->Permissions["can_translate"] = 1;
5155 }
5156 }
5157 }
5158 }
5159 return ( $this->Permissions["can_translate"] == 1 );
5160 }
5161
5167 function canRemove( )
5168 {
5169
5170 if ( !isset( $this->Permissions["can_remove"] ) )
5171 {
5172 $this->Permissions["can_remove"] = $this->checkAccess( 'remove' );
5173 }
5174 return ( $this->Permissions["can_remove"] == 1 );
5175 }
5176
5182 function canMoveFrom( )
5183 {
5184
5185 if ( !isset( $this->Permissions['can_move_from'] ) )
5186 {
5187 $this->Permissions['can_move_from'] = $this->checkAccess( 'edit' ) && $this->checkAccess( 'remove' );
5188 }
5189 return ( $this->Permissions['can_move_from'] == 1 );
5190 }
5191
5199 function className()
5200 {
5201 if ( !is_numeric( $this->ClassID ) )
5202 {
5203 return null;
5204 }
5205
5206 if ( $this->ClassName !== false )
5207 return $this->ClassName;
5208
5209 $db = eZDB::instance();
5210 $id = (int)$this->ClassID;
5211 $sql = "SELECT serialized_name_list FROM ezcontentclass WHERE id=$id and version=0";
5212 $rows = $db->arrayQuery( $sql );
5213 if ( count( $rows ) > 0 )
5214 {
5215 $this->ClassName = eZContentClass::nameFromSerializedString( $rows[0]['serialized_name_list'] );
5216 }
5217 return $this->ClassName;
5218 }
5219
5225 function contentActionList()
5226 {
5227 $version = $this->attribute( 'current_version' );
5228 $language = $this->initialLanguageCode();
5229 if ( !isset( $this->ContentObjectAttributeArray[$version][$language] ) )
5230 {
5231 $attributeList = $this->contentObjectAttributes();
5232 $this->ContentObjectAttributeArray[$version][$language] =& $attributeList;
5233 }
5234 else
5235 $attributeList = $this->ContentObjectAttributeArray[$version][$language];
5236
5237 // Fetch content actions if not already fetched
5238 if ( $this->ContentActionList === false )
5239 {
5240 foreach ( $attributeList as $attribute )
5241 {
5242 $contentActionList = $attribute->contentActionList();
5243 if ( is_array( $contentActionList ) && !empty( $contentActionList ) )
5244 {
5245 foreach ( $contentActionList as $action )
5246 {
5247 if ( !$this->hasContentAction( $action['action'] ) )
5248 {
5249 $this->ContentActionList[] = $action;
5250 }
5251 }
5252 }
5253 }
5254 }
5255 return $this->ContentActionList;
5256 }
5257
5264 function hasContentAction( $name )
5265 {
5266 $return = false;
5267 if ( is_array ( $this->ContentActionList ) )
5268 {
5269 foreach ( $this->ContentActionList as $action )
5270 {
5271 if ( $action['action'] == $name )
5272 {
5273 $return = true;
5274 }
5275 }
5276 }
5277 return $return;
5278 }
5279
5285 function availableLanguages()
5286 {
5287 $languages = array();
5288 $languageObjects = $this->languages();
5289
5290 foreach ( $languageObjects as $languageObject )
5291 {
5292 $languages[] = $languageObject->attribute( 'locale' );
5293 }
5294
5295 return $languages;
5296 }
5297
5303 function availableLanguagesJsArray()
5304 {
5305 return eZContentLanguage::jsArrayByMask( $this->LanguageMask );
5306 }
5307
5311 function languages()
5312 {
5313 return isset( $this->LanguageMask ) ?
5314 eZContentLanguage::prioritizedLanguagesByMask( $this->LanguageMask ) :
5315 array();
5316 }
5317
5321 function allLanguages()
5322 {
5323 $languages = isset( $this->LanguageMask ) ? eZContentLanguage::languagesByMask( $this->LanguageMask ) : array();
5324 return $languages;
5325 }
5326
5330 static function defaultLanguage()
5331 {
5332 if ( ! isset( $GLOBALS['eZContentObjectDefaultLanguage'] ) )
5333 {
5334 $defaultLanguage = false;
5335 $language = eZContentLanguage::topPriorityLanguage();
5336 if ( $language )
5337 {
5338 $defaultLanguage = $language->attribute( 'locale' );
5339 }
5340 else
5341 {
5342 $ini = eZINI::instance();
5343 if ( $ini->hasVariable( 'RegionalSettings', 'ContentObjectLocale' ) )
5344 {
5345 $defaultLanguage = $ini->variable( 'RegionalSettings', 'ContentObjectLocale' );
5346 eZContentLanguage::fetchByLocale( $defaultLanguage, true );
5347 }
5348 }
5349 $GLOBALS['eZContentObjectDefaultLanguage'] = $defaultLanguage;
5350 }
5351
5352 return $GLOBALS['eZContentObjectDefaultLanguage'];
5353 }
5354
5362 static function setDefaultLanguage( $lang )
5363 {
5364 return false;
5365 }
5366
5370 function setClassName( $name )
5371 {
5372 $this->ClassName = $name;
5373 }
5374
5383 static function translationStringList()
5384 {
5385 $translationList = array();
5386 $languageList = eZContentLanguage::fetchList();
5387
5388 foreach ( $languageList as $language )
5389 {
5390 $translationList[] = $language->attribute( 'locale' );
5391 }
5392
5393 return $translationList;
5394 }
5395
5404 static function translationList()
5405 {
5406 $translationList = array();
5407 $languageList = eZContentLanguage::fetchList();
5408
5409 foreach ( $languageList as $language )
5410 {
5411 $translationList[] = $language->localeObject();
5412 }
5413
5414 return $translationList;
5415 }
5416
5424 function fetchClassAttributes( $version = 0, $asObject = true )
5425 {
5426 return eZContentClassAttribute::fetchListByClassID( $this->attribute( 'contentclass_id' ), $version, $asObject );
5427 }
5428
5438 static function mapLanguage( $language, $options )
5439 {
5440 if ( isset( $options['language_map'][$language] ) )
5441 {
5442 return $options['language_map'][$language];
5443 }
5444 return $language;
5445 }
5446
5460 static function unserialize( $package, $domNode, &$options, $ownerID = false, $handlerType = 'ezcontentobject' )
5461 {
5462 if ( $domNode->localName != 'object' )
5463 {
5464 $retValue = false;
5465 return $retValue;
5466 }
5467
5468 $initialLanguage = eZContentObject::mapLanguage( $domNode->getAttribute( 'initial_language' ), $options );
5469 if( $initialLanguage === 'skip' )
5470 {
5471 $retValue = true;
5472 return $retValue;
5473 }
5474
5475 $sectionID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'section_id' );
5476 if ( $ownerID === false )
5477 {
5478 $ownerID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'owner_id' );
5479 }
5480 $remoteID = $domNode->getAttribute( 'remote_id' );
5481 $name = $domNode->getAttribute( 'name' );
5482 $classRemoteID = $domNode->getAttribute( 'class_remote_id' );
5483 $classIdentifier = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'class_identifier' );
5484 $alwaysAvailable = ( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'always_available' ) == '1' );
5485
5486 $contentClass = eZContentClass::fetchByRemoteID( $classRemoteID );
5487 if ( !$contentClass )
5488 {
5489 $contentClass = eZContentClass::fetchByIdentifier( $classIdentifier );
5490 }
5491
5492 if ( !$contentClass )
5493 {
5494 $options['error'] = array( 'error_code' => self::PACKAGE_ERROR_NO_CLASS,
5495 'element_id' => $remoteID,
5496 'description' => "Can't install object '$name': Unable to fetch class with remoteID: $classRemoteID." );
5497 $retValue = false;
5498 return $retValue;
5499 }
5500
5502 $versionListNode = $domNode->getElementsByTagName( 'version-list' )->item( 0 );
5503
5504 $importedLanguages = array();
5505 foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode )
5506 {
5508 foreach ( $versionDOMNode->getElementsByTagName( 'object-translation' ) as $versionDOMNodeChild )
5509 {
5511 $importedLanguage = eZContentObject::mapLanguage( $versionDOMNodeChild->getAttribute( 'language' ), $options );
5512 $language = eZContentLanguage::fetchByLocale( $importedLanguage );
5513 // Check if the language is allowed in this setup.
5514 if ( $language )
5515 {
5516 $hasTranslation = true;
5517 }
5518 else
5519 {
5520 if ( $importedLanguage == 'skip' )
5521 continue;
5522
5523 // if there is no needed translation in system then add it
5524 $locale = eZLocale::instance( $importedLanguage );
5525 $translationName = $locale->internationalLanguageName();
5526 $translationLocale = $locale->localeCode();
5527
5528 if ( $locale->isValid() )
5529 {
5530 eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() );
5531 $hasTranslation = true;
5532 }
5533 else
5534 $hasTranslation = false;
5535 }
5536 if ( $hasTranslation )
5537 {
5538 $importedLanguages[] = $importedLanguage;
5539 $importedLanguages = array_unique( $importedLanguages );
5540 }
5541 }
5542 }
5543
5544 // If object exists we return a error.
5545 // Minimum install element is an object now.
5546
5547 $contentObject = eZContentObject::fetchByRemoteID( $remoteID );
5548 // Figure out initial language
5549 if ( !$initialLanguage ||
5550 !in_array( $initialLanguage, $importedLanguages ) )
5551 {
5552 $initialLanguage = false;
5553 foreach ( eZContentLanguage::prioritizedLanguages() as $language )
5554 {
5555 if ( in_array( $language->attribute( 'locale' ), $importedLanguages ) )
5556 {
5557 $initialLanguage = $language->attribute( 'locale' );
5558 break;
5559 }
5560 }
5561 }
5562 if ( !$contentObject )
5563 {
5564 $firstVersion = true;
5565 $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID );
5566 }
5567 else
5568 {
5569 $firstVersion = false;
5570 $description = "Object '$name' already exists.";
5571
5572 $choosenAction = eZPackageHandler::errorChoosenAction( self::PACKAGE_ERROR_EXISTS,
5573 $options, $description, $handlerType, false );
5574
5575 switch( $choosenAction )
5576 {
5577 case eZPackage::NON_INTERACTIVE:
5578 case self::PACKAGE_UPDATE:
5579 {
5580 // Keep existing contentobject.
5581 } break;
5582
5583 case self::PACKAGE_REPLACE:
5584 {
5585 eZContentObjectOperations::remove( $contentObject->attribute( 'id' ) );
5586
5587 unset( $contentObject );
5588 $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID );
5589 $firstVersion = true;
5590 } break;
5591
5592 case self::PACKAGE_SKIP:
5593 {
5594 $retValue = true;
5595 return $retValue;
5596 } break;
5597
5598 case self::PACKAGE_NEW:
5599 {
5600 $contentObject->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'object' ) );
5601 $contentObject->store();
5602 unset( $contentObject );
5603 $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID );
5604 $firstVersion = true;
5605 } break;
5606
5607 default:
5608 {
5609 $options['error'] = array( 'error_code' => self::PACKAGE_ERROR_EXISTS,
5610 'element_id' => $remoteID,
5611 'description' => $description,
5612 'actions' => array( self::PACKAGE_REPLACE => ezpI18n::tr( 'kernel/classes', 'Replace existing object' ),
5613 self::PACKAGE_SKIP => ezpI18n::tr( 'kernel/classes', 'Skip object' ),
5614 self::PACKAGE_NEW => ezpI18n::tr( 'kernel/classes', 'Keep existing and create a new one' ),
5615 self::PACKAGE_UPDATE => ezpI18n::tr( 'kernel/classes', 'Update existing object' ) ) );
5616 $retValue = false;
5617 return $retValue;
5618 } break;
5619 }
5620 }
5621
5622 $db = eZDB::instance();
5623 $db->begin();
5624
5625 if ( $alwaysAvailable )
5626 {
5627 // Make sure always available bit is set.
5628 $contentObject->setAttribute( 'language_mask', (int)$contentObject->attribute( 'language_mask' ) | 1 );
5629 }
5630
5631 $contentObject->setAttribute( 'section_id', $sectionID );
5632 $contentObject->store();
5633 $activeVersion = false;
5634 $lastVersion = false;
5635 $versionListActiveVersion = $versionListNode->getAttribute( 'active_version' );
5636
5637 $contentObject->setAttribute( 'remote_id', $remoteID );
5638 $contentObject->setAttribute( 'contentclass_id', $contentClass->attribute( 'id' ) );
5639 $contentObject->store();
5640
5641 $sectionObject = eZSection::fetch( $sectionID );
5642 if ( $sectionObject instanceof eZSection )
5643 {
5644 $updateWithParentSection = false;
5645 }
5646 else
5647 {
5648 $updateWithParentSection = true;
5649 }
5650
5651 $options['language_array'] = $importedLanguages;
5652 $versionList = array();
5653 foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode )
5654 {
5655 unset( $nodeList );
5656 $nodeList = array();
5657 $contentObjectVersion = eZContentObjectVersion::unserialize( $versionDOMNode,
5658 $contentObject,
5659 $ownerID,
5660 $sectionID,
5661 $versionListActiveVersion,
5662 $firstVersion,
5663 $nodeList,
5664 $options,
5665 $package,
5666 'ezcontentobject',
5667 $initialLanguage );
5668
5669 if ( !$contentObjectVersion )
5670 {
5671 $db->commit();
5672
5673 $retValue = false;
5674 return $retValue;
5675 }
5676
5677 $versionStatus = $versionDOMNode->getAttributeNS( 'http://ez.no/ezobject', 'status' );
5678 $versionList[$versionDOMNode->getAttributeNS( 'http://ez.no/ezobject', 'version' )] = array( 'node_list' => $nodeList,
5679 'status' => $versionStatus );
5680 unset( $versionStatus );
5681
5682 $firstVersion = false;
5683 $lastVersion = $contentObjectVersion->attribute( 'version' );
5684 if ( $versionDOMNode->getAttribute( 'version' ) == $versionListActiveVersion )
5685 {
5686 $activeVersion = $contentObjectVersion->attribute( 'version' );
5687 }
5688 eZNodeAssignment::setNewMainAssignment( $contentObject->attribute( 'id' ), $lastVersion );
5689
5690 eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ),
5691 'version' => $lastVersion ) );
5692
5693 $mainNodeInfo = null;
5694 foreach ( $nodeList as $nodeInfo )
5695 {
5696 if ( $nodeInfo['is_main'] )
5697 {
5698 $mainNodeInfo =& $nodeInfo;
5699 break;
5700 }
5701 }
5702 if ( $mainNodeInfo )
5703 {
5704 $existingMainNode = eZContentObjectTreeNode::fetchByRemoteID( $mainNodeInfo['parent_remote_id'], false );
5705 if ( $existingMainNode )
5706 {
5707 eZContentObjectTreeNode::updateMainNodeID( $existingMainNode['node_id'],
5708 $mainNodeInfo['contentobject_id'],
5709 $mainNodeInfo['contentobject_version'],
5710 $mainNodeInfo['parent_node'],
5711 $updateWithParentSection );
5712 }
5713 }
5714 unset( $mainNodeInfo );
5715 // Refresh $contentObject from DB.
5716 $contentObject = eZContentObject::fetch( $contentObject->attribute( 'id' ) );
5717 }
5718 if ( !$activeVersion )
5719 {
5720 $activeVersion = $lastVersion;
5721 }
5722
5723 /*
5724 $contentObject->setAttribute( 'current_version', $activeVersion );
5725 */
5726 $contentObject->setAttribute( 'name', $name );
5727 if ( isset( $options['use_dates_from_package'] ) && $options['use_dates_from_package'] )
5728 {
5729 $contentObject->setAttribute( 'published', eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'published' ) ) );
5730 $contentObject->setAttribute( 'modified', eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'modified' ) ) );
5731 }
5732 $contentObject->store();
5733
5734 $versions = $contentObject->versions();
5735 $objectName = $contentObject->name();
5736 $objectID = $contentObject->attribute( 'id' );
5737 foreach ( $versions as $version )
5738 {
5739 $versionNum = $version->attribute( 'version' );
5740 $oldVersionStatus = $version->attribute( 'status' );
5741 $newVersionStatus = isset( $versionList[$versionNum] ) ? $versionList[$versionNum]['status'] : null;
5742
5743 // set the correct status for non-published versions
5744 if ( isset( $newVersionStatus ) && $oldVersionStatus != $newVersionStatus && $newVersionStatus != eZContentObjectVersion::STATUS_PUBLISHED )
5745 {
5746 $version->setAttribute( 'status', $newVersionStatus );
5747 $version->store( array( 'status' ) );
5748 }
5749
5750 // when translation does not have object name set then we copy object name from the current object version
5751 $translations = $version->translations( false );
5752 if ( !$translations )
5753 continue;
5754 foreach ( $translations as $translation )
5755 {
5756 if ( ! $contentObject->name( $versionNum, $translation ) )
5757 {
5758 eZDebug::writeNotice( "Setting name '$objectName' for version ($versionNum) of the content object ($objectID) in language($translation)", __METHOD__ );
5759 $contentObject->setName( $objectName, $versionNum, $translation );
5760 }
5761 }
5762 }
5763
5764 foreach ( $versionList[$versionListActiveVersion]['node_list'] as $nodeInfo )
5765 {
5766 unset( $parentNode );
5767 $parentNode = eZContentObjectTreeNode::fetchNode( $contentObject->attribute( 'id' ),
5768 $nodeInfo['parent_node'] );
5769 if ( is_object( $parentNode ) )
5770 {
5771 $parentNode->setAttribute( 'priority', $nodeInfo['priority'] );
5772 $parentNode->store( array( 'priority' ) );
5773 }
5774 }
5775
5776 $db->commit();
5777
5778 return $contentObject;
5779 }
5780
5787 function postUnserialize( $package )
5788 {
5789 foreach( $this->versions() as $version )
5790 {
5791 $version->postUnserialize( $package );
5792 }
5793 }
5794
5808 function serialize( $package, $specificVersion = false, $options = false, $contentNodeIDArray = false, $topNodeIDArray = false )
5809 {
5810 if ( $options &&
5811 $options['node_assignment'] == 'main' )
5812 {
5813 if ( !isset( $contentNodeIDArray[$this->attribute( 'main_node_id' )] ) )
5814 {
5815 return false;
5816 }
5817 }
5818
5819 $dom = new DomDocument();
5820 $objectNode = $dom->createElementNS( 'http://ez.no/ezobject', 'ezremote:object' );
5821
5822 $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:id', $this->ID );
5823 $objectNode->setAttribute( 'name', $this->Name );
5824 $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:section_id', $this->SectionID );
5825 $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:owner_id', $this->OwnerID );
5826 $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:class_id', $this->ClassID );
5827 $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:published', eZDateUtils::rfc1123Date( $this->attribute( 'published' ) ) );
5828 $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:modified', eZDateUtils::rfc1123Date( $this->attribute( 'modified' ) ) );
5829 if ( !$this->attribute( 'remote_id' ) )
5830 {
5831 $this->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'object' ) );
5832 $this->store();
5833 }
5834 $objectNode->setAttribute( 'remote_id', $this->attribute( 'remote_id' ) );
5835 $contentClass = $this->attribute( 'content_class' );
5836 $objectNode->setAttribute( 'class_remote_id', $contentClass->attribute( 'remote_id' ) );
5837 $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:class_identifier', $contentClass->attribute( 'identifier' ) );
5838 $alwaysAvailableText = '0';
5839 if ( (int)$this->attribute( 'language_mask' ) & 1 )
5840 {
5841 $alwaysAvailableText = '1';
5842 }
5843 $objectNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:always_available', $alwaysAvailableText );
5844
5845 $versions = array();
5846 $oneLanguagePerVersion = false;
5847 if ( $specificVersion === false )
5848 {
5849 $versions = $this->versions();
5850 // Since we are exporting all versions it should only contain
5851 // one language per version
5852 //$oneLanguagePerVersion = true; // uncomment to get one language per version
5853 }
5854 else if ( $specificVersion === true )
5855 {
5856 $versions[] = $this->currentVersion();
5857 }
5858 else
5859 {
5860 $versions[] = $this->version( $specificVersion );
5861 // Since we are exporting a specific version it should only contain
5862 // one language per version?
5863 $oneLanguagePerVersion = true;
5864 }
5865
5866 $this->fetchClassAttributes();
5867
5868 $exportedLanguages = array();
5869
5870 $versionsNode = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:version-list' );
5871 $versionsNode->setAttribute( 'active_version', $this->CurrentVersion );
5872 foreach ( $versions as $version )
5873 {
5874 if ( !$version )
5875 {
5876 continue;
5877 }
5878 $options['only_initial_language'] = $oneLanguagePerVersion;
5879 $versionNode = $version->serialize( $package, $options, $contentNodeIDArray, $topNodeIDArray );
5880 if ( $versionNode )
5881 {
5882 $importedVersionNode = $dom->importNode( $versionNode, true );
5883 $versionsNode->appendChild( $importedVersionNode );
5884 foreach ( $versionNode->getElementsByTagName( 'object-translation' ) as $versionNodeChild )
5885 {
5886 $exportedLanguage = $versionNodeChild->getAttribute( 'language' );
5887 $exportedLanguages[] = $exportedLanguage;
5888 $exportedLanguages = array_unique( $exportedLanguages );
5889 }
5890 }
5891 unset( $versionNode );
5892 unset( $versionNode );
5893 }
5894 $initialLanguageCode = $this->attribute( 'initial_language_code' );
5895 if ( in_array( $initialLanguageCode, $exportedLanguages ) )
5896 {
5897 $objectNode->setAttribute( 'initial_language', $initialLanguageCode );
5898 }
5899 $objectNode->appendChild( $versionsNode );
5900 return $objectNode;
5901 }
5902
5909 function cacheInfo( $Params )
5910 {
5911 $contentCacheInfo =& $GLOBALS['eZContentCacheInfo'];
5912 if ( !isset( $contentCacheInfo ) )
5913 {
5914 $user = eZUser::currentUser();
5915 $language = false;
5916 if ( isset( $Params['Language'] ) )
5917 {
5918 $language = $Params['Language'];
5919 }
5920 $roleList = $user->roleIDList();
5921 $discountList = eZUserDiscountRule::fetchIDListByUserID( $user->attribute( 'contentobject_id' ) );
5922 $contentCacheInfo = array( 'language' => $language,
5923 'role_list' => $roleList,
5924 'discount_list' => $discountList );
5925 }
5926 return $contentCacheInfo;
5927 }
5928
5932 static function expireAllViewCache()
5933 {
5934 $handler = eZExpiryHandler::instance();
5935 $handler->setTimestamp( 'content-view-cache', time() );
5936 $handler->store();
5937 }
5938
5947 static function expireAllCache()
5948 {
5949 $handler = eZExpiryHandler::instance();
5950 $handler->setTimestamp( 'content-view-cache', time() );
5951 $handler->setTimestamp( 'template-block-cache', time() );
5952 $handler->setTimestamp( 'content-tree-menu', time() );
5953 $handler->store();
5954 }
5955
5962 static function expireTemplateBlockCache()
5963 {
5964 $handler = eZExpiryHandler::instance();
5965 $handler->setTimestamp( 'template-block-cache', time() );
5966 $handler->store();
5967 }
5968
5975 static function expireComplexViewModeCache()
5976 {
5977 $handler = eZExpiryHandler::instance();
5978 $handler->setTimestamp( 'content-complex-viewmode-cache', time() );
5979 $handler->store();
5980 }
5981
5988 static function isCacheExpired( $timestamp )
5989 {
5990 $handler = eZExpiryHandler::instance();
5991 if ( !$handler->hasTimestamp( 'content-view-cache' ) )
5992 return false;
5993 $expiryTime = $handler->timestamp( 'content-view-cache' );
5994 if ( $expiryTime > $timestamp )
5995 return true;
5996 return false;
5997 }
5998
6005 static function isComplexViewMode( $viewMode )
6006 {
6007 $ini = eZINI::instance();
6008 $viewModes = $ini->variableArray( 'ContentSettings', 'ComplexDisplayViewModes' );
6009 return in_array( $viewMode, $viewModes );
6010 }
6011
6019 static function isComplexViewModeCacheExpired( $viewMode, $timestamp )
6020 {
6021 if ( !eZContentObject::isComplexViewMode( $viewMode ) )
6022 return false;
6023 $handler = eZExpiryHandler::instance();
6024 if ( !$handler->hasTimestamp( 'content-complex-viewmode-cache' ) )
6025 return false;
6026 $expiryTime = $handler->timestamp( 'content-complex-viewmode-cache' );
6027 if ( $expiryTime > $timestamp )
6028 return true;
6029 return false;
6030 }
6031
6037 function authorArray()
6038 {
6039 $db = eZDB::instance();
6040
6041 $userArray = $db->arrayQuery( "SELECT DISTINCT ezuser.contentobject_id, ezuser.login, ezuser.email, ezuser.password_hash, ezuser.password_hash_type
6042 FROM ezcontentobject_version, ezuser where ezcontentobject_version.contentobject_id='$this->ID'
6043 AND ezcontentobject_version.creator_id=ezuser.contentobject_id" );
6044
6045 $return = array();
6046
6047 foreach ( $userArray as $userRow )
6048 {
6049 $return[] = new eZUser( $userRow );
6050 }
6051 return $return;
6052 }
6053
6062 static function fetchObjectCountByUserID( $classID, $userID, $status = false )
6063 {
6064 $count = 0;
6065 if ( is_numeric( $classID ) and is_numeric( $userID ) )
6066 {
6067 $db = eZDB::instance();
6068 $classID = (int) $classID;
6069 $userID = (int) $userID;
6070 $statusSQL = $status !== false ? ( ' AND status=' . (int) $status ) : '';
6071 $countArray = $db->arrayQuery( "SELECT count(*) AS count FROM ezcontentobject WHERE contentclass_id=$classID AND owner_id=$userID$statusSQL" );
6072 $count = $countArray[0]['count'];
6073 }
6074 return $count;
6075 }
6076
6081 static function removeVersions( $versionStatus = false )
6082 {
6083 eZContentObjectVersion::removeVersions( $versionStatus );
6084 }
6085
6092 function rename( $newName )
6093 {
6094 // get 'object name pattern'
6095 $objectNamePattern = '';
6096 $contentClass = $this->contentClass();
6097 if ( is_object( $contentClass ) )
6098 $objectNamePattern = $contentClass->ContentObjectName;
6099
6100 if ( $objectNamePattern == '' )
6101 return false;
6102
6103 // get parts of object's name pattern( like <attr1|attr2>, <attr3> )
6104 $objectNamePatternPartsPattern = '/<([^>]+)>/U';
6105 preg_match_all( $objectNamePatternPartsPattern, $objectNamePattern, $objectNamePatternParts );
6106
6107 if( count( $objectNamePatternParts ) === 0 || count( $objectNamePatternParts[1] ) == 0 )
6108 return false;
6109
6110 $objectNamePatternParts = $objectNamePatternParts[1];
6111
6112 // replace all <...> with (.*)
6113 $newNamePattern = preg_replace( $objectNamePatternPartsPattern, '(.*)', $objectNamePattern );
6114 // add terminators
6115 $newNamePattern = '/' . $newNamePattern . '/';
6116
6117 // find parts of $newName
6118 preg_match_all( $newNamePattern, $newName, $newNameParts );
6119
6120 // looks ok, we can create new version of object
6121 $contentObjectVersion = $this->createNewVersion();
6122 // get contentObjectAttributes
6123 $dataMap = $contentObjectVersion->attribute( 'data_map' );
6124 if ( count( $dataMap ) === 0 )
6125 return false;
6126
6127 // assign parts of $newName to the object's attributes.
6128 $pos = 0;
6129 while( $pos < count( $objectNamePatternParts ) )
6130 {
6131 $attributes = $objectNamePatternParts[$pos];
6132
6133 // if we have something like <attr1|attr2> then
6134 // 'attr1' will be updated only.
6135 $attributes = explode( '|', $attributes );
6136 $attribute = $attributes[0];
6137
6138 $newNamePart = $newNameParts[$pos+1];
6139 if ( count( $newNamePart ) === 0 )
6140 {
6141 if( $pos === 0 )
6142 {
6143 // whole $newName goes into the first attribute
6144 $attributeValue = $newName;
6145 }
6146 else
6147 {
6148 // all other attibutes will be set to ''
6149 $attributeValue = '';
6150 }
6151 }
6152 else
6153 {
6154 $attributeValue = $newNamePart[0];
6155 }
6156
6157 $contentAttribute =& $dataMap[$attribute];
6158 $dataType = $contentAttribute->dataType();
6159 if( is_object( $dataType ) && $dataType->isSimpleStringInsertionSupported() )
6160 {
6161 $result = '';
6162 $dataType->insertSimpleString( $this, $contentObjectVersion, false, $contentAttribute, $attributeValue, $result );
6163 $contentAttribute->store();
6164 }
6165
6166 ++$pos;
6167 }
6168
6169 $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $this->attribute( 'id' ),
6170 'version' => $contentObjectVersion->attribute( 'version') ) );
6171 return ($operationResult != null ? true : false);
6172 }
6173
6180 function removeTranslation( $languageID )
6181 {
6182 $language = eZContentLanguage::fetch( $languageID );
6183
6184 if ( !$language )
6185 {
6186 return false;
6187 }
6188
6189 // check permissions for editing
6190 if ( !$this->checkAccess( 'edit', false, false, false, $languageID ) )
6191 {
6192 return false;
6193 }
6194
6195 // check if it is not the initial language
6196 $objectInitialLanguageID = $this->attribute( 'initial_language_id' );
6197 if ( $objectInitialLanguageID == $languageID )
6198 {
6199 return false;
6200 }
6201
6202 // change language_mask of the object
6203 $languageMask = (int) $this->attribute( 'language_mask' );
6204 $languageMask = (int) $languageMask & ~ (int) $languageID;
6205 $this->setAttribute( 'language_mask', $languageMask );
6206
6207 $db = eZDB::instance();
6208 $db->begin();
6209
6210 $this->store();
6211
6212 $objectID = $this->ID;
6213
6214 // If the current version has initial_language_id $languageID, change it to the initial_language_id of the object.
6215 $currentVersion = $this->currentVersion();
6216 if ( $currentVersion->attribute( 'initial_language_id' ) == $languageID )
6217 {
6218 $currentVersion->setAttribute( 'initial_language_id', $objectInitialLanguageID );
6219 $currentVersion->store();
6220 }
6221
6222 // Remove all versions which had the language as its initial ID. Because of previous checks, it is sure we will not remove the published version.
6223 $versionsToRemove = $this->versions( true, array( 'conditions' => array( 'initial_language_id' => $languageID ) ) );
6224 foreach ( $versionsToRemove as $version )
6225 {
6226 $version->removeThis();
6227 }
6228
6229 $altLanguageID = $languageID++;
6230
6231 // Remove all attributes in the language
6232 $attributes = $db->arrayQuery( "SELECT * FROM ezcontentobject_attribute
6233 WHERE contentobject_id='$objectID'
6234 AND ( language_id='$languageID' OR language_id='$altLanguageID' )" );
6235 foreach ( $attributes as $attribute )
6236 {
6237 $attributeObject = new eZContentObjectAttribute( $attribute );
6238 $attributeObject->remove( $attributeObject->attribute( 'id' ), $attributeObject->attribute( 'version' ) );
6239 unset( $attributeObject );
6240 }
6241
6242 // Remove all names in the language
6243 $db->query( "DELETE FROM ezcontentobject_name
6244 WHERE contentobject_id='$objectID'
6245 AND ( language_id='$languageID' OR language_id='$altLanguageID' )" );
6246
6247 // Update masks of the objects
6248 $mask = eZContentLanguage::maskForRealLanguages() - (int) $languageID;
6249
6250 if ( $db->databaseName() == 'oracle' )
6251 {
6252 $db->query( "UPDATE ezcontentobject_version SET language_mask = bitand( language_mask, $mask )
6253 WHERE contentobject_id='$objectID'" );
6254 }
6255 else
6256 {
6257 $db->query( "UPDATE ezcontentobject_version SET language_mask = language_mask & $mask
6258 WHERE contentobject_id='$objectID'" );
6259 }
6260
6261 $urlElementfilter = new eZURLAliasQuery();
6262 $urlElementfilter->type = 'name';
6263 // We want all languages present here, so we are turning off
6264 // language filtering
6265 $urlElementfilter->languages = false;
6266 $urlElementfilter->limit = false;
6267
6268 $nodes = $this->assignedNodes();
6269
6270 foreach ( $nodes as $node )
6271 {
6272 $parent = null;
6273 $textMD5 = null;
6274
6275 $urlElementfilter->actions = array( 'eznode:' . $node->attribute( 'node_id' ) );
6276 $urlElementfilter->prepare();
6277 $urlElements = $urlElementfilter->fetchAll();
6278
6279 foreach ($urlElements as $url )
6280 {
6281 if ( $url->attribute( 'lang_mask' ) === (int)$languageID or
6282 $url->attribute( 'lang_mask') === (int)$altLanguageID )
6283 {
6284 $parent = $url->attribute( 'parent');
6285 $textMD5 = $url->attribute( 'text_md5' );
6286 break;
6287 }
6288 }
6289
6290 if ( $parent !== null and $textMD5 !== null )
6291 eZURLAliasML::removeSingleEntry( $parent, $textMD5, $language );
6292 }
6293 $db->commit();
6294
6295 return true;
6296 }
6297
6301 function isAlwaysAvailable()
6302 {
6303 return ( $this->attribute( 'language_mask' ) & 1 );
6304 }
6305
6310 function setAlwaysAvailableLanguageID( $languageID, $version = false )
6311 {
6312 $db = eZDB::instance();
6313 $db->begin();
6314
6315 if ( $version == false )
6316 {
6317 $version = $this->currentVersion();
6318 if ( $languageID )
6319 {
6320 $this->setAttribute( 'language_mask', (int)$this->attribute( 'language_mask' ) | 1 );
6321 }
6322 else
6323 {
6324 $this->setAttribute( 'language_mask', (int)$this->attribute( 'language_mask' ) & ~1 );
6325 }
6326 $this->store();
6327 }
6328
6329 $objectID = $this->attribute( 'id' );
6330 $versionID = $version->attribute( 'version' );
6331
6332 // reset 'always available' flag
6333 $sql = "UPDATE ezcontentobject_name SET language_id=";
6334 if ( $db->databaseName() == 'oracle' )
6335 {
6336 $sql .= "bitand( language_id, -2 )";
6337 }
6338 else
6339 {
6340 $sql .= "language_id & ~1";
6341 }
6342 $sql .= " WHERE contentobject_id = '$objectID' AND content_version = '$versionID'";
6343 $db->query( $sql );
6344
6345 if ( $languageID != false )
6346 {
6347 $newLanguageID = $languageID | 1;
6348 $sql = "UPDATE ezcontentobject_name
6349 SET language_id='$newLanguageID'
6350 WHERE language_id='$languageID' AND contentobject_id = '$objectID' AND content_version = '$versionID'";
6351 $db->query( $sql );
6352 }
6353
6354 $version->setAlwaysAvailableLanguageID( $languageID );
6355
6356 // Update url alias for all locations
6357 $nodeRows = eZContentObjectTreeNode::fetchByContentObjectID( $objectID, false );
6358 $actions = array();
6359 foreach ( $nodeRows as $nodeRow )
6360 {
6361 $nodeID = (int)$nodeRow['node_id'];
6362 $actions[] = array( 'eznode', $nodeID );
6363 }
6364 eZURLAliasML::setLangMaskAlwaysAvailable( $languageID, $actions, null );
6365
6366 $db->commit();
6367 }
6368
6372 function allowedAssignSectionList()
6373 {
6374 $currentUser = eZUser::currentUser();
6375 $sectionIDList = $currentUser->canAssignToObjectSectionList( $this );
6376
6377 $sectionList = array();
6378 if ( in_array( '*', $sectionIDList ) )
6379 {
6380 $sectionList = eZSection::fetchList( false );
6381 }
6382 else
6383 {
6384 $sectionIDList[] = $this->attribute( 'section_id' );
6385 $sectionList = eZSection::fetchFilteredList( array( 'id' => array( $sectionIDList ) ), false, false, false );
6386 }
6387 return $sectionList;
6388 }
6389
6396 function allowedAssignStateIDList( eZUser|null $user = null )
6397 {
6398 if ( !$user instanceof eZUser )
6399 {
6400 $user = eZUser::currentUser();
6401 }
6402
6403 $access = $user->hasAccessTo( 'state', 'assign' );
6404
6405 $db = eZDB::instance();
6406 $sql = 'SELECT ezcobj_state.id
6407 FROM ezcobj_state, ezcobj_state_group
6408 WHERE ezcobj_state.group_id = ezcobj_state_group.id
6409 AND ezcobj_state_group.identifier NOT LIKE \'ez%\'';
6410 if ( $access['accessWord'] == 'yes' )
6411 {
6412 $allowedStateIDList = $db->arrayQuery( $sql, array( 'column' => 'id' ) );
6413 }
6414 else if ( $access['accessWord'] == 'limited' )
6415 {
6416 $userID = $user->attribute( 'contentobject_id' );
6417 $classID = $this->attribute( 'contentclass_id' );
6418 $ownerID = $this->attribute( 'owner_id' );
6419 $sectionID = $this->attribute( 'section_id' );
6420 $stateIDArray = $this->attribute( 'state_id_array' );
6421
6422 $allowedStateIDList = array();
6423 foreach ( $access['policies'] as $policy )
6424 {
6425 foreach ( $policy as $ident => $values )
6426 {
6427 $allowed = true;
6428
6429 switch ( $ident )
6430 {
6431 case 'Class':
6432 {
6433 $allowed = in_array( $classID, $values );
6434 } break;
6435
6436 case 'Owner':
6437 {
6438 $allowed = in_array( 1, $values ) and $userID != $ownerID;
6439 } break;
6440
6441 case 'Group':
6442 {
6443 $allowed = $this->checkGroupLimitationAccess( $values, $userID ) === 'allowed';
6444 } break;
6445
6446 case 'Section':
6447 case 'User_Section':
6448 {
6449 $allowed = in_array( $sectionID, $values );
6450 } break;
6451
6452 //This case is based on the similar if statement in the method : classListFromPolicy
6453 case 'User_Subtree':
6454 {
6455 $allowed = false;
6456 foreach ( $this->attribute( 'assigned_nodes' ) as $assignedNode )
6457 {
6458 $path = $assignedNode->attribute( 'path_string' );
6459 foreach ( $policy['User_Subtree'] as $subtreeString )
6460 {
6461 if ( strpos( $path, $subtreeString ) !== false )
6462 {
6463 $allowed = true;
6464 break;
6465 }
6466 }
6467 }
6468 } break;
6469
6470 default:
6471 {
6472 if ( strncmp( $ident, 'StateGroup_', 11 ) === 0 )
6473 {
6474 $allowed = count( array_intersect( $values, $stateIDArray ) ) > 0;
6475 }
6476 }
6477 }
6478
6479 if ( !$allowed )
6480 {
6481 continue 2;
6482 }
6483 }
6484
6485 if ( isset( $policy['NewState'] ) and count( $policy['NewState'] ) > 0 )
6486 {
6487 $allowedStateIDList = array_merge( $allowedStateIDList, $policy['NewState'] );
6488 }
6489 else
6490 {
6491 $allowedStateIDList = $db->arrayQuery( $sql, array( 'column' => 'id' ) );
6492 break;
6493 }
6494 }
6495
6496 $allowedStateIDList = array_merge( $allowedStateIDList, $stateIDArray );
6497 }
6498 else
6499 {
6500 $stateIDArray = $this->attribute( 'state_id_array' );
6501 $allowedStateIDList = $stateIDArray;
6502 }
6503
6504 $allowedStateIDList = array_unique( $allowedStateIDList );
6505
6506 return $allowedStateIDList;
6507 }
6508
6513 function allowedAssignStateList( eZUser|null $user = null )
6514 {
6515 $allowedStateIDList = $this->allowedAssignStateIDList( $user );
6516
6517 // retrieve state groups, and for each state group the allowed states (including the current state)
6518 $groups = eZContentObjectStateGroup::fetchByOffset( false, false );
6519
6520 $allowedAssignList = array();
6521 foreach ( $groups as $group )
6522 {
6523 // we do not return any internal state
6524 // all internal states are prepended with the string : "ez_"
6525 if( strpos( $group->attribute( 'identifier' ), 'ez' ) === 0 )
6526 continue;
6527
6528 $states = array();
6529 $groupStates = $group->attribute( 'states' );
6530
6531 $currentStateIDArray = $this->attribute( 'state_id_array' );
6532
6533 $current = false;
6534 foreach ( $groupStates as $groupState )
6535 {
6536 $stateID = $groupState->attribute( 'id' );
6537 if ( in_array( $stateID, $allowedStateIDList ) )
6538 {
6539 $states[] = $groupState;
6540 }
6541
6542 if ( in_array( $stateID, $currentStateIDArray ) )
6543 {
6544 $current = $groupState;
6545 }
6546 }
6547
6548 $allowedAssignList[] = array( 'group' => $group, 'states' => $states, 'current' => $current );
6549 }
6550 return $allowedAssignList;
6551 }
6552
6561 function stateIDArray( $refreshCache = false )
6562 {
6563 if ( !$this->ID )
6564 return array();
6565
6566 if ( $refreshCache || !is_array( $this->StateIDArray ) )
6567 {
6568 $this->StateIDArray = array();
6569 $contentObjectID = $this->ID;
6570 eZDebug::accumulatorStart( 'state_id_array', 'states' );
6571 $sql = "SELECT contentobject_state_id, group_id FROM ezcobj_state_link, ezcobj_state
6572 WHERE ezcobj_state.id=ezcobj_state_link.contentobject_state_id AND
6573 contentobject_id=$contentObjectID";
6574 $db = eZDB::instance();
6575 $rows = $db->arrayQuery( $sql );
6576 foreach ( $rows as $row )
6577 {
6578 $this->StateIDArray[$row['group_id']] = $row['contentobject_state_id'];
6579 }
6580 eZDebug::accumulatorStop( 'state_id_array' );
6581 }
6582
6583 return $this->StateIDArray;
6584 }
6585
6589 function stateIdentifierArray()
6590 {
6591 if ( !$this->ID )
6592 return array();
6593
6594 eZDebug::accumulatorStart( 'state_identifier_array', 'states' );
6595 $return = array();
6596 $sql = "SELECT l.contentobject_state_id, s.identifier AS state_identifier, g.identifier AS state_group_identifier
6597 FROM ezcobj_state_link l, ezcobj_state s, ezcobj_state_group g
6598 WHERE l.contentobject_id={$this->ID} AND
6599 s.id=l.contentobject_state_id AND
6600 g.id=s.group_id";
6601 $db = eZDB::instance();
6602 $rows = $db->arrayQuery( $sql );
6603 foreach ( $rows as $row )
6604 {
6605 $return[] = $row['state_group_identifier'] . '/' . $row['state_identifier'];
6606 }
6607 eZDebug::accumulatorStop( 'state_identifier_array' );
6608 return $return;
6609 }
6610
6620 function assignState( eZContentObjectState $state )
6621 {
6622 $groupID = $state->attribute( 'group_id' );
6623 $stateID = $state->attribute( 'id' );
6624 $contentObjectID = $this->ID;
6625
6626 $currentStateIDArray = $this->stateIDArray( true );
6627 $currentStateID = $currentStateIDArray[$groupID];
6628
6629 if ( $currentStateID == $stateID )
6630 {
6631 return false;
6632 }
6633
6634 $sql = "UPDATE ezcobj_state_link
6635 SET contentobject_state_id=$stateID
6636 WHERE contentobject_state_id=$currentStateID AND
6637 contentobject_id=$contentObjectID";
6638 eZDB::instance()->query( $sql );
6639
6640 $this->StateIDArray[$groupID] = $stateID;
6641
6642 return true;
6643 }
6644
6651 function assignDefaultStates()
6652 {
6653 $db = eZDB::instance();
6654 $db->begin();
6655 $defaultStates = eZContentObjectState::defaults();
6656 $contentObjectID = $this->ID;
6657 foreach ( $defaultStates as $state )
6658 {
6659 $stateID = $state->attribute( 'id' );
6660 $db->query( "INSERT INTO ezcobj_state_link (contentobject_state_id, contentobject_id)
6661 VALUES($stateID, $contentObjectID)" );
6662 }
6663 $db->commit();
6664 }
6665
6669 public function restoreObjectAttributes()
6670 {
6671 $db = eZDB::instance();
6672 $db->begin();
6673
6674 foreach ( $this->allContentObjectAttributes( $this->attribute( "id" ) ) as $contentObjectAttribute )
6675 {
6676 $datatype = $contentObjectAttribute->dataType();
6677 if ( !$datatype instanceof eZDataType )
6678 {
6679 eZDebug::writeError( "Attribute #{$contentObjectAttribute->attribute( "id" )} from contentobject #{$this->attribute( "id" )} isn't valid", __METHOD__ );
6680 continue;
6681 }
6682
6683 $datatype->restoreTrashedObjectAttribute( $contentObjectAttribute );
6684 }
6685
6686 $db->commit();
6687 }
6688
6694 public function sectionIdentifier()
6695 {
6696 $section = eZSection::fetch( $this->attribute( 'section_id' ) );
6697 if( $section instanceof eZSection )
6698 {
6699 return $section->attribute( 'identifier' );
6700 }
6701 return false;
6702 }
6703
6707 public $ID;
6708
6712 public $Name;
6713
6717 public $CurrentLanguage;
6718
6722 public $ClassName;
6723
6727 public $ClassIdentifier;
6728
6732 public $DataMap = array();
6733
6737 public $ContentActionList = false;
6738
6742 public $ContentObjectAttributes = array();
6743
6747 public $MainNodeID = false;
6748
6752 public $InputRelationList = array();
6753
6754 public $Permissions;
6755 public $ContentObject;
6756
6763 private $StateIDArray = false;
6764 }
6765
6766 ?>
eZAudit\writeAudit
static writeAudit( $auditName, $auditAttributes=array())
Definition: ezaudit.php:51
eZContentCacheManager\clearObjectViewCacheArray
static clearObjectViewCacheArray(array $objectIDList)
Definition: ezcontentcachemanager.php:711
eZContentClassAttribute\fetchListByClassID
static fetchListByClassID( $classID, $version=eZContentClass::VERSION_STATUS_DEFINED, $asObject=true)
Definition: ezcontentclassattribute.php:450
eZContentClassName\sqlFilter
static sqlFilter( $languageTable='ezcontentclass')
Definition: ezcontentclassname.php:75
eZContentClass
Handles eZ Publish content classes.
Definition: ezcontentclass.php:20
eZContentClass\fetchByRemoteID
static fetchByRemoteID( $remoteID, $asObject=true, $version=eZContentClass::VERSION_STATUS_DEFINED, $user_id=false, $parent_id=null)
Definition: ezcontentclass.php:1170
eZContentClass\fetchByIdentifier
static fetchByIdentifier( $identifier, $asObject=true, $version=eZContentClass::VERSION_STATUS_DEFINED, $user_id=false, $parent_id=null)
Definition: ezcontentclass.php:1203
eZContentClass\classIdentifierByID
static classIdentifierByID( $id)
Definition: ezcontentclass.php:1819
eZContentClass\fetch
static fetch( $id, $asObject=true, $version=eZContentClass::VERSION_STATUS_DEFINED, $user_id=false, $parent_id=null)
Definition: ezcontentclass.php:1116
eZContentClass\versionHistoryLimit
static versionHistoryLimit( $class)
Definition: ezcontentclass.php:1927
eZContentClass\VERSION_STATUS_DEFINED
const VERSION_STATUS_DEFINED
Definition: ezcontentclass.php:22
eZContentClass\nameFromSerializedString
static nameFromSerializedString( $serializedNameList)
Definition: ezcontentclass.php:1529
eZContentLanguage\topPriorityLanguage
static topPriorityLanguage()
Definition: ezcontentlanguage.php:404
eZContentLanguage\fetchList
static fetchList( $forceReloading=false)
Definition: ezcontentlanguage.php:163
eZContentLanguage\fetchLocaleList
static fetchLocaleList()
Definition: ezcontentlanguage.php:231
eZContentLanguage\sqlFilter
static sqlFilter( $languageTable, $languageListTable=null, $languageAttributeName='language_id', $languageListAttributeName='language_mask', $lang=false)
Definition: ezcontentlanguage.php:692
eZContentLanguage\fetch
static fetch( $id)
Definition: ezcontentlanguage.php:251
eZContentLanguage\prioritizedLanguages
static prioritizedLanguages( $languageList=false)
Definition: ezcontentlanguage.php:294
eZContentLanguage\addLanguage
static addLanguage( $locale, $name=null)
Definition: ezcontentlanguage.php:52
eZContentLanguage\jsArrayByMask
static jsArrayByMask( $mask)
Definition: ezcontentlanguage.php:878
eZContentLanguage\idByLocale
static idByLocale( $locale)
Definition: ezcontentlanguage.php:637
eZContentLanguage\topPriorityLanguageByMask
static topPriorityLanguageByMask( $mask)
Definition: ezcontentlanguage.php:502
eZContentLanguage\maskForRealLanguages
static maskForRealLanguages()
Definition: ezcontentlanguage.php:901
eZContentLanguage\prioritizedLanguagesByMask
static prioritizedLanguagesByMask( $mask)
Definition: ezcontentlanguage.php:454
eZContentLanguage\maskByLocale
static maskByLocale( $locales, $setZerothBit=false)
Definition: ezcontentlanguage.php:546
eZContentLanguage\languagesByMask
static languagesByMask( $mask)
Definition: ezcontentlanguage.php:432
eZContentLanguage\fetchByLocale
static fetchByLocale( $locale, $createIfNotExist=false)
Definition: ezcontentlanguage.php:264
eZContentObjectAttribute
Encapsulates the data for an object attribute.
Definition: ezcontentobjectattribute.php:20
eZContentObjectAttribute\definition
static definition()
Definition: ezcontentobjectattribute.php:38
eZContentObjectAttribute\fetchByClassAttributeID
static fetchByClassAttributeID( $classAttributeID, $objectID, $version, $languageID, $asObject=true)
Definition: ezcontentobjectattribute.php:182
eZContentObjectOperations\remove
static remove( $objectID, $removeSubtrees=true)
Definition: ezcontentobjectoperations.php:25
eZContentObjectTrashNode\purgeForObject
static purgeForObject( $contentObjectID)
Definition: ezcontentobjecttrashnode.php:193
eZContentObjectTreeNode\makeObjectsArray
static makeObjectsArray( $array, $with_contentobject=true, array|null $propertiesOverride=null, $lang=null)
Definition: ezcontentobjecttreenode.php:5227
eZContentObjectTreeNode\createSortingSQLStrings
static createSortingSQLStrings( $sortList, $treeTableName='ezcontentobject_tree', $allowCustomColumns=false)
Definition: ezcontentobjecttreenode.php:560
eZContentObjectTreeNode\SORT_FIELD_PUBLISHED
const SORT_FIELD_PUBLISHED
Definition: ezcontentobjecttreenode.php:19
eZContentObjectTreeNode\getParentNodeIdListByContentObjectID
static getParentNodeIdListByContentObjectID( $objectIDs, $groupByObjectId=false, $onlyMainNode=false)
Definition: ezcontentobjecttreenode.php:5368
eZContentObjectTreeNode\fetchByRemoteID
static fetchByRemoteID( $remoteID, $asObject=true)
Definition: ezcontentobjecttreenode.php:2933
eZContentObjectTreeNode\SORT_ORDER_DESC
const SORT_ORDER_DESC
Definition: ezcontentobjecttreenode.php:32
eZContentObjectTreeNode\updateMainNodeID
static updateMainNodeID( $mainNodeID, $objectID, $version, $parentMainNodeID, $updateSection=true)
Definition: ezcontentobjecttreenode.php:2882
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
eZContentObjectTreeNode\findMainNode
static findMainNode( $objectID, $asObject=false)
Definition: ezcontentobjecttreenode.php:2981
eZContentObjectTreeNode\removeNode
static removeNode( $nodeID=0)
Definition: ezcontentobjecttreenode.php:3689
eZContentObjectTreeNode\fetchNode
static fetchNode( $contentObjectID, $parentNodeID)
Definition: ezcontentobjecttreenode.php:3172
eZContentObjectTreeNode\fetchByContentObjectID
static fetchByContentObjectID( $contentObjectID, $asObject=true, $contentObjectVersion=false)
Definition: ezcontentobjecttreenode.php:2918
eZContentObjectTreeNode\addChildTo
static addChildTo( $contentobjectID, $nodeID, $asObject=false, $contentObjectVersion=false)
Definition: ezcontentobjecttreenode.php:3324
eZContentObjectVersion\STATUS_DRAFT
const STATUS_DRAFT
Definition: ezcontentobjectversion.php:29
eZContentObjectVersion\removeVersions
static removeVersions( $versionStatus=false, $limit=false, $expiryTime=false, $fetchPortionSize=50)
Definition: ezcontentobjectversion.php:1079
eZContentObjectVersion\definition
static definition()
Definition: ezcontentobjectversion.php:49
eZContentObjectVersion\STATUS_PUBLISHED
const STATUS_PUBLISHED
Definition: ezcontentobjectversion.php:30
eZContentObjectVersion\STATUS_ARCHIVED
const STATUS_ARCHIVED
Definition: ezcontentobjectversion.php:32
eZContentObjectVersion\STATUS_INTERNAL_DRAFT
const STATUS_INTERNAL_DRAFT
Definition: ezcontentobjectversion.php:34
eZContentObjectVersion\create
static create( $contentobjectID, $userID=false, $version=1, $initialLanguageCode=false)
Definition: ezcontentobjectversion.php:937
eZContentObjectVersion\fetchForUser
static fetchForUser( $userID, $status=eZContentObjectVersion::STATUS_DRAFT)
Definition: ezcontentobjectversion.php:281
eZContentObjectVersion\fetchVersion
static fetchVersion( $version, $contentObjectID, $asObject=true)
Definition: ezcontentobjectversion.php:166
eZContentObjectVersion\unserialize
static unserialize( $domNode, $contentObject, $ownerID, $sectionID, $activeVersion, $firstVersion, &$nodeList, &$options, $package, $handlerType='ezcontentobject', $firstVersioninitialLanguage=false)
Definition: ezcontentobjectversion.php:1340
eZContentObject
Definition: ezcontentobject.php:17
eZContentObject\setClassName
setClassName( $name)
Definition: ezcontentobject.php:5370
eZContentObject\hasVisibleNode
hasVisibleNode()
Definition: ezcontentobject.php:3893
eZContentObject\embeddedContentObjectList
embeddedContentObjectList( $fromObjectVersion=false, $fromObjectID=false)
Definition: ezcontentobject.php:3422
eZContentObject\fillNodeListAttributes
static fillNodeListAttributes( $objList, $asObject=true)
Definition: ezcontentobject.php:2290
eZContentObject\recursionProtectionEnd
static recursionProtectionEnd()
Definition: ezcontentobject.php:2718
eZContentObject\copyContentObjectRelations
copyContentObjectRelations( $currentVersion, $newVersion, $newObjectID=false)
Definition: ezcontentobject.php:3074
eZContentObject\authorArray
authorArray()
Definition: ezcontentobject.php:6037
eZContentObject\classListFromPolicy
classListFromPolicy( $policy, $allowedLanguageCodes=false)
Definition: ezcontentobject.php:4693
eZContentObject\contentClass
contentClass()
Definition: ezcontentobject.php:816
eZContentObject\checkGroupLimitationAccess
checkGroupLimitationAccess( $limitationValueList, $userID, $contentObjectID=false)
Definition: ezcontentobject.php:4058
eZContentObject\$ContentActionList
$ContentActionList
Definition: ezcontentobject.php:6737
eZContentObject\rename
rename( $newName)
Definition: ezcontentobject.php:6092
eZContentObject\STATUS_PUBLISHED
const STATUS_PUBLISHED
Definition: ezcontentobject.php:20
eZContentObject\owner
owner()
Definition: ezcontentobject.php:768
eZContentObject\setPermissions
setPermissions( $permissionArray)
Definition: ezcontentobject.php:3992
eZContentObject\fixupInput
fixupInput( $contentObjectAttributes, $attributeDataBaseName)
Definition: ezcontentobject.php:2564
eZContentObject\STATUS_ARCHIVED
const STATUS_ARCHIVED
Definition: ezcontentobject.php:21
eZContentObject\expireComplexViewModeCache
static expireComplexViewModeCache()
Definition: ezcontentobject.php:5975
eZContentObject\canPdf
canPdf()
Definition: ezcontentobject.php:5045
eZContentObject\$ClassName
$ClassName
Definition: ezcontentobject.php:6722
eZContentObject\fetchInput
fetchInput( $contentObjectAttributes, $attributeDataBaseName, $customActionAttributeArray, $customActionParameters)
Definition: ezcontentobject.php:2580
eZContentObject\clearCache
static clearCache( $idArray=array())
Definition: ezcontentobject.php:284
eZContentObject\recursionProtectionStart
static recursionProtectionStart()
Definition: ezcontentobject.php:2693
eZContentObject\versionLanguageName
versionLanguageName( $version, $lang=false)
Definition: ezcontentobject.php:388
eZContentObject\reverseLinkedObjectList
reverseLinkedObjectList( $fromObjectVersion=false, $fromObjectID=false)
Definition: ezcontentobject.php:3440
eZContentObject\fetchAttributesByIdentifier
fetchAttributesByIdentifier( $identifierArray, $version=false, $languageArray=false, $asObject=true)
Definition: ezcontentobject.php:681
eZContentObject\PACKAGE_UPDATE
const PACKAGE_UPDATE
Definition: ezcontentobject.php:32
eZContentObject\allowedAssignSectionList
allowedAssignSectionList()
Definition: ezcontentobject.php:6372
eZContentObject\fetchListCount
static fetchListCount( $conditions=null)
Definition: ezcontentobject.php:1224
eZContentObject\$CurrentLanguage
$CurrentLanguage
Definition: ezcontentobject.php:6717
eZContentObject\$MainNodeID
$MainNodeID
Definition: ezcontentobject.php:6747
eZContentObject\fetchIDArray
static fetchIDArray( $idArray, $asObject=true, $lang=false)
Definition: ezcontentobject.php:1132
eZContentObject\RELATION_LINK
const RELATION_LINK
Definition: ezcontentobject.php:39
eZContentObject\setCachedName
setCachedName( $name)
Definition: ezcontentobject.php:468
eZContentObject\parentNodeIDArray
parentNodeIDArray()
Definition: ezcontentobject.php:3751
eZContentObject\relatedContentObjectList
relatedContentObjectList( $fromObjectVersion=false, $fromObjectID=false, $attributeID=0, $groupByAttribute=false, $params=false)
Definition: ezcontentobject.php:3385
eZContentObject\names
names()
Definition: ezcontentobject.php:365
eZContentObject\allowedAssignStateIDList
allowedAssignStateIDList(eZUser|null $user=null)
Definition: ezcontentobject.php:6396
eZContentObject\className
className()
Definition: ezcontentobject.php:5199
eZContentObject\expireTemplateBlockCache
static expireTemplateBlockCache()
Definition: ezcontentobject.php:5962
eZContentObject\assignedNodes
assignedNodes( $asObject=true, $checkVisibility=false)
Definition: ezcontentobject.php:3922
eZContentObject\relatedContentObjectArray
relatedContentObjectArray( $fromObjectVersion=false, $fromObjectID=false, $attributeID=0, $params=false)
Definition: ezcontentobject.php:3481
eZContentObject\PACKAGE_REPLACE
const PACKAGE_REPLACE
Definition: ezcontentobject.php:29
eZContentObject\reverseEmbeddedObjectCount
reverseEmbeddedObjectCount( $fromObjectVersion=false)
Definition: ezcontentobject.php:3589
eZContentObject\$ContentObjectAttributeArray
$ContentObjectAttributeArray
Definition: ezcontentobject.php:18
eZContentObject\defaultLanguage
static defaultLanguage()
Definition: ezcontentobject.php:5330
eZContentObject\createNewVersionIn
createNewVersionIn( $languageCode, $copyFromLanguageCode=false, $copyFromVersion=false, $versionCheck=true, $status=eZContentObjectVersion::STATUS_DRAFT)
Definition: ezcontentobject.php:1408
eZContentObject\canDiff
canDiff()
Definition: ezcontentobject.php:5073
eZContentObject\fetch
static fetch( $id, $asObject=true)
Definition: ezcontentobject.php:885
eZContentObject\relatedObjectCount
relatedObjectCount( $version=false, $attributeID=0, $reverseRelatedObjects=false, $params=false)
Definition: ezcontentobject.php:3624
eZContentObject\publishedVersion
publishedVersion()
Definition: ezcontentobject.php:1287
eZContentObject\sectionIdentifier
sectionIdentifier()
Definition: ezcontentobject.php:6694
eZContentObject\copyVersion
copyVersion(&$newObject, &$version, $newVersionNumber, $contentObjectID=false, $status=eZContentObjectVersion::STATUS_DRAFT, $languageCode=false, $copyFromLanguageCode=false)
Definition: ezcontentobject.php:1538
eZContentObject\setName
setName( $objectName, $versionNum=false, $languageCode=false)
Definition: ezcontentobject.php:483
eZContentObject\assignDefaultStates
assignDefaultStates()
Definition: ezcontentobject.php:6651
eZContentObject\removeContentObjectRelation
removeContentObjectRelation( $toObjectID=false, $fromObjectVersion=false, $attributeID=0, $relationType=eZContentObject::RELATION_COMMON)
Definition: ezcontentobject.php:2996
eZContentObject\recursionProtect
static recursionProtect( $id)
Definition: ezcontentobject.php:2702
eZContentObject\visibleNodes
visibleNodes()
Definition: ezcontentobject.php:3867
eZContentObject\$Permissions
$Permissions
Definition: ezcontentobject.php:6754
eZContentObject\fetchDataMap
fetchDataMap( $version=false, $language=false)
Definition: ezcontentobject.php:609
eZContentObject\serialize
serialize( $package, $specificVersion=false, $options=false, $contentNodeIDArray=false, $topNodeIDArray=false)
Definition: ezcontentobject.php:5808
eZContentObject\fetchByNodeID
static fetchByNodeID( $nodeID, $asObject=true)
Definition: ezcontentobject.php:1072
eZContentObject\relatedContentObjectCount
relatedContentObjectCount( $fromObjectVersion=false, $attributeID=0, $params=false)
Definition: ezcontentobject.php:3503
eZContentObject\checkAccess
checkAccess( $functionName, $originalClassID=false, $parentClassID=false, $returnAccessList=false, $language=false)
Definition: ezcontentobject.php:4115
eZContentObject\definition
static definition()
Definition: ezcontentobject.php:100
eZContentObject\PACKAGE_KEEP
const PACKAGE_KEEP
Definition: ezcontentobject.php:35
eZContentObject\mapLanguage
static mapLanguage( $language, $options)
Definition: ezcontentobject.php:5438
eZContentObject\cacheInfo
cacheInfo( $Params)
Definition: ezcontentobject.php:5909
eZContentObject\initialLanguage
initialLanguage()
Definition: ezcontentobject.php:2840
eZContentObject\nextVersion
nextVersion()
Definition: ezcontentobject.php:2751
eZContentObject\isObjectRelationTyped
static isObjectRelationTyped()
Definition: ezcontentobject.php:3107
eZContentObject\mainNode
mainNode()
Definition: ezcontentobject.php:3982
eZContentObject\addContentObjectRelation
addContentObjectRelation( $toObjectID, $fromObjectVersion=false, $attributeID=0, $relationType=eZContentObject::RELATION_COMMON)
Definition: ezcontentobject.php:2905
eZContentObject\isComplexViewModeCacheExpired
static isComplexViewModeCacheExpired( $viewMode, $timestamp)
Definition: ezcontentobject.php:6019
eZContentObject\create
static create( $name, $contentclassID, $userID, $sectionID=1, $version=1, $languageCode=false)
Definition: ezcontentobject.php:1669
eZContentObject\purge
purge()
Definition: ezcontentobject.php:1877
eZContentObject\createInitialVersion
createInitialVersion( $userID, $initialLanguageCode=false)
Definition: ezcontentobject.php:1392
eZContentObject\relatedObjects
relatedObjects( $fromObjectVersion=false, $objectID=false, $attributeID=0, $groupByAttribute=false, $params=false, $reverseRelatedObjects=false)
Definition: ezcontentobject.php:3180
eZContentObject\PACKAGE_ERROR_EXISTS
const PACKAGE_ERROR_EXISTS
Definition: ezcontentobject.php:24
eZContentObject\translationStringList
static translationStringList()
Definition: ezcontentobject.php:5383
eZContentObject\canEdit
canEdit( $originalClassID=false, $parentClassID=false, $returnAccessList=false, $language=false)
Definition: ezcontentobject.php:5105
eZContentObject\commitInputRelations
commitInputRelations( $editVersion)
Definition: ezcontentobject.php:2406
eZContentObject\groupedDataMap
groupedDataMap()
Definition: ezcontentobject.php:565
eZContentObject\fetchClassAttributes
fetchClassAttributes( $version=0, $asObject=true)
Definition: ezcontentobject.php:5424
eZContentObject\canEditLanguages
canEditLanguages()
Definition: ezcontentobject.php:4012
eZContentObject\$StateIDArray
$StateIDArray
Definition: ezcontentobject.php:6763
eZContentObject\handleCustomHTTPActions
handleCustomHTTPActions( $contentObjectAttribute, $attributeDataBaseName, $customActionAttributeArray, $customActionParameters)
Definition: ezcontentobject.php:2645
eZContentObject\canTranslate
canTranslate()
Definition: ezcontentobject.php:5141
eZContentObject\allowedAssignStateList
allowedAssignStateList(eZUser|null $user=null)
Definition: ezcontentobject.php:6513
eZContentObject\createFetchSQLString
static createFetchSQLString( $id)
Definition: ezcontentobject.php:1027
eZContentObject\currentLanguage
currentLanguage()
Definition: ezcontentobject.php:2800
eZContentObject\copy
copy( $allVersions=true)
Definition: ezcontentobject.php:1714
eZContentObject\contentActionList
contentActionList()
Definition: ezcontentobject.php:5225
eZContentObject\setAlwaysAvailableLanguageID
setAlwaysAvailableLanguageID( $languageID, $version=false)
Definition: ezcontentobject.php:6310
eZContentObject\canRead
canRead()
Definition: ezcontentobject.php:5031
eZContentObject\setCurrentLanguage
setCurrentLanguage( $lang)
Definition: ezcontentobject.php:2829
eZContentObject\linkedContentObjectCount
linkedContentObjectCount( $fromObjectVersion=false)
Definition: ezcontentobject.php:3541
eZContentObject\createGroupedDataMap
static createGroupedDataMap( $contentObjectAttributes)
Definition: ezcontentobject.php:579
eZContentObject\isCacheExpired
static isCacheExpired( $timestamp)
Definition: ezcontentobject.php:5988
eZContentObject\removeThis
removeThis( $nodeID=null)
Definition: ezcontentobject.php:2015
eZContentObject\createNodeAssignment
createNodeAssignment( $parentNodeID, $isMain, $remoteID=false, $sortField=eZContentObjectTreeNode::SORT_FIELD_PUBLISHED, $sortOrder=eZContentObjectTreeNode::SORT_ORDER_DESC)
Definition: ezcontentobject.php:3805
eZContentObject\canCreateLanguages
canCreateLanguages()
Definition: ezcontentobject.php:4035
eZContentObject\canCreate
canCreate()
Definition: ezcontentobject.php:5087
eZContentObject\relationTypeMask
static relationTypeMask( $allRelations=false)
Definition: ezcontentobject.php:3124
eZContentObject\PACKAGE_ERROR_HAS_CHILDREN
const PACKAGE_ERROR_HAS_CHILDREN
Definition: ezcontentobject.php:27
eZContentObject\permissions
permissions()
Definition: ezcontentobject.php:4002
eZContentObject\storeInput
storeInput( $contentObjectAttributes, $attributeInputMap)
Definition: ezcontentobject.php:2730
eZContentObject\canCreateClassList
canCreateClassList( $asObject=false, $includeFilter=true, $groupList=false, $fetchID=false)
Definition: ezcontentobject.php:4868
eZContentObject\version
version( $version, $asObject=true)
Definition: ezcontentobject.php:1310
eZContentObject\$ClassIdentifier
$ClassIdentifier
Definition: ezcontentobject.php:6727
eZContentObject\RELATION_COMMON
const RELATION_COMMON
Definition: ezcontentobject.php:37
eZContentObject\fetchByRemoteID
static fetchByRemoteID( $remoteID, $asObject=true)
Definition: ezcontentobject.php:865
eZContentObject\canMoveFrom
canMoveFrom()
Definition: ezcontentobject.php:5182
eZContentObject\reverseRelatedObjectCount
reverseRelatedObjectCount( $version=false, $attributeID=0, $params=false)
Definition: ezcontentobject.php:3727
eZContentObject\handleAllCustomHTTPActions
handleAllCustomHTTPActions( $attributeDataBaseName, $customActionAttributeArray, $customActionParameters, $objectVersion=false)
Definition: ezcontentobject.php:2667
eZContentObject\allContentObjectAttributes
allContentObjectAttributes( $contentObjectID, $asObject=true, $limit=null)
Definition: ezcontentobject.php:2166
eZContentObject\removeVersions
static removeVersions( $versionStatus=false)
Definition: ezcontentobject.php:6081
eZContentObject\eZContentObject
eZContentObject( $row)
Definition: ezcontentobject.php:95
eZContentObject\contentClassGroupIDList
contentClassGroupIDList()
Definition: ezcontentobject.php:782
eZContentObject\PACKAGE_ERROR_MODIFIED
const PACKAGE_ERROR_MODIFIED
Definition: ezcontentobject.php:26
eZContentObject\$Name
$Name
Definition: ezcontentobject.php:6712
eZContentObject\validateInput
validateInput( $contentObjectAttributes, $attributeDataBaseName, $inputParameters=false, $parameters=array())
Definition: ezcontentobject.php:2437
eZContentObject\isComplexViewMode
static isComplexViewMode( $viewMode)
Definition: ezcontentobject.php:6005
eZContentObject\availableLanguagesJsArray
availableLanguagesJsArray()
Definition: ezcontentobject.php:5303
eZContentObject\__construct
__construct( $row)
Definition: ezcontentobject.php:49
eZContentObject\name
name( $version=false, $lang=false)
Definition: ezcontentobject.php:340
eZContentObject\reverseLinkedObjectCount
reverseLinkedObjectCount( $fromObjectVersion=false)
Definition: ezcontentobject.php:3573
eZContentObject\fetchList
static fetchList( $asObject=true, $conditions=null, $offset=false, $limit=false)
Definition: ezcontentobject.php:1185
eZContentObject\canViewEmbed
canViewEmbed()
Definition: ezcontentobject.php:5059
eZContentObject\postUnserialize
postUnserialize( $package)
Definition: ezcontentobject.php:5787
eZContentObject\PACKAGE_ERROR_NODE_EXISTS
const PACKAGE_ERROR_NODE_EXISTS
Definition: ezcontentobject.php:25
eZContentObject\fixReverseRelations
static fixReverseRelations( $objectID, $mode=false, $clearCacheIfEnabled=true)
Definition: ezcontentobject.php:1843
eZContentObject\storeNodeModified
storeNodeModified()
Definition: ezcontentobject.php:317
eZContentObject\hasContentAction
hasContentAction( $name)
Definition: ezcontentobject.php:5264
eZContentObject\accessList
accessList( $function)
Definition: ezcontentobject.php:5009
eZContentObject\setContentObjectAttributes
setContentObjectAttributes(&$attributes, $version, $language)
Definition: ezcontentobject.php:2279
eZContentObject\createWithNodeAssignment
static createWithNodeAssignment( $parentNode, $contentClassID, $languageCode, $remoteID=false)
Definition: ezcontentobject.php:3831
eZContentObject\versions
versions( $asObject=true, $parameters=array())
Definition: ezcontentobject.php:1342
eZContentObject\RELATION_ATTRIBUTE
const RELATION_ATTRIBUTE
Definition: ezcontentobject.php:40
eZContentObject\STATUS_DRAFT
const STATUS_DRAFT
Definition: ezcontentobject.php:19
eZContentObject\setDefaultLanguage
static setDefaultLanguage( $lang)
Definition: ezcontentobject.php:5362
eZContentObject\stateIdentifierArray
stateIdentifierArray()
Definition: ezcontentobject.php:6589
eZContentObject\embeddedContentObjectCount
embeddedContentObjectCount( $fromObjectVersion=false)
Definition: ezcontentobject.php:3557
eZContentObject\allLanguages
allLanguages()
Definition: ezcontentobject.php:5321
eZContentObject\dataMap
dataMap()
Definition: ezcontentobject.php:552
eZContentObject\canRemove
canRemove()
Definition: ezcontentobject.php:5167
eZContentObject\PACKAGE_NEW
const PACKAGE_NEW
Definition: ezcontentobject.php:31
eZContentObject\PACKAGE_SKIP
const PACKAGE_SKIP
Definition: ezcontentobject.php:30
eZContentObject\reverseEmbeddedObjectList
reverseEmbeddedObjectList( $fromObjectVersion=false, $fromObjectID=false)
Definition: ezcontentobject.php:3459
eZContentObject\linkedContentObjectList
linkedContentObjectList( $fromObjectVersion=false, $fromObjectID=false)
Definition: ezcontentobject.php:3404
eZContentObject\fetchSameClassList
static fetchSameClassList( $contentClassID, $asObject=true, $offset=false, $limit=false)
Definition: ezcontentobject.php:1247
eZContentObject\store
store( $fieldFilters=null)
Definition: ezcontentobject.php:260
eZContentObject\PACKAGE_DELETE
const PACKAGE_DELETE
Definition: ezcontentobject.php:34
eZContentObject\fetchForUpdate
static fetchForUpdate( $id, $asObject=true)
Definition: ezcontentobject.php:943
eZContentObject\availableLanguages
availableLanguages()
Definition: ezcontentobject.php:5285
eZContentObject\RELATION_EMBED
const RELATION_EMBED
Definition: ezcontentobject.php:38
eZContentObject\expireAllViewCache
static expireAllViewCache()
Definition: ezcontentobject.php:5932
eZContentObject\fetchSameClassListCount
static fetchSameClassListCount( $contentClassID)
Definition: ezcontentobject.php:1259
eZContentObject\initialLanguageCode
initialLanguageCode()
Definition: ezcontentobject.php:2850
eZContentObject\matchIngroupIDList
matchIngroupIDList()
Definition: ezcontentobject.php:240
eZContentObject\contentClassIdentifier
contentClassIdentifier()
Definition: ezcontentobject.php:795
eZContentObject\currentLanguageObject
currentLanguageObject()
Definition: ezcontentobject.php:2810
eZContentObject\copyRevertTo
copyRevertTo( $version, $language=false)
Definition: ezcontentobject.php:1827
eZContentObject\$ID
$ID
Definition: ezcontentobject.php:6707
eZContentObject\PACKAGE_ERROR_NO_CLASS
const PACKAGE_ERROR_NO_CLASS
Definition: ezcontentobject.php:23
eZContentObject\translationList
static translationList()
Definition: ezcontentobject.php:5404
eZContentObject\exists
static exists( $id)
Definition: ezcontentobject.php:999
eZContentObject\appendInputRelationList
appendInputRelationList( $addingIDList, $relationType)
Definition: ezcontentobject.php:2377
eZContentObject\fetchObjectCountByUserID
static fetchObjectCountByUserID( $classID, $userID, $status=false)
Definition: ezcontentobject.php:6062
eZContentObject\$DataMap
$DataMap
Definition: ezcontentobject.php:6732
eZContentObject\expireAllCache
static expireAllCache()
Definition: ezcontentobject.php:5947
eZContentObject\createNewVersion
createNewVersion( $copyFromVersion=false, $versionCheck=true, $languageCode=false, $copyFromLanguageCode=false, $status=eZContentObjectVersion::STATUS_DRAFT)
Definition: ezcontentobject.php:1427
eZContentObject\parentNodes
parentNodes( $version=false, $asObject=true)
Definition: ezcontentobject.php:3763
eZContentObject\previousVersion
previousVersion()
Definition: ezcontentobject.php:2765
eZContentObject\contentObjectAttributes
contentObjectAttributes( $asObject=true, $version=false, $language=false, $contentObjectAttributeID=false, $distinctItemsOnly=false)
Definition: ezcontentobject.php:2190
eZContentObject\$ContentObjectAttributes
$ContentObjectAttributes
Definition: ezcontentobject.php:6742
eZContentObject\removeTranslation
removeTranslation( $languageID)
Definition: ezcontentobject.php:6180
eZContentObject\currentVersion
currentVersion( $asObject=true)
Definition: ezcontentobject.php:1277
eZContentObject\restoreObjectAttributes
restoreObjectAttributes()
Definition: ezcontentobject.php:6669
eZContentObject\contentObjectListRelatingThis
contentObjectListRelatingThis( $version=false)
Definition: ezcontentobject.php:3741
eZContentObject\fetchFilteredList
static fetchFilteredList( $conditions=null, $offset=false, $limit=false, $asObject=true)
Definition: ezcontentobject.php:1207
eZContentObject\mainNodeID
mainNodeID()
Definition: ezcontentobject.php:3967
eZContentObject\remoteID
remoteID()
Definition: ezcontentobject.php:832
eZContentObject\$ContentObject
$ContentObject
Definition: ezcontentobject.php:6755
eZContentObject\hasRemainingVersions
hasRemainingVersions()
Definition: ezcontentobject.php:1374
eZContentObject\getVersionCount
getVersionCount()
Definition: ezcontentobject.php:2786
eZContentObject\resetDataMap
resetDataMap()
Definition: ezcontentobject.php:663
eZContentObject\cleanupAllInternalDrafts
static cleanupAllInternalDrafts( $userID=false, $timeDuration=86400)
Definition: ezcontentobject.php:2131
eZContentObject\languages
languages()
Definition: ezcontentobject.php:5311
eZContentObject\createFilterByVisibilitySQLString
static createFilterByVisibilitySQLString( $IgnoreVisibility=false, $ezcontentobjectTable='ezcontentobject')
Definition: ezcontentobject.php:1055
eZContentObject\$InputRelationList
$InputRelationList
Definition: ezcontentobject.php:6752
eZContentObject\stateIDArray
stateIDArray( $refreshCache=false)
Definition: ezcontentobject.php:6561
eZContentObject\assignState
assignState(eZContentObjectState $state)
Definition: ezcontentobject.php:6620
eZContentObject\resetInputRelationList
resetInputRelationList()
Definition: ezcontentobject.php:2367
eZContentObject\isAlwaysAvailable
isAlwaysAvailable()
Definition: ezcontentobject.php:6301
eZContentObject\__clone
__clone()
Definition: ezcontentobject.php:1697
eZContentObject\cleanupInternalDrafts
cleanupInternalDrafts( $userID=false, $timeDuration=86400)
Definition: ezcontentobject.php:2098
eZContentObject\mainParentNodeID
mainParentNodeID()
Definition: ezcontentobject.php:852
eZContentObject\addLocation
addLocation( $parentNodeID, $asObject=false)
Definition: ezcontentobject.php:2868
eZContentObject\reverseRelatedObjectList
reverseRelatedObjectList( $version=false, $attributeID=0, $groupByAttribute=false, $params=false)
Definition: ezcontentobject.php:3525
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDateUtils\textToDate
static textToDate( $dateText)
Definition: ezdateutils.php:88
eZDateUtils\rfc1123Date
static rfc1123Date( $timestamp=false)
Definition: ezdateutils.php:34
eZDebugSetting\writeDebug
static writeDebug( $conditionName, $string, $label="")
Definition: ezdebugsetting.php:127
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZDebug\accumulatorStart
static accumulatorStart( $key, $inGroup=false, $name=false, $recursive=false)
Definition: ezdebug.php:1361
eZDebug\accumulatorStop
static accumulatorStop( $key, $recursive=false)
Definition: ezdebug.php:1389
eZHTTPTool\instance
static instance()
Definition: ezhttptool.php:189
eZInformationCollection\removeContentObject
static removeContentObject( $delID)
Definition: ezinformationcollection.php:95
eZInputValidator\STATE_INTERMEDIATE
const STATE_INTERMEDIATE
Definition: ezinputvalidator.php:80
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
eZLocale\instance
static instance( $localeString=false)
Definition: ezlocale.php:1536
eZNodeAssignment\OP_CODE_SET
const OP_CODE_SET
Definition: eznodeassignment.php:35
eZNodeAssignment\fetchForObject
static fetchForObject( $contentObjectID, $version=1, $main=0, $asObject=true)
Definition: eznodeassignment.php:392
eZNodeAssignment\setNewMainAssignment
static setNewMainAssignment( $objectID, $version)
Definition: eznodeassignment.php:550
eZNodeAssignment\OP_CODE_CREATE_NOP
const OP_CODE_CREATE_NOP
Definition: eznodeassignment.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
eZPackageHandler\errorChoosenAction
static errorChoosenAction( $errorCode, &$installParameters, $description, $handlerType, $resetError=true)
Definition: ezpackagehandler.php:213
eZPackage\NON_INTERACTIVE
const NON_INTERACTIVE
Definition: ezpackage.php:33
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\sync
sync( $fieldFilters=null)
Definition: ezpersistentobject.php:319
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\setAttribute
setAttribute( $attr, $val)
Definition: ezpersistentobject.php:1374
eZPersistentObject\handleRows
static handleRows( $rows, $class_name, $asObject)
Definition: ezpersistentobject.php:963
eZPersistentObject\$CurrentVersion
$CurrentVersion
Definition: ezpersistentobject.php:1455
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZPreferences\value
static value( $name, $user=false)
Definition: ezpreferences.php:106
eZProductCollectionItem\definition
static definition()
Definition: ezproductcollectionitem.php:21
eZRemoteIdUtility\generate
static generate( $type='')
Definition: ezremoteidutility.php:21
eZSearch\removeObjectById
static removeObjectById( $contentObjectId, $commit=null)
Definition: ezsearch.php:80
eZSection
eZSection handles grouping of content in eZ Publish
Definition: ezsection.php:18
eZSection\fetchFilteredList
static fetchFilteredList( $conditions=null, $offset=false, $limit=false, $asObject=true)
Definition: ezsection.php:127
eZSection\fetchList
static fetchList( $asObject=true)
Definition: ezsection.php:139
eZSection\fetch
static fetch( $sectionID, $asObject=true)
Definition: ezsection.php:64
eZURLAliasML\removeSingleEntry
static removeSingleEntry( $parentID, $textMD5, $language)
Definition: ezurlaliasml.php:323
eZURLAliasML\setLangMaskAlwaysAvailable
static setLangMaskAlwaysAvailable( $langID, $actionName, $actionValue)
Definition: ezurlaliasml.php:1951
eZURLAliasQuery
Handles querying of URL aliases with different filters.
Definition: ezurlaliasquery.php:34
eZUserDiscountRule\fetchIDListByUserID
static fetchIDListByUserID( $userID)
Definition: ezuserdiscountrule.php:84
eZUser
eZUser handles eZ Publish user accounts
Definition: ezuser.php:19
eZUser\currentUserID
static currentUserID()
Definition: ezuser.php:1731
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
eZWishList\definition
static definition()
Definition: ezwishlist.php:25
eZWorkflowType\fetchRegisteredTypes
static fetchRegisteredTypes()
Definition: ezworkflowtype.php:115
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.