Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcontentclassattribute.php
Go to the documentation of this file.
1 <?php
18 class eZContentClassAttribute extends eZPersistentObject
19 {
20 public function __construct( $row )
21 {
22 parent::__construct($row);
23
24 $this->Content = null;
25 $this->DisplayInfo = null;
26 $this->Module = null;
27
28 $this->NameList = new eZSerializedObjectNameList();
29 if ( isset( $row['serialized_name_list'] ) )
30 $this->NameList->initFromSerializedList( $row['serialized_name_list'] );
31 else
32 $this->NameList->initDefault();
33
34 $this->DescriptionList = new eZSerializedObjectNameList();
35 if ( isset( $row['serialized_description_list'] ) )
36 $this->DescriptionList->initFromSerializedList( $row['serialized_description_list'] );
37 else
38 $this->DescriptionList->initDefault();
39
40 $this->DataTextI18nList = new eZSerializedObjectNameList();
41 if ( isset( $row['serialized_data_text'] ) )
42 $this->DataTextI18nList->initFromSerializedList( $row['serialized_data_text'] );
43 else
44 $this->DataTextI18nList->initDefault();
45
46 // Make sure datatype gets final say if attribute should be translatable
47 if ( isset( $row['can_translate'] ) && $row['can_translate'] )
48 {
49 $datatype = $this->dataType();
50 if ( $datatype instanceof eZDataType )
51 {
52 if ( !$datatype->isTranslatable() )
53 $this->setAttribute('can_translate', 0);
54 }
55 else
56 {
57 eZDebug::writeError( 'Could not get instance of datatype: ' . $row['data_type_string'], __METHOD__ );
58 }
59 }
60 }
61
62 static function definition()
63 {
64 static $definition = array( 'fields' => array( 'id' => array( 'name' => 'ID',
65 'datatype' => 'integer',
66 'default' => 0,
67 'required' => true ),
68 'serialized_name_list' => array( 'name' => 'SerializedNameList',
69 'datatype' => 'string',
70 'default' => '',
71 'required' => true ),
72 'serialized_description_list' => array( 'name' => 'SerializedDescriptionList',
73 'datatype' => 'string',
74 'default' => '',
75 'required' => true ),
76 'version' => array( 'name' => 'Version',
77 'datatype' => 'integer',
78 'default' => 0,
79 'required' => true ),
80 'contentclass_id' => array( 'name' => 'ContentClassID',
81 'datatype' => 'integer',
82 'default' => 0,
83 'required' => true,
84 'foreign_class' => 'eZContentClass',
85 'foreign_attribute' => 'id',
86 'multiplicity' => '1..*' ),
87 'identifier' => array( 'name' => 'Identifier',
88 'datatype' => 'string',
89 'default' => '',
90 'required' => true,
91 'max_length' => 50 ),
92 'placement' => array( 'name' => 'Position',
93 'datatype' => 'integer',
94 'default' => 0,
95 'required' => true ),
96 'is_searchable' => array( 'name' => 'IsSearchable',
97 'datatype' => 'integer',
98 'default' => 0
99 ),
100 'is_required' => array( 'name' => 'IsRequired',
101 'datatype' => 'integer',
102 'default' => 0,
103 'required' => true ),
104 'can_translate' => array( 'name' => 'CanTranslate',
105 'datatype' => 'integer',
106 'default' => 0
107 ),
108 'is_information_collector' => array( 'name' => 'IsInformationCollector',
109 'datatype' => 'integer',
110 'default' => 0,
111 'required' => true ),
112 'data_type_string' => array( 'name' => 'DataTypeString',
113 'datatype' => 'string',
114 'default' => '',
115 'required' => true ),
116 'data_int1' => array( 'name' => 'DataInt1',
117 'datatype' => 'integer',
118 'default' => 0,
119 'required' => true ),
120 'data_int2' => array( 'name' => 'DataInt2',
121 'datatype' => 'integer',
122 'default' => 0,
123 'required' => true ),
124 'data_int3' => array( 'name' => 'DataInt3',
125 'datatype' => 'integer',
126 'default' => 0,
127 'required' => true ),
128 'data_int4' => array( 'name' => 'DataInt4',
129 'datatype' => 'integer',
130 'default' => 0,
131 'required' => true ),
132 'data_float1' => array( 'name' => 'DataFloat1',
133 'datatype' => 'float',
134 'default' => 0,
135 'required' => true ),
136 'data_float2' => array( 'name' => 'DataFloat2',
137 'datatype' => 'float',
138 'default' => 0,
139 'required' => true ),
140 'data_float3' => array( 'name' => 'DataFloat3',
141 'datatype' => 'float',
142 'default' => 0,
143 'required' => true ),
144 'data_float4' => array( 'name' => 'DataFloat4',
145 'datatype' => 'float',
146 'default' => 0,
147 'required' => true ),
148 'data_text1' => array( 'name' => 'DataText1',
149 'datatype' => 'text',
150 'default' => '',
151 'required' => true ),
152 'data_text2' => array( 'name' => 'DataText2',
153 'datatype' => 'text',
154 'default' => '',
155 'required' => true ),
156 'data_text3' => array( 'name' => 'DataText3',
157 'datatype' => 'text',
158 'default' => '',
159 'required' => true ),
160 'data_text4' => array( 'name' => 'DataText4',
161 'datatype' => 'text',
162 'default' => '',
163 'required' => true ),
164 'data_text5' => array( 'name' => 'DataText5',
165 'datatype' => 'text',
166 'default' => '',
167 'required' => true ),
168 'serialized_data_text' => array( 'name' => 'SerializedDataText',
169 'datatype' => 'string',
170 'default' => '',
171 'required' => true ),
172 'category' => array( 'name' => 'Category',
173 'datatype' => 'text',
174 'default' => '',
175 'required' => true )),
176 'keys' => array( 'id', 'version' ),
177 "function_attributes" => array( "content" => "content",
178 'temporary_object_attribute' => 'instantiateTemporary',
179 'data_type' => 'dataType',
180 'display_info' => 'displayInfo',
181 'name' => 'name',
182 'nameList' => 'nameList',
183 'description' => 'description',
184 'descriptionList' => 'descriptionList',
185 'data_text_i18n' => 'dataTextI18n',
186 'data_text_i18n_list' => 'dataTextI18nList' ),
187 'set_functions' => array( 'name' => 'setName',
188 'description' => 'setDescription',
189 'data_text_i18n' => 'setDataTextI18n' ),
190 'increment_key' => 'id',
191 'sort' => array( 'placement' => 'asc' ),
192 'class_name' => 'eZContentClassAttribute',
193 'name' => 'ezcontentclass_attribute' );
194 return $definition;
195 }
196
197 function __clone()
198 {
199 $this->ID = null;
200 }
201
221 static function create( $class_id, $data_type_string, $optionalValues = array(), $languageLocale = false )
222 {
223 $nameList = new eZSerializedObjectNameList();
224 if ( isset( $optionalValues['serialized_name_list'] ) )
225 $nameList->initFromSerializedList( $optionalValues['serialized_name_list'] );
226 else if ( isset( $optionalValues['name'] ) )
227 $nameList->initFromString( $optionalValues['name'], $languageLocale );
228 else
229 $nameList->initFromString( '', $languageLocale );
230
231 $descriptionList = new eZSerializedObjectNameList();
232 if ( isset( $optionalValues['serialized_description_list'] ) )
233 $descriptionList->initFromSerializedList( $optionalValues['serialized_description_list'] );
234 else if ( isset( $optionalValues['description'] ) )
235 $descriptionList->initFromString( $optionalValues['description'], $languageLocale );
236 else
237 $descriptionList->initFromString( '', $languageLocale );
238
239 if ( isset( $optionalValues['data_text_i18n'] ) )
240 {
241 $dataTextI18nList = new eZSerializedObjectNameList( $optionalValues['data_text_i18n'] );
242 $optionalValues['serialized_data_text'] = $dataTextI18nList->serializeNames();
243 }
244
245 $row = array(
246 'id' => null,
247 'version' => eZContentClass::VERSION_STATUS_TEMPORARY,
248 'contentclass_id' => $class_id,
249 'identifier' => '',
250 'serialized_name_list' => $nameList->serializeNames(),
251 'serialized_description_list' => $descriptionList->serializeNames(),
252 'is_searchable' => 1,
253 'is_required' => 0,
254 'can_translate' => 1,
255 'is_information_collector' => 0,
256 'data_type_string' => $data_type_string,
257 'placement' => eZPersistentObject::newObjectOrder( eZContentClassAttribute::definition(),
258 'placement',
259 array( 'version' => 1,
260 'contentclass_id' => $class_id ) ) );
261 $row = array_merge( $row, $optionalValues );
262 $attribute = new eZContentClassAttribute( $row );
263
264 return $attribute;
265 }
266
267 function instantiate( $contentobjectID, $languageCode = false, $version = 1 )
268 {
269 $attribute = eZContentObjectAttribute::create( $this->attribute( 'id' ), $contentobjectID, $version, $languageCode );
270 $attribute->initialize();
271 $attribute->store();
272 $attribute->postInitialize();
273 }
274
275 function instantiateTemporary( $contentobjectID = false )
276 {
277 return eZContentObjectAttribute::create( $this->attribute( 'id' ), $contentobjectID );
278 }
279
280 function store( $fieldFilters = null )
281 {
282 $dataType = $this->dataType();
283 if ( !$dataType )
284 {
285 return false;
286 }
287
288 self::expireCache( $this->ID, $this->attribute( 'contentclass_id' ) );
289
290 $dataType->preStoreClassAttribute( $this, $this->attribute( 'version' ) );
291
292 $this->setAttribute( 'serialized_name_list', $this->NameList->serializeNames() );
293 $this->setAttribute( 'serialized_description_list', $this->DescriptionList->serializeNames() );
294 $this->setAttribute( 'serialized_data_text', $this->DataTextI18nList->serializeNames() );
295
296 $stored = parent::store( $fieldFilters );
297
298 // store the content data for this attribute
299 $dataType->storeClassAttribute( $this, $this->attribute( 'version' ) );
300
301 return $stored;
302 }
303
312 function storeDefined()
313 {
314 return $this->storeVersioned( eZContentClass::VERSION_STATUS_DEFINED );
315 }
316
327 function storeVersioned( $version )
328 {
329 $dataType = $this->dataType();
330 if ( !$dataType )
331 {
332 return false;
333 }
334
335 self::expireCache( $this->ID, $this->attribute( 'contentclass_id' ) );
336
337 $db = eZDB::instance();
338 $db->begin();
339 $dataType->preStoreVersionedClassAttribute( $this, $version );
340
341 $this->setAttribute( 'serialized_name_list', $this->NameList->serializeNames() );
342 $this->setAttribute( 'serialized_description_list', $this->DescriptionList->serializeNames() );
343 $this->setAttribute( 'serialized_data_text', $this->DataTextI18nList->serializeNames() );
344
345 parent::store();
346
347 // store the content data for this attribute
348 $dataType->storeVersionedClassAttribute( $this, $version );
349 $db->commit();
350 }
351
356 function removeThis( $quiet = false )
357 {
358 $dataType = $this->dataType();
359 if ( $dataType->isClassAttributeRemovable( $this ) )
360 {
361 self::expireCache( $this->ID, $this->attribute( 'contentclass_id' ) );
362
363 $db = eZDB::instance();
364 $db->begin();
365 $dataType->deleteStoredClassAttribute( $this, $this->Version );
366 $this->remove();
367 $db->commit();
368 return true;
369 }
370 else
371 {
372 if ( !$quiet )
373 {
374 eZDebug::writeError( 'Datatype [' . $dataType->attribute( 'name' ) . '] can not be deleted to avoid system crash' );
375 }
376 return false;
377 }
378 }
379
380 static function fetch( $id, $asObject = true, $version = eZContentClass::VERSION_STATUS_DEFINED, $field_filters = null )
381 {
382 $object = null;
383 if ( $field_filters === null and $asObject and
384 isset( $GLOBALS['eZContentClassAttributeCache'][$id][$version] ) )
385 {
386 $object = $GLOBALS['eZContentClassAttributeCache'][$id][$version];
387 }
388 if ( $object === null )
389 {
390 $object = eZPersistentObject::fetchObject( eZContentClassAttribute::definition(),
391 $field_filters,
392 array( 'id' => $id,
393 'version' => $version ),
394 $asObject );
395 if ( $field_filters === null and $asObject )
396 {
397 $GLOBALS['eZContentClassAttributeCache'][$id][$version] = $object;
398 }
399 }
400 return $object;
401 }
402
403 static function fetchList( $asObject = true, $parameters = array() )
404 {
405 $parameters = array_merge( array( 'data_type' => false,
406 'version' => false ),
407 $parameters );
408 $dataType = $parameters['data_type'];
409 $version = $parameters['version'];
410 $objects = null;
411 if ( $asObject &&
412 $dataType === false &&
413 $version === false )
414 {
415 $objects = $GLOBALS['eZContentClassAttributeCacheListFull'];
416 }
417 if ( !isset( $objects ) or
418 $objects === null )
419 {
420 $conditions = null;
421 if ( $dataType !== false or
422 $version !== false )
423 {
424 $conditions = array();
425 if ( $dataType !== false )
426 $conditions['data_type_string'] = $dataType;
427 if ( $version !== false )
428 $conditions['version'] = $version;
429 }
430 $objects = eZPersistentObject::fetchObjectList( eZContentClassAttribute::definition(),
431 null, $conditions, null, null,
432 $asObject );
433 if ( $asObject )
434 {
435 foreach ( $objects as $objectItem )
436 {
437 $objectID = $objectItem->ID;
438 $objectVersion = $objectItem->Version;
439 $GLOBALS['eZContentClassAttributeCache'][$objectID][$objectVersion] = $objectItem;
440 }
441 if ( $dataType === false && $version === false )
442 {
443 $GLOBALS['eZContentClassAttributeCacheListFull'] = $objects;
444 }
445 }
446 }
447 return $objects;
448 }
449
450 static function fetchListByClassID( $classID, $version = eZContentClass::VERSION_STATUS_DEFINED, $asObject = true )
451 {
452 $objects = null;
453 if ( $asObject )
454 {
455 if ( isset( $GLOBALS['eZContentClassAttributeCacheList'][$classID][$version] ) )
456 $objects = $GLOBALS['eZContentClassAttributeCacheList'][$classID][$version];
457 }
458 if ( !isset( $objects ) or
459 $objects === null )
460 {
461 $cond = array( 'contentclass_id' => $classID,
462 'version' => $version );
463 $objects = eZPersistentObject::fetchObjectList( eZContentClassAttribute::definition(),
464 null, $cond, null, null,
465 $asObject );
466 if ( $asObject )
467 {
468 foreach ( $objects as $objectItem )
469 {
470 $objectID = $objectItem->ID;
471 $objectVersion = $objectItem->Version;
472 if ( !isset( $GLOBALS['eZContentClassAttributeCache'][$objectID][$objectVersion] ) )
473 $GLOBALS['eZContentClassAttributeCache'][$objectID][$objectVersion] = $objectItem;
474 }
475 $GLOBALS['eZContentClassAttributeCacheList'][$classID][$version] = $objects;
476 }
477 }
478 return $objects;
479 }
480
481 static function fetchFilteredList( $cond, $asObject = true )
482 {
483 $objectList = eZPersistentObject::fetchObjectList( eZContentClassAttribute::definition(),
484 null, $cond, null, null,
485 $asObject );
486 if ( $asObject )
487 {
488 foreach ( $objectList as $objectItem )
489 {
490 $objectID = $objectItem->ID;
491 $objectVersion = $objectItem->Version;
492 if ( !isset( $GLOBALS['eZContentClassAttributeCache'][$objectID][$objectVersion] ) )
493 $GLOBALS['eZContentClassAttributeCache'][$objectID][$objectVersion] = $objectItem;
494 }
495 }
496 return $objectList;
497 }
498
505 function move( $down, $params = null )
506 {
507 if ( is_array( $params ) )
508 {
509 $pos = $params['placement'];
510 $cid = $params['contentclass_id'];
511 $version = $params['version'];
512 }
513 else
514 {
515 $pos = $this->Position;
516 $cid = $this->ContentClassID;
517 $version = $this->Version;
518 }
519 eZPersistentObject::reorderObject( eZContentClassAttribute::definition(),
520 array( 'placement' => $pos ),
521 array( 'contentclass_id' => $cid,
522 'version' => $version ),
523 $down );
524 }
525
529 function dataType()
530 {
531 return eZDataType::create( $this->DataTypeString );
532 }
533
537 function content()
538 {
539 if ( $this->Content === null )
540 {
541 $dataType = $this->dataType();
542 $this->Content = $dataType->classAttributeContent( $this );
543 }
544
545 return $this->Content;
546 }
547
551 function setContent( $content )
552 {
553 $this->Content = $content;
554 }
555
560 function displayInfo()
561 {
562 if ( !$this->DisplayInfo )
563 {
564 $dataType = $this->dataType();
565 if ( is_object( $dataType ) )
566 {
567 $this->DisplayInfo = $dataType->classDisplayInformation( $this, false );
568 }
569 }
570 return $this->DisplayInfo;
571 }
572
576 function customHTTPAction( $module, $http, $action )
577 {
578 $dataType = $this->dataType();
579 $this->Module = $module;
580 $dataType->customClassAttributeHTTPAction( $http, $action, $this );
581 unset( $this->Module );
582 $this->Module = null;
583 }
584
589 function currentModule()
590 {
591 return $this->Module;
592 }
593
594 static function cachedInfo()
595 {
596 $info = array();
597 $db = eZDB::instance();
598 $dbName = md5( $db->DB );
599
600 $cacheDir = eZSys::cacheDirectory();
601 $phpCache = new eZPHPCreator( "$cacheDir", "sortkey_$dbName.php", '', array( 'clustering' => 'sortkey' ) );
602 $handler = eZExpiryHandler::instance();
603 $expiryTime = 0;
604
605 if ( $handler->hasTimestamp( 'sort-key-cache' ) )
606 {
607 $expiryTime = $handler->timestamp( 'sort-key-cache' );
608 }
609
610 if ( $phpCache->canRestore( $expiryTime ) )
611 {
612 $info = $phpCache->restore( array( 'sortkey_type_array' => 'sortKeyTypeArray',
613 'attribute_type_array' => 'attributeTypeArray' ) );
614 }
615 else
616 {
617 // Fetch all datatypes and id's used
618 $query = "SELECT id, data_type_string FROM ezcontentclass_attribute";
619 $attributeArray = $db->arrayQuery( $query );
620
621 $attributeTypeArray = array();
622 $sortKeyTypeArray = array();
623 foreach ( $attributeArray as $attribute )
624 {
625 $attributeTypeArray[$attribute['id']] = $attribute['data_type_string'];
626 $sortKeyTypeArray[$attribute['data_type_string']] = 0;
627 }
628
629 // Fetch datatype for every unique datatype
630 foreach ( array_keys( $sortKeyTypeArray ) as $key )
631 {
632 unset( $dataType );
633 $dataType = eZDataType::create( $key );
634 if( is_object( $dataType ) )
635 $sortKeyTypeArray[$key] = $dataType->sortKeyType();
636 }
637 unset( $dataType );
638
639 // Store identifier list to cache file
640 $phpCache->addVariable( 'sortKeyTypeArray', $sortKeyTypeArray );
641 $phpCache->addVariable( 'attributeTypeArray', $attributeTypeArray );
642 $phpCache->store();
643
644 $info['sortkey_type_array'] = $sortKeyTypeArray;
645 $info['attribute_type_array'] = $attributeTypeArray;
646 }
647
648 return $info;
649 }
650
654 static function sortKeyTypeByID( $classAttributeID )
655 {
656 $sortKeyType = false;
657
658 $info = eZContentClassAttribute::cachedInfo();
659 if ( isset( $info['attribute_type_array'][$classAttributeID] ) )
660 {
661 $classAttributeType = $info['attribute_type_array'][$classAttributeID];
662 $sortKeyType = $info['sortkey_type_array'][$classAttributeType];
663 }
664
665 return $sortKeyType;
666 }
667
671 static function dataTypeByID( $classAttributeID )
672 {
673 $dataTypeString = false;
674 $info = eZContentClassAttribute::cachedInfo();
675
676 if ( isset( $info['attribute_type_array'][$classAttributeID] ) )
677 $dataTypeString = $info['attribute_type_array'][$classAttributeID];
678
679 return $dataTypeString;
680 }
681
685 function diff( $old, $new )
686 {
687 $datatype = $this->dataType();
688 $result = $datatype->diff( $old, $new );
689 return $result;
690 }
691
699 static function nameFromSerializedString( $serializedNameList, $languageLocale = false )
700 {
701 return eZSerializedObjectNameList::nameFromSerializedString( $serializedNameList, $languageLocale );
702 }
703
710 function name( $languageLocale = false )
711 {
712 return $this->NameList->name( $languageLocale );
713 }
714
722 function setName( $name, $languageLocale = false )
723 {
724 return $this->NameList->setName( $name, $languageLocale );
725 }
726
732 function nameList()
733 {
734 return $this->NameList->nameList();
735 }
736
743 function description( $languageLocale = false )
744 {
745 return $this->DescriptionList->name( $languageLocale );
746 }
747
755 function setDescription( $description, $languageLocale = false )
756 {
757 return $this->DescriptionList->setName( $description, $languageLocale );
758 }
759
765 function descriptionList()
766 {
767 return $this->DescriptionList->nameList();
768 }
769
776 function dataTextI18n( $languageLocale = false )
777 {
778 return $this->DataTextI18nList->name( $languageLocale );
779 }
780
788 function setDataTextI18n( $string, $languageLocale = false )
789 {
790 return $this->DataTextI18nList->setName( $string, $languageLocale );
791 }
792
798 function dataTextI18nList()
799 {
800 return $this->DataTextI18nList->nameList();
801 }
802
808 function editLocale()
809 {
810 return $this->EditLocale;
811 }
812
818 function setEditLocale( $languageLocale = false )
819 {
820 $this->EditLocale = $languageLocale;
821 }
822
828 function setAlwaysAvailableLanguage( $languageLocale )
829 {
830 if ( $languageLocale )
831 {
832 $this->NameList->setAlwaysAvailableLanguage( $languageLocale );
833 $this->DescriptionList->setAlwaysAvailableLanguage( $languageLocale );
834 $this->DataTextI18nList->setAlwaysAvailableLanguage( $languageLocale );
835 }
836 else
837 {
838 $this->NameList->setAlwaysAvailableLanguage( false );
839 $this->DescriptionList->setAlwaysAvailableLanguage( false );
840 $this->DataTextI18nList->setAlwaysAvailableLanguage( false );
841 }
842 }
843
849 function removeTranslation( $languageLocale )
850 {
851 $this->NameList->removeName( $languageLocale );
852 $this->DescriptionList->removeName( $languageLocale );
853 $this->DataTextI18nList->removeName( $languageLocale );
854 }
855
865 public static function classAttributeIDByIdentifier( $identifier )
866 {
867 $identifierHash = self::classAttributeIdentifiersHash();
868
869 if ( isset( $identifierHash[$identifier] ) )
870 return $identifierHash[$identifier];
871 else
872 return false;
873 }
874
882 public static function classAttributeIdentifierByID( $id )
883 {
884 $identifierHash = array_flip( self::classAttributeIdentifiersHash() );
885
886 if ( isset( $identifierHash[$id] ) )
887 {
888 $classAndClassAttributeIdentifier = explode( '/', $identifierHash[$id] );
889 return $classAndClassAttributeIdentifier[1];
890 }
891 else
892 return false;
893 }
894
904 protected static function classAttributeIdentifiersHash()
905 {
906 if ( self::$identifierHash === null )
907 {
908 $db = eZDB::instance();
909 $dbName = md5( $db->DB );
910
911 $cacheDir = eZSys::cacheDirectory();
912 $phpCache = new eZPHPCreator( $cacheDir,
913 'classattributeidentifiers_' . $dbName . '.php',
914 '',
915 array( 'clustering' => 'classattridentifiers' ) );
916
917 $handler = eZExpiryHandler::instance();
918 $expiryTime = 0;
919 if ( $handler->hasTimestamp( 'class-identifier-cache' ) )
920 {
921 $expiryTime = $handler->timestamp( 'class-identifier-cache' );
922 }
923
924 if ( $phpCache->canRestore( $expiryTime ) )
925 {
926 $var = $phpCache->restore( array( 'identifierHash' => 'identifier_hash' ) );
927 self::$identifierHash = $var['identifierHash'];
928 }
929 else
930 {
931 // Fetch identifier/id pair from db
932 $query = "SELECT ezcontentclass_attribute.id as attribute_id, ezcontentclass_attribute.identifier as attribute_identifier, ezcontentclass.identifier as class_identifier
933 FROM ezcontentclass_attribute, ezcontentclass
934 WHERE ezcontentclass.id=ezcontentclass_attribute.contentclass_id";
935 $identifierArray = $db->arrayQuery( $query );
936
937 self::$identifierHash = array();
938 foreach ( $identifierArray as $identifierRow )
939 {
940 $combinedIdentifier = $identifierRow['class_identifier'] . '/' . $identifierRow['attribute_identifier'];
941 self::$identifierHash[$combinedIdentifier] = (int) $identifierRow['attribute_id'];
942 }
943
944 // Store identifier list to cache file
945 $phpCache->addVariable( 'identifier_hash', self::$identifierHash );
946 $phpCache->store();
947 }
948 }
949 return self::$identifierHash;
950 }
951
958 function initializeObjectAttributes( &$objects = null )
959 {
960 $classAttributeID = $this->ID;
961 $classID = $this->ContentClassID;
962 $dataType = $this->attribute( 'data_type' );
963 if ( $dataType->supportsBatchInitializeObjectAttribute() )
964 {
965 $db = eZDB::instance();
966
967 $data = array( 'contentobject_id' => 'a.contentobject_id',
968 'version' => 'a.version',
969 'contentclassattribute_id' => $classAttributeID,
970 'data_type_string' => "'" . $db->escapeString( $this->DataTypeString ) . "'",
971 'language_code' => 'a.language_code',
972 'language_id' => 'MAX(a.language_id)' );
973
974 $datatypeData = $dataType->batchInitializeObjectAttributeData( $this );
975 $data = array_merge( $data, $datatypeData );
976
977 $cols = implode( ', ', array_keys( $data ) );
978 $values = implode( ', ', $data );
979
980 if( $db->DatabaseName() == 'sqlite' )
981 {
982 $sql = "INSERT OR REPLACE INTO ezcontentobject_attribute( $cols )
983 SELECT $values
984 FROM ezcontentobject_attribute a, ezcontentobject o
985 WHERE o.id = a.contentobject_id AND
986 o.contentclass_id=$classID
987 GROUP BY contentobject_id,
988 version,
989 language_code";
990 }
991 else
992 {
993 $sql = "INSERT INTO ezcontentobject_attribute( $cols )
994 SELECT $values
995 FROM ezcontentobject_attribute a, ezcontentobject o
996 WHERE o.id = a.contentobject_id AND
997 o.contentclass_id=$classID
998 GROUP BY contentobject_id,
999 version,
1000 language_code";
1001 }
1002
1003 $db->query( $sql );
1004
1005 // update ids to keep them same with one attribute for different versions
1006 if( $db->databaseName() == 'mysql' )
1007 {
1008 $updateSql = "UPDATE ezcontentobject_attribute,
1009 ( SELECT contentobject_id, language_code, version, contentclassattribute_id, MIN( id ) AS minid
1010 FROM ezcontentobject_attribute WHERE contentclassattribute_id = $classAttributeID
1011 GROUP BY contentobject_id, language_code, version, contentclassattribute_id ) t
1012 SET ezcontentobject_attribute.id = t.minid
1013 WHERE ezcontentobject_attribute.contentobject_id = t.contentobject_id
1014 AND ezcontentobject_attribute.language_code = t.language_code
1015 AND ezcontentobject_attribute.contentclassattribute_id = $classAttributeID";
1016 }
1017 else if( $db->databaseName() == 'postgresql' )
1018 {
1019 $updateSql = "UPDATE ezcontentobject_attribute
1020 SET id=t.minid FROM
1021 ( SELECT contentobject_id, language_code, version, contentclassattribute_id, MIN( id ) AS minid
1022 FROM ezcontentobject_attribute WHERE contentclassattribute_id = $classAttributeID
1023 GROUP BY contentobject_id, language_code, version, contentclassattribute_id ) t
1024 WHERE ezcontentobject_attribute.contentobject_id = t.contentobject_id
1025 AND ezcontentobject_attribute.language_code = t.language_code
1026 AND ezcontentobject_attribute.contentclassattribute_id = $classAttributeID";
1027 }
1028 else if( $db->databaseName() == 'oracle' )
1029 {
1030 $updateSql = "UPDATE ezcontentobject_attribute a SET a.id = (
1031 SELECT MIN( id ) FROM ezcontentobject_attribute b
1032 WHERE b.contentclassattribute_id = $classAttributeID
1033 AND b.contentobject_id = a.contentobject_id
1034 AND b.language_code = a.language_code )
1035 WHERE a.contentclassattribute_id = $classAttributeID";
1036 }
1037 else
1038 {
1039 $updateSql = "";
1040 }
1041 $db->query( $updateSql );
1042 }
1043 else
1044 {
1045 $limit = 100;
1046 $offset = 0;
1047 while ( true )
1048 {
1049 $contentObjects = eZContentObject::fetchSameClassList( $classID, true, $offset, $limit );
1050 if ( empty( $contentObjects ) )
1051 {
1052 break;
1053 }
1054
1055 foreach ( $contentObjects as $object )
1056 {
1057 $contentobjectID = $object->attribute( 'id' );
1058 $objectVersions = $object->versions();
1059 // the start version ID, to make sure one attribute in different version has same id.
1060 $startAttributeID = array();
1061 foreach ( $objectVersions as $objectVersion )
1062 {
1063 $translations = $objectVersion->translations( false );
1064 $version = $objectVersion->attribute( 'version' );
1065 foreach ( $translations as $translation )
1066 {
1067 $objectAttribute = eZContentObjectAttribute::create( $classAttributeID, $contentobjectID, $version, $translation );
1068 if( array_key_exists( $translation, $startAttributeID ) )
1069 {
1070 $objectAttribute->setAttribute( 'id', $startAttributeID[$translation] );
1071 }
1072 $objectAttribute->setAttribute( 'language_code', $translation );
1073 $objectAttribute->initialize();
1074 $objectAttribute->store();
1075 if( !array_key_exists( $translation, $startAttributeID ) )
1076 {
1077 $startAttributeID[$translation] = $objectAttribute->attribute( 'id' );
1078 }
1079 $objectAttribute->postInitialize();
1080 }
1081 }
1082 }
1083
1084 $offset += $limit;
1085 eZContentObject::clearCache();
1086 }
1087 }
1088 }
1089
1099 public static function expireCache( $contentClassAttributeID = false, $contentClassID = false)
1100 {
1101 unset( $GLOBALS['eZContentClassAttributeCacheListFull'] );
1102 if ( $contentClassID !== false )
1103 {
1104 if ( isset( $GLOBALS['eZContentClassAttributeCacheList'][$contentClassID] ) )
1105 {
1106 unset( $GLOBALS['eZContentClassAttributeCacheList'][$contentClassID] );
1107 }
1108 }
1109 else
1110 {
1111 unset( $GLOBALS['eZContentClassAttributeCacheList'] );
1112 }
1113 if ( $contentClassAttributeID !== false )
1114 {
1115 if ( isset( $GLOBALS['eZContentClassAttributeCache'][$contentClassAttributeID] ) )
1116 {
1117 unset( $GLOBALS['eZContentClassAttributeCache'][$contentClassAttributeID] );
1118 }
1119 }
1120 else
1121 {
1122 unset( $GLOBALS['eZContentClassAttributeCache'] );
1123 }
1124
1125 // expire cache file by timestamp
1126 $handler = eZExpiryHandler::instance();
1127 $handler->setTimestamp( 'class-identifier-cache', time() + 1 );
1128 $handler->store();
1129
1130 // expire local, in-memory cache
1131 self::$identifierHash = null;
1132 }
1133
1136 public $Content;
1138 public $DisplayInfo;
1139 public $ID;
1140 public $Version;
1141 public $ContentClassID;
1142 public $Identifier;
1143 // serialized array of translated names
1144 public $SerializedNameList;
1145 // unserialized attribute names
1146 public $NameList;
1147 // unserialized attribute description
1148 public $DescriptionList;
1149 public $DataTypeString;
1150 public $Position;
1151 public $IsSearchable;
1152 public $IsRequired;
1153 public $IsInformationCollector;
1154 public $Module;
1155 public $DataTextI18nList;
1156
1157 // Used locale for use by datatypes in class/edit when storing data
1158 protected $EditLocale = false;
1159
1163 private static $identifierHash = null;
1164 }
1165
1166 ?>
eZContentClassAttribute
Encapsulates data for a class attribute.
Definition: ezcontentclassattribute.php:19
eZContentClassAttribute\storeDefined
storeDefined()
Definition: ezcontentclassattribute.php:312
eZContentClassAttribute\nameList
nameList()
Definition: ezcontentclassattribute.php:732
eZContentClassAttribute\$Content
$Content
Definition: ezcontentclassattribute.php:1136
eZContentClassAttribute\editLocale
editLocale()
Definition: ezcontentclassattribute.php:808
eZContentClassAttribute\move
move( $down, $params=null)
Definition: ezcontentclassattribute.php:505
eZContentClassAttribute\initializeObjectAttributes
initializeObjectAttributes(&$objects=null)
Definition: ezcontentclassattribute.php:958
eZContentClassAttribute\descriptionList
descriptionList()
Definition: ezcontentclassattribute.php:765
eZContentClassAttribute\expireCache
static expireCache( $contentClassAttributeID=false, $contentClassID=false)
Definition: ezcontentclassattribute.php:1099
eZContentClassAttribute\fetchListByClassID
static fetchListByClassID( $classID, $version=eZContentClass::VERSION_STATUS_DEFINED, $asObject=true)
Definition: ezcontentclassattribute.php:450
eZContentClassAttribute\$IsSearchable
$IsSearchable
Definition: ezcontentclassattribute.php:1151
eZContentClassAttribute\setAlwaysAvailableLanguage
setAlwaysAvailableLanguage( $languageLocale)
Definition: ezcontentclassattribute.php:828
eZContentClassAttribute\dataTextI18n
dataTextI18n( $languageLocale=false)
Definition: ezcontentclassattribute.php:776
eZContentClassAttribute\dataTextI18nList
dataTextI18nList()
Definition: ezcontentclassattribute.php:798
eZContentClassAttribute\$Version
$Version
Definition: ezcontentclassattribute.php:1140
eZContentClassAttribute\classAttributeIdentifierByID
static classAttributeIdentifierByID( $id)
Definition: ezcontentclassattribute.php:882
eZContentClassAttribute\content
content()
Definition: ezcontentclassattribute.php:537
eZContentClassAttribute\definition
static definition()
Definition: ezcontentclassattribute.php:62
eZContentClassAttribute\sortKeyTypeByID
static sortKeyTypeByID( $classAttributeID)
Definition: ezcontentclassattribute.php:654
eZContentClassAttribute\store
store( $fieldFilters=null)
Definition: ezcontentclassattribute.php:280
eZContentClassAttribute\$DataTextI18nList
$DataTextI18nList
Definition: ezcontentclassattribute.php:1155
eZContentClassAttribute\nameFromSerializedString
static nameFromSerializedString( $serializedNameList, $languageLocale=false)
Definition: ezcontentclassattribute.php:699
eZContentClassAttribute\fetchList
static fetchList( $asObject=true, $parameters=array())
Definition: ezcontentclassattribute.php:403
eZContentClassAttribute\instantiateTemporary
instantiateTemporary( $contentobjectID=false)
Definition: ezcontentclassattribute.php:275
eZContentClassAttribute\$SerializedNameList
$SerializedNameList
Definition: ezcontentclassattribute.php:1144
eZContentClassAttribute\storeVersioned
storeVersioned( $version)
Definition: ezcontentclassattribute.php:327
eZContentClassAttribute\$IsInformationCollector
$IsInformationCollector
Definition: ezcontentclassattribute.php:1153
eZContentClassAttribute\dataType
dataType()
Definition: ezcontentclassattribute.php:529
eZContentClassAttribute\__clone
__clone()
Definition: ezcontentclassattribute.php:197
eZContentClassAttribute\displayInfo
displayInfo()
Definition: ezcontentclassattribute.php:560
eZContentClassAttribute\__construct
__construct( $row)
Definition: ezcontentclassattribute.php:20
eZContentClassAttribute\$NameList
$NameList
Definition: ezcontentclassattribute.php:1146
eZContentClassAttribute\classAttributeIDByIdentifier
static classAttributeIDByIdentifier( $identifier)
Definition: ezcontentclassattribute.php:865
eZContentClassAttribute\$Module
$Module
Definition: ezcontentclassattribute.php:1154
eZContentClassAttribute\$DescriptionList
$DescriptionList
Definition: ezcontentclassattribute.php:1148
eZContentClassAttribute\removeThis
removeThis( $quiet=false)
Definition: ezcontentclassattribute.php:356
eZContentClassAttribute\$Position
$Position
Definition: ezcontentclassattribute.php:1150
eZContentClassAttribute\instantiate
instantiate( $contentobjectID, $languageCode=false, $version=1)
Definition: ezcontentclassattribute.php:267
eZContentClassAttribute\create
static create( $class_id, $data_type_string, $optionalValues=array(), $languageLocale=false)
Definition: ezcontentclassattribute.php:221
eZContentClassAttribute\setDescription
setDescription( $description, $languageLocale=false)
Definition: ezcontentclassattribute.php:755
eZContentClassAttribute\cachedInfo
static cachedInfo()
Definition: ezcontentclassattribute.php:594
eZContentClassAttribute\$EditLocale
$EditLocale
Definition: ezcontentclassattribute.php:1158
eZContentClassAttribute\customHTTPAction
customHTTPAction( $module, $http, $action)
Definition: ezcontentclassattribute.php:576
eZContentClassAttribute\dataTypeByID
static dataTypeByID( $classAttributeID)
Definition: ezcontentclassattribute.php:671
eZContentClassAttribute\description
description( $languageLocale=false)
Definition: ezcontentclassattribute.php:743
eZContentClassAttribute\$Identifier
$Identifier
Definition: ezcontentclassattribute.php:1142
eZContentClassAttribute\$identifierHash
static $identifierHash
Definition: ezcontentclassattribute.php:1163
eZContentClassAttribute\$ID
$ID
Definition: ezcontentclassattribute.php:1139
eZContentClassAttribute\name
name( $languageLocale=false)
Definition: ezcontentclassattribute.php:710
eZContentClassAttribute\removeTranslation
removeTranslation( $languageLocale)
Definition: ezcontentclassattribute.php:849
eZContentClassAttribute\classAttributeIdentifiersHash
static classAttributeIdentifiersHash()
Definition: ezcontentclassattribute.php:904
eZContentClassAttribute\currentModule
currentModule()
Definition: ezcontentclassattribute.php:589
eZContentClassAttribute\diff
diff( $old, $new)
Definition: ezcontentclassattribute.php:685
eZContentClassAttribute\$ContentClassID
$ContentClassID
Definition: ezcontentclassattribute.php:1141
eZContentClassAttribute\fetch
static fetch( $id, $asObject=true, $version=eZContentClass::VERSION_STATUS_DEFINED, $field_filters=null)
Definition: ezcontentclassattribute.php:380
eZContentClassAttribute\setEditLocale
setEditLocale( $languageLocale=false)
Definition: ezcontentclassattribute.php:818
eZContentClassAttribute\$DisplayInfo
$DisplayInfo
Contains information on how to display the current attribute in various viewmodes.
Definition: ezcontentclassattribute.php:1138
eZContentClassAttribute\setDataTextI18n
setDataTextI18n( $string, $languageLocale=false)
Definition: ezcontentclassattribute.php:788
eZContentClassAttribute\fetchFilteredList
static fetchFilteredList( $cond, $asObject=true)
Definition: ezcontentclassattribute.php:481
eZContentClassAttribute\$DataTypeString
$DataTypeString
Definition: ezcontentclassattribute.php:1149
eZContentClassAttribute\$IsRequired
$IsRequired
Definition: ezcontentclassattribute.php:1152
eZContentClassAttribute\setContent
setContent( $content)
Definition: ezcontentclassattribute.php:551
eZContentClassAttribute\setName
setName( $name, $languageLocale=false)
Definition: ezcontentclassattribute.php:722
eZContentClass\VERSION_STATUS_DEFINED
const VERSION_STATUS_DEFINED
Definition: ezcontentclass.php:22
eZContentClass\VERSION_STATUS_TEMPORARY
const VERSION_STATUS_TEMPORARY
Definition: ezcontentclass.php:23
eZContentObjectAttribute\create
static create( $contentclassAttributeID, $contentobjectID, $version=1, $languageCode=false)
Definition: ezcontentobjectattribute.php:254
eZContentObject\clearCache
static clearCache( $idArray=array())
Definition: ezcontentobject.php:284
eZContentObject\fetchSameClassList
static fetchSameClassList( $contentClassID, $asObject=true, $offset=false, $limit=false)
Definition: ezcontentobject.php:1247
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDataType\create
static create( $dataTypeString)
Definition: ezdatatype.php:151
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZPHPCreator
eZPHPCreator provides a simple interface for creating and executing PHP code.
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\newObjectOrder
static newObjectOrder( $def, $orderField, $conditions)
Definition: ezpersistentobject.php:1034
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\reorderObject
static reorderObject( $def, $orderField, $conditions, $down=true)
Definition: ezpersistentobject.php:1069
eZPersistentObject\setAttribute
setAttribute( $attr, $val)
Definition: ezpersistentobject.php:1374
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
eZSerializedObjectNameList
Definition: ezserializedobjectnamelist.php:12
eZSerializedObjectNameList\nameFromSerializedString
static nameFromSerializedString( $serializedNames, $languageLocale=false)
Definition: ezserializedobjectnamelist.php:267
eZSys\cacheDirectory
static cacheDirectory()
Definition: ezsys.php:527
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.