/
ezcollaborationitemmessagelink.php
213 lines (191 loc) · 9.41 KB
/
ezcollaborationitemmessagelink.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
/**
* File containing the eZCollaborationItemMessageLink class.
*
* @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
* @version //autogentag//
* @package kernel
*/
/*!
\class eZCollaborationItemMessageLink ezcollaborationitemmessagelink.php
\brief The class eZCollaborationItemMessageLink does
*/
class eZCollaborationItemMessageLink extends eZPersistentObject
{
/*!
Constructor
*/
function eZCollaborationItemMessageLink( $row )
{
$this->eZPersistentObject( $row );
}
static function definition()
{
return array( 'fields' => array( 'id' => array( 'name' => 'ID',
'datatype' => 'integer',
'default' => 0,
'required' => true ),
'collaboration_id' => array( 'name' => 'CollaborationID',
'datatype' => 'integer',
'default' => 0,
'required' => true,
'foreign_class' => 'eZCollaborationItem',
'foreign_attribute' => 'id',
'multiplicity' => '1..*' ),
'message_id' => array( 'name' => 'MessageID',
'datatype' => 'integer',
'default' => 0,
'required' => true,
'foreign_class' => 'eZCollaborationSimpleMessage',
'foreign_attribute' => 'id',
'multiplicity' => '1..*' ),
'message_type' => array( 'name' => 'MessageType',
'datatype' => 'integer',
'default' => 0,
'required' => true ),
'participant_id' => array( 'name' => 'ParticipantID',
'datatype' => 'integer',
'default' => 0,
'required' => true,
'foreign_class' => 'eZUser',
'foreign_attribute' => 'contentobject_id',
'multiplicity' => '1..*' ),
'created' => array( 'name' => 'Created',
'datatype' => 'integer',
'default' => 0,
'required' => true ),
'modified' => array( 'name' => 'Modified',
'datatype' => 'integer',
'default' => 0,
'required' => true ) ),
'keys' => array( 'id' ),
'function_attributes' => array( 'collaboration_item' => 'collaborationItem',
'participant' => 'participant',
'simple_message' => 'simpleMessage' ),
'increment_key' => 'id',
'class_name' => 'eZCollaborationItemMessageLink',
'name' => 'ezcollab_item_message_link' );
}
static function create( $collaborationID, $messageID, $messageType, $participantID )
{
$dateTime = time();
$row = array(
'collaboration_id' => $collaborationID,
'message_id' => $messageID,
'message_type' => $messageType,
'participant_id' => $participantID,
'created' => $dateTime,
'modified' => $dateTime );
return new eZCollaborationItemMessageLink( $row );
}
/*!
\note Transaction unsafe. If you call several transaction unsafe methods you must enclose
the calls within a db transaction; thus within db->begin and db->commit.
*/
static function addMessage( $collaborationItem, $message, $messageType, $participantID = false )
{
$messageID = $message->attribute( 'id' );
if ( !$messageID )
{
eZDebug::writeError( 'No message ID, cannot create link', __METHOD__ );
$retValue = null;
return $retValue;
}
if ( $participantID === false )
{
$user = eZUser::currentUser();
$participantID = $user->attribute( 'contentobject_id' );
}
$collaborationID = $collaborationItem->attribute( 'id' );
$timestamp = time();
$collaborationItem->setAttribute( 'modified', $timestamp );
$db = eZDB::instance();
$db->begin();
$collaborationItem->sync();
$link = eZCollaborationItemMessageLink::create( $collaborationID, $messageID, $messageType, $participantID );
$link->store();
$db->commit();
return $link;
}
static function fetch( $id, $asObject = true )
{
return eZPersistentObject::fetchObject( eZCollaborationItemMessageLink::definition(),
null,
array( "id" => $id ),
null, null,
$asObject );
}
static function fetchItemCount( $parameters )
{
$parameters = array_merge( array( 'item_id' => false,
'conditions' => null ),
$parameters );
$itemID = $parameters['item_id'];
$conditions = $parameters['conditions'];
if ( $conditions === null )
$conditions = array();
$conditions['collaboration_id'] = $itemID;
$objectList = eZPersistentObject::fetchObjectList( eZCollaborationItemMessageLink::definition(),
array(),
$conditions,
false,
null,
false,
false,
array( array( 'operation' => 'count( id )',
'name' => 'count' ) ) );
return $objectList[0]['count'];
}
static function fetchItemList( $parameters )
{
$parameters = array_merge( array( 'as_object' => true,
'item_id' => false,
'offset' => false,
'limit' => false,
'sort_by' => false ),
$parameters );
$itemID = $parameters['item_id'];
$asObject = $parameters['as_object'];
$offset = $parameters['offset'];
$limit = $parameters['limit'];
$limitArray = null;
if ( $offset and $limit )
{
$limitArray = array( 'offset' => $offset,
'limit' => $limit );
}
return eZPersistentObject::fetchObjectList( eZCollaborationItemMessageLink::definition(),
null,
array( "collaboration_id" => $itemID ),
null, $limitArray,
$asObject );
}
function collaborationItem()
{
if ( isset( $this->CollaborationID ) and $this->CollaborationID )
{
return eZCollaborationItem::fetch( $this->CollaborationID );
}
return null;
}
function participant()
{
return eZCollaborationItemParticipantLink::fetch( $this->CollaborationID, $this->ParticipantID );
}
function simpleMessage()
{
if ( isset( $this->MessageID ) and $this->MessageID )
{
return eZCollaborationSimpleMessage::fetch( $this->MessageID );
}
return null;
}
/// \privatesection
public $CollaborationID;
public $MessageID;
public $ParticipantID;
public $Created;
public $Modified;
}
?>