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( '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
00051
00052 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
00096
00097
00098
00099 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
00114
00115
00116
00117
00118
00119
00120
00121 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
00140
00141
00142
00143
00144
00145 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
00162
00163
00164
00165
00166
00167 function templateForObject( &$object )
00168 {
00169 return eZInformationCollection::typeForObject( $object );
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179 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
00221
00222
00223 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
00263
00264
00265
00266
00267
00268
00269
00270 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 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 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 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
00410
00411
00412 function fetch( $id, $asObject = true )
00413 {
00414 return eZPersistentObject::fetchObject( eZInformationCollection::definition(),
00415 null,
00416 array( 'id' => $id ),
00417 $asObject );
00418 }
00419
00420
00421
00422
00423
00424 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 function fetchCountForAttribute( $objectAttributeID, $value )
00436 {
00437 $db =& eZDB::instance();
00438
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 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
00470
00471
00472
00473
00474
00475
00476
00477 function getSortArrayFromParam( $definition, $sortArray )
00478 {
00479 if ( count( $sortArray ) < 2 )
00480 return null;
00481
00482 $sortField = $sortArray[0];
00483
00484
00485 if ( isset( $definition[ 'fields' ][ $sortField ] ) )
00486 {
00487 $sortDir = $sortArray[1] ? 'asc' : 'desc';
00488 $sorts = array( $sortField => $sortDir );
00489 return $sorts;
00490 }
00491 eZDebug::writeWarning( 'Unknown sort field: ' . $sortField, 'eZInformationCollection ::fetchCollectionsList::getSortArrayFromParam' );
00492 return null;
00493 }
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 function fetchCollectionsList( $contentObjectID = false, $creatorID = false , $userIdentifier = false, $limitArray = false, $sortArray = false, $asObject = true )
00510 {
00511 $conditions = array();
00512 if ( $contentObjectID )
00513 $conditions = array( 'contentobject_id' => $contentObjectID );
00514 if ( $creatorID )
00515 $conditions['creator_id'] = $creatorID;
00516 if ( $userIdentifier )
00517 $conditions['user_identifier'] = $userIdentifier;
00518
00519 $limit = null;
00520 if ( isset( $limitArray['limit'] ) )
00521 {
00522 $limit = $limitArray;
00523 if ( ! ( $limit['offset'] ) )
00524 $limit['offset'] = 0;
00525 }
00526
00527 $sorts = null;
00528 if ( !( $sortArray === false ) )
00529 {
00530 if ( count( $sortArray ) >= 2 )
00531 {
00532 $def = eZInformationCollection::definition();
00533
00534 if ( ! ( is_array( $sortArray[0] ) ) )
00535 {
00536 $sortArray = array( 0 => $sortArray );
00537 }
00538
00539 foreach ( $sortArray as $sortElement )
00540 {
00541 $result = eZInformationCollection::getSortArrayFromParam( $def, $sortElement );
00542 $sorts = array_merge($sorts, $result );
00543 }
00544 }
00545 else
00546 {
00547 eZDebug::writeWarning( 'Too few parameters for setting sorting in fetch, ignoring', 'eZInformationCollection ::fetchCollectionsList' );
00548 }
00549 }
00550
00551 return eZPersistentObject::fetchObjectList( eZInformationCollection::definition(),
00552 null,
00553 $conditions,
00554 $sorts,
00555 $limit,
00556 $asObject );
00557 }
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568 function fetchCollectionsCount( $contentObjectID = false, $creatorID = false, $userIdentifier = false )
00569 {
00570 $conditions = array();
00571 if ( is_numeric( $contentObjectID ) )
00572 $conditions = array( 'contentobject_id' => $contentObjectID );
00573 if ( is_numeric( $creatorID ) )
00574 $conditions['creator_id'] = $creatorID ;
00575 if ( $userIdentifier )
00576 $conditions['user_identifier'] = $userIdentifier;
00577
00578 $resultSet = eZPersistentObject::fetchObjectList( eZInformationCollection::definition(),
00579 array(),
00580 $conditions,
00581 false,
00582 null,
00583 false,
00584 false,
00585 array( array( 'operation' => 'count( id )',
00586 'name' => 'count' ) ) );
00587 return $resultSet[0]['count'];
00588 }
00589
00590 function fetchCountList( $objectAttributeID )
00591 {
00592 $db =& eZDB::instance();
00593
00594 $valueSQL = "";
00595
00596
00597
00598
00599
00600
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
00653
00654
00655
00656
00657 function &dataMap()
00658 {
00659
00660 $informationCollectionAttributes =& $this->informationCollectionAttributes();
00661
00662 $retArray = array();
00663
00664
00665
00666
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 $object =& eZContentObject::fetch( $this->ContentObjectID );
00680 return $object;
00681 }
00682
00683
00684
00685
00686 function currentUserIdentifier()
00687 {
00688 $user = null;
00689 return eZInformationCollection::generateUserIdentifier( $user );
00690 }
00691
00692
00693
00694
00695
00696
00697
00698
00699 function generateUserIdentifier( &$user )
00700 {
00701 if ( !$user )
00702 {
00703 $user =& eZUser::currentUser();
00704 }
00705 $userIdentifierBase = false;
00706 if ( $user->attribute( 'is_logged_in' ) )
00707 {
00708 $userIdentifierBase = 'ezuser-' . $user->attribute( 'contentobject_id' );
00709 $userIdentifier = md5( $userIdentifierBase );
00710 }
00711 else
00712 {
00713 $userIdentifier = session_id();
00714
00715 }
00716 return $userIdentifier;
00717 }
00718
00719
00720
00721
00722 function &create( $contentObjectID, $userIdentifier, $creatorID = false )
00723 {
00724 $timestamp = time();
00725
00726 if ( $creatorID === false )
00727 {
00728 $user = eZUser::currentUser();
00729 $creatorID = $user->id();
00730 }
00731 $row = array( 'contentobject_id' => $contentObjectID,
00732 'user_identifier' => $userIdentifier,
00733 'creator_id' => $creatorID,
00734 'created' => $timestamp,
00735 'modified' => $timestamp );
00736 $newInformationCollection = new eZInformationCollection( $row );
00737 return $newInformationCollection;
00738 }
00739
00740
00741
00742
00743
00744
00745
00746 function cleanup()
00747 {
00748 $db =& eZDB::instance();
00749 $db->begin();
00750 eZInformationCollectionAttribute::cleanup();
00751 $db->query( "DELETE FROM ezinfocollection" );
00752 $db->commit();
00753 }
00754 }
00755
00756 ?>