[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/notification/ -> eznotificationeventfilter.php (source)

   1  <?php
   2  //
   3  // Definition of eZNotificationEventFilter class
   4  //
   5  // Created on: <09-May-2003 16:05:40 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 eznotificationeventfilter.php
  30  */
  31  
  32  /*!
  33    \class eZNotificationEventFilter eznotificationeventfilter.php
  34    \brief The class eZNotificationEventFilter does
  35  
  36  */
  37  include_once ( 'kernel/classes/notification/eznotificationevent.php' );
  38  class eZNotificationEventFilter
  39  {
  40      /*!
  41       Constructor
  42      */
  43      function eZNotificationEventFilter()
  44      {
  45      }
  46  
  47      /*!
  48       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
  49       the calls within a db transaction; thus within db->begin and db->commit.
  50       */
  51      function process()
  52      {
  53          $eventList = eZNotificationEvent::fetchUnhandledList();
  54          $availableHandlers =& eZNotificationEventFilter::availableHandlers();
  55          foreach( array_keys( $eventList ) as $key )
  56          {
  57              $event =& $eventList[$key];
  58              foreach( array_keys( $availableHandlers ) as $handlerKey )
  59              {
  60                  $handler =& $availableHandlers[$handlerKey];
  61                  if ( $handler === false )
  62                  {
  63                      eZDebug::writeError( "Notification handler does not exist: $handlerKey", 'eZNotificationEventFilter::process()' );
  64                  }
  65                  else
  66                  {
  67                      $handler->handle( $event );
  68                  }
  69              }
  70              $itemCountLeft = eZNotificationCollectionItem::fetchCountForEvent( $event->attribute( 'id' ) );
  71              if ( $itemCountLeft == 0 )
  72              {
  73                  $event->remove();
  74              }
  75              else
  76              {
  77                  $event->setAttribute( 'status', EZ_NOTIFICATIONEVENT_STATUS_HANDLED );
  78                  $event->store();
  79              }
  80          }
  81          eZNotificationCollection::removeEmpty();
  82      }
  83  
  84      function &availableHandlers()
  85      {
  86          include_once ( 'lib/ezutils/classes/ezextension.php' );
  87          $baseDirectory = eZExtension::baseDirectory();
  88          $notificationINI =& eZINI::instance( 'notification.ini' );
  89          $availableHandlers = $notificationINI->variable( 'NotificationEventHandlerSettings', 'AvailableNotificationEventTypes' );
  90          $repositoryDirectories = array();
  91          $extensionDirectories = $notificationINI->variable( 'NotificationEventHandlerSettings', 'ExtensionDirectories' );
  92          foreach ( $extensionDirectories as $extensionDirectory )
  93          {
  94              $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/notification/handler';
  95              if ( file_exists( $extensionPath ) )
  96                  $repositoryDirectories[] = $extensionPath;
  97          }
  98          $handlers = array();
  99          foreach( $availableHandlers as $handlerString )
 100          {
 101              $eventHandler = eZNotificationEventFilter::loadHandler( $repositoryDirectories, $handlerString );
 102              if ( is_object( $eventHandler ) )
 103                  $handlers[$handlerString] = $eventHandler;
 104          }
 105          return $handlers;
 106      }
 107  
 108      function loadHandler( $directories, $handlerString )
 109      {
 110          $foundHandler = false;
 111          $includeFile = '';
 112  
 113  
 114          include_once ( 'lib/ezutils/classes/ezextension.php' );
 115          $baseDirectory = eZExtension::baseDirectory();
 116          $notificationINI =& eZINI::instance( 'notification.ini' );
 117          $repositoryDirectories = $notificationINI->variable( 'NotificationEventHandlerSettings', 'RepositoryDirectories' );
 118          $extensionDirectories = $notificationINI->variable( 'NotificationEventHandlerSettings', 'ExtensionDirectories' );
 119          foreach ( $extensionDirectories as $extensionDirectory )
 120          {
 121              $extensionPath = "{$baseDirectory}/{$extensionDirectory}/notification/handler/";        
 122              if ( file_exists( $extensionPath ) )
 123                  $repositoryDirectories[] = $extensionPath;
 124          }
 125  
 126          foreach ( $repositoryDirectories as $repositoryDirectory )
 127          {
 128              $repositoryDirectory = trim( $repositoryDirectory, '/' );
 129              $includeFile = "{$repositoryDirectory}/{$handlerString}/{$handlerString}handler.php";
 130              if ( file_exists( $includeFile ) )
 131              {
 132                  $foundHandler = true;
 133                  break;
 134              }
 135          }
 136          if ( !$foundHandler  )
 137          {
 138              eZDebug::writeError( "Notification handler does not exist: $handlerString", 'eZNotificationEventFilter::loadHandler()' );
 139              return false;
 140          }
 141          include_once( $includeFile );
 142          $className = $handlerString . "handler";
 143          return new $className();
 144      }
 145  
 146      /*!
 147       \static
 148       Goes through all event handlers and tells them to cleanup.
 149       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 150       the calls within a db transaction; thus within db->begin and db->commit.
 151      */
 152      function cleanup()
 153      {
 154          $availableHandlers =& eZNotificationEventFilter::availableHandlers();
 155  
 156          $db =& eZDB::instance();
 157          $db->begin();
 158          foreach( array_keys( $availableHandlers ) as $handlerKey )
 159          {
 160              $handler =& $availableHandlers[$handlerKey];
 161              if ( $handler !== false )
 162              {
 163                  $handler->cleanup();
 164              }
 165          }
 166          $db->commit();
 167      }
 168  }
 169  
 170  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7