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_PARTICIPANT_TYPE_USER", 1 );
00041 define( "EZ_COLLABORATION_PARTICIPANT_TYPE_USERGROUP", 2 );
00042
00043
00044 define( "EZ_COLLABORATION_PARTICIPANT_TYPE_CUSTOM", 1024 );
00045
00046 define( "EZ_COLLABORATION_PARTICIPANT_ROLE_STANDARD", 1 );
00047 define( "EZ_COLLABORATION_PARTICIPANT_ROLE_OBSERVER", 2 );
00048 define( "EZ_COLLABORATION_PARTICIPANT_ROLE_OWNER", 3 );
00049 define( "EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER", 4 );
00050 define( "EZ_COLLABORATION_PARTICIPANT_ROLE_AUTHOR", 5 );
00051
00052
00053 define( "EZ_COLLABORATION_PARTICIPANT_ROLE_CUSTOM", 1024 );
00054
00055 include_once( 'kernel/classes/ezpersistentobject.php' );
00056
00057 class eZCollaborationItemParticipantLink extends eZPersistentObject
00058 {
00059
00060
00061
00062 function eZCollaborationItemParticipantLink( $row )
00063 {
00064 $this->eZPersistentObject( $row );
00065 }
00066
00067 function definition()
00068 {
00069 return array( 'fields' => array( 'collaboration_id' => array( 'name' => 'CollaborationID',
00070 'datatype' => 'integer',
00071 'default' => 0,
00072 'required' => true,
00073 'foreign_class' => 'eZCollaborationItem',
00074 'foreign_attribute' => 'id',
00075 'multiplicity' => '1..*' ),
00076 'participant_id' => array( 'name' => 'ParticipantID',
00077 'datatype' => 'integer',
00078 'default' => 0,
00079 'required' => true,
00080 'foreign_class' => 'eZContentObject',
00081 'foreign_attribute' => 'id',
00082 'multiplicity' => '1..*' ),
00083 'participant_type' => array( 'name' => 'ParticipantType',
00084 'datatype' => 'integer',
00085 'default' => 1,
00086 'required' => true ),
00087 'participant_role' => array( 'name' => 'ParticipantRole',
00088 'datatype' => 'integer',
00089 'default' => 1,
00090 'required' => true ),
00091 'last_read' => array( 'name' => 'LastRead',
00092 'datatype' => 'integer',
00093 'default' => 0,
00094 'required' => true ),
00095 'created' => array( 'name' => 'Created',
00096 'datatype' => 'integer',
00097 'default' => 0,
00098 'required' => true ),
00099 'modified' => array( 'name' => 'Modified',
00100 'datatype' => 'integer',
00101 'default' => 0,
00102 'required' => true ) ),
00103 'keys' => array( 'collaboration_id', 'participant_id' ),
00104 'function_attributes' => array( 'collaboration_item' => 'collaborationItem',
00105 'participant' => 'participant',
00106 'participant_type_string' => 'participantTypeString',
00107 'participant_role_string' => 'participantRoleString',
00108 'is_builtin_type' => 'isBuiltinType',
00109 'is_builtin_role' => 'isBuiltinRole' ),
00110 'class_name' => 'eZCollaborationItemParticipantLink',
00111 'name' => 'ezcollab_item_participant_link' );
00112 }
00113
00114 function &create( $collaborationID, $participantID,
00115 $participantRole = EZ_COLLABORATION_PARTICIPANT_ROLE_STANDARD, $participantType = EZ_COLLABORATION_PARTICIPANT_TYPE_USER )
00116 {
00117 $dateTime = time();
00118 $row = array( 'collaboration_id' => $collaborationID,
00119 'participant_id' => $participantID,
00120 'participant_role' => $participantRole,
00121 'participant_type' => $participantType,
00122 'created' => $dateTime,
00123 'modified' => $dateTime );
00124 $newCollaborationItemParticipantLink = new eZCollaborationItemParticipantLink( $row );
00125 return $newCollaborationItemParticipantLink;
00126 }
00127
00128
00129
00130
00131 function setLastRead( $collaborationID, $userID = false, $timestamp = false )
00132 {
00133 if ( $userID === false )
00134 {
00135 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00136 $userID = eZUser::currentUserID();
00137 }
00138 if ( $timestamp === false )
00139 {
00140 $timestamp = time();
00141 }
00142 include_once( 'lib/ezdb/classes/ezdb.php' );
00143 $db =& eZDB::instance();
00144 $userID = (int) $userID;
00145 $timestamp = (int) $timestamp;
00146 $sql = "UPDATE ezcollab_item_participant_link set last_read='$timestamp'
00147 WHERE collaboration_id='$collaborationID' AND participant_id='$userID'";
00148 $db->query( $sql );
00149 $collabLink =& $GLOBALS["eZCollaborationItemParticipantLinkCache"][$collaborationID][$userID];
00150 if ( isset( $collabLink ) )
00151 $collabLink->setAttribute( 'last_read', $timestamp );
00152 }
00153
00154 function &fetch( $collaborationID, $participantID, $asObject = true )
00155 {
00156 $collabLink =& $GLOBALS["eZCollaborationItemParticipantLinkCache"][$collaborationID][$participantID];
00157 if ( isset( $collabLink ) )
00158 return $collabLink;
00159 $collabLink = eZPersistentObject::fetchObject( eZCollaborationItemParticipantLink::definition(),
00160 null,
00161 array( "collaboration_id" => $collaborationID,
00162 'participant_id' => $participantID ),
00163 $asObject );
00164 return $collabLink;
00165 }
00166
00167 function &fetchParticipantList( $parameters = array() )
00168 {
00169 $parameters = array_merge( array( 'as_object' => true,
00170 'item_id' => false,
00171 'offset' => false,
00172 'limit' => false,
00173 'sort_by' => false ),
00174 $parameters );
00175 $itemID = $parameters['item_id'];
00176 $asObject = $parameters['as_object'];
00177 $offset = $parameters['offset'];
00178 $limit = $parameters['limit'];
00179 $linkList = null;
00180 if ( !$offset and !$limit )
00181 {
00182 $linkList =& $GLOBALS['eZCollaborationItemParticipantLinkListCache'];
00183 if ( isset( $linkList ) )
00184 return $linkList;
00185 }
00186 $limitArray = null;
00187 if ( $offset and $limit )
00188 $limitArray = array( 'offset' => $offset, 'length' => $limit );
00189 $linkList = eZPersistentObject::fetchObjectList( eZCollaborationItemParticipantLink::definition(),
00190 null,
00191 array( "collaboration_id" => $itemID ),
00192 null, $limitArray,
00193 $asObject );
00194 for ( $i = 0; $i < count( $linkList ); ++$i )
00195 {
00196 $linkItem =& $linkList[$i];
00197 if ( $asObject )
00198 $participantID =& $linkItem->attribute( 'participant_id' );
00199 else
00200 $participantID =& $linkItem['participant_id'];
00201 if ( !isset( $GLOBALS["eZCollaborationItemParticipantLinkCache"][$itemID][$participantID] ) )
00202 $GLOBALS["eZCollaborationItemParticipantLinkCache"][$itemID][$participantID] =& $linkList[$i];
00203 }
00204 return $linkList;
00205 }
00206
00207 function &fetchParticipantMap( $originalParameters = array() )
00208 {
00209 $parameters = array_merge( array( 'sort_field' => 'role' ),
00210 $originalParameters );
00211 $itemID = $parameters['item_id'];
00212 $sortField = $parameters['sort_field'];
00213 $list =& eZCollaborationItemParticipantLink::fetchParticipantList( $originalParameters );
00214 if ( $list === null )
00215 {
00216 $listMap = null;
00217 return $listMap;
00218 }
00219
00220 $listKeys = array_keys( $list );
00221 $listMap = array();
00222 foreach ( $listKeys as $listKey )
00223 {
00224 $listItem =& $list[$listKey];
00225 $sortKey = null;
00226 if ( $sortField == 'role' )
00227 {
00228 $sortKey = $listItem->attribute( 'participant_role' );
00229 }
00230 if ( $sortKey !== null )
00231 {
00232 if ( !isset( $listMap[$sortKey] ) )
00233 {
00234 if ( $sortField == 'role' )
00235 {
00236 $sortName = eZCollaborationItemParticipantLink::roleName( $itemID, $sortKey );
00237 }
00238 $listMap[$sortKey] = array( 'name' => $sortName,
00239 'items' => array() );
00240 }
00241 $listMap[$sortKey]['items'][] =& $listItem;
00242 }
00243 }
00244 return $listMap;
00245 }
00246
00247 function &typeString( $participantType )
00248 {
00249 $typeMap =& $GLOBALS['eZCollaborationParticipantTypeMap'];
00250 if ( !isset( $typeMap ) )
00251 {
00252 $typeMap = array( EZ_COLLABORATION_PARTICIPANT_TYPE_USER => 'user',
00253 EZ_COLLABORATION_PARTICIPANT_TYPE_USERGROUP => 'usergroup' );
00254 }
00255 if ( isset( $typeMap[$participantType] ) )
00256 $retString = $typeMap[$participantType];
00257 else
00258 $retString = null;
00259 return $retString;
00260 }
00261
00262 function &roleString( $participantRole )
00263 {
00264 $roleMap =& $GLOBALS['eZCollaborationParticipantRoleMap'];
00265 if ( !isset( $roleMap ) )
00266 {
00267 $roleMap = array( EZ_COLLABORATION_PARTICIPANT_ROLE_STANDARD => 'standard',
00268 EZ_COLLABORATION_PARTICIPANT_ROLE_OBSERVER => 'observer',
00269 EZ_COLLABORATION_PARTICIPANT_ROLE_OWNER => 'owner',
00270 EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER => 'approver',
00271 EZ_COLLABORATION_PARTICIPANT_ROLE_AUTHOR => 'author' );
00272 }
00273 if ( isset( $roleMap[$participantRole] ) )
00274 $retString = $roleMap[$participantRole];
00275 else
00276 $retString = null;
00277 return $retString;
00278 }
00279
00280 function &roleName( $collaborationID, $roleID )
00281 {
00282 if ( $roleID < EZ_COLLABORATION_PARTICIPANT_TYPE_CUSTOM )
00283 {
00284 $roleNameMap =& $GLOBALS['eZCollaborationParticipantRoleNameMap'];
00285 if ( !isset( $roleNameMap ) )
00286 {
00287 include_once( 'kernel/common/i18n.php' );
00288 $roleNameMap = array( EZ_COLLABORATION_PARTICIPANT_ROLE_STANDARD => ezi18n( 'kernel/classes', 'Standard' ),
00289 EZ_COLLABORATION_PARTICIPANT_ROLE_OBSERVER => ezi18n( 'kernel/classes', 'Observer' ),
00290 EZ_COLLABORATION_PARTICIPANT_ROLE_OWNER => ezi18n( 'kernel/classes', 'Owner' ),
00291 EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER => ezi18n( 'kernel/classes', 'Approver' ),
00292 EZ_COLLABORATION_PARTICIPANT_ROLE_AUTHOR => ezi18n( 'kernel/classes', 'Author' ) );
00293 }
00294 if ( isset( $roleNameMap[$roleID] ) )
00295 $retRoleName = $roleNameMap[$roleID];
00296 else
00297 $retRoleName = null;
00298 }
00299 else
00300 {
00301 $item = eZCollaborationItem::fetch( $collaborationID );
00302 $itemHandler =& $item->handler();
00303 $retRoleName = $itemHandler->roleName( $collaborationID, $roleID );
00304 }
00305 return $retRoleName;
00306 }
00307
00308 function &collaborationItem()
00309 {
00310 include_once( 'kernel/classes/ezcollaborationitem.php' );
00311 $item = eZCollaborationItem::fetch( $this->CollaborationID );
00312 return $item;
00313 }
00314
00315 function &participant()
00316 {
00317 if ( $this->ParticipantType == EZ_COLLABORATION_PARTICIPANT_TYPE_USER )
00318 {
00319 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00320 $participant = eZUser::fetch( $this->ParticipantID );
00321 }
00322 else if ( $this->ParticipantType == EZ_COLLABORATION_PARTICIPANT_TYPE_USERGROUP )
00323 {
00324 include_once( 'kernel/classes/ezcontentobject.php' );
00325 $participant =& eZContentObject::fetch( $this->ParticipantID );
00326 }
00327 else
00328 {
00329 $participant = null;
00330 }
00331 return $participant;
00332 }
00333
00334 function &participantTypeString()
00335 {
00336 if ( $this->ParticipantType < EZ_COLLABORATION_PARTICIPANT_TYPE_CUSTOM )
00337 {
00338 $typeString =& eZCollaborationItemParticipantLink::typeString( $this->ParticipantType );
00339 }
00340 else
00341 {
00342 $item = eZCollaborationItem::fetch( $this->CollaborationID );
00343 $itemHandler =& $item->handler();
00344 $typeString = $item->attribute( 'type_identifier' ) . '_' . $itemHandler->participantTypeString( $this->ParticipantType );
00345 }
00346 return $typeString;
00347 }
00348
00349 function &participantRoleString()
00350 {
00351 if ( $this->ParticipantRole < EZ_COLLABORATION_PARTICIPANT_ROLE_CUSTOM )
00352 {
00353 $roleString =& eZCollaborationItemParticipantLink::roleString( $this->ParticipantRole );
00354 }
00355 else
00356 {
00357 $item = eZCollaborationItem::fetch( $this->CollaborationID );
00358 $itemHandler =& $item->handler();
00359 $roleString = $item->attribute( 'type_identifier' ) . '_' . $itemHandler->participantRoleString( $this->ParticipantRole );
00360 }
00361 return $roleString;
00362 }
00363
00364 function &isBuiltinType()
00365 {
00366 $isBuiltinType = $this->ParticipantType < EZ_COLLABORATION_PARTICIPANT_TYPE_CUSTOM;
00367 return $isBuiltinType;
00368 }
00369
00370 function &isBuiltinRole()
00371 {
00372 $isBuiltinRole = $this->ParticipantRole < EZ_COLLABORATION_PARTICIPANT_ROLE_CUSTOM;
00373 return $isBuiltinRole;
00374 }
00375
00376
00377 var $CollaborationID;
00378 var $ParticipantID;
00379 var $ParticipantType;
00380 var $IsRead;
00381 var $IsActive;
00382 var $Created;
00383 var $Modified;
00384 }
00385
00386 ?>