Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcollaborationitem.php
Go to the documentation of this file.
1 <?php
17 class eZCollaborationItem extends eZPersistentObject
18 {
19 const STATUS_ACTIVE = 1;
20 const STATUS_INACTIVE = 2;
21 const STATUS_ARCHIVE = 3;
22
23 static function definition()
24 {
25 return array( 'fields' => array( 'id' => array( 'name' => 'ID',
26 'datatype' => 'integer',
27 'default' => 0,
28 'required' => true ),
29 'type_identifier' => array( 'name' => 'TypeIdentifier',
30 'datatype' => 'string',
31 'default' => '',
32 'required' => true ),
33 'creator_id' => array( 'name' => 'CreatorID',
34 'datatype' => 'integer',
35 'default' => 0,
36 'required' => true,
37 'foreign_class' => 'eZUser',
38 'foreign_attribute' => 'contentobject_id',
39 'multiplicity' => '1..*' ),
40 'status' => array( 'name' => 'Status',
41 'datatype' => 'integer',
42 'default' => 1,
43 'required' => true ),
44 'data_text1' => array( 'name' => 'DataText1',
45 'datatype' => 'text',
46 'default' => '',
47 'required' => true ),
48 'data_text2' => array( 'name' => 'DataText2',
49 'datatype' => 'text',
50 'default' => '',
51 'required' => true ),
52 'data_text3' => array( 'name' => 'DataText3',
53 'datatype' => 'text',
54 'default' => '',
55 'required' => true ),
56 'data_int1' => array( 'name' => 'DataInt1',
57 'datatype' => 'integer',
58 'default' => 0,
59 'required' => true ),
60 'data_int2' => array( 'name' => 'DataInt2',
61 'datatype' => 'integer',
62 'default' => 0,
63 'required' => true ),
64 'data_int3' => array( 'name' => 'DataInt3',
65 'datatype' => 'integer',
66 'default' => 0,
67 'required' => true ),
68 'data_float1' => array( 'name' => 'DataFloat1',
69 'datatype' => 'float',
70 'default' => 0,
71 'required' => true ),
72 'data_float2' => array( 'name' => 'DataFloat2',
73 'datatype' => 'float',
74 'default' => 0,
75 'required' => true ),
76 'data_float3' => array( 'name' => 'DataFloat3',
77 'datatype' => 'float',
78 'default' => 0,
79 'required' => true ),
80 'created' => array( 'name' => 'Created',
81 'datatype' => 'integer',
82 'default' => 0,
83 'required' => true ),
84 'modified' => array( 'name' => 'Modified',
85 'datatype' => 'integer',
86 'default' => 0,
87 'required' => true ) ),
88 'keys' => array( 'id' ),
89 'function_attributes' => array( 'creator' => 'creator',
90 'is_creator' => 'isCreator',
91 'participant_list' => 'participantList',
92 'user_status' => 'userStatus',
93 'handler' => 'handler',
94 'use_messages' => 'useMessages',
95 'message_count' => 'messageCount',
96 'unread_message_count' => 'unreadMessageCount',
97 'content' => 'content',
98 'title' => 'title' ),
99 'increment_key' => 'id',
100 'class_name' => 'eZCollaborationItem',
101 'sort' => array( 'modified' => 'asc' ),
102 'name' => 'ezcollab_item' );
103 }
104
105 static function create( $typeIdentifier, $creatorID, $status = self::STATUS_ACTIVE )
106 {
107 $date_time = time();
108 $row = array(
109 'id' => null,
110 'type_identifier' => $typeIdentifier,
111 'creator_id' => $creatorID,
112 'status' => $status,
113 'created' => $date_time,
114 'modified' => $date_time );
115 return new eZCollaborationItem( $row );
116 }
117
122 function createNotificationEvent( $subType = false )
123 {
124 $handler = $this->attribute( 'handler' );
125 $info = $handler->attribute( 'info' );
126 $type = $info['type-identifier'];
127 if ( $subType )
128 $type .= '_' . $subType;
129 $event = eZNotificationEvent::create( 'ezcollaboration', array( 'collaboration_id' => $this->attribute( 'id' ),
130 'collaboration_identifier' => $type ) );
131 $event->store();
132 return $event;
133 }
134
135 static function fetch( $id, $creatorID = false, $asObject = true )
136 {
137 $conditions = array( 'id' => $id );
138 if ( $creatorID !== false )
139 $conditions['creator_id'] = $creatorID;
140 return eZPersistentObject::fetchObject( eZCollaborationItem::definition(),
141 null,
142 $conditions,
143 $asObject );
144 }
145
146 function creator()
147 {
148 if ( isset( $this->CreatorID ) and $this->CreatorID )
149 {
150 return eZUser::fetch( $this->CreatorID );
151 }
152 return null;
153 }
154
155 function isCreator()
156 {
157 if ( isset( $this->CreatorID ) and $this->CreatorID )
158 {
159 return ( eZUser::currentUserID() == $this->CreatorID );
160 }
161 return false;
162 }
163
164 function participantList()
165 {
166 return eZCollaborationItemParticipantLink::fetchParticipantList( array('item_id' => $this->ID ) );
167 }
168
169 function userStatus()
170 {
171 $userID = eZUser::currentUserID();
172 return eZCollaborationItemStatus::fetch( $this->ID, $userID );
173 }
174
175 function handler()
176 {
177 return eZCollaborationItemHandler::instantiate( $this->attribute( 'type_identifier' ) );
178 }
179
184 function useMessages()
185 {
186 $handler = $this->handler();
187 if ( $handler )
188 {
189 return $handler->useMessages( $this );
190 }
191 return null;
192 }
193
198 function messageCount()
199 {
200 $handler = $this->handler();
201 if ( $handler )
202 {
203 return $handler->messageCount( $this );
204 }
205 return 0;
206 }
207
213 function unreadMessageCount()
214 {
215 $handler = $this->handler();
216 if ( $handler )
217 {
218 return $handler->unreadMessageCount( $this );
219 }
220 return 0;
221 }
222
223 function content()
224 {
225 $handler = $this->handler();
226 if ( $handler )
227 {
228 return $handler->content( $this );
229 }
230 return null;
231 }
232
233 function title()
234 {
235 $handler = $this->handler();
236 if ( $handler )
237 {
238 return $handler->title( $this );
239 }
240 return null;
241 }
242
243
244 function hasContentAttribute( $attribute )
245 {
246 $handler =& $this->handler();
247 if ( !$handler )
248 $hasContentAttribute = null;
249 else
250 $hasContentAttribute = $handler->hasContentAttribute( $this, $attribute );
251 return $hasContentAttribute;
252 }
253
254 function contentAttribute( $attribute )
255 {
256 $handler = $this->handler();
257 if ( $handler )
258 {
259 return $handler->contentAttribute( $this, $attribute );
260 }
261 return null;
262 }
263
264 function setIsActive( $active, $userID = false )
265 {
266 $active = intval($active);
267 eZCollaborationItemStatus::updateFields( $this->attribute( 'id' ), $userID, array( 'is_active' => $active ) );
268 }
269
270 static function fetchListCount( $parameters = array() )
271 {
272 return eZCollaborationItem::fetchListTool( $parameters, true );
273 // $parameters = array_merge( array( 'status' => false
274 // 'is_active' => null,
275 // 'is_read' => null ),
276 // $parameters );
277 // $statusTypes = $parameters['status'];
278 // $isRead = $parameters['is_read'];
279 // $isActive = $parameters['is_active'];
280
281 // $user = eZUser::currentUser();
282 // $userID =& $user->attribute( 'contentobject_id' );
283
284 // $isReadText = '';
285 // if ( $isRead !== null )
286 // {
287 // $isReadValue = $isRead ? 1 : 0;
288 // $isReadText = "ezcollab_item_group_link.is_read = '$isReadValue' AND";
289 // }
290
291 // $isActiveText = '';
292 // if ( $isActive !== null )
293 // {
294 // $isActiveValue = $isActive ? 1 : 0;
295 // $isActiveText = "ezcollab_item_group_link.is_active = '$isActiveValue' AND";
296 // }
297
298 // $statusText = '';
299 // if ( $statusTypes === false )
300 // $statusTypes = array( self::STATUS_ACTIVE,
301 // self::STATUS_INACTIVE );
302 // $statusText = implode( ', ', $statusTypes );
303
304 // $sql = "SELECT count( ezcollab_item.id ) as count
305 // FROM
306 // ezcollab_item,
307 // ezcollab_item_group_link
308 // WHERE ezcollab_item.status IN ( $statusText ) AND
309 // $isReadText
310 // $isActiveText
311 // ezcollab_item.id = ezcollab_item_group_link.collaboration_id AND
312 // ezcollab_item_group_link.user_id=$userID";
313
314 // $db = eZDB::instance();
315 // $itemCount = $db->arrayQuery( $sql );
316 // return $itemCount[0]['count'];
317 }
318
319 function setLastRead( $userID = false, $timestamp = false )
320 {
321 if ( $userID === false )
322 $userID = eZUser::currentUserID();
323 if ( $timestamp === false )
324 $timestamp = time();
325 $collaborationID = $this->attribute( 'id' );
326
327 eZCollaborationItemStatus::setLastRead( $collaborationID, $userID, $timestamp );
328 eZCollaborationItemParticipantLink::setLastRead( $collaborationID, $userID, $timestamp );
329 }
330
331 static function fetchList( $parameters = array() )
332 {
333 return eZCollaborationItem::fetchListTool( $parameters, false );
334 }
335
336 static function fetchListTool( $parameters = array(), $asCount )
337 {
338 $parameters = array_merge( array( 'as_object' => true,
339 'offset' => false,
340 'parent_group_id' => false,
341 'limit' => false,
342 'is_active' => null,
343 'is_read' => null,
344 'status' => false,
345 'sort_by' => false ),
346 $parameters );
347 $asObject = $parameters['as_object'];
348 $offset = $parameters['offset'];
349 $limit = $parameters['limit'];
350 $statusTypes = $parameters['status'];
351 $isRead = $parameters['is_read'];
352 $isActive = $parameters['is_active'];
353 $parentGroupID = $parameters['parent_group_id'];
354
355 $sortText = '';
356 if ( !$asCount )
357 {
358 $sortCount = 0;
359 $sortList = $parameters['sort_by'];
360 if ( is_array( $sortList ) and
361 count( $sortList ) > 0 )
362 {
363 if ( count( $sortList ) > 1 and
364 !is_array( $sortList[0] ) )
365 {
366 $sortList = array( $sortList );
367 }
368 }
369 if ( $sortList !== false )
370 {
371 $sortingFields = '';
372 foreach ( $sortList as $sortBy )
373 {
374 if ( is_array( $sortBy ) and count( $sortBy ) > 0 )
375 {
376 if ( $sortCount > 0 )
377 $sortingFields .= ', ';
378 $sortField = $sortBy[0];
379 switch ( $sortField )
380 {
381 case 'created':
382 {
383 $sortingFields .= 'ezcollab_item_group_link.created';
384 } break;
385 case 'modified':
386 {
387 $sortingFields .= 'ezcollab_item_group_link.modified';
388 } break;
389 default:
390 {
391 eZDebug::writeWarning( 'Unknown sort field: ' . $sortField, __METHOD__ );
392 continue 2;
393 }
394 }
395 $sortOrder = true; // true is ascending
396 if ( isset( $sortBy[1] ) )
397 $sortOrder = $sortBy[1];
398 $sortingFields .= $sortOrder ? ' ASC' : ' DESC';
399 ++$sortCount;
400 }
401 }
402 }
403 if ( $sortCount == 0 )
404 {
405 $sortingFields = ' ezcollab_item_group_link.modified DESC';
406 }
407 $sortText = "ORDER BY $sortingFields";
408 }
409
410 $parentGroupText = '';
411 if ( $parentGroupID > 0 )
412 {
413 $parentGroupText = "ezcollab_item_group_link.group_id = '$parentGroupID' AND";
414 }
415
416 $isReadText = '';
417 if ( $isRead !== null )
418 {
419 $isReadValue = $isRead ? 1 : 0;
420 $isReadText = "ezcollab_item_status.is_read = '$isReadValue' AND";
421 }
422
423 $isActiveText = '';
424 if ( $isActive !== null )
425 {
426 $isActiveValue = $isActive ? 1 : 0;
427 $isActiveText = "ezcollab_item_status.is_active = '$isActiveValue' AND";
428 }
429
430 $userID = eZUser::currentUserID();
431
432 $statusText = '';
433 if ( $statusTypes === false )
434 $statusTypes = array( self::STATUS_ACTIVE,
435 self::STATUS_INACTIVE );
436 $statusText = implode( ', ', $statusTypes );
437
438 if ( $asCount )
439 $selectText = 'count( ezcollab_item.id ) as count';
440 else
441 $selectText = 'ezcollab_item.*, ezcollab_item_status.is_read, ezcollab_item_status.is_active, ezcollab_item_status.last_read';
442
443 $sql = "SELECT $selectText
444 FROM
445 ezcollab_item,
446 ezcollab_item_status,
447 ezcollab_item_group_link
448 WHERE ezcollab_item.status IN ( $statusText ) AND
449 $isReadText
450 $isActiveText
451 ezcollab_item.id = ezcollab_item_status.collaboration_id AND
452 ezcollab_item.id = ezcollab_item_group_link.collaboration_id AND
453 $parentGroupText
454 ezcollab_item_status.user_id = '$userID' AND
455 ezcollab_item_group_link.user_id = '$userID'
456 $sortText";
457
458 $db = eZDB::instance();
459 if ( !$asCount )
460 {
461 $sqlParameters = array();
462 if ( $offset !== false and $limit !== false )
463 {
464 $sqlParameters['offset'] = $offset;
465 $sqlParameters['limit'] = $limit;
466 }
467 $itemListArray = $db->arrayQuery( $sql, $sqlParameters );
468
469 foreach( $itemListArray as $key => $value )
470 {
471 $itemData =& $itemListArray[$key];
472 $statusObject = eZCollaborationItemStatus::create( $itemData['id'], $userID );
473 $statusObject->setAttribute( 'is_read', $itemData['is_read'] );
474 $statusObject->setAttribute( 'is_active', $itemData['is_active'] );
475 $statusObject->setAttribute( 'last_read', $itemData['last_read'] );
476 $statusObject->updateCache();
477 }
478 $returnItemList = eZPersistentObject::handleRows( $itemListArray, 'eZCollaborationItem', $asObject );
479 eZDebugSetting::writeDebug( 'collaboration-item-list', $returnItemList );
480 return $returnItemList;
481 }
482 else
483 {
484 $itemCount = $db->arrayQuery( $sql );
485 return $itemCount[0]['count'];
486 }
487 }
488
489 function handleView( $viewMode )
490 {
491 $handler = $this->handler();
492 $handler->readItem( $this, $viewMode );
493 return true;
494 }
495
501 public function userIsParticipant( eZUser $user )
502 {
504 foreach ( $this->participantList() as $participantLink )
505 {
506 $participant = $participantLink->participant();
507
508 if ( $participant instanceof eZUser )
509 {
510 if ( $participant->attribute( 'contentobject_id' ) == $user->attribute( 'contentobject_id' ) )
511 {
512 return true;
513 }
514 }
515 // user group
516 else if ( $participant instanceof eZContentObject )
517 {
518 foreach ( $user->groups() as $userGroup )
519 {
520 if ( $participant->attribute( 'id' ) == $userGroup->attribute( 'id' ) )
521 {
522 return true;
523 }
524 }
525 }
526 }
527 return false;
528 }
529
536 static function cleanup()
537 {
538 $db = eZDB::instance();
539 $db->begin();
540 $db->query( "DELETE FROM ezcollab_item" );
541 $db->query( "DELETE FROM ezcollab_item_group_link" );
542 $db->query( "DELETE FROM ezcollab_item_message_link" );
543 $db->query( "DELETE FROM ezcollab_item_participant_link" );
544 $db->query( "DELETE FROM ezcollab_item_status" );
545 $db->query( "DELETE FROM ezcollab_notification_rule" );
546 $db->query( "DELETE FROM ezcollab_profile" );
547 $db->query( "DELETE FROM ezcollab_simple_message" );
548 $db->commit();
549 }
550
552 public $ID;
553 public $TypeIdentifier;
554 public $CreatorID;
555 public $Status;
556 public $Created;
557 public $Modified;
558 public $DataText1;
559 public $DataText2;
560 public $DataText3;
561 public $DataInt1;
562 public $DataInt2;
563 public $DataInt3;
564 public $DataFloat1;
565 public $DataFloat2;
566 public $DataFloat3;
567 }
568
569 ?>
eZCollaborationItemHandler\instantiate
static instantiate( $handler, $repositories=false)
Definition: ezcollaborationitemhandler.php:504
eZCollaborationItemParticipantLink\setLastRead
static setLastRead( $collaborationID, $userID=false, $timestamp=false)
Definition: ezcollaborationitemparticipantlink.php:98
eZCollaborationItemParticipantLink\fetchParticipantList
static fetchParticipantList( $parameters=array())
Definition: ezcollaborationitemparticipantlink.php:132
eZCollaborationItemStatus\setLastRead
static setLastRead( $collaborationID, $userID=false, $timestamp=false)
Definition: ezcollaborationitemstatus.php:99
eZCollaborationItemStatus\create
static create( $collaborationID, $userID=false)
Definition: ezcollaborationitemstatus.php:53
eZCollaborationItemStatus\updateFields
static updateFields( $collaborationID, $userID=false, $fields)
Definition: ezcollaborationitemstatus.php:108
eZCollaborationItemStatus\fetch
static fetch( $collaborationID, $userID=false, $asObject=true)
Definition: ezcollaborationitemstatus.php:80
eZCollaborationItem
The class eZCollaborationItem does.
Definition: ezcollaborationitem.php:18
eZCollaborationItem\cleanup
static cleanup()
Definition: ezcollaborationitem.php:536
eZCollaborationItem\$ID
$ID
Definition: ezcollaborationitem.php:552
eZCollaborationItem\content
content()
Definition: ezcollaborationitem.php:223
eZCollaborationItem\$CreatorID
$CreatorID
Definition: ezcollaborationitem.php:554
eZCollaborationItem\STATUS_INACTIVE
const STATUS_INACTIVE
Definition: ezcollaborationitem.php:20
eZCollaborationItem\$DataText3
$DataText3
Definition: ezcollaborationitem.php:560
eZCollaborationItem\definition
static definition()
Definition: ezcollaborationitem.php:23
eZCollaborationItem\$DataFloat3
$DataFloat3
Definition: ezcollaborationitem.php:566
eZCollaborationItem\setLastRead
setLastRead( $userID=false, $timestamp=false)
Definition: ezcollaborationitem.php:319
eZCollaborationItem\$Created
$Created
Definition: ezcollaborationitem.php:556
eZCollaborationItem\$TypeIdentifier
$TypeIdentifier
Definition: ezcollaborationitem.php:553
eZCollaborationItem\fetch
static fetch( $id, $creatorID=false, $asObject=true)
Definition: ezcollaborationitem.php:135
eZCollaborationItem\$DataText2
$DataText2
Definition: ezcollaborationitem.php:559
eZCollaborationItem\STATUS_ACTIVE
const STATUS_ACTIVE
Definition: ezcollaborationitem.php:19
eZCollaborationItem\isCreator
isCreator()
Definition: ezcollaborationitem.php:155
eZCollaborationItem\participantList
participantList()
Definition: ezcollaborationitem.php:164
eZCollaborationItem\title
title()
Definition: ezcollaborationitem.php:233
eZCollaborationItem\$DataInt1
$DataInt1
Definition: ezcollaborationitem.php:561
eZCollaborationItem\setIsActive
setIsActive( $active, $userID=false)
Definition: ezcollaborationitem.php:264
eZCollaborationItem\fetchList
static fetchList( $parameters=array())
Definition: ezcollaborationitem.php:331
eZCollaborationItem\handleView
handleView( $viewMode)
Definition: ezcollaborationitem.php:489
eZCollaborationItem\$Status
$Status
Definition: ezcollaborationitem.php:555
eZCollaborationItem\$DataInt3
$DataInt3
Definition: ezcollaborationitem.php:563
eZCollaborationItem\creator
creator()
Definition: ezcollaborationitem.php:146
eZCollaborationItem\fetchListTool
static fetchListTool( $parameters=array(), $asCount)
Definition: ezcollaborationitem.php:336
eZCollaborationItem\$DataFloat2
$DataFloat2
Definition: ezcollaborationitem.php:565
eZCollaborationItem\$DataFloat1
$DataFloat1
Definition: ezcollaborationitem.php:564
eZCollaborationItem\contentAttribute
contentAttribute( $attribute)
Definition: ezcollaborationitem.php:254
eZCollaborationItem\userStatus
userStatus()
Definition: ezcollaborationitem.php:169
eZCollaborationItem\hasContentAttribute
hasContentAttribute( $attribute)
Definition: ezcollaborationitem.php:244
eZCollaborationItem\$Modified
$Modified
Definition: ezcollaborationitem.php:557
eZCollaborationItem\create
static create( $typeIdentifier, $creatorID, $status=self::STATUS_ACTIVE)
Definition: ezcollaborationitem.php:105
eZCollaborationItem\unreadMessageCount
unreadMessageCount()
Definition: ezcollaborationitem.php:213
eZCollaborationItem\$DataInt2
$DataInt2
Definition: ezcollaborationitem.php:562
eZCollaborationItem\useMessages
useMessages()
Definition: ezcollaborationitem.php:184
eZCollaborationItem\handler
handler()
Definition: ezcollaborationitem.php:175
eZCollaborationItem\messageCount
messageCount()
Definition: ezcollaborationitem.php:198
eZCollaborationItem\STATUS_ARCHIVE
const STATUS_ARCHIVE
Definition: ezcollaborationitem.php:21
eZCollaborationItem\fetchListCount
static fetchListCount( $parameters=array())
Definition: ezcollaborationitem.php:270
eZCollaborationItem\createNotificationEvent
createNotificationEvent( $subType=false)
Definition: ezcollaborationitem.php:122
eZCollaborationItem\$DataText1
$DataText1
Definition: ezcollaborationitem.php:558
eZContentObject
Definition: ezcontentobject.php:17
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebugSetting\writeDebug
static writeDebug( $conditionName, $string, $label="")
Definition: ezdebugsetting.php:127
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZNotificationEvent\create
static create( $type, $params=array())
Definition: eznotificationevent.php:83
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\handleRows
static handleRows( $rows, $class_name, $asObject)
Definition: ezpersistentobject.php:963
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZUser
eZUser handles eZ Publish user accounts
Definition: ezuser.php:19
eZUser\groups
groups( $asObject=false)
Definition: ezuser.php:2566
eZUser\fetch
static fetch( $id, $asObject=true)
Definition: ezuser.php:351
eZUser\currentUserID
static currentUserID()
Definition: ezuser.php:1731
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.