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/ezcontentclassclassgroup.php" );
00044 include_once( "kernel/classes/ezcontentclassnamelist.php" );
00045 include_once( "kernel/common/i18n.php" );
00046
00047 define( "EZ_CLASS_VERSION_STATUS_DEFINED", 0 );
00048 define( "EZ_CLASS_VERSION_STATUS_TEMPORARY", 1 );
00049 define( "EZ_CLASS_VERSION_STATUS_MODIFED", 2 );
00050
00051 class eZContentClass extends eZPersistentObject
00052 {
00053 function eZContentClass( $row )
00054 {
00055 if ( is_array( $row ) )
00056 {
00057 $this->eZPersistentObject( $row );
00058 $this->VersionCount = false;
00059 $this->InGroups = null;
00060 $this->AllGroups = null;
00061 if ( isset( $row["version_count"] ) )
00062 $this->VersionCount = $row["version_count"];
00063
00064 $this->NameList = new eZContentClassNameList();
00065 if ( isset( $row['serialized_name_list'] ) )
00066 $this->NameList->initFromSerializedList( $row['serialized_name_list'] );
00067 else
00068 $this->NameList->initDefault();
00069 }
00070 $this->DataMap = false;
00071 }
00072
00073 function definition()
00074 {
00075 return array( "fields" => array( "id" => array( 'name' => 'ID',
00076 'datatype' => 'integer',
00077 'default' => 0,
00078 'required' => true ),
00079 "version" => array( 'name' => 'Version',
00080 'datatype' => 'integer',
00081 'default' => 0,
00082 'required' => true ),
00083 "serialized_name_list" => array( 'name' => 'SerializedNameList',
00084 'datatype' => 'string',
00085 'default' => '',
00086 'required' => true ),
00087 "identifier" => array( 'name' => "Identifier",
00088 'datatype' => 'string',
00089 'default' => '',
00090 'required' => true ),
00091 "contentobject_name" => array( 'name' => "ContentObjectName",
00092 'datatype' => 'string',
00093 'default' => '',
00094 'required' => true ),
00095 "creator_id" => array( 'name' => "CreatorID",
00096 'datatype' => 'integer',
00097 'default' => 0,
00098 'required' => true,
00099 'foreign_class' => 'eZUser',
00100 'foreign_attribute' => 'contentobject_id',
00101 'multiplicity' => '1..*' ),
00102 "modifier_id" => array( 'name' => "ModifierID",
00103 'datatype' => 'integer',
00104 'default' => 0,
00105 'required' => true,
00106 'foreign_class' => 'eZUser',
00107 'foreign_attribute' => 'contentobject_id',
00108 'multiplicity' => '1..*' ),
00109 "created" => array( 'name' => "Created",
00110 'datatype' => 'integer',
00111 'default' => 0,
00112 'required' => true ),
00113 "remote_id" => array( 'name' => "RemoteID",
00114 'datatype' => 'string',
00115 'default' => '',
00116 'required' => true ),
00117 "modified" => array( 'name' => "Modified",
00118 'datatype' => 'integer',
00119 'default' => 0,
00120 'required' => true ),
00121 "is_container" => array( 'name' => "IsContainer",
00122 'datatype' => 'integer',
00123 'default' => 0,
00124 'required' => true ),
00125 'always_available' => array( 'name' => "AlwaysAvailable",
00126 'datatype' => 'integer',
00127 'default' => 0,
00128 'required' => true ),
00129 'language_mask' => array( 'name' => "LanguageMask",
00130 'datatype' => 'integer',
00131 'default' => 0,
00132 'required' => true ),
00133 'initial_language_id' => array( 'name' => "InitialLanguageID",
00134 'datatype' => 'integer',
00135 'default' => 0,
00136 'required' => true,
00137 'foreign_class' => 'eZContentLanguage',
00138 'foreign_attribute' => 'id',
00139 'multiplicity' => '1..*' ),
00140 'sort_field' => array( 'name' => 'SortField',
00141 'datatype' => 'integer',
00142 'default' => 1,
00143 'required' => true ),
00144 'sort_order' => array( 'name' => 'SortOrder',
00145 'datatype' => 'integer',
00146 'default' => 1,
00147 'required' => true ) ),
00148 "keys" => array( "id", "version" ),
00149 "function_attributes" => array( "data_map" => "dataMap",
00150 'object_count' => 'objectCount',
00151 'object_list' => 'objectList',
00152 'version_count' => 'versionCount',
00153 'version_status' => 'versionStatus',
00154 'remote_id' => 'remoteID',
00155 'ingroup_list' => 'fetchGroupList',
00156 'ingroup_id_list' => 'fetchGroupIDList',
00157 'match_ingroup_id_list' => 'fetchMatchGroupIDList',
00158 'group_list' => 'fetchAllGroups',
00159 'creator' => 'creator',
00160 'modifier' => 'modifier',
00161 'can_instantiate_languages' => 'canInstantiateLanguages',
00162 'name' => 'name',
00163 'nameList' => 'nameList',
00164 'languages' => 'languages',
00165 'prioritized_languages' => 'prioritizedLanguages',
00166 'prioritized_languages_js_array' => 'prioritizedLanguagesJsArray',
00167 'can_create_languages' => 'canCreateLanguages',
00168 'top_priority_language_locale' => 'topPriorityLanguageLocale',
00169 'always_available_language' => 'alwaysAvailableLanguage' ),
00170 'set_functions' => array( 'name' => 'setName' ),
00171 "increment_key" => "id",
00172 "class_name" => "eZContentClass",
00173 "sort" => array( "id" => "asc" ),
00174 "name" => "ezcontentclass" );
00175 }
00176
00177 function clone()
00178 {
00179 $row = array(
00180 "id" => null,
00181 "version" => $this->attribute( 'version' ),
00182 "serialized_name_list" => $this->attribute( 'serialized_name_list' ),
00183 "identifier" => $this->attribute( 'identifier' ),
00184 "contentobject_name" => $this->attribute( 'contentobject_name' ),
00185 "creator_id" => $this->attribute( 'creator_id' ),
00186 "modifier_id" => $this->attribute( 'modifier_id' ),
00187 "created" => $this->attribute( 'created' ),
00188 "modified" => $this->attribute( 'modified' ),
00189 "is_container" => $this->attribute( 'is_container' ),
00190 "always_available" => $this->attribute( 'always_available' ),
00191 'language_mask' => $this->attribute( 'language_mask' ),
00192 'initital_language_id' => $this->attribute( 'initial_language_id' ),
00193 "sort_field" => $this->attribute( 'sort_field' ),
00194 "sort_order" => $this->attribute( 'sort_order' ) );
00195
00196 $tmpClass = new eZContentClass( $row );
00197 return $tmpClass;
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 function create( $userID = false, $optionalValues = array(), $languageLocale = false )
00223 {
00224 $dateTime = time();
00225 if ( !$userID )
00226 $userID = eZUser::currentUserID();
00227
00228 $nameList = new eZContentClassNameList();
00229 if ( isset( $optionalValues['serialized_name_list'] ) )
00230 $nameList->initFromSerializedList( $optionalValues['serialized_name_list'] );
00231 else if ( isset( $optionalValues['name'] ) )
00232 $nameList->initFromString( $optionalValues['name'], $languageLocale );
00233 else
00234 $nameList->initFromString( '', $languageLocale );
00235
00236 $languageMask = $nameList->languageMask();
00237 $initialLanguageID = $nameList->alwaysAvailableLanguageID();
00238
00239 $contentClassDefinition = eZContentClass::definition();
00240 $row = array(
00241 "id" => null,
00242 "version" => 1,
00243 "serialized_name_list" => $nameList->serializeNames(),
00244 "identifier" => "",
00245 "contentobject_name" => "",
00246 "creator_id" => $userID,
00247 "modifier_id" => $userID,
00248 "created" => $dateTime,
00249 'remote_id' => md5( (string)mt_rand() . (string)mktime() ),
00250 "modified" => $dateTime,
00251 "is_container" => $contentClassDefinition[ 'fields' ][ 'is_container' ][ 'default' ],
00252 "always_available" => $contentClassDefinition[ 'fields' ][ 'always_available' ][ 'default' ],
00253 'language_mask' => $languageMask,
00254 'initial_language_id' => $initialLanguageID,
00255 "sort_field" => $contentClassDefinition[ 'fields' ][ 'sort_field' ][ 'default' ],
00256 "sort_order" => $contentClassDefinition[ 'fields' ][ 'sort_order' ][ 'default' ] );
00257
00258 $row = array_merge( $row, $optionalValues );
00259
00260 $contentClass = new eZContentClass( $row );
00261
00262
00263 $contentClass->NameList->setHasDirtyData( true );
00264
00265 return $contentClass;
00266 }
00267
00268 function instantiateIn( $lang, $userID = false, $sectionID = 0, $versionNumber = false, $versionStatus = EZ_VERSION_STATUS_INTERNAL_DRAFT )
00269 {
00270 return eZContentClass::instantiate( $userID, $sectionID, $versionNumber, $lang, $versionStatus );
00271 }
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 function instantiate( $userID = false, $sectionID = 0, $versionNumber = false, $languageCode = false, $versionStatus = EZ_VERSION_STATUS_INTERNAL_DRAFT )
00283 {
00284 $attributes = $this->fetchAttributes();
00285
00286 $user =& eZUser::currentUser();
00287 if ( $userID === false )
00288 {
00289 $userID =& $user->attribute( 'contentobject_id' );
00290 }
00291
00292 if ( $languageCode == false )
00293 {
00294 $languageCode = eZContentObject::defaultLanguage();
00295 }
00296
00297 $object = eZContentObject::create( ezi18n( "kernel/contentclass", "New %1", null, array( $this->name( $languageCode ) ) ),
00298 $this->attribute( "id" ),
00299 $userID,
00300 $sectionID,
00301 1,
00302 $languageCode );
00303
00304 if ( $this->attribute( 'always_available' ) )
00305 {
00306 $object->setAttribute( 'language_mask', (int)$object->attribute( 'language_mask') | 1 );
00307 }
00308
00309 $db =& eZDB::instance();
00310 $db->begin();
00311
00312 $object->store();
00313 $object->setName( ezi18n( "kernel/contentclass", "New %1", null, array( $this->name( $languageCode ) ) ), false, $languageCode );
00314
00315 if ( !$versionNumber )
00316 {
00317 $version = $object->createInitialVersion( $userID, $languageCode );
00318 }
00319 else
00320 {
00321 $version = eZContentObjectVersion::create( $object->attribute( "id" ), $userID, $versionNumber, $languageCode );
00322 }
00323 if ( $versionStatus !== false )
00324 {
00325 $version->setAttribute( 'status', $versionStatus );
00326 }
00327
00328 $version->store();
00329
00330 foreach ( array_keys( $attributes ) as $attributeKey )
00331 {
00332 $attribute =& $attributes[$attributeKey];
00333 $attribute->instantiate( $object->attribute( 'id' ), $languageCode );
00334 }
00335
00336 if ( $user->isAnonymous() )
00337 {
00338 include_once( 'kernel/classes/ezpreferences.php' );
00339 $createdObjectIDList = eZPreferences::value( 'ObjectCreationIDList' );
00340 if ( !$createdObjectIDList )
00341 {
00342 $createdObjectIDList = array( $object->attribute( 'id' ) );
00343 }
00344 else
00345 {
00346 $createdObjectIDList = unserialize( $createdObjectIDList );
00347 $createdObjectIDList[] = $object->attribute( 'id' );
00348 }
00349 eZPreferences::setValue( 'ObjectCreationIDList', serialize( $createdObjectIDList ) );
00350 }
00351
00352 $db->commit();
00353 return $object;
00354 }
00355
00356 function canInstantiateClasses()
00357 {
00358 $ini =& eZINI::instance();
00359 $enableCaching = $ini->variable( 'RoleSettings', 'EnableCaching' );
00360
00361 if ( $enableCaching == 'true' )
00362 {
00363 $http =& eZHTTPTool::instance();
00364
00365 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
00366 $handler =& eZExpiryHandler::instance();
00367 $expiredTimeStamp = 0;
00368 if ( $handler->hasTimestamp( 'user-class-cache' ) )
00369 $expiredTimeStamp = $handler->timestamp( 'user-class-cache' );
00370
00371 $classesCachedForUser = $http->sessionVariable( 'CanInstantiateClassesCachedForUser' );
00372 $classesCachedTimestamp = $http->sessionVariable( 'ClassesCachedTimestamp' );
00373 $user =& eZUser::currentUser();
00374 $userID = $user->id();
00375
00376 if ( ( $classesCachedTimestamp >= $expiredTimeStamp ) && $classesCachedForUser == $userID )
00377 {
00378 if ( $http->hasSessionVariable( 'CanInstantiateClasses' ) )
00379 {
00380 return $http->sessionVariable( 'CanInstantiateClasses' );
00381 }
00382 }
00383 else
00384 {
00385
00386 $http->setSessionVariable( 'CanInstantiateClassesCachedForUser', $userID );
00387 }
00388 }
00389 $user =& eZUser::currentUser();
00390 $accessResult = $user->hasAccessTo( 'content' , 'create' );
00391 $accessWord = $accessResult['accessWord'];
00392 $canInstantiateClasses = 1;
00393 if ( $accessWord == 'no' )
00394 {
00395 $canInstantiateClasses = 0;
00396 }
00397
00398 if ( $enableCaching == 'true' )
00399 {
00400 $http->setSessionVariable( 'CanInstantiateClasses', $canInstantiateClasses );
00401 }
00402 return $canInstantiateClasses;
00403 }
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 function &canInstantiateClassList( $asObject = false, $includeFilter = true, $groupList = false, $fetchID = false )
00425 {
00426 $ini =& eZINI::instance();
00427 $groupArray = array();
00428
00429 $enableCaching = ( $ini->variable( 'RoleSettings', 'EnableCaching' ) == 'true' );
00430 if ( is_array( $groupList ) )
00431 {
00432 if ( $fetchID == false )
00433 $enableCaching = false;
00434 }
00435
00436 if ( $enableCaching )
00437 {
00438 $http =& eZHTTPTool::instance();
00439 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
00440 $handler =& eZExpiryHandler::instance();
00441 $expiredTimeStamp = 0;
00442 if ( $handler->hasTimestamp( 'user-class-cache' ) )
00443 $expiredTimeStamp = $handler->timestamp( 'user-class-cache' );
00444
00445 $classesCachedForUser = $http->sessionVariable( 'ClassesCachedForUser' );
00446 $classesCachedTimestamp = $http->sessionVariable( 'ClassesCachedTimestamp' );
00447
00448 $cacheVar = 'CanInstantiateClassList';
00449 if ( is_array( $groupList ) and $fetchID !== false )
00450 {
00451 $cacheVar = 'CanInstantiateClassListGroup';
00452 }
00453
00454 $user =& eZUser::currentUser();
00455 $userID = $user->id();
00456 if ( ( $classesCachedTimestamp >= $expiredTimeStamp ) && $classesCachedForUser == $userID )
00457 {
00458 if ( $http->hasSessionVariable( $cacheVar ) )
00459 {
00460 if ( $fetchID !== false )
00461 {
00462
00463 $groupArray = $http->sessionVariable( $cacheVar );
00464 if ( isset( $groupArray[$fetchID] ) )
00465 {
00466 return $groupArray[$fetchID];
00467 }
00468 }
00469 else
00470 {
00471 return $http->sessionVariable( $cacheVar );
00472 }
00473 }
00474 }
00475 else
00476 {
00477 $http->setSessionVariable( 'ClassesCachedForUser' , $userID );
00478 $http->setSessionVariable( 'ClassesCachedTimestamp', mktime() );
00479 }
00480 }
00481
00482 $languageCodeList = eZContentLanguage::fetchLocaleList();
00483 $allowedLanguages = array( '*' => array() );
00484
00485 $user =& eZUser::currentUser();
00486 $accessResult = $user->hasAccessTo( 'content' , 'create' );
00487 $accessWord = $accessResult['accessWord'];
00488
00489 $classIDArray = array();
00490 $classList = array();
00491 $fetchAll = false;
00492 if ( $accessWord == 'yes' )
00493 {
00494 $fetchAll = true;
00495 $allowedLanguages['*'] = $languageCodeList;
00496 }
00497 else if ( $accessWord == 'no' )
00498 {
00499
00500 return $classList;
00501 }
00502 else
00503 {
00504 $policies = $accessResult['policies'];
00505 foreach ( $policies as $policyKey => $policy )
00506 {
00507 $classIDArrayPart = '*';
00508 if ( isset( $policy['Class'] ) )
00509 {
00510 $classIDArrayPart = $policy['Class'];
00511 }
00512 $languageCodeArrayPart = $languageCodeList;
00513 if ( isset( $policy['Language'] ) )
00514 {
00515 $languageCodeArrayPart = array_intersect( $policy['Language'], $languageCodeList );
00516 }
00517
00518 if ( $classIDArrayPart == '*' )
00519 {
00520 $fetchAll = true;
00521 $allowedLanguages['*'] = array_unique( array_merge( $allowedLanguages['*'], $languageCodeArrayPart ) );
00522 }
00523 else
00524 {
00525 foreach( $classIDArrayPart as $class )
00526 {
00527 if ( isset( $allowedLanguages[$class] ) )
00528 {
00529 $allowedLanguages[$class] = array_unique( array_merge( $allowedLanguages[$class], $languageCodeArrayPart ) );
00530 }
00531 else
00532 {
00533 $allowedLanguages[$class] = $languageCodeArrayPart;
00534 }
00535 }
00536 $classIDArray = array_merge( $classIDArray, array_diff( $classIDArrayPart, $classIDArray ) );
00537 }
00538 }
00539 }
00540
00541 $filterTableSQL = '';
00542 $filterSQL = '';
00543
00544 if ( is_array( $groupList ) )
00545 {
00546 $filterTableSQL = ', ezcontentclass_classgroup ccg';
00547 $filterSQL = ( " AND\n" .
00548 " cc.id = ccg.contentclass_id AND\n" .
00549 " ccg.group_id " );
00550 $groupText = implode( ', ', $groupList );
00551 if ( $includeFilter )
00552 $filterSQL .= "IN ( $groupText )";
00553 else
00554 $filterSQL .= "NOT IN ( $groupText )";
00555 }
00556
00557 $classNameFilter = eZContentClassName::sqlFilter( 'cc' );
00558 $filterSQL .= " AND\n cc.id=" . $classNameFilter['from'] . ".contentclass_id";
00559
00560 if ( $fetchAll )
00561 {
00562 $classList = array();
00563 $db =& eZDb::instance();
00564
00565 $fields = $asObject ? "cc.*, $classNameFilter[nameField]" : "cc.id, $classNameFilter[nameField]";
00566 $rows = $db->arrayQuery( "SELECT DISTINCT $fields\n" .
00567 "FROM ezcontentclass cc$filterTableSQL, $classNameFilter[from]\n" .
00568 "WHERE cc.version = " . EZ_CLASS_VERSION_STATUS_DEFINED . " $filterSQL\n" .
00569 "ORDER BY $classNameFilter[nameField] ASC" );
00570 $classList = eZPersistentObject::handleRows( $rows, 'ezcontentclass', $asObject );
00571 }
00572 else
00573 {
00574
00575 if ( count( $classIDArray ) == 0 )
00576 {
00577 $classList = array();
00578 return $classList;
00579 }
00580
00581 $classList = array();
00582 $db =& eZDb::instance();
00583 $classString = implode( ',', $classIDArray );
00584
00585 $fields = $asObject ? "cc.*, $classNameFilter[nameField]" : "cc.id, $classNameFilter[nameField]";
00586 $rows = $db->arrayQuery( "SELECT DISTINCT $fields\n" .
00587 "FROM ezcontentclass cc$filterTableSQL, $classNameFilter[from]\n" .
00588 "WHERE cc.id IN ( $classString ) AND\n" .
00589 " cc.version = " . EZ_CLASS_VERSION_STATUS_DEFINED . " $filterSQL\n" .
00590 "ORDER BY $classNameFilter[nameField] ASC" );
00591 $classList = eZPersistentObject::handleRows( $rows, 'ezcontentclass', $asObject );
00592 }
00593
00594 if ( $asObject )
00595 {
00596 foreach ( $classList as $key => $class )
00597 {
00598 $id = $class->attribute( 'id' );
00599 if ( isset( $allowedLanguages[$id] ) )
00600 {
00601 $languageCodes = array_unique( array_merge( $allowedLanguages['*'], $allowedLanguages[$id] ) );
00602 }
00603 else
00604 {
00605 $languageCodes = $allowedLanguages['*'];
00606 }
00607 $classList[$key]->setCanInstantiateLanguages( $languageCodes );
00608 }
00609 }
00610
00611 eZDebugSetting::writeDebug( 'kernel-content-class', $classList, "class list fetched from db" );
00612 if ( $enableCaching )
00613 {
00614 if ( $fetchID !== false )
00615 {
00616 $groupArray[$fetchID] = $classList;
00617 $http->setSessionVariable( $cacheVar, $groupArray );
00618 }
00619 else
00620 {
00621 $http->setSessionVariable( $cacheVar, $classList );
00622 }
00623 }
00624
00625 return $classList;
00626 }
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636 function &creator()
00637 {
00638 if ( isset( $this->CreatorID ) and $this->CreatorID )
00639 {
00640 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00641 $user = eZUser::fetch( $this->CreatorID );
00642 }
00643 else
00644 $user = null;
00645 return $user;
00646 }
00647
00648
00649
00650
00651
00652
00653 function &modifier()
00654 {
00655 if ( isset( $this->ModifierID ) and $this->ModifierID )
00656 {
00657 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00658 $user = eZUser::fetch( $this->ModifierID );
00659 }
00660 else
00661 $user = null;
00662 return $user;
00663 }
00664
00665
00666
00667
00668
00669
00670
00671
00672 function &fetchGroupList()
00673 {
00674 $this->InGroups = eZContentClassClassGroup::fetchGroupList( $this->attribute( "id" ),
00675 $this->attribute( "version" ),
00676 true );
00677 return $this->InGroups;
00678 }
00679
00680
00681
00682
00683
00684
00685
00686
00687 function &fetchGroupIDList()
00688 {
00689 $list = eZContentClassClassGroup::fetchGroupList( $this->attribute( "id" ),
00690 $this->attribute( "version" ),
00691 false );
00692 $this->InGroupIDs = array();
00693 foreach ( $list as $item )
00694 {
00695 $this->InGroupIDs[] = $item['group_id'];
00696 }
00697 return $this->InGroupIDs;
00698 }
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709 function &fetchMatchGroupIDList()
00710 {
00711 include_once( 'lib/ezutils/classes/ezini.php' );
00712 $contentINI =& eZINI::instance( 'content.ini' );
00713 if( $contentINI->variable( 'ContentOverrideSettings', 'EnableClassGroupOverride' ) == 'true' )
00714 {
00715 $retValue =& $this->attribute( 'ingroup_id_list' );
00716 }
00717 else
00718 {
00719 $retValue = false;
00720 }
00721 return $retValue;
00722 }
00723
00724
00725
00726
00727
00728
00729
00730 function &fetchAllClasses( $asObject = true, $includeFilter = true, $groupList = false )
00731 {
00732 $filterTableSQL = '';
00733 $filterSQL = '';
00734 if ( is_array( $groupList ) )
00735 {
00736 $filterTableSQL = ', ezcontentclass_classgroup ccg';
00737 $filterSQL = ( " AND\n" .
00738 " cc.id = ccg.contentclass_id AND\n" .
00739 " ccg.group_id " );
00740 $groupText = implode( ', ', $groupList );
00741 if ( $includeFilter )
00742 $filterSQL .= "IN ( $groupText )";
00743 else
00744 $filterSQL .= "NOT IN ( $groupText )";
00745 }
00746
00747 $classNameFilter = eZContentClassName::sqlFilter( 'cc' );
00748
00749 $classList = array();
00750 $db =& eZDb::instance();
00751
00752 $fields = $asObject ? "cc.*" : "cc.id, $classNameFilter[nameField]";
00753 $rows = $db->arrayQuery( "SELECT DISTINCT $fields\n" .
00754 "FROM ezcontentclass cc$filterTableSQL, $classNameFilter[from]\n" .
00755 "WHERE cc.version = " . EZ_CLASS_VERSION_STATUS_DEFINED . "$filterSQL AND $classNameFilter[where]\n" .
00756 "ORDER BY $classNameFilter[nameField] ASC" );
00757
00758 $classList = eZPersistentObject::handleRows( $rows, 'ezcontentclass', $asObject );
00759 return $classList;
00760 }
00761
00762
00763
00764
00765
00766
00767
00768
00769 function &fetchAllGroups()
00770 {
00771 $this->AllGroups = eZContentClassGroup::fetchList();
00772 return $this->AllGroups;
00773 }
00774
00775
00776
00777
00778 function inGroup( $groupID )
00779 {
00780 return eZContentClassClassGroup::classInGroup( $this->attribute( 'id' ),
00781 $this->attribute( 'version' ),
00782 $groupID );
00783 }
00784
00785
00786
00787
00788
00789 function removeTemporary()
00790 {
00791 $version = EZ_CLASS_VERSION_STATUS_TEMPORARY;
00792 $temporaryClasses = eZContentClass::fetchList( $version, true );
00793 $db =& eZDb::instance();
00794 $db->begin();
00795 foreach ( $temporaryClasses as $class )
00796 {
00797 $class->remove( true, $version );
00798 }
00799 eZPersistentObject::removeObject( eZContentClassAttribute::definition(),
00800 array( 'version' => $version ) );
00801
00802 $db->commit();
00803 }
00804
00805
00806
00807
00808 function &remoteID()
00809 {
00810 $remoteID = eZPersistentObject::attribute( 'remote_id', true );
00811 if ( !$remoteID &&
00812 $this->Version == EZ_CLASS_VERSION_STATUS_DEFINED )
00813 {
00814 $this->setAttribute( 'remote_id', md5( (string)mt_rand() . (string)mktime() ) );
00815 $this->sync( array( 'remote_id' ) );
00816 $remoteID = eZPersistentObject::attribute( 'remote_id', true );
00817 }
00818
00819 return $remoteID;
00820 }
00821
00822
00823
00824
00825
00826 function remove( $removeAttributes = false, $version = EZ_CLASS_VERSION_STATUS_DEFINED )
00827 {
00828
00829 if ( $this->Version != EZ_CLASS_VERSION_STATUS_TEMPORARY && !$this->isRemovable() )
00830 return false;
00831
00832 if ( is_array( $removeAttributes ) or $removeAttributes )
00833 $this->removeAttributes( $removeAttributes );
00834
00835 $this->NameList->remove( $this );
00836 eZPersistentObject::remove();
00837 }
00838
00839
00840
00841
00842
00843 function isRemovable()
00844 {
00845 $info = $this->removableInformation( false );
00846 return count( $info['list'] ) == 0;
00847 }
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861 function removableInformation( $includeAll = true )
00862 {
00863 $result = array( 'text' => ezi18n( 'kernel/contentclass', "Cannot remove class '%class_name':",
00864 null, array( '%class_name' => $this->attribute( 'name' ) ) ),
00865 'list' => array() );
00866 $reasons =& $result['list'];
00867 $db =& eZDB::instance();
00868
00869
00870 $rows = $db->arrayQuery( "SELECT ezcot.node_id
00871 FROM ezcontentobject_tree ezcot, ezcontentobject ezco
00872 WHERE ezcot.depth = 1 AND
00873 ezco.contentclass_id = $this->ID AND
00874 ezco.id=ezcot.contentobject_id" );
00875 if ( count( $rows ) > 0 )
00876 {
00877 $reasons[] = array( 'text' => ezi18n( 'kernel/contentclass', 'The class is used by a top-level node and cannot be removed.
00878 You will need to change the class of the node by using the swap functionality.' ) );
00879 if ( !$includeAll )
00880 return $result;
00881 }
00882
00883
00884 $attributes =& $this->fetchAttributes();
00885 foreach ( $attributes as $key => $attribute )
00886 {
00887 $dataType = $attribute->dataType();
00888 if ( !$dataType->isClassAttributeRemovable( $attribute ) )
00889 {
00890 $info = $dataType->classAttributeRemovableInformation( $attribute, $includeAll );
00891 $reasons[] = $info;
00892 if ( !$includeAll )
00893 return $result;
00894 }
00895 }
00896
00897 return $result;
00898 }
00899
00900
00901
00902
00903 function removeAttributes( $removeAttributes = false, $contentClassID = false, $version = false )
00904 {
00905 if ( is_array( $removeAttributes ) )
00906 {
00907 $db =& eZDB::instance();
00908 $db->begin();
00909 for ( $i = 0; $i < count( $removeAttributes ); ++$i )
00910 {
00911 $attribute =& $removeAttributes[$i];
00912 $attribute->remove();
00913 }
00914 $db->commit();
00915 }
00916 else
00917 {
00918 if ( $version === false )
00919 {
00920 if ( isset( $this ) and strtolower( get_class( $this ) ) == 'ezcontentclass' )
00921 {
00922 $version = $this->Version;
00923 }
00924 else
00925 return;
00926 }
00927 if ( $contentClassID === false )
00928 {
00929 if ( isset( $this ) and strtolower( get_class( $this ) ) == 'ezcontentclass' )
00930 {
00931 $contentClassID = $this->ID;
00932 }
00933 else
00934 return;
00935 }
00936
00937 $contentClass = eZContentClass::fetch( $contentClassID, true, $version );
00938
00939 if ( !is_object( $contentClass ) )
00940 return;
00941
00942 $classAttributes =& $contentClass->fetchAttributes( );
00943
00944 $db =& eZDB::instance();
00945 $db->begin();
00946 foreach ( $classAttributes as $classAttribute )
00947 {
00948 $dataType = $classAttribute->dataType();
00949 $dataType->deleteStoredClassAttribute( $classAttribute, $version );
00950 }
00951 eZPersistentObject::removeObject( eZContentClassAttribute::definition(),
00952 array( 'contentclass_id' => $contentClassID,
00953 'version' => $version ) );
00954 $db->commit();
00955 }
00956 }
00957
00958 function compareAttributes( $attr1, $attr2 )
00959 {
00960 return ( $attr1->attribute( "placement" ) > $attr2->attribute( "placement" ) ) ? 1 : -1;
00961 }
00962
00963 function adjustAttributePlacements( &$attributes )
00964 {
00965 if ( !is_array( $attributes ) )
00966 return;
00967 usort( $attributes, array( $this, "compareAttributes" ) );
00968 for ( $i = 0; $i < count( $attributes ); ++$i )
00969 {
00970 $attribute =& $attributes[$i];
00971 $attribute->setAttribute( "placement", $i + 1 );
00972 }
00973 }
00974
00975
00976
00977
00978 function store( $store_childs = false, $fieldFilters = null )
00979 {
00980
00981 global $eZContentClassObjectCache;
00982 unset( $eZContentClassObjectCache[$this->ID] );
00983
00984 $db =& eZDB::instance();
00985 $db->begin();
00986
00987 if ( is_array( $store_childs ) or $store_childs )
00988 {
00989 if ( is_array( $store_childs ) )
00990 $attributes =& $store_childs;
00991 else
00992 $attributes =& $this->fetchAttributes();
00993
00994 for ( $i = 0; $i < count( $attributes ); ++$i )
00995 {
00996 $attribute =& $attributes[$i];
00997 if ( is_object ( $attribute ) )
00998 $attribute->store();
00999 }
01000 }
01001
01002 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
01003 $handler =& eZExpiryHandler::instance();
01004 $handler->setTimestamp( 'user-class-cache', mktime() );
01005 $handler->store();
01006
01007 $this->setAttribute( 'serialized_name_list', $this->NameList->serializeNames() );
01008
01009 eZPersistentObject::store( $fieldFilters );
01010
01011 $this->NameList->store( $this );
01012
01013 $db->commit();
01014 }
01015
01016
01017
01018
01019 function sync( $fieldFilters = null )
01020 {
01021 if ( $this->hasDirtyData() )
01022 $this->store( false, $fieldFilters );
01023 }
01024
01025
01026
01027
01028
01029
01030
01031 function initializeCopy( &$originalClass )
01032 {
01033 $name = ezi18n( 'kernel/class', 'Copy of %class_name', null,
01034 array( '%class_name' => $originalClass->attribute( 'name' ) ) );
01035 $identifier = 'copy_of_' . $originalClass->attribute( 'identifier' );
01036 $db =& eZDB::instance();
01037 $sql = "SELECT count( ezcontentclass_name.name ) AS count FROM ezcontentclass, ezcontentclass_name WHERE ezcontentclass.id = ezcontentclass_name.contentclass_id AND ezcontentclass_name.name like '" . $db->escapeString( $name ) . "%'";
01038 $rows = $db->arrayQuery( $sql );
01039 $count = $rows[0]['count'];
01040 if ( $count > 0 )
01041 {
01042 ++$count;
01043 $name .= $count;
01044 $identifier .= $count;
01045 }
01046 $this->setName( $name );
01047 $this->setAttribute( 'identifier', $identifier );
01048 $this->setAttribute( 'created', time() );
01049 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
01050 $user =& eZUser::currentUser();
01051 $userID = $user->attribute( "contentobject_id" );
01052 $this->setAttribute( 'creator_id', $userID );
01053 }
01054
01055
01056
01057
01058
01059
01060 function storeDefined( &$attributes )
01061 {
01062 $db =& eZDB::instance();
01063 $db->begin();
01064
01065 eZContentClass::removeAttributes( false, $this->attribute( "id" ), EZ_CLASS_VERSION_STATUS_DEFINED );
01066 eZContentClass::removeAttributes( false, $this->attribute( "id" ), EZ_CLASS_VERSION_STATUS_TEMPORARY );
01067 $this->remove( false );
01068 $this->setVersion( EZ_CLASS_VERSION_STATUS_DEFINED, $attributes );
01069 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
01070 $user =& eZUser::currentUser();
01071 $user_id = $user->attribute( "contentobject_id" );
01072 $this->setAttribute( "modifier_id", $user_id );
01073 $this->setAttribute( "modified", time() );
01074 $this->adjustAttributePlacements( $attributes );
01075
01076 for ( $i = 0; $i < count( $attributes ); ++$i )
01077 {
01078 $attribute =& $attributes[$i];
01079 $attribute->storeDefined();
01080 }
01081
01082
01083 if ( count( $attributes ) > 0 )
01084 {
01085 $identifier = $attributes[0]->attribute( 'identifier' );
01086 $identifier = '<' . $identifier . '>';
01087 if ( trim( $this->attribute( 'contentobject_name' ) ) == '' )
01088 {
01089 $this->setAttribute( 'contentobject_name', $identifier );
01090 }
01091 }
01092
01093
01094 eZContentClassClassGroup::removeClassMembers( $this->ID, EZ_CLASS_VERSION_STATUS_DEFINED );
01095 $classgroups = eZContentClassClassGroup::fetchGroupList( $this->ID, EZ_CLASS_VERSION_STATUS_TEMPORARY );
01096 for ( $i = 0; $i < count( $classgroups ); $i++ )
01097 {
01098 $classgroup =& $classgroups[$i];
01099 $classgroup->setAttribute( 'contentclass_version', EZ_CLASS_VERSION_STATUS_DEFINED );
01100 $classgroup->store();
01101 }
01102 eZContentClassClassGroup::removeClassMembers( $this->ID, EZ_CLASS_VERSION_STATUS_TEMPORARY );
01103
01104 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
01105 $handler =& eZExpiryHandler::instance();
01106 $time = time();
01107 $handler->setTimestamp( 'user-class-cache', $time );
01108 $handler->setTimestamp( 'class-identifier-cache', $time );
01109 $handler->setTimestamp( 'sort-key-cache', $time );
01110 $handler->store();
01111
01112 include_once( 'kernel/classes/ezcontentcachemanager.php' );
01113 eZContentCacheManager::clearAllContentCache();
01114
01115 $this->setAttribute( 'serialized_name_list', $this->NameList->serializeNames() );
01116 eZPersistentObject::store();
01117 $this->NameList->store( $this );
01118
01119 $db->commit();
01120 }
01121
01122 function setVersion( $version, $set_childs = false )
01123 {
01124 if ( is_array( $set_childs ) or $set_childs )
01125 {
01126 if ( is_array( $set_childs ) )
01127 $attributes =& $set_childs;
01128 else
01129 $attributes =& $this->fetchAttributes();
01130 for ( $i = 0; $i < count( $attributes ); ++$i )
01131 {
01132 $attribute =& $attributes[$i];
01133 $attribute->setAttribute( "version", $version );
01134 }
01135 }
01136
01137 if ( $this->Version != $version )
01138 $this->NameList->setHasDirtyData();
01139
01140 eZPersistentObject::setAttribute( "version", $version );
01141 }
01142
01143 function exists( $id, $version = EZ_CLASS_VERSION_STATUS_DEFINED, $userID = false, $useIdentifier = false )
01144 {
01145 $conds = array( "version" => $version );
01146 if ( $useIdentifier )
01147 $conds["identifier"] = $id;
01148 else
01149 $conds["id"] = $id;
01150 if ( $userID !== false and is_numeric( $userID ) )
01151 $conds["creator_id"] = $userID;
01152 $version_sort = "desc";
01153 if ( $version == EZ_CLASS_VERSION_STATUS_DEFINED )
01154 $conds['version'] = $version;
01155 $rows = eZPersistentObject::fetchObjectList( eZContentClass::definition(),
01156 null,
01157 $conds,
01158 null,
01159 array( "offset" => 0,
01160 "length" => 1 ),
01161 false );
01162 if ( count( $rows ) > 0 )
01163 return $rows[0]['id'];
01164 return false;
01165 }
01166
01167 function fetch( $id, $asObject = true, $version = EZ_CLASS_VERSION_STATUS_DEFINED, $user_id = false ,$parent_id = null )
01168 {
01169 global $eZContentClassObjectCache;
01170
01171
01172
01173 if ( !isset( $eZContentClassObjectCache[$id] ) or $asObject === false or $version != EZ_CLASS_VERSION_STATUS_DEFINED )
01174 {
01175 $conds = array( "id" => $id,
01176 "version" => $version );
01177
01178 if ( $user_id !== false and is_numeric( $user_id ) )
01179 $conds["creator_id"] = $user_id;
01180
01181 $version_sort = "desc";
01182 if ( $version == EZ_CLASS_VERSION_STATUS_DEFINED )
01183 $version_sort = "asc";
01184 $rows = eZPersistentObject::fetchObjectList( eZContentClass::definition(),
01185 null,
01186 $conds,
01187 array( "version" => $version_sort ),
01188 array( "offset" => 0,
01189 "length" => 2 ),
01190 false );
01191
01192 if ( count( $rows ) == 0 )
01193 {
01194 $contentClass = null;
01195 return $contentClass;
01196 }
01197
01198 $row =& $rows[0];
01199 $row["version_count"] = count( $rows );
01200
01201 if ( $asObject )
01202 {
01203 $contentClass = new eZContentClass( $row );
01204 if ( $version == EZ_CLASS_VERSION_STATUS_DEFINED )
01205 $eZContentClassObjectCache[$id] =& $contentClass;
01206 }
01207 else
01208 $contentClass = $row;
01209 }
01210 else
01211 {
01212 $contentClass = $eZContentClassObjectCache[$id];
01213 }
01214
01215 return $contentClass;
01216 }
01217
01218 function fetchByRemoteID( $remoteID, $asObject = true, $version = EZ_CLASS_VERSION_STATUS_DEFINED, $user_id = false ,$parent_id = null )
01219 {
01220 $conds = array( "remote_id" => $remoteID,
01221 "version" => $version );
01222 if ( $user_id !== false and is_numeric( $user_id ) )
01223 $conds["creator_id"] = $user_id;
01224 $version_sort = "desc";
01225 if ( $version == EZ_CLASS_VERSION_STATUS_DEFINED )
01226 $version_sort = "asc";
01227 $rows = eZPersistentObject::fetchObjectList( eZContentClass::definition(),
01228 null,
01229 $conds,
01230 array( "version" => $version_sort ),
01231 array( "offset" => 0,
01232 "length" => 2 ),
01233 false );
01234 if ( count( $rows ) == 0 )
01235 {
01236 $contentClass = null;
01237 return $contentClass;
01238 }
01239
01240 $row =& $rows[0];
01241 $row["version_count"] = count( $rows );
01242
01243 if ( $asObject )
01244 $contentClass = new eZContentClass( $row );
01245 else
01246 $contentClass = $row;
01247
01248 return $contentClass;
01249
01250 }
01251
01252 function fetchByIdentifier( $identifier, $asObject = true, $version = EZ_CLASS_VERSION_STATUS_DEFINED, $user_id = false ,$parent_id = null )
01253 {
01254 $conds = array( "identifier" => $identifier,
01255 "version" => $version );
01256 if ( $user_id !== false and is_numeric( $user_id ) )
01257 $conds["creator_id"] = $user_id;
01258 $version_sort = "desc";
01259 if ( $version == EZ_CLASS_VERSION_STATUS_DEFINED )
01260 $version_sort = "asc";
01261 $rows = eZPersistentObject::fetchObjectList( eZContentClass::definition(),
01262 null,
01263 $conds,
01264 array( "version" => $version_sort ),
01265 array( "offset" => 0,
01266 "length" => 2 ),
01267 false );
01268 if ( count( $rows ) == 0 )
01269 {
01270 $contentClass = null;
01271 return $contentClass;
01272 }
01273
01274 $row =& $rows[0];
01275 $row["version_count"] = count( $rows );
01276
01277 if ( $asObject )
01278 $contentClass = new eZContentClass( $row );
01279 else
01280 $contentClass = $row;
01281
01282 return $contentClass;
01283 }
01284
01285
01286
01287
01288 function fetchList( $version = EZ_CLASS_VERSION_STATUS_DEFINED, $asObject = true, $user_id = false,
01289 $sorts = null, $fields = null, $classFilter = false, $limit = null )
01290 {
01291 $conds = array();
01292 $custom_fields = null;
01293 $custom_tables = null;
01294 $custom_conds = null;
01295
01296 if ( is_numeric( $version ) )
01297 $conds["version"] = $version;
01298 if ( $user_id !== false and is_numeric( $user_id ) )
01299 $conds["creator_id"] = $user_id;
01300 if ( $classFilter )
01301 {
01302 $classIDCount = 0;
01303 $classIdentifierCount = 0;
01304
01305 $classIDFilter = array();
01306 $classIdentifierFilter = array();
01307 foreach ( $classFilter as $classType )
01308 {
01309 if ( is_numeric( $classType ) )
01310 {
01311 $classIDFilter[] = $classType;
01312 $classIDCount++;
01313 }
01314 else
01315 {
01316 $classIdentifierFilter[] = $classType;
01317 $classIdentifierCount++;
01318 }
01319 }
01320
01321 if ( $classIDCount > 1 )
01322 $conds['id'] = array( $classIDFilter );
01323 else if ( $classIDCount == 1 )
01324 $conds['id'] = $classIDFilter[0];
01325 if ( $classIdentifierCount > 1 )
01326 $conds['identifier'] = array( $classIdentifierFilter );
01327 else if ( $classIdentifierCount == 1 )
01328 $conds['identifier'] = $classIdentifierFilter[0];
01329 }
01330
01331 if ( $sorts && isset( $sorts['name'] ) )
01332 {
01333 $nameFiler = eZContentClassName::sqlFilter( 'ezcontentclass' );
01334 $custom_tables = array( $nameFiler['from'] );
01335 $custom_conds = "AND " . $nameFiler['where'];
01336 $custom_fields = array( $nameFiler['nameField'] );
01337
01338 $sorts[$nameFiler['orderBy']] = $sorts['name'];
01339 unset( $sorts['name'] );
01340 }
01341
01342 return eZPersistentObject::fetchObjectList( eZContentClass::definition(),
01343 $fields,
01344 $conds,
01345 $sorts,
01346 $limit,
01347 $asObject,
01348 false,
01349 $custom_fields,
01350 $custom_tables,
01351 $custom_conds );
01352 }
01353
01354
01355
01356
01357 function &dataMap()
01358 {
01359 $map =& $this->DataMap[$this->Version];
01360 if ( !isset( $map ) )
01361 {
01362 $map = array();
01363 $attributes = $this->fetchAttributes( false, true, $this->Version );
01364 foreach ( array_keys( $attributes ) as $attributeKey )
01365 {
01366 $attribute =& $attributes[$attributeKey];
01367 $map[$attribute->attribute( 'identifier' )] =& $attribute;
01368 }
01369 }
01370 return $map;
01371 }
01372
01373 function &fetchAttributes( $id = false, $asObject = true, $version = EZ_CLASS_VERSION_STATUS_DEFINED )
01374 {
01375 if ( $id === false )
01376 {
01377 if ( isset( $this ) and
01378 get_class( $this ) == "ezcontentclass" )
01379 {
01380 $id = $this->ID;
01381 $version = $this->Version;
01382 }
01383 else
01384 {
01385 $attributes = null;
01386 return $attributes;
01387 }
01388 }
01389
01390 $filteredList =& eZContentClassAttribute::fetchFilteredList( array( "contentclass_id" => $id,
01391 "version" => $version ),
01392 $asObject );
01393 return $filteredList;
01394 }
01395
01396
01397
01398
01399
01400
01401
01402
01403 function &fetchAttributeByIdentifier( $identifier, $asObject = true )
01404 {
01405 $attributeArray =& eZContentClassAttribute::fetchFilteredList( array( 'contentclass_id' => $this->ID,
01406 'version' => $this->Version,
01407 'identifier' => $identifier ), $asObject );
01408 if ( count( $attributeArray ) > 0 )
01409 return $attributeArray[0];
01410 $retValue = null;
01411 return $retValue;
01412 }
01413
01414 function fetchSearchableAttributes( $id = false, $asObject = true, $version = EZ_CLASS_VERSION_STATUS_DEFINED )
01415 {
01416 if ( $id === false )
01417 {
01418 if ( isset( $this ) and
01419 get_class( $this ) == "ezcontentclass" )
01420 {
01421 $id = $this->ID;
01422 $version = $this->Version;
01423 }
01424 else
01425 return null;
01426 }
01427
01428 return eZContentClassAttribute::fetchFilteredList( array( "contentclass_id" => $id,
01429 "is_searchable" => 1,
01430 "version" => $version ), $asObject );
01431 }
01432
01433
01434
01435
01436
01437 function &versionStatus()
01438 {
01439
01440 if ( $this->VersionCount == 1 )
01441 {
01442 if ( $this->Version == EZ_CLASS_VERSION_STATUS_TEMPORARY )
01443 $status = EZ_CLASS_VERSION_STATUS_TEMPORARY;
01444 else
01445 $status = EZ_CLASS_VERSION_STATUS_DEFINED;
01446 }
01447 else
01448 $status = EZ_CLASS_VERSION_STATUS_MODIFED;
01449 return $status;
01450 }
01451
01452
01453
01454
01455
01456
01457
01458 function &versionCount()
01459 {
01460 return $this->VersionCount;
01461 }
01462
01463
01464
01465
01466
01467 function contentObjectName( &$contentObject, $version = false, $translation = false )
01468 {
01469
01470 $contentObjectName = $this->ContentObjectName;
01471 $dataMap =& $contentObject->fetchDataMap( $version, $translation );
01472
01473 eZDebugSetting::writeDebug( 'kernel-content-class', $dataMap, "data map" );
01474 preg_match_all( "/[<|\|](\(.+\))[\||>]/U",
01475 $contentObjectName,
01476 $subTagMatchArray );
01477
01478 $i = 0;
01479 $tmpTagResultArray = array();
01480 foreach ( $subTagMatchArray[1] as $subTag )
01481 {
01482 $tmpTag = 'tmptag' . $i;
01483
01484 $contentObjectName = str_replace( $subTag, $tmpTag, $contentObjectName );
01485
01486 $subTag = substr( $subTag, 1,strlen($subTag) - 2 );
01487 $tmpTagResultArray[$tmpTag] = eZContentClass::buildContentObjectName( $subTag, $dataMap );
01488 $i++;
01489 }
01490 $contentObjectName = eZContentClass::buildContentObjectName( $contentObjectName, $dataMap, $tmpTagResultArray );
01491 return $contentObjectName;
01492 }
01493
01494
01495
01496
01497
01498 function buildContentObjectName( &$contentObjectName, $dataMap, $tmpTags = false )
01499 {
01500
01501 preg_match_all( "|<[^>]+>|U",
01502 $contentObjectName,
01503 $tagMatchArray );
01504
01505 foreach ( $tagMatchArray[0] as $tag )
01506 {
01507 $tagName = str_replace( "<", "", $tag );
01508 $tagName = str_replace( ">", "", $tagName );
01509
01510 $tagParts = explode( '|', $tagName );
01511
01512 $namePart = "";
01513 foreach ( $tagParts as $name )
01514 {
01515
01516 if ( isset( $dataMap[$name] ) )
01517 {
01518 $namePart = $dataMap[$name]->title();
01519 if ( $namePart != "" )
01520 break;
01521 }
01522 elseif ( $tmpTags && isset( $tmpTags[$name] ) && $tmpTags[$name] != '' )
01523 {
01524 $namePart = $tmpTags[$name];
01525 break;
01526 }
01527
01528 }
01529
01530
01531 $contentObjectName = str_replace( $tag, $namePart, $contentObjectName );
01532 }
01533 return $contentObjectName;
01534 }
01535
01536
01537
01538
01539 function &objectCount()
01540 {
01541 $db =& eZDB::instance();
01542
01543 $countRow = $db->arrayQuery( 'SELECT count(*) AS count FROM ezcontentobject '.
01544 'WHERE contentclass_id='.$this->ID ." and status = " . EZ_CONTENT_OBJECT_STATUS_PUBLISHED );
01545
01546 return $countRow[0]['count'];
01547 }
01548
01549
01550
01551
01552 function &objectList()
01553 {
01554 $resultList = eZContentObject::fetchSameClassList( $this->ID );
01555 return $resultList;
01556 }
01557
01558
01559
01560
01561
01562 function setCanInstantiateLanguages( $languageCodes )
01563 {
01564 $this->CanInstantiateLanguages = $languageCodes;
01565 }
01566
01567 function &canInstantiateLanguages()
01568 {
01569 if ( is_array( $this->CanInstantiateLanguages ) )
01570 $languageCodes = array_intersect( eZContentLanguage::prioritizedLanguageCodes(), $this->CanInstantiateLanguages );
01571 else
01572 $languageCodes = array();
01573 return $languageCodes;
01574 }
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584 function nameFromSerializedString( $serailizedNameList )
01585 {
01586 return eZContentClassNameList::nameFromSerializedString( $serailizedNameList );
01587 }
01588
01589 function hasNameInLanguage( $languageLocale )
01590 {
01591 $hasName = $this->NameList->hasNameInLocale( $languageLocale );
01592 return $hasName;
01593 }
01594
01595
01596
01597
01598
01599
01600
01601 function &name( $languageLocale = false )
01602 {
01603 $name = $this->NameList->name( $languageLocale );
01604 return $name;
01605 }
01606
01607 function setName( $name, $languageLocale = false )
01608 {
01609 if ( !$languageLocale )
01610 $languageLocale = $this->topPriorityLanguageLocale();
01611 $this->NameList->setNameByLanguageLocale( $name, $languageLocale );
01612
01613 $languageID = eZContentLanguage::idByLocale( $languageLocale );
01614 $languageMask = $this->attribute( 'language_mask' );
01615 $this->setAttribute( 'language_mask', $languageMask | $languageID );
01616 }
01617
01618 function setAlwaysAvailableLanguageID( $languageID, $updateChilds = true )
01619 {
01620 $db =& eZDB::instance();
01621 $db->begin();
01622
01623 $languageLocale = false;
01624 if ( $languageID )
01625 {
01626 $language = eZContentLanguage::fetch( $languageID );
01627 $languageLocale = $language->attribute( 'locale' );
01628 }
01629
01630 if ( $languageID )
01631 {
01632 $this->setAttribute( 'language_mask', (int)$this->attribute( 'language_mask' ) | 1 );
01633 $this->NameList->setAlwaysAvailableLanguage( $languageLocale );
01634 }
01635 else
01636 {
01637 $this->setAttribute( 'language_mask', (int)$this->attribute( 'language_mask' ) & ~1 );
01638 $this->NameList->setAlwaysAvailableLanguage( false );
01639 }
01640 $this->store();
01641
01642 $classID = $this->attribute( 'id' );
01643 $version = $this->attribute( 'version' );
01644
01645 $attributes =& $this->fetchAttributes();
01646 foreach( array_keys( $attributes ) as $attrKey )
01647 {
01648 $attribute =& $attributes[$attrKey];
01649 $attribute->setAlwaysAvailableLanguage( $languageLocale );
01650 $attribute->store();
01651 }
01652
01653
01654 $sql = "UPDATE ezcontentclass_name SET language_id=";
01655 if ( $db->databaseName() == 'oracle' )
01656 {
01657 $sql .= "bitand( language_id, -2 )";
01658 }
01659 else
01660 {
01661 $sql .= "language_id & ~1";
01662 }
01663 $sql .= " WHERE contentclass_id = '$classID' AND contentclass_version = '$version'";
01664 $db->query( $sql );
01665
01666 if ( $languageID != false )
01667 {
01668 $newLanguageID = $languageID | 1;
01669
01670 $sql = "UPDATE ezcontentclass_name
01671 SET language_id='$newLanguageID'
01672 WHERE language_id='$languageID' AND contentclass_id = '$classID' AND contentclass_version = '$version'";
01673 $db->query( $sql );
01674 }
01675
01676 $db->commit();
01677 }
01678
01679 function clearAlwaysAvailableLanguageID()
01680 {
01681 $this->setAlwaysAvailableLanguageID( false );
01682 }
01683
01684
01685
01686
01687 function &languages()
01688 {
01689 $languages = $this->NameList->languages();
01690 return $languages;
01691 }
01692
01693
01694
01695
01696 function &prioritizedLanguages()
01697 {
01698 $languages = $this->NameList->prioritizedLanguages();
01699 return $languages;
01700 }
01701
01702 function &prioritizedLanguagesJsArray()
01703 {
01704 $languages = $this->NameList->prioritizedLanguagesJsArray();
01705 return $languages;
01706 }
01707
01708
01709
01710
01711 function &canCreateLanguages()
01712 {
01713 $languages = $this->NameList->untranslatedLanguages();
01714 return $languages;
01715 }
01716
01717
01718
01719
01720 function &topPriorityLanguageLocale()
01721 {
01722 $languageLocale = $this->NameList->topPriorityLanguageLocale();
01723 return $languageLocale;
01724 }
01725
01726
01727
01728
01729
01730
01731 function &alwaysAvailableLanguage()
01732 {
01733 $language = $this->NameList->alwaysAvailableLanguage();
01734 return $language;
01735 }
01736
01737
01738
01739
01740
01741
01742 function alwaysAvailableLanguageLocale()
01743 {
01744 $language = $this->NameList->alwaysAvailableLanguageLocale();
01745 return $language;
01746 }
01747
01748 function &nameList()
01749 {
01750 $nameList = $this->NameList->nameList();
01751 return $nameList;
01752 }
01753
01754
01755
01756
01757 function removeTranslation( $languageID )
01758 {
01759 $language = eZContentLanguage::fetch( $languageID );
01760
01761 if ( !$language )
01762 {
01763 return false;
01764 }
01765
01766
01767 $classInitialLanguageID = $this->attribute( 'initial_language_id' );
01768 if ( $classInitialLanguageID == $languageID )
01769 {
01770 return false;
01771 }
01772
01773 $db =& eZDB::instance();
01774 $db->begin();
01775
01776 $classID = $this->attribute( 'id' );
01777 $languageID = $language->attribute( 'id' );
01778
01779
01780 $languageMask = (int) $this->attribute( 'language_mask' );
01781 $languageMask = (int) $languageMask & ~ (int) $languageID;
01782 $this->setAttribute( 'language_mask', $languageMask );
01783
01784
01785 $db->query( "DELETE FROM ezcontentclass_name
01786 WHERE contentclass_id='$classID'
01787 AND language_id='$languageID'" );
01788
01789 $languageLocale = $language->attribute( 'locale' );
01790 $this->NameList->removeName( $languageLocale );
01791
01792 $this->store();
01793
01794
01795 $attributes = $this->fetchAttributes();
01796 foreach ( array_keys( $attributes ) as $attr_key )
01797 {
01798 $attribute =& $attributes[$attr_key];
01799 $attribute->removeTranslation( $languageLocale );
01800 $attribute->store();
01801 unset( $attribute );
01802 }
01803
01804 $db->commit();
01805
01806 return true;
01807 }
01808
01809
01810 var $ID;
01811
01812 var $SerializedNameList;
01813
01814 var $NameList;
01815 var $Identifier;
01816 var $ContentObjectName;
01817 var $Version;
01818 var $VersionCount;
01819 var $CreatorID;
01820 var $ModifierID;
01821 var $Created;
01822 var $Modified;
01823 var $InGroups;
01824 var $AllGroups;
01825 var $IsContainer;
01826 var $CanInstantiateLanguages;
01827 var $LanguageMask;
01828 }
01829
01830 ?>