| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZGeneralDigestHandler class 4 // 5 // Created on: <16-May-2003 10:55:24 sp> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezgeneraldigesthandler.php 30 */ 31 32 /*! 33 \class eZGeneralDigestHandler ezgeneraldigesthandler.php 34 \brief The class eZGeneralDigestHandler does 35 36 */ 37 include_once ( 'kernel/classes/notification/eznotificationeventhandler.php' ); 38 include_once ( 'kernel/classes/notification/eznotificationcollection.php' ); 39 define( 'EZ_GENERALDIGEST_NOTIFICATION_HANDLER_ID', 'ezgeneraldigest' ); 40 include_once ( 'kernel/classes/notification/handler/ezgeneraldigest/ezgeneraldigestusersettings.php' ); 41 42 class eZGeneralDigestHandler extends eZNotificationEventHandler 43 { 44 /*! 45 Constructor 46 */ 47 function eZGeneralDigestHandler() 48 { 49 $this->eZNotificationEventHandler( EZ_GENERALDIGEST_NOTIFICATION_HANDLER_ID, "General Digest Handler" ); 50 51 } 52 53 function attributes() 54 { 55 return array_merge( array( 'settings', 56 'all_week_days', 57 'all_month_days', 58 'available_hours' ), 59 eZNotificationEventHandler::attributes() ); 60 } 61 62 function hasAttribute( $attr ) 63 { 64 return in_array( $attr, $this->attributes() ); 65 } 66 67 function &attribute( $attr ) 68 { 69 if ( $attr == 'settings' ) 70 { 71 $user =& eZUser::currentUser(); 72 $settings =& $this->settings( $user ); 73 return $settings; 74 } 75 else if ( $attr == 'all_week_days' ) 76 { 77 $locale =& eZLocale::instance(); 78 $nameList =& $locale->attribute( 'weekday_name_list' ); 79 return $nameList; 80 } 81 else if ( $attr == 'all_month_days' ) 82 { 83 $range = range( 1, 31 ); 84 return $range; 85 } 86 else if ( $attr == 'available_hours' ) 87 { 88 $hours = array( '0:00', 89 '1:00', 90 '2:00', 91 '3:00', 92 '4:00', 93 '5:00', 94 '6:00', 95 '7:00', 96 '8:00', 97 '9:00', 98 '10:00', 99 '11:00', 100 '12:00', 101 '13:00', 102 '14:00', 103 '15:00', 104 '16:00', 105 '17:00', 106 '18:00', 107 '19:00', 108 '20:00', 109 '21:00', 110 '22:00', 111 '23:00' ); 112 return $hours; 113 } 114 return eZNotificationEventHandler::attribute( $attr ); 115 } 116 117 function &settings( $user = false ) 118 { 119 if ( $user === false ) 120 { 121 $user =& eZUser::currentUser(); 122 } 123 $address = $user->attribute( 'email' ); 124 $settings = eZGeneralDigestUserSettings::fetchForUser( $address ); 125 if ( $settings == null ) 126 { 127 $settings = eZGeneralDigestUserSettings::create( $address ); 128 $settings->store(); 129 } 130 return $settings; 131 } 132 133 function handle( &$event ) 134 { 135 eZDebugSetting::writeDebug( 'kernel-notification', $event, "trying to handle event" ); 136 if ( $event->attribute( 'event_type_string' ) == 'ezcurrenttime' ) 137 { 138 $date =& $event->content(); 139 $timestamp = $date->attribute( 'timestamp' ); 140 141 $addressArray = $this->fetchUsersForDigest( $timestamp ); 142 143 include_once ( 'kernel/common/template.php' ); 144 $tpl =& templateInit(); 145 146 foreach ( $addressArray as $address ) 147 { 148 $tpl->setVariable( 'date', $date ); 149 $tpl->setVariable( 'address', $address['address'] ); 150 $result = $tpl->fetch( 'design:notification/handler/ezgeneraldigest/view/plain.tpl' ); 151 $subject = $tpl->variable( 'subject' ); 152 $transport =& eZNotificationTransport::instance( 'ezmail' ); 153 $transport->send( $address, $subject, $result); 154 eZDebugSetting::writeDebug( 'kernel-notification', $result, "digest result" ); 155 } 156 157 $collectionItemIDList =& $tpl->variable( 'collection_item_id_list' ); 158 eZDebugSetting::writeDebug( 'kernel-notification', $collectionItemIDList, "handled items" ); 159 160 if ( is_array( $collectionItemIDList ) && count( $collectionItemIDList ) > 0 ) 161 { 162 $ini =& eZINI::instance( 'notification.ini' ); 163 $countElements = $ini->variable( 'RuleSettings', 'LimitDeleteElements' ); 164 if ( !$countElements ) 165 { 166 $countElements = 50; 167 } 168 $splited = array_chunk( $collectionItemIDList, $countElements ); 169 foreach ( $splited as $key => $value ) 170 { 171 eZPersistentObject::removeObject( eZNotificationCollectionItem::definition(), array( 'id' => array( $value, '' ) ) ); 172 } 173 } 174 175 } 176 return true; 177 } 178 179 180 function fetchUsersForDigest( $timestamp ) 181 { 182 return eZPersistentObject::fetchObjectList( eZNotificationCollectionItem::definition(), 183 array(), array( 'send_date' => array( '', array( 1, $timestamp ) ) ), 184 array( 'address' => 'asc' ),null, 185 false,false,array( array( 'operation' => 'distinct address' ) ) ); 186 187 } 188 189 function fetchHandlersForUser( $time, $address ) 190 { 191 $db =& eZDB::instance(); 192 193 $time = (int)$time; 194 $address = $db->escapeString( $address ); 195 196 $query = "select distinct handler 197 from eznotificationcollection, 198 eznotificationcollection_item 199 where eznotificationcollection_item.collection_id = eznotificationcollection.id and 200 address='$address' and 201 send_date != 0 and 202 send_date < $time"; 203 $handlerResult = $db->arrayQuery( $query ); 204 $handlers = array(); 205 $availableHandlers =& eZNotificationEventFilter::availableHandlers(); 206 foreach ( $handlerResult as $handlerName ) 207 { 208 $handlers[$handlerName['handler']] =& $availableHandlers[$handlerName['handler']]; 209 } 210 return $handlers; 211 } 212 213 function fetchItemsForUser( $time, $address, $handler ) 214 { 215 $db =& eZDB::instance(); 216 217 $time = (int)$time; 218 $address = $db->escapeString( $address ); 219 $handler = $db->escapeString( $handler ); 220 221 $query = "select eznotificationcollection_item.* 222 from eznotificationcollection, 223 eznotificationcollection_item 224 where eznotificationcollection_item.collection_id = eznotificationcollection.id and 225 address='$address' and 226 send_date != 0 and 227 send_date < $time and 228 handler = '$handler' 229 order by eznotificationcollection_item.event_id"; 230 $itemResult = $db->arrayQuery( $query ); 231 $items = array(); 232 foreach ( $itemResult as $itemRow ) 233 { 234 $items[] = new eZNotificationCollectionItem( $itemRow ); 235 } 236 return $items; 237 } 238 239 function storeSettings( &$http, &$module ) 240 { 241 $user =& eZUser::currentUser(); 242 $address = $user->attribute( 'email' ); 243 $settings = eZGeneralDigestUserSettings::fetchForUser( $address ); 244 245 if ( $http->hasPostVariable( 'ReceiveDigest_' . EZ_GENERALDIGEST_NOTIFICATION_HANDLER_ID ) && 246 $http->hasPostVariable( 'ReceiveDigest_' . EZ_GENERALDIGEST_NOTIFICATION_HANDLER_ID ) == '1' ) 247 { 248 $settings->setAttribute( 'receive_digest', 1 ); 249 $digestType = $http->postVariable( 'DigestType_' . EZ_GENERALDIGEST_NOTIFICATION_HANDLER_ID ); 250 $settings->setAttribute( 'digest_type', $digestType ); 251 if ( $digestType == 1 ) 252 { 253 $settings->setAttribute( 'day', $http->postVariable( 'Weekday_' . EZ_GENERALDIGEST_NOTIFICATION_HANDLER_ID ) ); 254 } 255 else if ( $digestType == 2 ) 256 { 257 $settings->setAttribute( 'day', $http->postVariable( 'Monthday_' . EZ_GENERALDIGEST_NOTIFICATION_HANDLER_ID ) ); 258 } 259 $settings->setAttribute( 'time', $http->postVariable( 'Time_' . EZ_GENERALDIGEST_NOTIFICATION_HANDLER_ID ) ); 260 $settings->store(); 261 } 262 else 263 { 264 $settings->setAttribute( 'receive_digest', 0 ); 265 $settings->store(); 266 } 267 } 268 269 /*! 270 \reimp 271 */ 272 function cleanup() 273 { 274 eZGeneralDigestUserSettings::cleanup(); 275 } 276 277 } 278 279 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |