|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Created on: <02-Dec-2002 13:15:49 bf> 00004 // 00005 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00006 // SOFTWARE NAME: eZ Publish 00007 // SOFTWARE RELEASE: 4.0.x 00008 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00009 // SOFTWARE LICENSE: GNU General Public License v2.0 00010 // NOTICE: > 00011 // This program is free software; you can redistribute it and/or 00012 // modify it under the terms of version 2.0 of the GNU General 00013 // Public License as published by the Free Software Foundation. 00014 // 00015 // This program is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of version 2.0 of the GNU General 00021 // Public License along with this program; if not, write to the Free 00022 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00023 // MA 02110-1301, USA. 00024 // 00025 // 00026 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00027 // 00028 00029 /*! 00030 \class eZInformationCollection ezinformationcollection.php 00031 \ingroup eZKernel 00032 \brief The class eZInformationCollection handles information collected by content objects 00033 00034 Content objects can contain attributes which are able to collect information. 00035 The information collected is handled by the eZInformationCollection class. 00036 00037 */ 00038 00039 //include_once( 'kernel/classes/ezinformationcollectionattribute.php' ); 00040 //include_once( 'lib/ezutils/classes/ezsys.php' ); 00041 00042 class eZInformationCollection extends eZPersistentObject 00043 { 00044 function eZInformationCollection( $row ) 00045 { 00046 $this->eZPersistentObject( $row ); 00047 } 00048 00049 /*! 00050 \return the persistent object definition for the eZInformationCollection class. 00051 */ 00052 static function definition() 00053 { 00054 return array( 'fields' => array( 'id' => array( 'name' => 'ID', 00055 'datatype' => 'integer', 00056 'default' => 0, 00057 'required' => true ), 00058 'contentobject_id' => array( 'name' => 'ContentObjectID', 00059 'datatype' => 'integer', 00060 'default' => 0, 00061 'required' => true, 00062 'foreign_class' => 'eZContentObject', 00063 'foreign_attribute' => 'id', 00064 'multiplicity' => '1..*' ), 00065 'user_identifier' => array( 'name' => 'UserIdentifier', 00066 'datatype' => 'string', 00067 'default' => '', 00068 'required' => true ), 00069 'creator_id' => array( 'name' => 'CreatorID', 00070 'datatype' => 'integer', 00071 'default' => 0, 00072 'required' => true, 00073 'foreign_class' => 'eZUser', 00074 'foreign_attribute' => 'contentobject_id', 00075 'multiplicity' => '1..*' ), 00076 'created' => array( 'name' => 'Created', 00077 'datatype' => 'integer', 00078 'default' => 0, 00079 'required' => true ), 00080 'modified' => array( 'name' => 'Modified', 00081 'datatype' => 'integer', 00082 'default' => 0, 00083 'required' => true ) ), 00084 'keys' => array( 'id' ), 00085 'function_attributes' => array( 'attributes' => 'informationCollectionAttributes', 00086 'data_map' => 'dataMap', 00087 'object' => 'object', 00088 'creator' => 'creator' ), 00089 'increment_key' => 'id', 00090 'class_name' => 'eZInformationCollection', 00091 'name' => 'ezinfocollection' ); 00092 } 00093 00094 /*! 00095 \static 00096 \return an array with attribute identifiers that are not to be shown in 00097 information collection templates. 00098 */ 00099 static function attributeHideList() 00100 { 00101 $attributes = array(); 00102 $ini = eZINI::instance( 'collect.ini' ); 00103 $attributes[] = $ini->variable( 'InfoSettings', 'TypeAttribute' ); 00104 $attributes[] = $ini->variable( 'EmailSettings', 'SendEmailAttribute' ); 00105 $attributes[] = $ini->variable( 'DisplaySettings', 'DisplayAttribute' ); 00106 $attributes[] = $ini->variable( 'DisplaySettings', 'RedirectURLAttribute' ); 00107 $attributes[] = $ini->variable( 'CollectionSettings', 'CollectAnonymousDataAttribute' ); 00108 $attributes[] = $ini->variable( 'CollectionSettings', 'CollectionUserDataAttribute' ); 00109 return $attributes; 00110 } 00111 00112 /*! 00113 \static 00114 00115 Remove infomation collection from specified contentobject_id 00116 00117 \param contentobject id 00118 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00119 the calls within a db transaction; thus within db->begin and db->commit. 00120 */ 00121 static function removeContentObject( $delID ) 00122 { 00123 if( !is_numeric( $delID ) ) 00124 { 00125 return; 00126 } 00127 00128 $db = eZDB::instance(); 00129 $db->begin(); 00130 00131 $db->query( "DELETE FROM ezinfocollection 00132 WHERE contentobject_id = '$delID'" ); 00133 $db->query( "DELETE FROM ezinfocollection_attribute 00134 WHERE contentobject_id = '$delID'" ); 00135 $db->commit(); 00136 } 00137 00138 /*! 00139 \static 00140 00141 Remove a specific collection 00142 00143 \param contentobject id 00144 */ 00145 static function removeCollection( $collectionID ) 00146 { 00147 if( !is_numeric( $collectionID ) ) 00148 { 00149 return; 00150 } 00151 00152 $db = eZDB::instance(); 00153 00154 $db->query( "DELETE FROM ezinfocollection 00155 WHERE id = '$collectionID'" ); 00156 $db->query( "DELETE FROM ezinfocollection_attribute 00157 WHERE informationcollection_id = '$collectionID'" ); 00158 } 00159 00160 /*! 00161 \static 00162 \return the name of the template to use for viewing a specific information collection. 00163 00164 The template name is determined from the content class type and object attributes. 00165 See settings/collect.ini for more information. 00166 */ 00167 static function templateForObject( $object ) 00168 { 00169 return eZInformationCollection::typeForObject( $object ); 00170 } 00171 00172 /*! 00173 \static 00174 \return the name of the template to use for viewing a specific information collection. 00175 00176 The template name is determined from the content class type and object attributes. 00177 See settings/collect.ini for more information. 00178 */ 00179 static function typeForObject( $object ) 00180 { 00181 if ( !$object ) 00182 return false; 00183 $class = $object->contentClass(); 00184 if ( !$class ) 00185 return false; 00186 00187 $ini = eZINI::instance( 'collect.ini' ); 00188 $typeList = $ini->variable( 'InfoSettings', 'TypeList' ); 00189 00190 $classID = $class->attribute( 'id' ); 00191 $classIdentifier = $class->attribute( 'identifier' ); 00192 00193 $type = false; 00194 00195 if ( isset( $typeList[$classID] ) ) 00196 $type = $typeList[$classID]; 00197 else if ( isset( $typeList[$classIdentifier] ) ) 00198 $type = $typeList[$classIdentifier]; 00199 00200 $typeAttribute = $ini->variable( 'InfoSettings', 'TypeAttribute' ); 00201 if ( $typeAttribute ) 00202 { 00203 $dataMap = $object->attribute( 'data_map' ); 00204 if ( isset( $dataMap[$typeAttribute] ) ) 00205 { 00206 $type = $dataMap[$typeAttribute]->content(); 00207 if ( is_array( $type ) or 00208 is_object( $type ) ) 00209 $type = false; 00210 } 00211 } 00212 00213 if ( !$type ) 00214 $type = $ini->variable( 'InfoSettings', 'Type' ); 00215 00216 return $type; 00217 } 00218 00219 /*! 00220 \static 00221 \return \c true if anonymous users can submit data to the information collection \a $contentObject. 00222 */ 00223 static function allowAnonymous( $contentObject ) 00224 { 00225 if ( !$contentObject ) 00226 return false; 00227 $type = eZInformationCollection::typeForObject( $contentObject ); 00228 00229 $ini = eZINI::instance( 'collect.ini' ); 00230 $collectAnonymousList = $ini->variable( 'CollectionSettings', 'CollectAnonymousDataList' ); 00231 00232 $collectAnonymous = false; 00233 00234 if ( isset( $collectAnonymousList[$type] ) ) 00235 $collectAnonymous = $collectAnonymousList[$type]; 00236 00237 $collectAnonymousAttribute = $ini->variable( 'CollectionSettings', 'CollectAnonymousDataAttribute' ); 00238 if ( $collectAnonymousAttribute ) 00239 { 00240 $dataMap = $contentObject->attribute( 'data_map' ); 00241 if ( isset( $dataMap[$collectAnonymousAttribute] ) ) 00242 { 00243 $collectAnonymous = $dataMap[$collectAnonymousAttribute]->content(); 00244 if ( is_array( $collectAnonymous ) or 00245 is_object( $collectAnonymous ) ) 00246 $collectAnonymous = false; 00247 } 00248 } 00249 00250 if ( !$collectAnonymous ) 00251 $collectAnonymous = $ini->variable( 'CollectionSettings', 'CollectAnonymousData' ); 00252 00253 if ( $collectAnonymous == 'enabled' ) 00254 $collectAnonymous = true; 00255 else 00256 $collectAnonymous = false; 00257 00258 return $collectAnonymous; 00259 } 00260 00261 /*! 00262 \static 00263 \return the type of handling that should be performed on user-data. 00264 00265 Possible return types are: 00266 - multiple 00267 - unique 00268 - overwrite 00269 */ 00270 static function userDataHandling( $contentObject ) 00271 { 00272 if ( !$contentObject ) 00273 return false; 00274 $type = eZInformationCollection::typeForObject( $contentObject ); 00275 00276 $ini = eZINI::instance( 'collect.ini' ); 00277 $userDataList = $ini->variable( 'CollectionSettings', 'CollectionUserDataList' ); 00278 00279 $userData = false; 00280 00281 if ( isset( $userDataList[$type] ) ) 00282 $userData = $userDataList[$type]; 00283 00284 $userDataAttribute = $ini->variable( 'CollectionSettings', 'CollectionUserDataAttribute' ); 00285 if ( $userDataAttribute ) 00286 { 00287 $dataMap = $contentObject->attribute( 'data_map' ); 00288 if ( isset( $dataMap[$userDataAttribute] ) ) 00289 { 00290 $userData = $dataMap[$userDataAttribute]->content(); 00291 if ( is_array( $userData ) or 00292 is_object( $userData ) ) 00293 $userData = false; 00294 } 00295 } 00296 00297 if ( !$userData ) 00298 $userData = $ini->variable( 'CollectionSettings', 'CollectionUserData' ); 00299 00300 if ( !in_array( $userData, array( 'multiple', 'unique', 'overwrite' ) ) ) 00301 $userData = 'unique'; 00302 00303 return $userData; 00304 } 00305 00306 static function sendOutEmail( $contentObject ) 00307 { 00308 if ( !$contentObject ) 00309 return false; 00310 $type = eZInformationCollection::typeForObject( $contentObject ); 00311 00312 $ini = eZINI::instance( 'collect.ini' ); 00313 $sendEmailList = $ini->variable( 'EmailSettings', 'SendEmailList' ); 00314 00315 $sendEmail = null; 00316 00317 if ( isset( $sendEmailList[$type] ) ) 00318 $sendEmail = $sendEmailList[$type] == 'enabled'; 00319 00320 $sendEmailAttribute = $ini->variable( 'EmailSettings', 'SendEmailAttribute' ); 00321 if ( $sendEmailAttribute ) 00322 { 00323 $dataMap = $contentObject->attribute( 'data_map' ); 00324 if ( isset( $dataMap[$sendEmailAttribute] ) ) 00325 { 00326 $sendEmail = $dataMap[$sendEmailAttribute]->content(); 00327 if ( is_array( $sendEmail ) or 00328 is_object( $sendEmail ) ) 00329 $sendEmail = null; 00330 } 00331 } 00332 00333 if ( $sendEmail === null ) 00334 $sendEmail = $ini->variable( 'EmailSettings', 'SendEmail' ) == 'enabled'; 00335 00336 return $sendEmail; 00337 } 00338 00339 static function displayHandling( $contentObject ) 00340 { 00341 if ( !$contentObject ) 00342 return false; 00343 $type = eZInformationCollection::typeForObject( $contentObject ); 00344 00345 $ini = eZINI::instance( 'collect.ini' ); 00346 $displayList = $ini->variable( 'DisplaySettings', 'DisplayList' ); 00347 00348 $display = false; 00349 00350 if ( isset( $displayList[$type] ) ) 00351 $display = $displayList[$type]; 00352 00353 $displayAttribute = $ini->variable( 'DisplaySettings', 'DisplayAttribute' ); 00354 if ( $displayAttribute ) 00355 { 00356 $dataMap = $contentObject->attribute( 'data_map' ); 00357 if ( isset( $dataMap[$displayAttribute] ) ) 00358 { 00359 $display = $dataMap[$displayAttribute]->content(); 00360 if ( is_array( $display ) or 00361 is_object( $display ) ) 00362 $display = false; 00363 } 00364 } 00365 00366 if ( !$display ) 00367 $display = $ini->variable( 'DisplaySettings', 'Display' ); 00368 00369 if ( !in_array( $display, array( 'result', 'redirect', 'node' ) ) ) 00370 $display = 'result'; 00371 00372 return $display; 00373 } 00374 00375 static function redirectURL( $contentObject ) 00376 { 00377 if ( !$contentObject ) 00378 return false; 00379 $type = eZInformationCollection::typeForObject( $contentObject ); 00380 00381 $ini = eZINI::instance( 'collect.ini' ); 00382 $redirectURLList = $ini->variable( 'DisplaySettings', 'RedirectURLList' ); 00383 00384 $redirectURL = false; 00385 00386 if ( isset( $redirectURLList[$type] ) ) 00387 $redirectURL = $redirectURLList[$type]; 00388 00389 $redirectURLAttribute = $ini->variable( 'DisplaySettings', 'RedirectURLAttribute' ); 00390 if ( $redirectURLAttribute ) 00391 { 00392 $dataMap = $contentObject->attribute( 'data_map' ); 00393 if ( isset( $dataMap[$redirectURLAttribute] ) ) 00394 { 00395 $redirectURL = $dataMap[$redirectURLAttribute]->content(); 00396 if ( is_array( $redirectURL ) or 00397 is_object( $redirectURL ) ) 00398 $redirectURL = false; 00399 } 00400 } 00401 00402 if ( !$redirectURL ) 00403 $redirectURL = $ini->variable( 'DisplaySettings', 'RedirectURL' ); 00404 00405 return $redirectURL; 00406 } 00407 00408 /*! 00409 \static 00410 Fetches the information collection by ID. 00411 */ 00412 static function fetch( $id, $asObject = true ) 00413 { 00414 return eZPersistentObject::fetchObject( eZInformationCollection::definition(), 00415 null, 00416 array( 'id' => $id ), 00417 $asObject ); 00418 } 00419 00420 /*! 00421 \static 00422 Fetches the information collection by user identifier. 00423 */ 00424 static function fetchByUserIdentifier( $userIdentifier, $contentObjectID = false, $asObject = true ) 00425 { 00426 $conditions = array( 'user_identifier' => $userIdentifier ); 00427 if ( $contentObjectID ) 00428 $conditions['contentobject_id'] = $contentObjectID; 00429 return eZPersistentObject::fetchObject( eZInformationCollection::definition(), 00430 null, 00431 $conditions, 00432 $asObject ); 00433 } 00434 00435 static function fetchCountForAttribute( $objectAttributeID, $value ) 00436 { 00437 $db = eZDB::instance(); 00438 // Do a count on the value of collected integer info. Useful for e.g. polls 00439 $valueSQL = ""; 00440 if ( $value !== false ) 00441 { 00442 if ( is_integer( $value ) ) 00443 { 00444 $valueSQL = " AND data_int='" . $db->escapeString( $value ) . "'"; 00445 } 00446 } 00447 $objectAttributeID =(int) $objectAttributeID; 00448 $resArray = $db->arrayQuery( "SELECT count( ezinfocollection_attribute.id ) as count FROM ezinfocollection_attribute, ezinfocollection 00449 WHERE ezinfocollection_attribute.informationcollection_id = ezinfocollection.id 00450 AND ezinfocollection_attribute.contentobject_attribute_id = '" . $objectAttributeID . "' " . $valueSQL ); 00451 00452 return $resArray[0]['count']; 00453 } 00454 00455 static function fetchCollectionCountForObject( $objectID ) 00456 { 00457 if( !is_numeric( $objectID ) ) 00458 { 00459 return false; 00460 } 00461 00462 $db = eZDB::instance(); 00463 $resultArray = $db->arrayQuery( 'SELECT COUNT( * ) as count FROM ezinfocollection WHERE contentobject_id=' . $objectID ); 00464 00465 return $resultArray[0]['count']; 00466 } 00467 00468 /*! 00469 \static 00470 \param $definition - required, definition of fields 00471 \param $sortArray - required, the input array 00472 00473 This function converts sorting on the form array ( 'field', true ) to the array( 'field' => true ) 00474 and checks if the field exists in the definition. The functions is used to make sorting the same 00475 way as done in fetch('content','list', ... ) 00476 */ 00477 static function getSortArrayFromParam( $definition, $sortArray ) 00478 { 00479 if ( count( $sortArray ) < 2 ) 00480 { 00481 return null; 00482 } 00483 00484 $sortField = $sortArray[0]; 00485 00486 // Check if we have the specified sort_field in the definition 00487 if ( isset( $definition[ 'fields' ][ $sortField ] ) ) 00488 { 00489 $sortDir = $sortArray[1] ? 'asc' : 'desc'; 00490 $sorts = array( $sortField => $sortDir ); 00491 return $sorts; 00492 } 00493 00494 eZDebug::writeWarning( 'Unknown sort field: ' . $sortField, 'eZInformationCollection ::fetchCollectionsList::getSortArrayFromParam' ); 00495 return null; 00496 } 00497 00498 /*! 00499 \static 00500 \param $creatorID - optional, default false, limits the fetched set to a creator_id 00501 \param $contentObjectID - optional, default false, limits the fetched set of collection to 00502 a specific content object 00503 \param $userIdentifier - optional, default false, limits the fetched set to a user_identifier 00504 \param $limitArray - optional, default false, limits the number of returned results 00505 on the form: array( 'limit' => $limit, 'offset' => $offset ) 00506 \param $sortArray - optional, default false, how to sort the result, 00507 on the form: array( 'field', true/false ), true = asc 00508 \param $asObject - optional, default true, specifies if results should be returned as objects. 00509 00510 Fetches a list of information collections. 00511 */ 00512 static function fetchCollectionsList( $contentObjectID = false, $creatorID = false , $userIdentifier = false, $limitArray = false, $sortArray = false, $asObject = true ) 00513 { 00514 $conditions = array(); 00515 if ( $contentObjectID ) 00516 $conditions = array( 'contentobject_id' => $contentObjectID ); 00517 if ( $creatorID ) 00518 $conditions['creator_id'] = $creatorID; 00519 if ( $userIdentifier ) 00520 $conditions['user_identifier'] = $userIdentifier; 00521 00522 $limit = null; 00523 if ( isset( $limitArray['limit'] ) ) 00524 { 00525 $limit = $limitArray; 00526 if ( ! ( $limit['offset'] ) ) 00527 { 00528 $limit['offset'] = 0; 00529 } 00530 } 00531 00532 $sorts = null; 00533 if ( $sortArray !== false ) 00534 { 00535 if ( count( $sortArray ) >= 2 ) 00536 { 00537 $sorts = array(); 00538 $def = eZInformationCollection::definition(); 00539 00540 if ( ! ( is_array( $sortArray[0] ) ) ) 00541 { 00542 $sortArray = array( 0 => $sortArray ); 00543 } 00544 00545 foreach ( $sortArray as $sortElement ) 00546 { 00547 $result = eZInformationCollection::getSortArrayFromParam( $def, $sortElement ); 00548 $sorts = array_merge($sorts, $result ); 00549 } 00550 } 00551 else 00552 { 00553 eZDebug::writeWarning( 'Too few parameters for setting sorting in fetch, ignoring', 'eZInformationCollection ::fetchCollectionsList' ); 00554 } 00555 } 00556 00557 return eZPersistentObject::fetchObjectList( eZInformationCollection::definition(), 00558 null, 00559 $conditions, 00560 $sorts, 00561 $limit, 00562 $asObject ); 00563 } 00564 00565 /*! 00566 \static 00567 00568 \param $creatorID - optional, default false, the user to fetch collections for 00569 \param $contentObjectID - optional, default false, limits the fetched set of collection to 00570 a specific content object 00571 00572 Fetch the number of items limited by the parameters 00573 */ 00574 static function fetchCollectionsCount( $contentObjectID = false, $creatorID = false, $userIdentifier = false ) 00575 { 00576 $conditions = array(); 00577 if ( is_numeric( $contentObjectID ) ) 00578 $conditions = array( 'contentobject_id' => $contentObjectID ); 00579 if ( is_numeric( $creatorID ) ) 00580 $conditions['creator_id'] = $creatorID ; 00581 if ( $userIdentifier ) 00582 $conditions['user_identifier'] = $userIdentifier; 00583 00584 $resultSet = eZPersistentObject::fetchObjectList( eZInformationCollection::definition(), 00585 array(), 00586 $conditions, 00587 false, 00588 null, 00589 false, 00590 false, 00591 array( array( 'operation' => 'count( id )', 00592 'name' => 'count' ) ) ); 00593 return $resultSet[0]['count']; 00594 } 00595 00596 static function fetchCountList( $objectAttributeID ) 00597 { 00598 $db = eZDB::instance(); 00599 // Do a count on the value of collected integer info. Useful for e.g. polls 00600 $valueSQL = ""; 00601 00602 $objectAttributeID =(int) $objectAttributeID; 00603 $resArray = $db->arrayQuery( "SELECT data_int, count( ezinfocollection_attribute.id ) as count FROM ezinfocollection_attribute, ezinfocollection 00604 WHERE ezinfocollection_attribute.informationcollection_id = ezinfocollection.id 00605 AND ezinfocollection_attribute.contentobject_attribute_id = '" . $objectAttributeID . "' " . $valueSQL . " 00606 GROUP BY data_int" ); 00607 00608 $result = array(); 00609 foreach ( $resArray as $res ) 00610 { 00611 $result[$res['data_int']] = $res['count']; 00612 } 00613 00614 return $result; 00615 } 00616 00617 function creator() 00618 { 00619 $creator = eZUser::fetch( $this->attribute( 'creator_id' ) ); 00620 return $creator; 00621 } 00622 00623 function informationCollectionAttributes( $asObject = true ) 00624 { 00625 $db = eZDB::instance(); 00626 00627 $arrayRes = $db->arrayQuery( "SELECT ica.id, ica.informationcollection_id, ica.contentclass_attribute_id, ica.contentobject_attribute_id, ica.contentobject_id, ica.data_text, ica.data_int, 00628 ica.data_float 00629 FROM ezinfocollection_attribute ica, ezcontentclass_attribute 00630 WHERE ezcontentclass_attribute.id=ica.contentclass_attribute_id 00631 AND informationcollection_id='" . $this->ID . "' 00632 AND ezcontentclass_attribute.version=0 00633 ORDER BY ezcontentclass_attribute.placement" ); 00634 00635 if ( $asObject ) 00636 { 00637 $retArray = array(); 00638 foreach ( $arrayRes as $row ) 00639 { 00640 $retArray[] = new eZInformationCollectionAttribute( $row ); 00641 } 00642 } 00643 else 00644 { 00645 $retArray = $arrayRes; 00646 } 00647 00648 return $retArray; 00649 } 00650 00651 /*! 00652 \return an array of attributes of the information collection by identifier. 00653 00654 Fetches information collection attributes and indexes by the 00655 content class attribute identifier. 00656 */ 00657 function dataMap() 00658 { 00659 // Retreive the indexed information collection attributes 00660 $informationCollectionAttributes = $this->informationCollectionAttributes(); 00661 00662 $retArray = array(); 00663 00664 // Loop through each attribute hashing the array with the 00665 // class attribute identifier associated with the information 00666 // collection attribute 00667 foreach ( $informationCollectionAttributes as $informationAttribute ) 00668 { 00669 $contentClassAttribute = $informationAttribute->attribute( 'contentclass_attribute' ); 00670 $id = $contentClassAttribute->attribute( 'identifier' ); 00671 $retArray[$id] = $informationAttribute; 00672 } 00673 00674 return $retArray; 00675 } 00676 00677 function object() 00678 { 00679 return eZContentObject::fetch( $this->ContentObjectID ); 00680 } 00681 00682 /*! 00683 Same as generateUserIdentifier but returns the user identifier for the current user. 00684 */ 00685 static function currentUserIdentifier() 00686 { 00687 $user = null; 00688 return eZInformationCollection::generateUserIdentifier( $user ); 00689 } 00690 00691 /*! 00692 Generates a user identifier for the user \a $user. 00693 If \a $user is \c null then the current user will be used. 00694 00695 The user identifier is either calculated from the unique user ID 00696 or the IP address when the user is anonymous. 00697 */ 00698 static function generateUserIdentifier( &$user ) 00699 { 00700 if ( !$user ) 00701 { 00702 $user = eZUser::currentUser(); 00703 } 00704 $userIdentifierBase = false; 00705 if ( $user->attribute( 'is_logged_in' ) ) 00706 { 00707 $userIdentifierBase = 'ezuser-' . $user->attribute( 'contentobject_id' ); 00708 $userIdentifier = md5( $userIdentifierBase ); 00709 } 00710 else 00711 { 00712 $userIdentifier = session_id(); 00713 //$userIdentifierBase = 'ezuser-anonymous-' . eZSys::serverVariable( 'REMOTE_ADDR' ); 00714 } 00715 return $userIdentifier; 00716 } 00717 00718 /*! 00719 Creates a new eZInformationCollection instance. 00720 */ 00721 static function create( $contentObjectID, $userIdentifier, $creatorID = false ) 00722 { 00723 $timestamp = time(); 00724 00725 if ( $creatorID === false ) 00726 { 00727 $user = eZUser::currentUser(); 00728 $creatorID = $user->id(); 00729 } 00730 $row = array( 'contentobject_id' => $contentObjectID, 00731 'user_identifier' => $userIdentifier, 00732 'creator_id' => $creatorID, 00733 'created' => $timestamp, 00734 'modified' => $timestamp ); 00735 return new eZInformationCollection( $row ); 00736 } 00737 00738 /*! 00739 \static 00740 Removes all collected information. 00741 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00742 the calls within a db transaction; thus within db->begin and db->commit. 00743 */ 00744 static function cleanup() 00745 { 00746 $db = eZDB::instance(); 00747 $db->begin(); 00748 eZInformationCollectionAttribute::cleanup(); 00749 $db->query( "DELETE FROM ezinfocollection" ); 00750 $db->commit(); 00751 } 00752 } 00753 00754 ?>