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
00040 define( 'EZ_COLLABORATION_STATUS_ACTIVE', 1 );
00041 define( 'EZ_COLLABORATION_STATUS_INACTIVE', 2 );
00042 define( 'EZ_COLLABORATION_STATUS_ARCHIVE', 3 );
00043
00044 include_once( 'kernel/classes/ezpersistentobject.php' );
00045 include_once( 'kernel/classes/ezcollaborationitemstatus.php' );
00046
00047 class eZCollaborationItem extends eZPersistentObject
00048 {
00049
00050
00051
00052 function eZCollaborationItem( $row )
00053 {
00054 $this->eZPersistentObject( $row );
00055 }
00056
00057 function definition()
00058 {
00059 return array( 'fields' => array( 'id' => array( 'name' => 'ID',
00060 'datatype' => 'integer',
00061 'default' => 0,
00062 'required' => true ),
00063 'type_identifier' => array( 'name' => 'TypeIdentifier',
00064 'datatype' => 'string',
00065 'default' => '',
00066 'required' => true ),
00067 'creator_id' => array( 'name' => 'CreatorID',
00068 'datatype' => 'integer',
00069 'default' => 0,
00070 'required' => true,
00071 'foreign_class' => 'eZUser',
00072 'foreign_attribute' => 'contentobject_id',
00073 'multiplicity' => '1..*' ),
00074 'status' => array( 'name' => 'Status',
00075 'datatype' => 'integer',
00076 'default' => 1,
00077 'required' => true ),
00078 'data_text1' => array( 'name' => 'DataText1',
00079 'datatype' => 'text',
00080 'default' => '',
00081 'required' => true ),
00082 'data_text2' => array( 'name' => 'DataText2',
00083 'datatype' => 'text',
00084 'default' => '',
00085 'required' => true ),
00086 'data_text3' => array( 'name' => 'DataText3',
00087 'datatype' => 'text',
00088 'default' => '',
00089 'required' => true ),
00090 'data_int1' => array( 'name' => 'DataInt1',
00091 'datatype' => 'integer',
00092 'default' => 0,
00093 'required' => true ),
00094 'data_int2' => array( 'name' => 'DataInt2',
00095 'datatype' => 'integer',
00096 'default' => 0,
00097 'required' => true ),
00098 'data_int3' => array( 'name' => 'DataInt3',
00099 'datatype' => 'integer',
00100 'default' => 0,
00101 'required' => true ),
00102 'data_float1' => array( 'name' => 'DataFloat1',
00103 'datatype' => 'float',
00104 'default' => 0,
00105 'required' => true ),
00106 'data_float2' => array( 'name' => 'DataFloat2',
00107 'datatype' => 'float',
00108 'default' => 0,
00109 'required' => true ),
00110 'data_float3' => array( 'name' => 'DataFloat3',
00111 'datatype' => 'float',
00112 'default' => 0,
00113 'required' => true ),
00114 'created' => array( 'name' => 'Created',
00115 'datatype' => 'integer',
00116 'default' => 0,
00117 'required' => true ),
00118 'modified' => array( 'name' => 'Modified',
00119 'datatype' => 'integer',
00120 'default' => 0,
00121 'required' => true ) ),
00122 'keys' => array( 'id' ),
00123 'function_attributes' => array( 'creator' => 'creator',
00124 'is_creator' => 'isCreator',
00125 'participant_list' => 'participantList',
00126 'user_status' => 'userStatus',
00127 'handler' => 'handler',
00128 'use_messages' => 'useMessages',
00129 'message_count' => 'messageCount',
00130 'unread_message_count' => 'unreadMessageCount',
00131 'content' => 'content',
00132 'title' => 'title' ),
00133 'increment_key' => 'id',
00134 'class_name' => 'eZCollaborationItem',
00135 'sort' => array( 'modified' => 'asc' ),
00136 'name' => 'ezcollab_item' );
00137 }
00138
00139 function create( $typeIdentifier, $creatorID, $status = EZ_COLLABORATION_STATUS_ACTIVE )
00140 {
00141 $date_time = time();
00142 $row = array(
00143 'id' => null,
00144 'type_identifier' => $typeIdentifier,
00145 'creator_id' => $creatorID,
00146 'status' => $status,
00147 'created' => $date_time,
00148 'modified' => $date_time );
00149 return new eZCollaborationItem( $row );
00150 }
00151
00152
00153
00154
00155
00156 function createNotificationEvent( $subType = false )
00157 {
00158 $handler =& $this->attribute( 'handler' );
00159 $info = $handler->attribute( 'info' );
00160 $type = $info['type-identifier'];
00161 if ( $subType )
00162 $type .= '_' . $subType;
00163 include_once( 'kernel/classes/notification/eznotificationevent.php' );
00164 $event = eZNotificationEvent::create( 'ezcollaboration', array( 'collaboration_id' => $this->attribute( 'id' ),
00165 'collaboration_identifier' => $type ) );
00166 $event->store();
00167 return $event;
00168 }
00169
00170 function fetch( $id, $creatorID = false, $asObject = true )
00171 {
00172 $conditions = array( 'id' => $id );
00173 if ( $creatorID !== false )
00174 $conditions['creator_id'] = $creatorID;
00175 return eZPersistentObject::fetchObject( eZCollaborationItem::definition(),
00176 null,
00177 $conditions,
00178 $asObject );
00179 }
00180
00181 function &creator()
00182 {
00183 if ( isset( $this->CreatorID ) and $this->CreatorID )
00184 {
00185 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00186 $user = eZUser::fetch( $this->CreatorID );
00187 }
00188 else
00189 $user = null;
00190 return $user;
00191 }
00192
00193 function &isCreator()
00194 {
00195 if ( isset( $this->CreatorID ) and $this->CreatorID )
00196 {
00197 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00198 $isCreator = ( eZUser::currentUserID() == $this->CreatorID );
00199 }
00200 else
00201 $isCreator = false;
00202 return $isCreator;
00203 }
00204
00205 function &participantList()
00206 {
00207 include_once( 'kernel/classes/ezcollaborationitemparticipantlink.php' );
00208 $list =& eZCollaborationItemParticipantLink::fetchParticipantList( array('item_id' => $this->ID ) );
00209 return $list;
00210 }
00211
00212 function &userStatus()
00213 {
00214 include_once( 'kernel/classes/ezcollaborationitemstatus.php' );
00215 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00216 $userID = eZUser::currentUserID();
00217 return eZCollaborationItemStatus::fetch( $this->ID, $userID );
00218 }
00219
00220 function &handler()
00221 {
00222 include_once( 'kernel/classes/ezcollaborationitemhandler.php' );
00223 $handler =& eZCollaborationItemHandler::instantiate( $this->attribute( 'type_identifier' ) );
00224 return $handler;
00225 }
00226
00227
00228
00229
00230
00231 function &useMessages()
00232 {
00233 $handler =& $this->handler();
00234 if ( !$handler )
00235 $useMessages = false;
00236 else
00237 $useMessages = $handler->useMessages( $this );
00238 return $useMessages;
00239 }
00240
00241
00242
00243
00244
00245 function &messageCount()
00246 {
00247 $handler =& $this->handler();
00248 if ( !$handler )
00249 $messageCount = 0;
00250 else
00251 $messageCount = $handler->messageCount( $this );
00252 return $messageCount;
00253 }
00254
00255
00256
00257
00258
00259
00260 function &unreadMessageCount()
00261 {
00262 $handler =& $this->handler();
00263 if ( !$handler )
00264 $unreadMessageCount = 0;
00265 else
00266 $unreadMessageCount = $handler->unreadMessageCount( $this );
00267 return $unreadMessageCount;
00268 }
00269
00270 function &content()
00271 {
00272 $handler =& $this->handler();
00273 if ( !$handler )
00274 $content = null;
00275 else
00276 $content = $handler->content( $this );
00277 return $content;
00278 }
00279
00280 function &title()
00281 {
00282 $handler =& $this->handler();
00283 if ( !$handler )
00284 $title = null;
00285 else
00286 $title = $handler->title( $this );
00287 return $title;
00288 }
00289
00290
00291 function hasContentAttribute( $attribute )
00292 {
00293 $handler =& $this->handler();
00294 if ( !$handler )
00295 $hasContentAttribute = null;
00296 else
00297 $hasContentAttribute = $handler->hasContentAttribute( $this, $attribute );
00298 return $hasContentAttribute;
00299 }
00300
00301 function &contentAttribute( $attribute )
00302 {
00303 $handler =& $this->handler();
00304 if ( !$handler )
00305 $contentAttribute = null;
00306 else
00307 $contentAttribute = $handler->contentAttribute( $this, $attribute );
00308 return $contentAttribute;
00309 }
00310
00311
00312
00313
00314 function setIsActive( $active, $userID = false )
00315 {
00316 $active = intval($active);
00317 eZCollaborationItemStatus::updateFields( $this->attribute( 'id' ), $userID, array( 'is_active' => $active ) );
00318 }
00319
00320 function fetchListCount( $parameters = array() )
00321 {
00322 return eZCollaborationItem::fetchListTool( $parameters, true );
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 }
00368
00369 function setLastRead( $userID = false, $timestamp = false )
00370 {
00371 if ( $userID === false )
00372 $userID = eZUser::currentUserID();
00373 if ( $timestamp === false )
00374 $timestamp = time();
00375 $collaborationID = $this->attribute( 'id' );
00376
00377 eZCollaborationItemStatus::setLastRead( $collaborationID, $userID, $timestamp );
00378 eZCollaborationItemParticipantLink::setLastRead( $collaborationID, $userID, $timestamp );
00379 }
00380
00381 function fetchList( $parameters = array() )
00382 {
00383 return eZCollaborationItem::fetchListTool( $parameters, false );
00384 }
00385
00386 function &fetchListTool( $parameters = array(), $asCount )
00387 {
00388 $parameters = array_merge( array( 'as_object' => true,
00389 'offset' => false,
00390 'parent_group_id' => false,
00391 'limit' => false,
00392 'is_active' => null,
00393 'is_read' => null,
00394 'status' => false,
00395 'sort_by' => false ),
00396 $parameters );
00397 $asObject = $parameters['as_object'];
00398 $offset = $parameters['offset'];
00399 $limit = $parameters['limit'];
00400 $statusTypes = $parameters['status'];
00401 $isRead = $parameters['is_read'];
00402 $isActive = $parameters['is_active'];
00403 $parentGroupID = $parameters['parent_group_id'];
00404
00405 $sortText = '';
00406 if ( !$asCount )
00407 {
00408 $sortCount = 0;
00409 $sortList = $parameters['sort_by'];
00410 if ( is_array( $sortList ) and
00411 count( $sortList ) > 0 )
00412 {
00413 if ( count( $sortList ) > 1 and
00414 !is_array( $sortList[0] ) )
00415 {
00416 $sortList = array( $sortList );
00417 }
00418 }
00419 if ( $sortList !== false )
00420 {
00421 $sortingFields = '';
00422 foreach ( $sortList as $sortBy )
00423 {
00424 if ( is_array( $sortBy ) and count( $sortBy ) > 0 )
00425 {
00426 if ( $sortCount > 0 )
00427 $sortingFields .= ', ';
00428 $sortField = $sortBy[0];
00429 switch ( $sortField )
00430 {
00431 case 'created':
00432 {
00433 $sortingFields .= 'ezcollab_item_group_link.created';
00434 } break;
00435 case 'modified':
00436 {
00437 $sortingFields .= 'ezcollab_item_group_link.modified';
00438 } break;
00439 default:
00440 {
00441 eZDebug::writeWarning( 'Unknown sort field: ' . $sortField, 'eZCollaborationItem::fetchList' );
00442 continue;
00443 };
00444 }
00445 $sortOrder = true;
00446 if ( isset( $sortBy[1] ) )
00447 $sortOrder = $sortBy[1];
00448 $sortingFields .= $sortOrder ? ' ASC' : ' DESC';
00449 ++$sortCount;
00450 }
00451 }
00452 }
00453 if ( $sortCount == 0 )
00454 {
00455 $sortingFields = ' ezcollab_item_group_link.modified DESC';
00456 }
00457 $sortText = "ORDER BY $sortingFields";
00458 }
00459
00460 $parentGroupText = '';
00461 if ( $parentGroupID > 0 )
00462 {
00463 $parentGroupText = "ezcollab_item_group_link.group_id = '$parentGroupID' AND";
00464 }
00465
00466 $isReadText = '';
00467 if ( $isRead !== null )
00468 {
00469 $isReadValue = $isRead ? 1 : 0;
00470 $isReadText = "ezcollab_item_status.is_read = '$isReadValue' AND";
00471 }
00472
00473 $isActiveText = '';
00474 if ( $isActive !== null )
00475 {
00476 $isActiveValue = $isActive ? 1 : 0;
00477 $isActiveText = "ezcollab_item_status.is_active = '$isActiveValue' AND";
00478 }
00479
00480 $userID = eZUser::currentUserID();
00481
00482 $statusText = '';
00483 if ( $statusTypes === false )
00484 $statusTypes = array( EZ_COLLABORATION_STATUS_ACTIVE,
00485 EZ_COLLABORATION_STATUS_INACTIVE );
00486 $statusText = implode( ', ', $statusTypes );
00487
00488 if ( $asCount )
00489 $selectText = 'count( ezcollab_item.id ) as count';
00490 else
00491 $selectText = 'ezcollab_item.*, ezcollab_item_status.is_read, ezcollab_item_status.is_active, ezcollab_item_status.last_read';
00492
00493 $sql = "SELECT $selectText
00494 FROM
00495 ezcollab_item,
00496 ezcollab_item_status,
00497 ezcollab_item_group_link
00498 WHERE ezcollab_item.status IN ( $statusText ) AND
00499 $isReadText
00500 $isActiveText
00501 ezcollab_item.id = ezcollab_item_status.collaboration_id AND
00502 ezcollab_item.id = ezcollab_item_group_link.collaboration_id AND
00503 $parentGroupText
00504 ezcollab_item_status.user_id = '$userID' AND
00505 ezcollab_item_group_link.user_id = '$userID'
00506 $sortText";
00507
00508 $db =& eZDB::instance();
00509 if ( !$asCount )
00510 {
00511 $sqlParameters = array();
00512 if ( $offset !== false and $limit !== false )
00513 {
00514 $sqlParameters['offset'] = $offset;
00515 $sqlParameters['limit'] = $limit;
00516 }
00517 $itemListArray = $db->arrayQuery( $sql, $sqlParameters );
00518
00519 foreach( $itemListArray as $key => $value )
00520 {
00521 $itemData =& $itemListArray[$key];
00522 $statusObject = eZCollaborationItemStatus::create( $itemData['id'], $userID );
00523 $statusObject->setAttribute( 'is_read', $itemData['is_read'] );
00524 $statusObject->setAttribute( 'is_active', $itemData['is_active'] );
00525 $statusObject->setAttribute( 'last_read', $itemData['last_read'] );
00526 $statusObject->updateCache();
00527 }
00528 $returnItemList = eZPersistentObject::handleRows( $itemListArray, 'eZCollaborationItem', $asObject );
00529 eZDebugSetting::writeDebug( 'collaboration-item-list', $returnItemList );
00530 return $returnItemList;
00531 }
00532 else
00533 {
00534 $itemCount = $db->arrayQuery( $sql );
00535 return $itemCount[0]['count'];
00536 }
00537 }
00538
00539 function handleView( $viewMode )
00540 {
00541 $handler =& $this->handler();
00542 $handler->readItem( $this, $viewMode );
00543 return true;
00544 }
00545
00546
00547
00548
00549
00550
00551
00552 function cleanup()
00553 {
00554 $db =& eZDB::instance();
00555 $db->begin();
00556 $db->query( "DELETE FROM ezcollab_item" );
00557 $db->query( "DELETE FROM ezcollab_item_group_link" );
00558 $db->query( "DELETE FROM ezcollab_item_message_link" );
00559 $db->query( "DELETE FROM ezcollab_item_participant_link" );
00560 $db->query( "DELETE FROM ezcollab_item_status" );
00561 $db->query( "DELETE FROM ezcollab_notification_rule" );
00562 $db->query( "DELETE FROM ezcollab_profile" );
00563 $db->query( "DELETE FROM ezcollab_simple_message" );
00564 $db->commit();
00565 }
00566
00567
00568 var $ID;
00569 var $TypeIdentifier;
00570 var $CreatorID;
00571 var $Status;
00572 var $Created;
00573 var $Modified;
00574 var $DataText1;
00575 var $DataText2;
00576 var $DataText3;
00577 var $DataInt1;
00578 var $DataInt2;
00579 var $DataInt3;
00580 var $DataFloat1;
00581 var $DataFloat2;
00582 var $DataFloat3;
00583 }
00584
00585 ?>