00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 include_once( "lib/ezdb/classes/ezdb.php" );
00040 include_once( "kernel/classes/ezpersistentobject.php" );
00041 include_once( "kernel/classes/ezcontentobject.php" );
00042 include_once( "kernel/classes/ezcontentclassattribute.php" );
00043 include_once( 'kernel/classes/ezdatatype.php' );
00044 include_once( 'kernel/classes/ezcontentlanguage.php' );
00045
00046 class eZContentObjectAttribute extends eZPersistentObject
00047 {
00048
00049
00050 function eZContentObjectAttribute( $row )
00051 {
00052 $this->Content = null;
00053 $this->DisplayInfo = null;
00054 $this->HTTPValue = null;
00055 $this->ValidationError = null;
00056 $this->ValidationLog = null;
00057 $this->ContentClassAttributeIdentifier = null;
00058 $this->ContentClassAttributeID = null;
00059 $this->InputParameters = false;
00060 $this->HasValidationError = false;
00061 $this->DataTypeCustom = null;
00062 $this->eZPersistentObject( $row );
00063 }
00064
00065 function definition()
00066 {
00067 return array( "fields" => array( "id" => array( 'name' => 'ID',
00068 'datatype' => 'integer',
00069 'default' => 0,
00070 'required' => true ),
00071 "contentobject_id" => array( 'name' => "ContentObjectID",
00072 'datatype' => 'integer',
00073 'default' => 0,
00074 'required' => true,
00075 'foreign_class' => 'eZContentObject',
00076 'foreign_attribute' => 'id',
00077 'multiplicity' => '1..*' ),
00078 "version" => array( 'name' => "Version",
00079 'datatype' => 'integer',
00080 'default' => 0,
00081 'required' => true ),
00082 "language_code" => array( 'name' => "LanguageCode",
00083 'datatype' => 'string',
00084 'default' => '',
00085 'required' => true ),
00086 'language_id' => array( 'name' => "LanguageID",
00087 'datatype' => 'integer',
00088 'default' => '0',
00089 'required' => true,
00090 'foreign_class' => 'eZContentLanguage',
00091 'foreign_attribute' => 'id',
00092 'multiplicity' => '1..*' ),
00093 "contentclassattribute_id" => array( 'name' => "ContentClassAttributeID",
00094 'datatype' => 'integer',
00095 'default' => 0,
00096 'required' => true,
00097 'foreign_class' => 'eZContentClassAttribute',
00098 'foreign_attribute' => 'id',
00099 'multiplicity' => '1..*' ),
00100 "attribute_original_id" => array( 'name' => "AttributeOriginalID",
00101 'datatype' => 'integer',
00102 'default' => 0,
00103 'required' => true,
00104 'foreign_class' => 'eZContentObjectAttribute',
00105 'foreign_attribute' => 'id',
00106 'multiplicity' => '1..*' ),
00107 "sort_key_int" => array( 'name' => "SortKeyInt",
00108 'datatype' => 'integer',
00109 'default' => '0',
00110 'required' => true ),
00111 "sort_key_string" => array( 'name' => "SortKeyString",
00112 'datatype' => 'string',
00113 'max_length' => 255,
00114 'default' => '',
00115 'required' => true ),
00116 "data_type_string" => array( 'name' => "DataTypeString",
00117 'datatype' => 'string',
00118 'default' => '',
00119 'required' => true ),
00120 "data_text" => array( 'name' => "DataText",
00121 'datatype' => 'text',
00122 'default' => '',
00123 'required' => true ),
00124 "data_int" => array( 'name' => "DataInt",
00125 'datatype' => 'integer',
00126 'default' => null,
00127 'required' => false ),
00128 "data_float" => array( 'name' => "DataFloat",
00129 'datatype' => 'float',
00130 'default' => 0,
00131 'required' => true ) ),
00132 "keys" => array( "id", "contentobject_id", "version", "language_code" ),
00133 "function_attributes" => array( "contentclass_attribute" => "contentClassAttribute",
00134 "contentclass_attribute_identifier" => "contentClassAttributeIdentifier",
00135 "contentclass_attribute_name" => "contentClassAttributeName",
00136 "can_translate" => "contentClassAttributeCanTranslate",
00137 "is_information_collector" => "contentClassAttributeIsInformationCollector",
00138 "is_required" => "contentClassAttributeIsRequired",
00139 "content" => "content",
00140 'has_http_value' => 'hasHTTPValue',
00141 'value' => 'value',
00142 'has_content' => 'hasContent',
00143 "class_content" => "classContent",
00144 "object" => "object",
00145 'object_version' => 'objectVersion',
00146 'view_template' => 'viewTemplateName',
00147 'edit_template' => 'editTemplateName',
00148 'result_template' => 'resultTemplate',
00149 "has_validation_error" => "hasValidationError",
00150 "validation_error" => "validationError",
00151 "validation_log" => "validationLog",
00152 "language" => "language",
00153 "is_a" => "isA",
00154 'display_info' => 'displayInfo',
00155 'class_display_info' => 'classDisplayInfo' ),
00156 "increment_key" => "id",
00157 "class_name" => "eZContentObjectAttribute",
00158 "sort" => array( "id" => "asc" ),
00159 "name" => "ezcontentobject_attribute" );
00160 }
00161
00162 function fetch( $id, $version, $asObject = true, $field_filters = null )
00163 {
00164 return eZPersistentObject::fetchObject( eZContentObjectAttribute::definition(),
00165 $field_filters,
00166 array( "id" => $id,
00167 "version" => $version ),
00168 $asObject );
00169 }
00170
00171 function &fetchListByClassID( $id, $version = false, $limit = null, $asObject = true, $asCount = false )
00172 {
00173 $conditions = array();
00174 if ( is_array( $id ) )
00175 $conditions['contentclassattribute_id'] = array( $id );
00176 else
00177 $conditions['contentclassattribute_id'] = $id;
00178 if ( $version !== false )
00179 $conditions["version"] = $version;
00180 $fieldFilters = null;
00181 $customFields = null;
00182 if ( $asCount )
00183 {
00184 $limit = null;
00185 $asObject = false;
00186 $fieldFilters = array();
00187 $customFields = array( array( 'operation' => 'count( id )',
00188 'name' => 'count' ) );
00189 }
00190 $objectList = eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
00191 $fieldFilters,
00192 $conditions,
00193 ( $asCount ? false : null ),
00194 $limit,
00195 $asObject,
00196 null,
00197 $customFields );
00198 if ( $asCount )
00199 return $objectList[0]['count'];
00200 else
00201 return $objectList;
00202 }
00203
00204 function fetchByClassAttributeID( $classAttributeID, $objectID, $version, $languageID, $asObject = true )
00205 {
00206 return eZPersistentObject::fetchObject( eZContentObjectAttribute::definition(),
00207 null,
00208 array( 'contentclassattribute_id' => $classAttributeID,
00209 'contentobject_id' => $objectID,
00210 'version' => $version,
00211 'language_id' => $languageID ),
00212 $asObject );
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 function fetchSameClassAttributeIDList( $contentClassAttributeID, $asObject = true, $version = false, $contentObjectID = false )
00224 {
00225 $conditions = array( "contentclassattribute_id" => $contentClassAttributeID );
00226 if ( $version !== false )
00227 $conditions['version'] = $version;
00228 if ( $contentObjectID !== false )
00229 $conditions['contentobject_id'] = $contentObjectID;
00230 return eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
00231 null,
00232 $conditions,
00233 null,
00234 null,
00235 $asObject);
00236 }
00237
00238
00239
00240
00241 function fetchAttributeTranslations( $asObject = true )
00242 {
00243 return eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
00244 null,
00245 array( "contentclassattribute_id" => $this->ContentClassAttributeID,
00246 "contentobject_id" => $this->ContentObjectID,
00247 "version" => $this->Version ),
00248 null,
00249 null,
00250 $asObject);
00251 }
00252
00253 function create( $contentclassAttributeID, $contentobjectID, $version = 1, $languageCode = false )
00254 {
00255 include_once( 'kernel/classes/ezcontentlanguage.php' );
00256 include_once( 'lib/ezlocale/classes/ezlocale.php' );
00257
00258 if ( $languageCode == false )
00259 {
00260 $languageCode = eZContentObject::defaultLanguage();
00261 }
00262
00263 $languageID = eZContentLanguage::idByLocale( $languageCode );
00264
00265 $row = array(
00266 "id" => null,
00267 "contentobject_id" => $contentobjectID,
00268 "version" => $version,
00269 "language_code" => $languageCode,
00270 'language_id' => $languageID,
00271 "contentclassattribute_id" => $contentclassAttributeID,
00272 'data_text' => '',
00273 'data_int' => null,
00274 'data_float' => 0.0 );
00275 return new eZContentObjectAttribute( $row );
00276 }
00277
00278
00279
00280
00281
00282
00283 function store()
00284 {
00285 require_once( 'kernel/classes/ezcontentlanguage.php' );
00286
00287
00288 global $eZContentObjectContentObjectCache;
00289 unset( $eZContentObjectContentObjectCache[$this->ContentObjectID] );
00290 global $eZContentObjectDataMapCache;
00291 unset( $eZContentObjectDataMapCache[$this->ContentObjectID] );
00292
00293 $classAttribute =& $this->contentClassAttribute();
00294
00295 $dataType = $classAttribute->dataType();
00296 if ( $dataType )
00297 {
00298 $this->setAttribute( 'data_type_string', $classAttribute->attribute( 'data_type_string' ) );
00299 $this->updateSortKey( false );
00300
00301 $db =& eZDB::instance();
00302 $db->begin();
00303
00304
00305 $dataType->storeObjectAttribute( $this );
00306
00307 eZPersistentObject::store();
00308 $dataType->postStore( $this );
00309 $db->commit();
00310 }
00311 }
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 function storeData()
00322 {
00323 require_once( 'kernel/classes/ezcontentlanguage.php' );
00324
00325
00326 global $eZContentObjectContentObjectCache;
00327 unset( $eZContentObjectContentObjectCache[$this->ContentObjectID] );
00328 global $eZContentObjectDataMapCache;
00329 unset( $eZContentObjectDataMapCache[$this->ContentObjectID] );
00330
00331 $classAttribute =& $this->contentClassAttribute();
00332 $dataType = $classAttribute->dataType();
00333 $this->setAttribute( 'data_type_string', $classAttribute->attribute( 'data_type_string' ) );
00334 $this->updateSortKey( false );
00335
00336 eZPersistentObject::store();
00337 }
00338
00339
00340
00341
00342
00343
00344
00345 function updateSortKey( $storeData = true )
00346 {
00347 $classAttribute =& $this->contentClassAttribute();
00348 $dataType = $classAttribute->dataType();
00349
00350 $return = false;
00351
00352 if ( $dataType )
00353 {
00354 $return = true;
00355
00356 $sortKey = $dataType->sortKey( $this );
00357 $this->setAttribute( 'sort_key_string', "" );
00358 $this->setAttribute( 'sort_key_int', 0 );
00359 if ( $dataType->sortKeyType() == 'string' )
00360 {
00361 $this->setAttribute( 'sort_key_string', $sortKey );
00362 $this->setAttribute( 'sort_key_int', 0 );
00363
00364 }
00365 else if ( $dataType->sortKeyType() == 'int' )
00366 {
00367 $this->setAttribute( 'sort_key_int', $sortKey );
00368 }
00369
00370 if ( $storeData )
00371 {
00372 $dataType->storeObjectAttribute( $this );
00373 $return = eZPersistentObject::store();
00374 }
00375 }
00376
00377 return $return;
00378 }
00379
00380
00381
00382
00383
00384
00385 function storeNewRow()
00386 {
00387 return eZPersistentObject::store();
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397 function fetchByIdentifier( $identifier, $asObject = true )
00398 {
00399 return eZPersistentObject::fetchObject( eZContentObjectAttribute::definition(),
00400 null,
00401 array( 'sort_key_string' => $identifier, 'data_type_string' => 'ezstring' ),
00402 $asObject );
00403 }
00404
00405 function &language( $languageCode = false, $asObject = true )
00406 {
00407 if ( !$languageCode )
00408 {
00409 $object =& $this->object();
00410 if ( !$object )
00411 {
00412 $result = null;
00413 return $result;
00414 }
00415 $languageCode = $object->initialLanguageCode();
00416 }
00417 $language = eZPersistentObject::fetchObject( eZContentObjectAttribute::definition(),
00418 null,
00419 array( "contentclassattribute_id" => $this->ContentClassAttributeID,
00420 "contentobject_id" => $this->ContentObjectID,
00421 "version" => $this->Version,
00422 "language_code" => $languageCode ),
00423 $asObject );
00424 return $language;
00425 }
00426
00427
00428
00429 function &object()
00430 {
00431 if( isset( $this->ContentObjectID ) and $this->ContentObjectID )
00432 $object =& eZContentObject::fetch( $this->ContentObjectID );
00433 else
00434 $object = null;
00435 return $object;
00436 }
00437
00438 function &objectVersion()
00439 {
00440 $version = eZContentObjectVersion::fetchVersion( $this->Version, $this->ContentObjectID );
00441
00442 return $version;
00443 }
00444
00445
00446
00447
00448 function &contentClassAttribute()
00449 {
00450 eZDebug::accumulatorStart( 'instantiate_class_attribute', 'class_abstraction', 'Instantiating content class attribute' );
00451 $classAttribute =& eZContentClassAttribute::fetch( $this->ContentClassAttributeID );
00452 eZDebug::accumulatorStop( 'instantiate_class_attribute' );
00453 return $classAttribute;
00454 }
00455
00456
00457
00458
00459 function setContentClassAttributeIdentifier( $identifier )
00460 {
00461 $this->ContentClassAttributeIdentifier = $identifier;
00462 }
00463
00464
00465
00466
00467 function setContentClassAttributeCanTranslate( $canTranslate )
00468 {
00469 $this->ContentClassAttributeCanTranslate = $canTranslate;
00470 }
00471
00472
00473
00474
00475 function setContentClassAttributeName( $name )
00476 {
00477 $this->ContentClassAttributeName = $name;
00478 }
00479
00480
00481
00482
00483
00484
00485 function &contentClassAttributeIsRequired()
00486 {
00487 if ( $this->ContentClassAttributeIsRequired === null )
00488 {
00489 eZDebug::accumulatorStart( 'class_a_is_req', 'Sytem overhead', 'Fetch class attribute is_required' );
00490
00491 $classAttribute =& eZContentClassAttribute::fetch( $this->ContentClassAttributeID );
00492 $this->ContentClassAttributeIsRequired = $classAttribute->attribute( 'is_required' );
00493 eZDebug::accumulatorStop( 'class_a_is_req' );
00494 }
00495
00496 return $this->ContentClassAttributeIsRequired;
00497 }
00498
00499
00500
00501
00502
00503
00504 function &contentClassAttributeIsInformationCollector()
00505 {
00506 if ( $this->ContentClassAttributeIsInformationCollector === null )
00507 {
00508 eZDebug::accumulatorStart( 'class_a_is_ic', 'Sytem overhead', 'Fetch class attribute name' );
00509
00510 $classAttribute =& eZContentClassAttribute::fetch( $this->ContentClassAttributeID );
00511 $this->ContentClassAttributeIsInformationCollector = $classAttribute->attribute( 'is_information_collector' );
00512 eZDebug::accumulatorStop( 'class_a_is_ic' );
00513 }
00514
00515 return $this->ContentClassAttributeIsInformationCollector;
00516 }
00517
00518
00519
00520
00521
00522
00523 function &contentClassAttributeName()
00524 {
00525 if ( $this->ContentClassAttributeName === null )
00526 {
00527 eZDebug::accumulatorStart( 'class_a_name', 'Sytem overhead', 'Fetch class attribute name' );
00528
00529 $classAttribute =& eZContentClassAttribute::fetch( $this->ContentClassAttributeID );
00530 $this->ContentClassAttributeName = $classAttribute->attribute( 'name' );
00531 eZDebug::accumulatorStop( 'class_a_name' );
00532 }
00533
00534 return $this->ContentClassAttributeName;
00535 }
00536
00537
00538
00539
00540
00541
00542 function &contentClassAttributeCanTranslate()
00543 {
00544 if ( $this->ContentClassAttributeCanTranslate === null )
00545 {
00546 eZDebug::accumulatorStart( 'class_a_can_translate', 'Sytem overhead', 'Fetch class attribute can translate value' );
00547
00548 $classAttribute =& eZContentClassAttribute::fetch( $this->ContentClassAttributeID );
00549
00550 $dataType = $classAttribute->dataType();
00551
00552 if ( $dataType &&
00553 $dataType->Attributes["properties"]["translation_allowed"] &&
00554 $classAttribute->attribute( 'can_translate' ) )
00555 $this->ContentClassAttributeCanTranslate = 1;
00556 else
00557 $this->ContentClassAttributeCanTranslate = 0;
00558 eZDebug::accumulatorStop( 'class_a_can_translate' );
00559 }
00560
00561 return $this->ContentClassAttributeCanTranslate;
00562 }
00563
00564
00565
00566
00567
00568
00569 function &contentClassAttributeIdentifier()
00570 {
00571 if ( $this->ContentClassAttributeIdentifier === null )
00572 {
00573 eZDebug::accumulatorStart( 'class_a_id', 'Sytem overhead', 'Fetch class attribute identifier' );
00574
00575 $classAttribute =& eZContentClassAttribute::fetch( $this->ContentClassAttributeID );
00576 $this->ContentClassAttributeIdentifier = $classAttribute->attribute( 'identifier' );
00577 eZDebug::accumulatorStop( 'class_a_id' );
00578 }
00579
00580 return $this->ContentClassAttributeIdentifier;
00581 }
00582
00583
00584
00585
00586
00587 function validateInput( &$http, $base,
00588 &$inputParameters, $validationParameters = array() )
00589 {
00590 $dataType = $this->dataType();
00591 if ( $dataType )
00592 {
00593 $this->setInputParameters( $inputParameters );
00594 $this->setValidationParameters( $validationParameters );
00595 $this->IsValid = $dataType->validateObjectAttributeHTTPInput( $http, $base, $this );
00596 $this->unsetValidationParameters();
00597 $this->unsetInputParameters();
00598 }
00599 return $this->IsValid;
00600 }
00601
00602
00603
00604
00605
00606
00607
00608
00609 function setInputParameters( &$parameters )
00610 {
00611 $this->InputParameters =& $parameters;
00612 }
00613
00614
00615
00616
00617
00618 function unsetInputParameters()
00619 {
00620 unset( $this->InputParameters );
00621 $this->InputParameters = false;
00622 }
00623
00624
00625
00626
00627
00628 function &inputParameters()
00629 {
00630 return $this->InputParameters;
00631 }
00632
00633
00634
00635
00636
00637
00638
00639
00640 function setValidationParameters( &$parameters )
00641 {
00642 $this->ValidationParameters =& $parameters;
00643 }
00644
00645
00646
00647
00648
00649 function unsetValidationParameters()
00650 {
00651 unset( $this->ValidationParameters );
00652 $this->ValidationParameters = false;
00653 }
00654
00655
00656
00657
00658
00659 function &validationParameters()
00660 {
00661 return $this->ValidationParameters;
00662 }
00663
00664
00665
00666
00667 function validateIsRequired()
00668 {
00669 $classAttribute =& $this->contentClassAttribute();
00670 $validationParameters =& $this->validationParameters();
00671 if ( !( isset( $validationParameters['skip-isRequired'] ) && $validationParameters['skip-isRequired'] === true ) && $classAttribute->attribute( "is_required" ) )
00672 return true;
00673
00674 return false;
00675 }
00676
00677
00678
00679
00680 function fixupInput( &$http, $base )
00681 {
00682 $dataType = $this->dataType();
00683 if ( $dataType )
00684 $dataType->fixupObjectAttributeHTTPInput( $http, $base, $this );
00685 }
00686
00687
00688
00689
00690 function fetchInput( &$http, $base )
00691 {
00692 $dataType = $this->dataType();
00693 if ( $dataType )
00694 return $dataType->fetchObjectAttributeHTTPInput( $http, $base, $this );
00695
00696 return false;
00697 }
00698
00699
00700
00701
00702 function validateInformation( &$http, $base,
00703 &$inputParameters, $validationParameters = array() )
00704 {
00705 $dataType = $this->dataType();
00706 if ( $dataType )
00707 {
00708 $this->setInputParameters( $inputParameters );
00709 $this->setValidationParameters( $validationParameters );
00710 $this->IsValid = $dataType->validateCollectionAttributeHTTPInput( $http, $base, $this );
00711 $this->unsetValidationParameters();
00712 $this->unsetInputParameters();
00713 }
00714 return $this->IsValid;
00715 }
00716
00717
00718
00719
00720 function collectInformation( &$collection, &$collectionAttribute, &$http, $base )
00721 {
00722 $dataType = $this->dataType();
00723 if ( $dataType )
00724 {
00725 $collectionAttribute->setAttribute( 'contentclass_attribute_id', $this->attribute( 'contentclassattribute_id' ) );
00726 $collectionAttribute->setAttribute( 'contentobject_attribute_id', $this->attribute( 'id' ) );
00727 $collectionAttribute->setAttribute( 'contentobject_id', $this->attribute( 'contentobject_id' ) );
00728 return $dataType->fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $this );
00729 }
00730
00731 return false;
00732 }
00733
00734
00735
00736
00737 function customHTTPAction( &$http, $action, $parameters = array() )
00738 {
00739 $dataType = $this->dataType();
00740 if ( $dataType )
00741 $dataType->customObjectAttributeHTTPAction( $http, $action, $this, $parameters );
00742 }
00743
00744
00745
00746
00747 function handleCustomHTTPActions( &$http, $attributeDataBaseName,
00748 $customActionAttributeArray, $customActionParameters )
00749 {
00750 $dataType = $this->dataType();
00751 if ( $dataType )
00752 {
00753 $customActionParameters['contentobject_attribute'] =& $this;
00754 $dataType->handleCustomObjectHTTPActions( $http, $attributeDataBaseName,
00755 $customActionAttributeArray, $customActionParameters );
00756 }
00757 }
00758
00759
00760
00761
00762
00763 function onPublish( &$object, &$nodes )
00764 {
00765 $dataType = $this->dataType();
00766 if ( $dataType )
00767 $dataType->onPublish( $this, $object, $nodes );
00768 }
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779 function insertHTTPFile( &$object, $objectVersion, $objectLanguage,
00780 &$httpFile, $mimeData,
00781 &$result )
00782 {
00783 if ( !$object )
00784 $object =& $this->object();
00785 if ( $objectVersion === false )
00786 $objectVersion = $object->attribute( 'current_version' );
00787 if ( $objectLanguage === false )
00788 $objectLanguage = $object->attribute( 'default_language' );
00789 $dataType = $this->dataType();
00790 return $dataType->insertHTTPFile( $object, $objectVersion, $objectLanguage,
00791 $this, $httpFile, $mimeData,
00792 $result );
00793 }
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804 function insertRegularFile( &$object, $objectVersion, $objectLanguage,
00805 $filePath,
00806 &$result )
00807 {
00808 if ( !$object )
00809 $object =& $this->object();
00810 if ( $objectVersion === false )
00811 $objectVersion = $object->attribute( 'current_version' );
00812 if ( $objectLanguage === false )
00813 $objectLanguage = $object->attribute( 'default_language' );
00814 $dataType = $this->dataType();
00815 return $dataType->insertRegularFile( $object, $objectVersion, $objectLanguage,
00816 $this, $filePath,
00817 $result );
00818 }
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829 function insertSimpleString( &$object, $objectVersion, $objectLanguage,
00830 $string,
00831 &$result )
00832 {
00833 if ( !$object )
00834 $object =& $this->object();
00835 if ( $objectVersion === false )
00836 $objectVersion = $object->attribute( 'current_version' );
00837 if ( $objectLanguage === false )
00838 $objectLanguage = $object->attribute( 'default_language' );
00839 $dataType = $this->dataType();
00840 return $dataType->insertSimpleString( $object, $objectVersion, $objectLanguage,
00841 $this, $string,
00842 $result );
00843 }
00844
00845
00846
00847
00848 function hasStoredFileInformation( &$object, $objectVersion, $objectLanguage )
00849 {
00850 if ( !$object )
00851 $object =& $this->object();
00852 if ( $objectVersion === false )
00853 $objectVersion = $object->attribute( 'current_version' );
00854 if ( $objectLanguage === false )
00855 $objectLanguage = $object->attribute( 'default_language' );
00856 $dataType = $this->dataType();
00857 return $dataType->hasStoredFileInformation( $object, $objectVersion, $objectLanguage,
00858 $this );
00859 }
00860
00861
00862
00863
00864 function storedFileInformation( &$object, $objectVersion, $objectLanguage )
00865 {
00866 if ( !$object )
00867 $object =& $this->object();
00868 if ( $objectVersion === false )
00869 $objectVersion = $object->attribute( 'current_version' );
00870 if ( $objectLanguage === false )
00871 $objectLanguage = $object->attribute( 'default_language' );
00872 $dataType = $this->dataType();
00873 return $dataType->storedFileInformation( $object, $objectVersion, $objectLanguage,
00874 $this );
00875 }
00876
00877
00878
00879
00880 function handleDownload( &$object, $objectVersion, $objectLanguage )
00881 {
00882 if ( !$object )
00883 $object =& $this->object();
00884 if ( $objectVersion === false )
00885 $objectVersion = $object->attribute( 'current_version' );
00886 if ( $objectLanguage === false )
00887 $objectLanguage = $object->attribute( 'default_language' );
00888 $dataType = $this->dataType();
00889 return $dataType->handleDownload( $object, $objectVersion, $objectLanguage,
00890 $this );
00891 }
00892
00893
00894
00895
00896
00897
00898 function initialize( $currentVersion = null, $originalContentObjectAttribute = null )
00899 {
00900 if ( $originalContentObjectAttribute === null )
00901 $originalContentObjectAttribute = $this;
00902 $classAttribute =& $this->contentClassAttribute();
00903 $dataType = $classAttribute->dataType();
00904 if ( $dataType )
00905 $dataType->initializeObjectAttribute( $this, $currentVersion, $originalContentObjectAttribute );
00906 }
00907
00908
00909
00910
00911 function postInitialize( $currentVersion = null, $originalContentObjectAttribute = null )
00912 {
00913 if ( $originalContentObjectAttribute === null )
00914 $originalContentObjectAttribute = $this;
00915 $classAttribute =& $this->contentClassAttribute();
00916 $dataType = $classAttribute->dataType();
00917 if ( $dataType )
00918 $dataType->postInitializeObjectAttribute( $this, $currentVersion, $originalContentObjectAttribute );
00919 }
00920
00921
00922
00923
00924
00925
00926 function remove( $id, $currentVersion = null )
00927 {
00928 $dataType = $this->dataType();
00929 if ( !$dataType )
00930 return false;
00931 $dataType->deleteStoredObjectAttribute( $this, $currentVersion );
00932 if( $currentVersion == null )
00933 {
00934 eZPersistentObject::removeObject( eZContentObjectAttribute::definition(),
00935 array( "id" => $id ) );
00936 }
00937 else
00938 {
00939 eZPersistentObject::removeObject( eZContentObjectAttribute::definition(),
00940 array( "id" => $id,
00941 "version" => $currentVersion ) );
00942 }
00943 }
00944
00945
00946
00947
00948
00949 function clone( $newVersionNumber, $currentVersionNumber, $contentObjectID = false, $newLanguageCode = false )
00950 {
00951 $tmp = $this;
00952 $tmp->setAttribute( "version", $newVersionNumber );
00953 if ( $contentObjectID != false )
00954 {
00955
00956 if ( $contentObjectID != $tmp->attribute( 'contentobject_id' ) )
00957 {
00958 $exAttr = eZPersistentObject::fetchObject( eZContentObjectAttribute::definition(),
00959 null,
00960 array( 'contentobject_id' => $contentObjectID,
00961 'contentclassattribute_id' => $tmp->attribute( 'contentclassattribute_id' ),
00962 'language_code' => $tmp->attribute( 'language_code' ) ),
00963 true );
00964
00965
00966 if ( is_object( $exAttr ) )
00967
00968 $id = $exAttr->attribute( 'id' );
00969 else
00970
00971 $id = null;
00972
00973 $tmp->setAttribute( 'id', $id );
00974 }
00975 $tmp->setAttribute( 'contentobject_id', $contentObjectID );
00976 }
00977 else
00978 {
00979
00980 $tmp->setAttribute( 'language_id', $tmp->attribute( 'language_id' ) & ~1 );
00981 }
00982
00983 if ( $newLanguageCode != false && $tmp->attribute( 'language_code' ) != $newLanguageCode )
00984 {
00985 $exAttr = eZPersistentObject::fetchObject( eZContentObjectAttribute::definition(),
00986 null,
00987 array( 'contentobject_id' => $contentObjectID? $contentObjectID: $tmp->attribute( 'contentobject_id' ),
00988 'contentclassattribute_id' => $tmp->attribute( 'contentclassattribute_id' ),
00989 'language_code' => $newLanguageCode ),
00990 true );
00991
00992 if ( is_object( $exAttr ) )
00993 {
00994 $id = $exAttr->attribute( 'id' );
00995 }
00996 else
00997 {
00998 $id = null;
00999 }
01000 $tmp->setAttribute( 'id', $id );
01001 $tmp->setAttribute( 'language_code', $newLanguageCode );
01002 $tmp->setAttribute( 'language_id', eZContentLanguage::idByLocale( $newLanguageCode ) );
01003 }
01004
01005 $db =& eZDB::instance();
01006 $db->begin();
01007 $tmp->sync();
01008 $tmp->initialize( $currentVersionNumber, $this );
01009 $tmp->sync();
01010 $tmp->postInitialize( $currentVersionNumber, $this );
01011 $db->commit();
01012
01013 return $tmp;
01014 }
01015
01016
01017
01018
01019
01020
01021
01022
01023 function &translateTo( $languageCode, $updateLanguageMask = true )
01024 {
01025 $languageID = eZContentLanguage::idByLocale( $languageCode );
01026
01027 $tmp = $this;
01028 $tmp->setAttribute( 'id', null );
01029 $tmp->setAttribute( 'language_code', $languageCode );
01030 $tmp->setAttribute( 'language_id', $languageID );
01031
01032 $db =& eZDB::instance();
01033 $db->begin();
01034 $tmp->sync();
01035 $currentVersionNumber = $this->attribute( 'version' );
01036 $tmp->initialize( $currentVersionNumber, $this );
01037 $tmp->sync();
01038 $tmp->postInitialize( $currentVersionNumber, $this );
01039 if ( $updateLanguageMask )
01040 {
01041 $version = $tmp->objectVersion();
01042 $version->updateLanguageMask( (int) $version->languageMask() | (int) $languageID, false );
01043 }
01044 $db->commit();
01045
01046
01047 $tmpnull = null;
01048 $tmp->setContent( $tmpnull );
01049
01050 return $tmp;
01051 }
01052
01053
01054
01055
01056 function dataType()
01057 {
01058 $dataType = null;
01059 if( !is_null( $this->DataTypeString ) )
01060 $dataType = eZDataType::create( $this->DataTypeString );
01061
01062 return $dataType;
01063 }
01064
01065
01066
01067
01068 function title()
01069 {
01070 $dataType = $this->dataType();
01071 if ( $dataType )
01072 return $dataType->title( $this );
01073
01074 return '';
01075 }
01076
01077
01078
01079
01080
01081
01082 function &classContent()
01083 {
01084 $attribute =& $this->contentClassAttribute();
01085 return $attribute->content();
01086 }
01087
01088
01089
01090
01091 function setHTTPValue( &$value )
01092 {
01093 $this->HTTPValue =& $value;
01094 }
01095
01096
01097
01098
01099 function &value()
01100 {
01101 if ( $this->HTTPValue !== null )
01102 return $this->HTTPValue;
01103 else
01104 return $this->content();
01105 }
01106
01107
01108
01109
01110
01111
01112 function &hasHTTPValue()
01113 {
01114 if ( $this->HTTPValue !== null )
01115 $hasValue = true;
01116 else
01117 $hasValue = false;
01118 return $hasValue;
01119 }
01120
01121
01122
01123
01124 function &content()
01125 {
01126 if ( $this->Content === null )
01127 {
01128 $dataType = $this->dataType();
01129 if ( $dataType )
01130 $this->Content =& $dataType->objectAttributeContent( $this );
01131 }
01132 return $this->Content;
01133 }
01134
01135
01136
01137
01138
01139
01140
01141
01142 function &hasContent()
01143 {
01144 $hasContent = false;
01145 $dataType = $this->dataType();
01146 if ( $dataType )
01147 {
01148 $hasContent = $dataType->hasObjectAttributeContent( $this );
01149 }
01150 return $hasContent;
01151 }
01152
01153
01154
01155
01156
01157 function metaData()
01158 {
01159 $dataType = $this->dataType();
01160 if ( $dataType )
01161 return $dataType->metaData( $this );
01162 else
01163 return false;
01164 }
01165
01166
01167
01168
01169 function toString()
01170 {
01171 $dataType = $this->dataType();
01172 if ( $dataType )
01173 return $dataType->toString( $this );
01174 else
01175 return false;
01176 }
01177
01178
01179
01180
01181 function fromString( $string )
01182 {
01183 $dataType = $this->dataType();
01184 if ( $dataType )
01185 return $dataType->fromString( $this, $string );
01186 else
01187 return false;
01188 }
01189
01190
01191
01192
01193
01194
01195
01196 function metaDataArray( &$attributes )
01197 {
01198 $metaDataArray = array();
01199 if ( !is_array( $attributes ) )
01200 return false;
01201 foreach( array_keys( $attributes ) as $key )
01202 {
01203 $attribute =& $attributes[$key];
01204 $classAttribute =& $attribute->contentClassAttribute();
01205 if ( $classAttribute->attribute( 'is_searchable' ) )
01206 {
01207 $attributeMetaData = $attribute->metaData();
01208 if ( $attributeMetaData !== false )
01209 {
01210 if ( !is_array( $attributeMetaData ) )
01211 {
01212 $attributeMetaData = array( array( 'id' => '',
01213 'text' => $attributeMetaData ) );
01214 }
01215 $metaDataArray = array_merge( $metaDataArray, $attributeMetaData );
01216 }
01217 }
01218 }
01219 return $metaDataArray;
01220 }
01221
01222
01223
01224
01225
01226 function setContent( &$content )
01227 {
01228 $this->Content =& $content;
01229 }
01230
01231
01232
01233
01234
01235 function &displayInfo()
01236 {
01237 if ( !$this->DisplayInfo )
01238 {
01239 $dataType = $this->dataType();
01240 if ( $dataType )
01241 $this->DisplayInfo = $dataType->objectDisplayInformation( $this, false );
01242 }
01243 return $this->DisplayInfo;
01244 }
01245
01246
01247
01248
01249
01250
01251 function &classDisplayInfo()
01252 {
01253 $classAttribute =& $this->contentClassAttribute();
01254 if ( !$classAttribute->DisplayInfo )
01255 {
01256 $dataType = $this->dataType();
01257 if ( $dataType )
01258 {
01259 $classAttribute->DisplayInfo =& $dataType->classDisplayInformation( $classAttribute, false );
01260 }
01261 }
01262 return $classAttribute->DisplayInfo;
01263 }
01264
01265
01266
01267
01268 function &contentActionList()
01269 {
01270 $dataType = $this->dataType();
01271 $result = false;
01272
01273 if ( $dataType )
01274 $result = $dataType->contentActionList( $this->contentClassAttribute() );
01275
01276 return $result;
01277 }
01278
01279 function setValidationError()
01280 {
01281 $numargs = func_num_args();
01282 if ( $numargs < 1 )
01283 {
01284 trigger_error( 'Function must take at least one parameter', WARNING );
01285 return;
01286 }
01287 $argList = func_get_args();
01288 $text = eZContentObjectAttribute::generateValidationErrorText( $numargs, $argList );
01289 $this->ValidationError = $text;
01290 $this->HasValidationError = true;
01291 }
01292
01293 function setHasValidationError( $hasError = true )
01294 {
01295 $this->HasValidationError = $hasError;
01296 }
01297
01298
01299
01300
01301
01302 function &hasValidationError()
01303 {
01304 return $this->HasValidationError;
01305 }
01306
01307 function generateValidationErrorText( $numargs, $argList )
01308 {
01309 $text = $argList[0];
01310 for ( $i = 1; $i < $numargs; ++$i )
01311 {
01312 $arg = $argList[$i];
01313 $text = str_replace( "%$i", $arg, $text );
01314 }
01315 return $text;
01316 }
01317
01318 function setValidationLog( $text )
01319 {
01320 if ( is_string( $text ) )
01321 {
01322 $logMessage = array();
01323 $logMessage[] = $text;
01324 $this->ValidationLog = $logMessage;
01325 }
01326 elseif ( is_array( $text ) )
01327 {
01328 $this->ValidationLog = $text;
01329 }
01330 else
01331 {
01332 $this->ValidationLog = null;
01333 }
01334 }
01335
01336
01337
01338
01339
01340 function &validationError()
01341 {
01342 return $this->ValidationError;
01343 }
01344
01345
01346
01347
01348
01349 function &validationLog()
01350 {
01351 return $this->ValidationLog;
01352 }
01353
01354
01355
01356 function serialize( &$package )
01357 {
01358 $result = false;
01359 $dataType = $this->dataType();
01360 if ( $dataType )
01361 $result = $dataType->serializeContentObjectAttribute( $package, $this );
01362
01363 return $result;
01364 }
01365
01366 function unserialize( &$package, $attributeDOMNode )
01367 {
01368 $dataType = $this->dataType();
01369 if ( $dataType )
01370 $dataType->unserializeContentObjectAttribute( $package, $this, $attributeDOMNode );
01371 }
01372
01373 function postUnserialize( &$package )
01374 {
01375 $dataType = $this->dataType();
01376 if ( $dataType )
01377 {
01378 $result = $dataType->postUnserializeContentObjectAttribute( $package, $this );
01379 if ( $result )
01380 {
01381 $this->store();
01382 }
01383 }
01384 }
01385
01386
01387
01388 function &isA()
01389 {
01390 $result = false;
01391 $dataType = $this->dataType();
01392 if ( $dataType )
01393 $result = $dataType->isA();
01394
01395 return $result;
01396 }
01397
01398
01399
01400
01401
01402
01403
01404
01405 function &viewTemplateName()
01406 {
01407
01408
01409
01410
01411
01412 $classAttribute =& $this->contentClassAttribute();
01413 if ( $classAttribute->attribute( 'is_information_collector' ) )
01414 $retValue =& $this->informationTemplate();
01415 else
01416 $retValue =& $this->viewTemplate();
01417 return $retValue;
01418 }
01419
01420
01421
01422
01423 function &editTemplateName()
01424 {
01425 $editTemplate =& $this->editTemplate();
01426 return $editTemplate;
01427 }
01428
01429
01430
01431
01432
01433
01434 function &viewTemplate()
01435 {
01436
01437
01438
01439
01440
01441 $result = false;
01442 $dataType = $this->dataType();
01443
01444 if ( $dataType )
01445 $result =& $dataType->viewTemplate( $this );
01446
01447 return $result;
01448 }
01449
01450
01451
01452
01453
01454
01455 function &editTemplate()
01456 {
01457 $result = false;
01458 $dataType = $this->dataType();
01459 if ( $dataType )
01460 $result =& $dataType->editTemplate( $this );
01461
01462 return $result;
01463
01464 }
01465
01466
01467
01468
01469
01470
01471 function &informationTemplate()
01472 {
01473
01474
01475
01476
01477 $result = false;
01478 $dataType = $this->dataType();
01479 if ( $dataType )
01480 $result =& $dataType->informationTemplate( $this );
01481
01482 return $result;
01483 }
01484
01485
01486
01487
01488
01489
01490 function &resultTemplate()
01491 {
01492
01493
01494
01495
01496 $result = false;
01497 $dataType = $this->dataType();
01498 if ( $dataType )
01499 $result = $dataType->resultTemplate( $this );
01500
01501 return $result;
01502 }
01503
01504
01505 var $HTTPValue;
01506
01507
01508 var $Content;
01509
01510
01511 var $DisplayInfo;
01512
01513
01514 var $IsValid;
01515
01516 var $ContentClassAttributeID;
01517
01518
01519 var $ValidationError;
01520
01521
01522 var $ValidationLog;
01523
01524
01525 var $ContentClassAttributeIdentifier;
01526 var $ContentClassAttributeCanTranslate;
01527 var $ContentClassAttributeName;
01528 var $ContentClassAttributeIsInformationCollector;
01529 var $ContentClassAttributeIsRequired;
01530 }
01531
01532 ?>