Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezgeneraldigesthandler.php
Go to the documentation of this file.
1 <?php
16 class eZGeneralDigestHandler extends eZNotificationEventHandler
17 {
18 const NOTIFICATION_HANDLER_ID = 'ezgeneraldigest';
19
20 public function __construct()
21 {
22 parent::__construct( self::NOTIFICATION_HANDLER_ID, "General Digest Handler" );
23
24 }
25
26 function attributes()
27 {
28 return array_merge( array( 'settings',
29 'all_week_days',
30 'all_month_days',
31 'available_hours' ),
32 eZNotificationEventHandler::attributes() );
33 }
34
35 function hasAttribute( $attr )
36 {
37 return in_array( $attr, $this->attributes() );
38 }
39
40 function attribute( $attr )
41 {
42 if ( $attr == 'settings' )
43 {
44 return $this->settings( eZUser::currentUser() );
45 }
46 else if ( $attr == 'all_week_days' )
47 {
48 return eZLocale::instance()->attribute( 'weekday_name_list' );
49 }
50 else if ( $attr == 'all_month_days' )
51 {
52 return range( 1, 31 );
53 }
54 else if ( $attr == 'available_hours' )
55 {
56 return array( '0:00',
57 '1:00',
58 '2:00',
59 '3:00',
60 '4:00',
61 '5:00',
62 '6:00',
63 '7:00',
64 '8:00',
65 '9:00',
66 '10:00',
67 '11:00',
68 '12:00',
69 '13:00',
70 '14:00',
71 '15:00',
72 '16:00',
73 '17:00',
74 '18:00',
75 '19:00',
76 '20:00',
77 '21:00',
78 '22:00',
79 '23:00' );
80 }
81 return eZNotificationEventHandler::attribute( $attr );
82 }
83
84 function settings( $user = false )
85 {
86 if ( $user === false )
87 {
88 $user = eZUser::currentUser();
89 }
90 $settings = eZGeneralDigestUserSettings::fetchByUserId( $user->attribute( 'contentobject_id' ) );
91 if ( $settings == null )
92 {
93 $settings = eZGeneralDigestUserSettings::create( $user->attribute( 'contentobject_id' ) );
94 $settings->store();
95 }
96 return $settings;
97 }
98
99 function handle( $event )
100 {
101 eZDebugSetting::writeDebug( 'kernel-notification', $event, "trying to handle event" );
102 if ( $event->attribute( 'event_type_string' ) == 'ezcurrenttime' )
103 {
104 $date = $event->content();
105 $timestamp = $date->attribute( 'timestamp' );
106
107 $addressArray = $this->fetchUsersForDigest( $timestamp );
108
109 $tpl = eZTemplate::factory();
110 $prevTplUsageStats = $tpl->setIsTemplatesUsageStatisticsEnabled( false );
111
112 $transport = eZNotificationTransport::instance( 'ezmail' );
113 foreach ( $addressArray as $address )
114 {
115 $tpl->setVariable( 'date', $date );
116 $tpl->setVariable( 'address', $address['address'] );
117 $result = $tpl->fetch( 'design:notification/handler/ezgeneraldigest/view/plain.tpl' );
118 $subject = $tpl->variable( 'subject' );
119
120 $parameters = array();
121 if ( $tpl->hasVariable( 'content_type' ) )
122 $parameters['content_type'] = $tpl->variable( 'content_type' );
123
124 $transport->send( $address, $subject, $result, null, $parameters );
125 eZDebugSetting::writeDebug( 'kernel-notification', $result, "digest result" );
126 }
127
128 $collectionItemIDList = $tpl->variable( 'collection_item_id_list' );
129 eZDebugSetting::writeDebug( 'kernel-notification', $collectionItemIDList, "handled items" );
130
131 $tpl->setIsTemplatesUsageStatisticsEnabled( $prevTplUsageStats );
132
133 if ( is_array( $collectionItemIDList ) && count( $collectionItemIDList ) > 0 )
134 {
135 $ini = eZINI::instance( 'notification.ini' );
136 $countElements = $ini->variable( 'RuleSettings', 'LimitDeleteElements' );
137 if ( !$countElements )
138 {
139 $countElements = 50;
140 }
141 $splited = array_chunk( $collectionItemIDList, $countElements );
142 foreach ( $splited as $key => $value )
143 {
144 eZPersistentObject::removeObject( eZNotificationCollectionItem::definition(), array( 'id' => array( $value, '' ) ) );
145 }
146 }
147
148 }
149 return true;
150 }
151
152
153 function fetchUsersForDigest( $timestamp )
154 {
155 return eZPersistentObject::fetchObjectList( eZNotificationCollectionItem::definition(),
156 array(), array( 'send_date' => array( '', array( 1, $timestamp ) ) ),
157 array( 'address' => 'asc' ),null,
158 false,false,array( array( 'operation' => 'distinct address' ) ) );
159
160 }
161
162 static function fetchHandlersForUser( $time, $address )
163 {
164 $db = eZDB::instance();
165
166 $time = (int)$time;
167 $address = $db->escapeString( $address );
168
169 $query = "select distinct handler
170 from eznotificationcollection,
171 eznotificationcollection_item
172 where eznotificationcollection_item.collection_id = eznotificationcollection.id and
173 address='$address' and
174 send_date != 0 and
175 send_date < $time";
176 $handlerResult = $db->arrayQuery( $query );
177 $handlers = array();
178 $availableHandlers = eZNotificationEventFilter::availableHandlers();
179 foreach ( $handlerResult as $handlerName )
180 {
181 $handlers[$handlerName['handler']] = $availableHandlers[$handlerName['handler']];
182 }
183 return $handlers;
184 }
185
186 static function fetchItemsForUser( $time, $address, $handler )
187 {
188 $db = eZDB::instance();
189
190 $time = (int)$time;
191 $address = $db->escapeString( $address );
192 $handler = $db->escapeString( $handler );
193
194 $query = "select eznotificationcollection_item.*
195 from eznotificationcollection,
196 eznotificationcollection_item
197 where eznotificationcollection_item.collection_id = eznotificationcollection.id and
198 address='$address' and
199 send_date != 0 and
200 send_date < $time and
201 handler = '$handler'
202 order by eznotificationcollection_item.event_id";
203 $itemResult = $db->arrayQuery( $query );
204 $items = array();
205 foreach ( $itemResult as $itemRow )
206 {
207 $items[] = new eZNotificationCollectionItem( $itemRow );
208 }
209 return $items;
210 }
211
212 function storeSettings( $http, $module )
213 {
214 $user = eZUser::currentUser();
215 $settings = eZGeneralDigestUserSettings::fetchByUserId( $user->attribute( 'contentobject_id' ) );
216
217 if ( $http->hasPostVariable( 'ReceiveDigest_' . self::NOTIFICATION_HANDLER_ID ) &&
218 $http->hasPostVariable( 'ReceiveDigest_' . self::NOTIFICATION_HANDLER_ID ) == '1' )
219 {
220 $settings->setAttribute( 'receive_digest', 1 );
221 $digestType = $http->postVariable( 'DigestType_' . self::NOTIFICATION_HANDLER_ID );
222 $settings->setAttribute( 'digest_type', $digestType );
223 if ( $digestType == 1 )
224 {
225 $settings->setAttribute( 'day', $http->postVariable( 'Weekday_' . self::NOTIFICATION_HANDLER_ID ) );
226 }
227 else if ( $digestType == 2 )
228 {
229 $settings->setAttribute( 'day', $http->postVariable( 'Monthday_' . self::NOTIFICATION_HANDLER_ID ) );
230 }
231 $settings->setAttribute( 'time', $http->postVariable( 'Time_' . self::NOTIFICATION_HANDLER_ID ) );
232 $settings->store();
233 }
234 else
235 {
236 $settings->setAttribute( 'receive_digest', 0 );
237 $settings->store();
238 }
239 }
240
241 function cleanup()
242 {
243 eZGeneralDigestUserSettings::cleanup();
244 }
245
246 }
247
248 ?>
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
eZGeneralDigestHandler
The class eZGeneralDigestHandler does.
Definition: ezgeneraldigesthandler.php:17
eZGeneralDigestHandler\cleanup
cleanup()
Definition: ezgeneraldigesthandler.php:241
eZGeneralDigestHandler\NOTIFICATION_HANDLER_ID
const NOTIFICATION_HANDLER_ID
Definition: ezgeneraldigesthandler.php:18
eZGeneralDigestHandler\handle
handle( $event)
Definition: ezgeneraldigesthandler.php:99
eZGeneralDigestHandler\fetchUsersForDigest
fetchUsersForDigest( $timestamp)
Definition: ezgeneraldigesthandler.php:153
eZGeneralDigestHandler\settings
settings( $user=false)
Definition: ezgeneraldigesthandler.php:84
eZGeneralDigestHandler\fetchItemsForUser
static fetchItemsForUser( $time, $address, $handler)
Definition: ezgeneraldigesthandler.php:186
eZGeneralDigestHandler\attribute
attribute( $attr)
Definition: ezgeneraldigesthandler.php:40
eZGeneralDigestHandler\__construct
__construct()
Definition: ezgeneraldigesthandler.php:20
eZGeneralDigestHandler\fetchHandlersForUser
static fetchHandlersForUser( $time, $address)
Definition: ezgeneraldigesthandler.php:162
eZGeneralDigestHandler\storeSettings
storeSettings( $http, $module)
Definition: ezgeneraldigesthandler.php:212
eZGeneralDigestHandler\hasAttribute
hasAttribute( $attr)
Definition: ezgeneraldigesthandler.php:35
eZGeneralDigestHandler\attributes
attributes()
Definition: ezgeneraldigesthandler.php:26
eZGeneralDigestUserSettings\create
static create( $userID, $receiveDigest=0, $digestType=self::TYPE_NONE, $day='', $time='')
Definition: ezgeneraldigestusersettings.php:77
eZGeneralDigestUserSettings\cleanup
static cleanup()
Definition: ezgeneraldigestusersettings.php:156
eZGeneralDigestUserSettings\fetchByUserId
static fetchByUserId( $userId, $asObject=true)
Definition: ezgeneraldigestusersettings.php:115
eZLocale\instance
static instance( $localeString=false)
Definition: ezlocale.php:1536
eZNotificationCollectionItem
The class eZNotificationCollectionItem does.
Definition: eznotificationcollectionitem.php:18
eZNotificationCollectionItem\definition
static definition()
Definition: eznotificationcollectionitem.php:19
eZNotificationEventFilter\availableHandlers
static availableHandlers()
Definition: eznotificationeventfilter.php:65
eZNotificationEventHandler
The class eZNotificationEventHandler does.
Definition: eznotificationeventhandler.php:18
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
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZTemplate\factory
static factory()
Definition: eztemplate.php:2380
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.