Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcollaborationnotificationhandler.php
Go to the documentation of this file.
1 <?php
17 class eZCollaborationNotificationHandler extends eZNotificationEventHandler
18 {
19 const NOTIFICATION_HANDLER_ID = 'ezcollaboration';
20 const TRANSPORT = 'ezmail';
21
22 public function __construct()
23 {
24 parent::__construct( self::NOTIFICATION_HANDLER_ID, "Collaboration Handler" );
25 }
26
27 function attributes()
28 {
29 return array_merge( array( 'collaboration_handlers',
30 'collaboration_selections' ),
31 eZNotificationEventHandler::attributes() );
32 }
33
34 function hasAttribute( $attr )
35 {
36 return in_array( $attr, $this->attributes() );
37 }
38
39 function attribute( $attr )
40 {
41 if ( $attr == 'collaboration_handlers' )
42 {
43 return $this->collaborationHandlers();
44 }
45 else if ( $attr == 'collaboration_selections' )
46 {
47 $selections = $this->collaborationSelections();
48 return $selections;
49 }
50 return eZNotificationEventHandler::attribute( $attr );
51 }
52
56 function collaborationHandlers()
57 {
58 return eZCollaborationItemHandler::fetchList();
59 }
60
61 function collaborationSelections()
62 {
63 $rules = eZCollaborationNotificationRule::fetchList();
64 $selection = array();
65 foreach( $rules as $rule )
66 {
67 $selection[] = $rule->attribute( 'collab_identifier' );
68 }
69 return $selection;
70 }
71
72 function handle( $event )
73 {
74 eZDebugSetting::writeDebug( 'kernel-notification', $event, "trying to handle event" );
75 if ( $event->attribute( 'event_type_string' ) == 'ezcollaboration' )
76 {
77 $parameters = array();
78 $status = $this->handleCollaborationEvent( $event, $parameters );
79 if ( $status == eZNotificationEventHandler::EVENT_HANDLED )
80 $this->sendMessage( $event, $parameters );
81 else
82 return false;
83 }
84 return true;
85 }
86
87 function handleCollaborationEvent( $event, &$parameters )
88 {
89 $collaborationItem = $event->attribute( 'content' );
90 if ( !$collaborationItem )
91 return eZNotificationEventHandler::EVENT_SKIPPED;
92 $collaborationHandler = $collaborationItem->attribute( 'handler' );
93 return $collaborationHandler->handleCollaborationEvent( $event, $collaborationItem, $parameters );
94 }
95
96 function sendMessage( $event, $parameters )
97 {
98 $collections = eZNotificationCollection::fetchListForHandler( self::NOTIFICATION_HANDLER_ID,
99 $event->attribute( 'id' ),
100 self::TRANSPORT );
101 foreach ( $collections as $collection )
102 {
103 $items = $collection->attribute( 'items_to_send' );
104 $addressList = array();
105 foreach ( $items as $item )
106 {
107 $addressList[] = $item->attribute( 'address' );
108 $item->remove();
109 }
110 $transport = eZNotificationTransport::instance( 'ezmail' );
111 $transport->send( $addressList,
112 $collection->attribute( 'data_subject' ),
113 $collection->attribute( 'data_text' ),
114 null,
115 $parameters );
116 if ( $collection->attribute( 'item_count' ) == 0 )
117 {
118 $collection->remove();
119 }
120 }
121 }
122
123 function rules( $user = false )
124 {
125 if ( $user === false )
126 {
127 $user = eZUser::currentUser();
128 }
129 $email = $user->attribute( 'email' );
130
131 return eZCollaborationNotificationRule::fetchList( $email );
132 }
133
134 function fetchHttpInput( $http, $module )
135 {
136 if ( $http->hasPostVariable( 'CollaborationHandlerSelection' ) )
137 {
138 $oldSelection = $this->collaborationSelections();
139 $selection = array();
140 if ( $http->hasPostVariable( 'CollaborationHandlerSelection_' . self::NOTIFICATION_HANDLER_ID ) )
141 $selection = $http->postVariable( 'CollaborationHandlerSelection_' . self::NOTIFICATION_HANDLER_ID );
142 $createRules = array_diff( $selection, $oldSelection );
143 $removeRules = array_diff( $oldSelection, $selection );
144 if ( count( $removeRules ) > 0 )
145 eZCollaborationNotificationRule::removeByIdentifier( array( $removeRules ) );
146 foreach ( $createRules as $createRule )
147 {
148 $rule = eZCollaborationNotificationRule::create( $createRule );
149 $rule->store();
150 }
151 }
152 }
153
154 function cleanup()
155 {
156 eZCollaborationNotificationRule::cleanup();
157 }
158 }
159
160 ?>
eZCollaborationItemHandler\fetchList
static fetchList()
Definition: ezcollaborationitemhandler.php:555
eZCollaborationNotificationHandler
The class eZCollaborationNotificationHandler does.
Definition: ezcollaborationnotificationhandler.php:18
eZCollaborationNotificationHandler\NOTIFICATION_HANDLER_ID
const NOTIFICATION_HANDLER_ID
Definition: ezcollaborationnotificationhandler.php:19
eZCollaborationNotificationHandler\rules
rules( $user=false)
Definition: ezcollaborationnotificationhandler.php:123
eZCollaborationNotificationHandler\handleCollaborationEvent
handleCollaborationEvent( $event, &$parameters)
Definition: ezcollaborationnotificationhandler.php:87
eZCollaborationNotificationHandler\sendMessage
sendMessage( $event, $parameters)
Definition: ezcollaborationnotificationhandler.php:96
eZCollaborationNotificationHandler\collaborationSelections
collaborationSelections()
Definition: ezcollaborationnotificationhandler.php:61
eZCollaborationNotificationHandler\attributes
attributes()
Definition: ezcollaborationnotificationhandler.php:27
eZCollaborationNotificationHandler\cleanup
cleanup()
Definition: ezcollaborationnotificationhandler.php:154
eZCollaborationNotificationHandler\hasAttribute
hasAttribute( $attr)
Definition: ezcollaborationnotificationhandler.php:34
eZCollaborationNotificationHandler\handle
handle( $event)
Definition: ezcollaborationnotificationhandler.php:72
eZCollaborationNotificationHandler\TRANSPORT
const TRANSPORT
Definition: ezcollaborationnotificationhandler.php:20
eZCollaborationNotificationHandler\__construct
__construct()
Definition: ezcollaborationnotificationhandler.php:22
eZCollaborationNotificationHandler\collaborationHandlers
collaborationHandlers()
Definition: ezcollaborationnotificationhandler.php:56
eZCollaborationNotificationHandler\fetchHttpInput
fetchHttpInput( $http, $module)
Definition: ezcollaborationnotificationhandler.php:134
eZCollaborationNotificationHandler\attribute
attribute( $attr)
Definition: ezcollaborationnotificationhandler.php:39
eZCollaborationNotificationRule\create
static create( $collaborationIdentifier, $userID=false)
Definition: ezcollaborationnotificationrule.php:48
eZCollaborationNotificationRule\removeByIdentifier
static removeByIdentifier( $collaborationIdentifier, $userID=false)
Definition: ezcollaborationnotificationrule.php:75
eZCollaborationNotificationRule\cleanup
static cleanup()
Definition: ezcollaborationnotificationrule.php:100
eZCollaborationNotificationRule\fetchList
static fetchList( $userID=false, $asObject=true)
Definition: ezcollaborationnotificationrule.php:56
eZDebugSetting\writeDebug
static writeDebug( $conditionName, $string, $label="")
Definition: ezdebugsetting.php:127
eZNotificationCollection\fetchListForHandler
static fetchListForHandler( $handler, $eventID, $transport)
Definition: eznotificationcollection.php:109
eZNotificationEventHandler
The class eZNotificationEventHandler does.
Definition: eznotificationeventhandler.php:18
eZNotificationEventHandler\EVENT_SKIPPED
const EVENT_SKIPPED
Definition: eznotificationeventhandler.php:20
eZNotificationEventHandler\EVENT_HANDLED
const EVENT_HANDLED
Definition: eznotificationeventhandler.php:19
eZNotificationEventHandler\attributes
attributes()
Definition: eznotificationeventhandler.php:36
eZNotificationEventHandler\attribute
attribute( $attr)
Definition: eznotificationeventhandler.php:47
eZNotificationTransport\instance
static instance( $transport=false, $forceNewInstance=false)
Definition: eznotificationtransport.php:26
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.