Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcollaborationitemhandler.php
Go to the documentation of this file.
1 <?php
17 class eZCollaborationItemHandler
18 {
19 public $NotificationCollectionHandling;
20 public $NotificationTypes;
21 /*
22 Definitions for notification handling for collaboration handlers.
23 */
24 const NOTIFICATION_COLLECTION_ONE_FOR_ALL = 1;
25 const NOTIFICATION_COLLECTION_PER_USER = 2;
26 const NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE = 3;
27
38 public function __construct( $typeIdentifier, $typeName, $parameters = array() )
39 {
40 $parameters = array_merge( array( 'use-messages' => false,
41 'type-class-list' => array(),
42 'notification-collection-handling' => self::NOTIFICATION_COLLECTION_ONE_FOR_ALL,
43 'notification-types' => false ),
44 $parameters );
45 $typeClassList = $parameters['type-class-list'];
46 $this->Info['type-identifier'] = $typeIdentifier;
47 $this->Info['type-class-list'] = $typeClassList;
48 $this->Info['type-name'] = $typeName;
49 $this->Info['use-messages'] = $parameters['use-messages'];
50 $this->Info['notification-collection-handling'] = $parameters['notification-collection-handling'];
51 $this->Info['notification-types'] = $parameters['notification-types'];
52 $this->NotificationCollectionHandling = $parameters['notification-collection-handling'];
53 $this->NotificationTypes = $parameters['notification-types'];
54 }
55
56 function attributes()
57 {
58 return array( 'info',
59 'notification_types' );
60 }
61
65 function hasAttribute( $attr )
66 {
67 return in_array( $attr, $this->attributes() );
68 }
69
73 function attribute( $attribute )
74 {
75 if ( $attribute == 'info' )
76 {
77 return $this->Info;
78 }
79 else if ( $attribute == 'notification_types' )
80 {
81 return $this->notificationTypes();
82 }
83
84 eZDebug::writeError( "Attribute '$attribute' does not exist", __METHOD__ );
85 return null;
86 }
87
94 function notificationTypes()
95 {
96 return $this->NotificationTypes;
97 }
98
103 function notificationCollectionHandling()
104 {
105 return $this->NotificationCollectionHandling;
106 }
107
108 function notificationParticipantTemplate( $participantRole )
109 {
110 return 'participant.tpl';
111 }
112
120 static function handleCollaborationEvent( $event, $item, &$parameters )
121 {
122 $participantList = eZCollaborationItemParticipantLink::fetchParticipantList( array( 'item_id' => $item->attribute( 'id' ),
123 'participant_type' => eZCollaborationItemParticipantLink::TYPE_USER,
124 'as_object' => false ) );
125
126 $userIDList = array();
127 $participantMap = array();
128 foreach ( $participantList as $participant )
129 {
130 $userIDList[] = $participant['participant_id'];
131 $participantMap[$participant['participant_id']] = $participant;
132 }
133
134 // $collaborationIdentifier = $event->attribute( 'collaboration_identifier' );
135 $collaborationIdentifier = $event->attribute( 'data_text1' );
136 $ruleList = eZCollaborationNotificationRule::fetchItemTypeList( $collaborationIdentifier, $userIDList, false );
137 $userIDList = array();
138 foreach ( $ruleList as $rule )
139 {
140 $userIDList[] = $rule['user_id'];
141 }
142 $userList = array();
143 if ( count( $userIDList ) > 0 )
144 {
145 $db = eZDB::instance();
146 $userIDListText = $db->generateSQLINStatement( $userIDList, 'contentobject_id', false, false, 'int' );
147 $userList = $db->arrayQuery( "SELECT contentobject_id, email FROM ezuser WHERE $userIDListText" );
148 }
149 else
150 return eZNotificationEventHandler::EVENT_SKIPPED;
151
152 $itemHandler = $item->attribute( 'handler' );
153 $collectionHandling = $itemHandler->notificationCollectionHandling();
154
155 $db = eZDB::instance();
156 $db->begin();
157 if ( $collectionHandling == self::NOTIFICATION_COLLECTION_ONE_FOR_ALL )
158 {
159 $tpl = eZTemplate::factory();
160 $tpl->resetVariables();
161 $tpl->setVariable( 'collaboration_item', $item );
162 $result = $tpl->fetch( 'design:notification/handler/ezcollaboration/view/plain.tpl' );
163 $subject = $tpl->variable( 'subject' );
164 if ( $tpl->hasVariable( 'message_id' ) )
165 $parameters['message_id'] = $tpl->variable( 'message_id' );
166 if ( $tpl->hasVariable( 'references' ) )
167 $parameters['references'] = $tpl->variable( 'references' );
168 if ( $tpl->hasVariable( 'reply_to' ) )
169 $parameters['reply_to'] = $tpl->variable( 'reply_to' );
170 if ( $tpl->hasVariable( 'from' ) )
171 $parameters['from'] = $tpl->variable( 'from' );
172 if ( $tpl->hasVariable( 'content_type' ) )
173 $parameters['content_type'] = $tpl->variable( 'content_type' );
174
175 $collection = eZNotificationCollection::create( $event->attribute( 'id' ),
176 eZCollaborationNotificationHandler::NOTIFICATION_HANDLER_ID,
177 eZCollaborationNotificationHandler::TRANSPORT );
178
179 $collection->setAttribute( 'data_subject', $subject );
180 $collection->setAttribute( 'data_text', $result );
181 $collection->store();
182
183 foreach( $userList as $subscriber )
184 {
185 $collection->addItem( $subscriber['email'] );
186 }
187 }
188 else if ( $collectionHandling == self::NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE )
189 {
190 $userCollection = array();
191 foreach( $userList as $subscriber )
192 {
193 $contentObjectID = $subscriber['contentobject_id'];
194 $participant = $participantMap[$contentObjectID];
195 $participantRole = $participant['participant_role'];
196 $userItem = array( 'participant' => $participant,
197 'email' => $subscriber['email'] );
198 if ( !isset( $userCollection[$participantRole] ) )
199 $userCollection[$participantRole] = array();
200 $userCollection[$participantRole][] = $userItem;
201 }
202
203 $tpl = eZTemplate::factory();
204 $tpl->resetVariables();
205 foreach( $userCollection as $participantRole => $collectionItems )
206 {
207 $templateName = $itemHandler->notificationParticipantTemplate( $participantRole );
208 if ( !$templateName )
209 $templateName = eZCollaborationItemHandler::notificationParticipantTemplate( $participantRole );
210
211 $itemInfo = $itemHandler->attribute( 'info' );
212 $typeIdentifier = $itemInfo['type-identifier'];
213 $tpl->setVariable( 'collaboration_item', $item );
214 $tpl->setVariable( 'collaboration_participant_role', $participantRole );
215 $result = $tpl->fetch( 'design:notification/handler/ezcollaboration/view/' . $typeIdentifier . '/' . $templateName );
216 $subject = $tpl->variable( 'subject' );
217 if ( $tpl->hasVariable( 'message_id' ) )
218 $parameters['message_id'] = $tpl->variable( 'message_id' );
219 if ( $tpl->hasVariable( 'references' ) )
220 $parameters['references'] = $tpl->variable( 'references' );
221 if ( $tpl->hasVariable( 'reply_to' ) )
222 $parameters['reply_to'] = $tpl->variable( 'reply_to' );
223 if ( $tpl->hasVariable( 'from' ) )
224 $parameters['from'] = $tpl->variable( 'from' );
225 if ( $tpl->hasVariable( 'content_type' ) )
226 $parameters['content_type'] = $tpl->variable( 'content_type' );
227
228 $collection = eZNotificationCollection::create( $event->attribute( 'id' ),
229 eZCollaborationNotificationHandler::NOTIFICATION_HANDLER_ID,
230 eZCollaborationNotificationHandler::TRANSPORT );
231
232 $collection->setAttribute( 'data_subject', $subject );
233 $collection->setAttribute( 'data_text', $result );
234 $collection->store();
235 foreach ( $collectionItems as $collectionItem )
236 {
237 $collection->addItem( $collectionItem['email'] );
238 }
239 }
240 }
241 else if ( $collectionHandling == self::NOTIFICATION_COLLECTION_PER_USER )
242 {
243 }
244 else
245 {
246 eZDebug::writeError( "Unknown collaboration notification collection handling type '$collectionHandling', skipping notification", __METHOD__ );
247 }
248 $db->commit();
249
250 return eZNotificationEventHandler::EVENT_HANDLED;
251 }
252
256 function hasContentAttribute( $collaborationItem, $attribute )
257 {
258 $content = $collaborationItem->content();
259 if ( is_array( $content ) )
260 {
261 return array_key_exists( $attribute, $content );
262 }
263 return false;
264 }
265
269 function contentAttribute( $collaborationItem, $attribute )
270 {
271 $content = $collaborationItem->content();
272 if ( is_array( $content ) )
273 {
274 if ( array_key_exists( $attribute, $content ) )
275 return $content[$attribute];
276 }
277 $content = null;
278 return $content;
279 }
280
284 function classes()
285 {
286 return $this->Info['type-class-list'];
287 }
288
292 function template( $viewMode )
293 {
294 $templateName = $this->templateName();
295 return "design:collaboration/handlers/view/$viewMode/$templateName";
296 }
297
302 function templateName()
303 {
304 return $this->Info['type-identifier'] . '.tpl';
305 }
306
310 function title( $collaborationItem )
311 {
312 return $this->Info['type-name'];
313 }
314
320 function useMessages( $collaborationItem )
321 {
322 return $this->Info['use-messages'];
323 }
324
330 function messageCount( $collaborationItem )
331 {
332 return 0;
333 }
334
340 function unreadMessageCount( $collaborationItem )
341 {
342 return 0;
343 }
344
350 function readItem( $collaborationItem, $viewMode = false )
351 {
352 }
353
359 function removeItem( $collaborationItem )
360 {
361 }
362
367 static function ini()
368 {
369 return eZINI::instance( 'collaboration.ini' );
370 }
371
376 function participantTypeString( $participantType )
377 {
378 return null;
379 }
380
385 function participantRoleString( $participantRole )
386 {
387 return null;
388 }
389
394 function roleName( $collaborationID, $roleID )
395 {
396 return null;
397 }
398
403 function content( $collaborationItem )
404 {
405 return null;
406 }
407
414 function handleCustomAction( $module, $collaborationItem )
415 {
416 }
417
421 function isCustomAction( $name )
422 {
423 $http = eZHTTPTool::instance();
424 $postVariable = 'CollaborationAction_' . $name;
425 return $http->hasPostVariable( $postVariable );
426 }
427
431 function hasCustomInput( $name )
432 {
433 $http = eZHTTPTool::instance();
434 $postVariable = 'Collaboration_' . $name;
435 return $http->hasPostVariable( $postVariable );
436 }
437
441 function customInput( $name )
442 {
443 $http = eZHTTPTool::instance();
444 $postVariable = 'Collaboration_' . $name;
445 return $http->postVariable( $postVariable );
446 }
447
453 static function defaultRepositories()
454 {
455 $collabINI = eZCollaborationItemHandler::ini();
456 return $collabINI->variable( 'HandlerSettings', 'Repositories' );
457 }
458
464 static function extensionRepositories()
465 {
466 $collabINI = eZCollaborationItemHandler::ini();
467 return $collabINI->variable( 'HandlerSettings', 'Extensions' );
468 }
469
475 static function handlerRepositories()
476 {
477 $extensions = eZCollaborationItemHandler::extensionRepositories();
478 $repositories = eZCollaborationItemHandler::defaultRepositories();
479 $extensionRoot = eZExtension::baseDirectory();
480 foreach ( $extensions as $extension )
481 {
482 $handlerPath = eZDir::path( array( $extensionRoot, $extension, 'collaboration' ) );
483 if ( file_exists( $handlerPath ) )
484 $repositories[] = $handlerPath;
485 }
486 return $repositories;
487 }
488
493 static function activeHandlers()
494 {
495 $collabINI = eZCollaborationItemHandler::ini();
496 return $collabINI->variable( 'HandlerSettings', 'Active' );
497 }
498
504 static function instantiate( $handler, $repositories = false )
505 {
506 $objectCache =& $GLOBALS["eZCollaborationHandlerObjectCache"];
507 if ( !isset( $objectCache ) )
508 $objectCache = array();
509 if ( isset( $objectCache[$handler] ) )
510 return $objectCache[$handler];
511 if ( $repositories === false )
512 {
513 $repositories = eZCollaborationItemHandler::handlerRepositories();
514 }
515 $handlerInstance = null;
516 $foundHandlerFile = false;
517 $foundHandler = false;
518 foreach ( $repositories as $repository )
519 {
520 $handlerFile = $handler . 'collaborationhandler.php';
521 $handlerClass = $handler . 'collaborationhandler';
522 $handlerPath = eZDir::path( array( $repository, $handler, $handlerFile ) );
523 if ( file_exists( $handlerPath ) )
524 {
525 $foundHandlerFile = true;
526 include_once( $handlerPath );
527 if ( class_exists( $handlerClass ) )
528 {
529 $foundHandler = true;
530 $handlerInstance = new $handlerClass( $handler, [] );
531 $objectCache[$handler] = $handlerInstance;
532 $handlerClasses = $handlerInstance->classes();
533 foreach ( $handlerClasses as $handlerClass )
534 {
535 }
536 }
537 }
538 }
539 if ( !$foundHandlerFile )
540 {
541 eZDebug::writeWarning( "Collaboration file '$handlerFile' could not be found in " . implode( ', ', $repositories ), __METHOD__ );
542 }
543 else if ( !$foundHandler )
544 {
545 eZDebug::writeWarning( "Collaboration class '$handlerClass' does not exist", __METHOD__ );
546 }
547 return $handlerInstance;
548 }
549
555 static function fetchList()
556 {
557 $list =& $GLOBALS['eZCollaborationList'];
558 if ( isset( $list ) )
559 return $list;
560 $list = array();
561 $activeHandlers = eZCollaborationItemHandler::activeHandlers();
562 $repositories = eZCollaborationItemHandler::handlerRepositories();
563 foreach ( $activeHandlers as $handler )
564 {
565 $handlerInstance = eZCollaborationItemHandler::instantiate( $handler, $repositories );
566 if ( $handlerInstance !== null )
567 $list[] = $handlerInstance;
568 }
569 return $list;
570 }
571
573 public $Info;
574 }
575
576 ?>
eZCollaborationItemHandler
The class eZCollaborationItemHandler does.
Definition: ezcollaborationitemhandler.php:18
eZCollaborationItemHandler\customInput
customInput( $name)
Definition: ezcollaborationitemhandler.php:441
eZCollaborationItemHandler\contentAttribute
contentAttribute( $collaborationItem, $attribute)
Definition: ezcollaborationitemhandler.php:269
eZCollaborationItemHandler\handlerRepositories
static handlerRepositories()
Definition: ezcollaborationitemhandler.php:475
eZCollaborationItemHandler\participantTypeString
participantTypeString( $participantType)
Definition: ezcollaborationitemhandler.php:376
eZCollaborationItemHandler\$NotificationTypes
$NotificationTypes
Definition: ezcollaborationitemhandler.php:20
eZCollaborationItemHandler\hasCustomInput
hasCustomInput( $name)
Definition: ezcollaborationitemhandler.php:431
eZCollaborationItemHandler\messageCount
messageCount( $collaborationItem)
Definition: ezcollaborationitemhandler.php:330
eZCollaborationItemHandler\NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE
const NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE
Definition: ezcollaborationitemhandler.php:26
eZCollaborationItemHandler\hasContentAttribute
hasContentAttribute( $collaborationItem, $attribute)
Definition: ezcollaborationitemhandler.php:256
eZCollaborationItemHandler\roleName
roleName( $collaborationID, $roleID)
Definition: ezcollaborationitemhandler.php:394
eZCollaborationItemHandler\unreadMessageCount
unreadMessageCount( $collaborationItem)
Definition: ezcollaborationitemhandler.php:340
eZCollaborationItemHandler\templateName
templateName()
Definition: ezcollaborationitemhandler.php:302
eZCollaborationItemHandler\participantRoleString
participantRoleString( $participantRole)
Definition: ezcollaborationitemhandler.php:385
eZCollaborationItemHandler\__construct
__construct( $typeIdentifier, $typeName, $parameters=array())
Definition: ezcollaborationitemhandler.php:38
eZCollaborationItemHandler\handleCustomAction
handleCustomAction( $module, $collaborationItem)
Definition: ezcollaborationitemhandler.php:414
eZCollaborationItemHandler\activeHandlers
static activeHandlers()
Definition: ezcollaborationitemhandler.php:493
eZCollaborationItemHandler\notificationParticipantTemplate
notificationParticipantTemplate( $participantRole)
Definition: ezcollaborationitemhandler.php:108
eZCollaborationItemHandler\$Info
$Info
Definition: ezcollaborationitemhandler.php:573
eZCollaborationItemHandler\notificationCollectionHandling
notificationCollectionHandling()
Definition: ezcollaborationitemhandler.php:103
eZCollaborationItemHandler\isCustomAction
isCustomAction( $name)
Definition: ezcollaborationitemhandler.php:421
eZCollaborationItemHandler\useMessages
useMessages( $collaborationItem)
Definition: ezcollaborationitemhandler.php:320
eZCollaborationItemHandler\handleCollaborationEvent
static handleCollaborationEvent( $event, $item, &$parameters)
Definition: ezcollaborationitemhandler.php:120
eZCollaborationItemHandler\readItem
readItem( $collaborationItem, $viewMode=false)
Definition: ezcollaborationitemhandler.php:350
eZCollaborationItemHandler\NOTIFICATION_COLLECTION_ONE_FOR_ALL
const NOTIFICATION_COLLECTION_ONE_FOR_ALL
Definition: ezcollaborationitemhandler.php:24
eZCollaborationItemHandler\$NotificationCollectionHandling
$NotificationCollectionHandling
Definition: ezcollaborationitemhandler.php:19
eZCollaborationItemHandler\ini
static ini()
Definition: ezcollaborationitemhandler.php:367
eZCollaborationItemHandler\attribute
attribute( $attribute)
Definition: ezcollaborationitemhandler.php:73
eZCollaborationItemHandler\defaultRepositories
static defaultRepositories()
Definition: ezcollaborationitemhandler.php:453
eZCollaborationItemHandler\content
content( $collaborationItem)
Definition: ezcollaborationitemhandler.php:403
eZCollaborationItemHandler\classes
classes()
Definition: ezcollaborationitemhandler.php:284
eZCollaborationItemHandler\NOTIFICATION_COLLECTION_PER_USER
const NOTIFICATION_COLLECTION_PER_USER
Definition: ezcollaborationitemhandler.php:25
eZCollaborationItemHandler\attributes
attributes()
Definition: ezcollaborationitemhandler.php:56
eZCollaborationItemHandler\hasAttribute
hasAttribute( $attr)
Definition: ezcollaborationitemhandler.php:65
eZCollaborationItemHandler\fetchList
static fetchList()
Definition: ezcollaborationitemhandler.php:555
eZCollaborationItemHandler\removeItem
removeItem( $collaborationItem)
Definition: ezcollaborationitemhandler.php:359
eZCollaborationItemHandler\title
title( $collaborationItem)
Definition: ezcollaborationitemhandler.php:310
eZCollaborationItemHandler\notificationTypes
notificationTypes()
Definition: ezcollaborationitemhandler.php:94
eZCollaborationItemHandler\instantiate
static instantiate( $handler, $repositories=false)
Definition: ezcollaborationitemhandler.php:504
eZCollaborationItemHandler\extensionRepositories
static extensionRepositories()
Definition: ezcollaborationitemhandler.php:464
eZCollaborationItemParticipantLink\fetchParticipantList
static fetchParticipantList( $parameters=array())
Definition: ezcollaborationitemparticipantlink.php:132
eZCollaborationItemParticipantLink\TYPE_USER
const TYPE_USER
Definition: ezcollaborationitemparticipantlink.php:20
eZCollaborationNotificationHandler\NOTIFICATION_HANDLER_ID
const NOTIFICATION_HANDLER_ID
Definition: ezcollaborationnotificationhandler.php:19
eZCollaborationNotificationHandler\TRANSPORT
const TRANSPORT
Definition: ezcollaborationnotificationhandler.php:20
eZCollaborationNotificationRule\fetchItemTypeList
static fetchItemTypeList( $collaborationIdentifier, $userIDList, $asObject=true)
Definition: ezcollaborationnotificationrule.php:65
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZDir\path
static path( $names, $includeEndSeparator=false, $type=self::SEPARATOR_UNIX)
Definition: ezdir.php:237
eZExtension\baseDirectory
static baseDirectory(eZINI|null $siteINI=null)
Definition: ezextension.php:39
eZHTTPTool\instance
static instance()
Definition: ezhttptool.php:189
eZNotificationCollection\create
static create( $eventID, $handler, $transport)
Definition: eznotificationcollection.php:58
eZNotificationEventHandler\EVENT_SKIPPED
const EVENT_SKIPPED
Definition: eznotificationeventhandler.php:20
eZNotificationEventHandler\EVENT_HANDLED
const EVENT_HANDLED
Definition: eznotificationeventhandler.php:19
eZTemplate\factory
static factory()
Definition: eztemplate.php:2380
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.