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 include_once( 'kernel/classes/ezpersistentobject.php' );
00041 include_once( "lib/ezdb/classes/ezdb.php" );
00042
00043 class eZCollaborationItemMessageLink extends eZPersistentObject
00044 {
00045
00046
00047
00048 function eZCollaborationItemMessageLink( $row )
00049 {
00050 $this->eZPersistentObject( $row );
00051 }
00052
00053 function definition()
00054 {
00055 return array( 'fields' => array( 'id' => array( 'name' => 'ID',
00056 'datatype' => 'integer',
00057 'default' => 0,
00058 'required' => true ),
00059 'collaboration_id' => array( 'name' => 'CollaborationID',
00060 'datatype' => 'integer',
00061 'default' => 0,
00062 'required' => true,
00063 'foreign_class' => 'eZCollaborationItem',
00064 'foreign_attribute' => 'id',
00065 'multiplicity' => '1..*' ),
00066 'message_id' => array( 'name' => 'MessageID',
00067 'datatype' => 'integer',
00068 'default' => 0,
00069 'required' => true,
00070 'foreign_class' => 'eZCollaborationSimpleMessage',
00071 'foreign_attribute' => 'id',
00072 'multiplicity' => '1..*' ),
00073 'message_type' => array( 'name' => 'MessageType',
00074 'datatype' => 'integer',
00075 'default' => 0,
00076 'required' => true ),
00077 'participant_id' => array( 'name' => 'ParticipantID',
00078 'datatype' => 'integer',
00079 'default' => 0,
00080 'required' => true,
00081 'foreign_class' => 'eZUser',
00082 'foreign_attribute' => 'contentobject_id',
00083 'multiplicity' => '1..*' ),
00084 'created' => array( 'name' => 'Created',
00085 'datatype' => 'integer',
00086 'default' => 0,
00087 'required' => true ),
00088 'modified' => array( 'name' => 'Modified',
00089 'datatype' => 'integer',
00090 'default' => 0,
00091 'required' => true ) ),
00092 'keys' => array( 'id' ),
00093 'function_attributes' => array( 'collaboration_item' => 'collaborationItem',
00094 'participant' => 'participant',
00095 'simple_message' => 'simpleMessage' ),
00096 'increment_key' => 'id',
00097 'class_name' => 'eZCollaborationItemMessageLink',
00098 'name' => 'ezcollab_item_message_link' );
00099 }
00100
00101 function create( $collaborationID, $messageID, $messageType, $participantID )
00102 {
00103 $dateTime = time();
00104 $row = array(
00105 'collaboration_id' => $collaborationID,
00106 'message_id' => $messageID,
00107 'message_type' => $messageType,
00108 'participant_id' => $participantID,
00109 'created' => $dateTime,
00110 'modified' => $dateTime );
00111 return new eZCollaborationItemMessageLink( $row );
00112 }
00113
00114
00115
00116
00117
00118 function &addMessage( &$collaborationItem, &$message, $messageType, $participantID = false )
00119 {
00120 $messageID =& $message->attribute( 'id' );
00121 eZDebug::writeDebug( $message );
00122 eZDebug::writeDebug( $messageID );
00123 if ( !$messageID )
00124 {
00125 eZDebug::writeError( 'No message ID, cannot create link', 'eZCollaborationItemMessageLink::addMessage' );
00126 $retValue = null;
00127 return $retValue;
00128 }
00129 if ( $participantID === false )
00130 {
00131 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00132 $user =& eZUser::currentUser();
00133 $participantID =& $user->attribute( 'contentobject_id' );
00134 }
00135 $collaborationID = $collaborationItem->attribute( 'id' );
00136 $timestamp = time();
00137 $collaborationItem->setAttribute( 'modified', $timestamp );
00138
00139 $db =& eZDB::instance();
00140 $db->begin();
00141 $collaborationItem->sync();
00142 $link = eZCollaborationItemMessageLink::create( $collaborationID, $messageID, $messageType, $participantID );
00143 $link->store();
00144 $db->commit();
00145
00146 return $link;
00147 }
00148
00149 function fetch( $id, $asObject = true )
00150 {
00151 return eZPersistentObject::fetchObject( eZCollaborationItemMessageLink::definition(),
00152 null,
00153 array( "id" => $id ),
00154 null, null,
00155 $asObject );
00156 }
00157
00158 function fetchItemCount( $parameters )
00159 {
00160 $parameters = array_merge( array( 'item_id' => false,
00161 'conditions' => null ),
00162 $parameters );
00163 $itemID = $parameters['item_id'];
00164 $conditions = $parameters['conditions'];
00165 if ( $conditions === null )
00166 $conditions = array();
00167 $conditions['collaboration_id'] = $itemID;
00168
00169 $objectList = eZPersistentObject::fetchObjectList( eZCollaborationItemMessageLink::definition(),
00170 array(),
00171 $conditions,
00172 false,
00173 null,
00174 false,
00175 false,
00176 array( array( 'operation' => 'count( id )',
00177 'name' => 'count' ) ) );
00178 return $objectList[0]['count'];
00179 }
00180
00181 function fetchItemList( $parameters )
00182 {
00183 $parameters = array_merge( array( 'as_object' => true,
00184 'item_id' => false,
00185 'offset' => false,
00186 'limit' => false,
00187 'sort_by' => false ),
00188 $parameters );
00189 $itemID = $parameters['item_id'];
00190 $asObject = $parameters['as_object'];
00191 $offset = $parameters['offset'];
00192 $limit = $parameters['limit'];
00193 $limitArray = null;
00194 if ( $offset and $limit )
00195 {
00196 $limitArray = array( 'offset' => $offset,
00197 'limit' => $limit );
00198 }
00199
00200 return eZPersistentObject::fetchObjectList( eZCollaborationItemMessageLink::definition(),
00201 null,
00202 array( "collaboration_id" => $itemID ),
00203 null, $limitArray,
00204 $asObject );
00205 }
00206
00207
00208 function &collaborationItem()
00209 {
00210 if ( isset( $this->CollaborationID ) and $this->CollaborationID )
00211 {
00212 include_once( 'kernel/classes/ezcollaborationitem.php' );
00213 $item = eZCollaborationItem::fetch( $this->CollaborationID );
00214 }
00215 else
00216 $item = null;
00217 return $item;
00218 }
00219
00220 function &participant()
00221 {
00222 $participantLink =& eZCollaborationItemParticipantLink::fetch( $this->CollaborationID, $this->ParticipantID );
00223 return $participantLink;
00224 }
00225
00226 function &simpleMessage()
00227 {
00228 if ( isset( $this->MessageID ) and $this->MessageID )
00229 {
00230 include_once( 'kernel/classes/ezcollaborationsimplemessage.php' );
00231 $message = eZCollaborationSimpleMessage::fetch( $this->MessageID );
00232 }
00233 else
00234 $message = null;
00235 return $message;
00236 }
00237
00238
00239 var $CollaborationID;
00240 var $MessageID;
00241 var $ParticipantID;
00242 var $Created;
00243 var $Modified;
00244 }
00245
00246 ?>