[ 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/handler/ezcollaborationnotification/ -> ezcollaborationnotificationhandler.php (source)

   1  <?php
   2  //
   3  // Definition of eZCollaborationNotificationHandler class
   4  //
   5  // Created on: <09-Jul-2003 16:37:01 amos>
   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 ezcollaborationnotificationhandler.php
  30  */
  31  
  32  /*!
  33    \class eZCollaborationNotificationHandler ezcollaborationnotificationhandler.php
  34    \brief The class eZCollaborationNotificationHandler does
  35  
  36  */
  37  
  38  define( 'EZ_COLLABORATION_NOTIFICATION_HANDLER_ID', 'ezcollaboration' );
  39  define( 'EZ_COLLABORATION_NOTIFICATION_HANDLER_TRANSPORT', 'ezmail' );
  40  
  41  include_once ( 'kernel/classes/notification/eznotificationeventhandler.php' );
  42  include_once ( 'kernel/classes/ezcollaborationitemhandler.php' );
  43  include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' );
  44  include_once ( 'kernel/classes/notification/eznotificationcollection.php' );
  45  include_once ( 'kernel/classes/notification/eznotificationschedule.php' );
  46  include_once ( 'kernel/classes/notification/handler/ezcollaborationnotification/ezcollaborationnotificationrule.php' );
  47  
  48  class eZCollaborationNotificationHandler extends eZNotificationEventHandler
  49  {
  50      /*!
  51       Constructor
  52      */
  53      function eZCollaborationNotificationHandler()
  54      {
  55          $this->eZNotificationEventHandler( EZ_COLLABORATION_NOTIFICATION_HANDLER_ID, "Collaboration Handler" );
  56      }
  57  
  58      function attributes()
  59      {
  60          return array_merge( array( 'collaboration_handlers',
  61                                     'collaboration_selections' ),
  62                              eZNotificationEventHandler::attributes() );
  63      }
  64  
  65      function hasAttribute( $attr )
  66      {
  67          return in_array( $attr, $this->attributes() );
  68      }
  69  
  70      function &attribute( $attr )
  71      {
  72          if ( $attr == 'collaboration_handlers' )
  73          {
  74              return $this->collaborationHandlers();
  75          }
  76          else if ( $attr == 'collaboration_selections' )
  77          {
  78              $selections = $this->collaborationSelections();
  79              return $selections;
  80          }
  81          return eZNotificationEventHandler::attribute( $attr );
  82      }
  83  
  84      /*!
  85       Returns the available collaboration handlers.
  86      */
  87      function &collaborationHandlers()
  88      {
  89          return eZCollaborationItemHandler::fetchList();
  90      }
  91  
  92      /*!
  93      */
  94      function collaborationSelections()
  95      {
  96          $rules = eZCollaborationNotificationRule::fetchList();
  97          $selection = array();
  98          for ( $i = 0; $i < count( $rules ); ++$i )
  99          {
 100              $rule =& $rules[$i];
 101              $selection[] = $rule->attribute( 'collab_identifier' );
 102          }
 103          return $selection;
 104      }
 105  
 106      function handle( &$event )
 107      {
 108          eZDebugSetting::writeDebug( 'kernel-notification', $event, "trying to handle event" );
 109          if ( $event->attribute( 'event_type_string' ) == 'ezcollaboration' )
 110          {
 111              $parameters = array();
 112              $status = $this->handleCollaborationEvent( $event, $parameters );
 113              if ( $status == EZ_NOTIFICATIONEVENTHANDLER_EVENT_HANDLED )
 114                  $this->sendMessage( $event, $parameters );
 115              else
 116                  return false;
 117          }
 118          return true;
 119      }
 120  
 121      function handleCollaborationEvent( &$event, &$parameters )
 122      {
 123          $collaborationItem =& $event->attribute( 'content' );
 124          if ( !$collaborationItem )
 125              return EZ_NOTIFICATIONEVENTHANDLER_EVENT_SKIPPED;
 126          $collaborationHandler =& $collaborationItem->attribute( 'handler' );
 127          return $collaborationHandler->handleCollaborationEvent( $event, $collaborationItem, $parameters );
 128      }
 129  
 130      function sendMessage( &$event, $parameters )
 131      {
 132          $collections = eZNotificationCollection::fetchListForHandler( EZ_COLLABORATION_NOTIFICATION_HANDLER_ID,
 133                                                                        $event->attribute( 'id' ),
 134                                                                        EZ_COLLABORATION_NOTIFICATION_HANDLER_TRANSPORT );
 135          foreach ( array_keys( $collections ) as $collectionKey )
 136          {
 137              $collection =& $collections[$collectionKey];
 138              $items =& $collection->attribute( 'items_to_send' );
 139              $addressList = array();
 140              foreach ( array_keys( $items ) as $key )
 141              {
 142                  $addressList[] = $items[$key]->attribute( 'address' );
 143                  $items[$key]->remove();
 144              }
 145              $transport =& eZNotificationTransport::instance( 'ezmail' );
 146              $transport->send( $addressList, $collection->attribute( 'data_subject' ), $collection->attribute( 'data_text' ), null,
 147                                $parameters );
 148              if ( $collection->attribute( 'item_count' ) == 0 )
 149              {
 150                  $collection->remove();
 151              }
 152          }
 153      }
 154  
 155      function &rules( $user = false )
 156      {
 157          if ( $user === false )
 158          {
 159              $user =& eZUser::currentUser();
 160          }
 161          $email = $user->attribute( 'email' );
 162  
 163          $ruleList = eZCollaborationNotificationRule::fetchList( $email );
 164          return $ruleList;
 165      }
 166  
 167      function fetchHttpInput( &$http, &$module )
 168      {
 169          if ( $http->hasPostVariable( 'CollaborationHandlerSelection'  ) )
 170          {
 171              $oldSelection = $this->collaborationSelections();
 172              $selection = array();
 173              if ( $http->hasPostVariable( 'CollaborationHandlerSelection_' . EZ_COLLABORATION_NOTIFICATION_HANDLER_ID  ) )
 174                  $selection = $http->postVariable( 'CollaborationHandlerSelection_' . EZ_COLLABORATION_NOTIFICATION_HANDLER_ID );
 175              $createRules = array_diff( $selection, $oldSelection );
 176              $removeRules = array_diff( $oldSelection, $selection );
 177              if ( count( $removeRules ) > 0 )
 178                  eZCollaborationNotificationRule::removeByIdentifier( array( $removeRules ) );
 179              foreach ( $createRules as $createRule )
 180              {
 181                  $rule = eZCollaborationNotificationRule::create( $createRule );
 182                  $rule->store();
 183              }
 184          }
 185      }
 186  
 187      /*!
 188       \reimp
 189      */
 190      function cleanup()
 191      {
 192          eZCollaborationNotificationRule::cleanup();
 193      }
 194  }
 195  
 196  ?>


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