|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZCollaborationItemMessageLink class 00004 // 00005 // Created on: <24-Jan-2003 15:11:23 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezcollaborationitemmessagelink.php 00032 */ 00033 00034 /*! 00035 \class eZCollaborationItemMessageLink ezcollaborationitemmessagelink.php 00036 \brief The class eZCollaborationItemMessageLink does 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 Constructor 00047 */ 00048 function eZCollaborationItemMessageLink( $row ) 00049 { 00050 $this->eZPersistentObject( $row ); 00051 } 00052 00053 static 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 static 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 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00116 the calls within a db transaction; thus within db->begin and db->commit. 00117 */ 00118 static function addMessage( $collaborationItem, $message, $messageType, $participantID = false ) 00119 { 00120 $messageID = $message->attribute( 'id' ); 00121 00122 if ( !$messageID ) 00123 { 00124 eZDebug::writeError( 'No message ID, cannot create link', 'eZCollaborationItemMessageLink::addMessage' ); 00125 $retValue = null; 00126 return $retValue; 00127 } 00128 if ( $participantID === false ) 00129 { 00130 //include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' ); 00131 $user = eZUser::currentUser(); 00132 $participantID = $user->attribute( 'contentobject_id' ); 00133 } 00134 $collaborationID = $collaborationItem->attribute( 'id' ); 00135 $timestamp = time(); 00136 $collaborationItem->setAttribute( 'modified', $timestamp ); 00137 00138 $db = eZDB::instance(); 00139 $db->begin(); 00140 $collaborationItem->sync(); 00141 $link = eZCollaborationItemMessageLink::create( $collaborationID, $messageID, $messageType, $participantID ); 00142 $link->store(); 00143 $db->commit(); 00144 00145 return $link; 00146 } 00147 00148 static function fetch( $id, $asObject = true ) 00149 { 00150 return eZPersistentObject::fetchObject( eZCollaborationItemMessageLink::definition(), 00151 null, 00152 array( "id" => $id ), 00153 null, null, 00154 $asObject ); 00155 } 00156 00157 static function fetchItemCount( $parameters ) 00158 { 00159 $parameters = array_merge( array( 'item_id' => false, 00160 'conditions' => null ), 00161 $parameters ); 00162 $itemID = $parameters['item_id']; 00163 $conditions = $parameters['conditions']; 00164 if ( $conditions === null ) 00165 $conditions = array(); 00166 $conditions['collaboration_id'] = $itemID; 00167 00168 $objectList = eZPersistentObject::fetchObjectList( eZCollaborationItemMessageLink::definition(), 00169 array(), 00170 $conditions, 00171 false, 00172 null, 00173 false, 00174 false, 00175 array( array( 'operation' => 'count( id )', 00176 'name' => 'count' ) ) ); 00177 return $objectList[0]['count']; 00178 } 00179 00180 static function fetchItemList( $parameters ) 00181 { 00182 $parameters = array_merge( array( 'as_object' => true, 00183 'item_id' => false, 00184 'offset' => false, 00185 'limit' => false, 00186 'sort_by' => false ), 00187 $parameters ); 00188 $itemID = $parameters['item_id']; 00189 $asObject = $parameters['as_object']; 00190 $offset = $parameters['offset']; 00191 $limit = $parameters['limit']; 00192 $limitArray = null; 00193 if ( $offset and $limit ) 00194 { 00195 $limitArray = array( 'offset' => $offset, 00196 'limit' => $limit ); 00197 } 00198 00199 return eZPersistentObject::fetchObjectList( eZCollaborationItemMessageLink::definition(), 00200 null, 00201 array( "collaboration_id" => $itemID ), 00202 null, $limitArray, 00203 $asObject ); 00204 } 00205 00206 00207 function collaborationItem() 00208 { 00209 if ( isset( $this->CollaborationID ) and $this->CollaborationID ) 00210 { 00211 //include_once( 'kernel/classes/ezcollaborationitem.php' ); 00212 return eZCollaborationItem::fetch( $this->CollaborationID ); 00213 } 00214 00215 return null; 00216 } 00217 00218 function participant() 00219 { 00220 return eZCollaborationItemParticipantLink::fetch( $this->CollaborationID, $this->ParticipantID ); 00221 } 00222 00223 function simpleMessage() 00224 { 00225 if ( isset( $this->MessageID ) and $this->MessageID ) 00226 { 00227 //include_once( 'kernel/classes/ezcollaborationsimplemessage.php' ); 00228 return eZCollaborationSimpleMessage::fetch( $this->MessageID ); 00229 } 00230 00231 return null; 00232 } 00233 00234 /// \privatesection 00235 public $CollaborationID; 00236 public $MessageID; 00237 public $ParticipantID; 00238 public $Created; 00239 public $Modified; 00240 } 00241 00242 ?>