eZ Publish  [4.0]
eznotificationeventtype.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZNotificationEventType class
00004 //
00005 // Created on: <12-May-2003 09:58:12 sp>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file eznotificationeventtype.php
00032 */
00033 
00034 /*!
00035   \class eZNotificationEventType eznotificationeventtype.php
00036   \brief The class eZNotificationEventType does
00037 
00038 */
00039 
00040 class eZNotificationEventType
00041 {
00042     /*!
00043      Constructor
00044     */
00045     function eZNotificationEventType( $notificationEventTypeString )
00046     {
00047         $this->NotificationEventTypeString = $notificationEventTypeString;
00048     }
00049 
00050     function initializeEvent( $event, $params )
00051     {
00052     }
00053 
00054     /*!
00055      \static
00056      Crates a datatype instance of the datatype string id \a $dataTypeString.
00057      \note It only creates one instance for each datatype.
00058     */
00059     static function create( $notificationEventTypeString )
00060     {
00061         $types =& $GLOBALS["eZNotificationEventTypes"];
00062         if( !isset( $types[$notificationEventTypeString] ) )
00063         {
00064             eZDebugSetting::writeDebug( 'kernel-notification', $types, 'notification types' );
00065             eZNotificationEventType::loadAndRegisterType( $notificationEventTypeString );
00066             eZDebugSetting::writeDebug( 'kernel-notification', $types, 'notification types 2' );
00067         }
00068         $def = null;
00069         if ( isset( $types[$notificationEventTypeString] ) )
00070         {
00071             $className = $types[$notificationEventTypeString];
00072             $def =& $GLOBALS["eZNotificationEventTypeObjects"][$notificationEventTypeString];
00073 
00074             if ( !is_object( $def ) || strtolower( get_class( $def ) ) != $className )
00075             {
00076                 $def = new $className();
00077             }
00078         }
00079         return $def;
00080     }
00081 
00082 
00083     function attributes()
00084     {
00085         return array_merge( array( 'description' ),
00086                             array_keys( $this->Attributes ) );
00087     }
00088 
00089     function hasAttribute( $attr )
00090     {
00091         return in_array( $attr, $this->attributes() );
00092     }
00093 
00094     function attribute( $attr )
00095     {
00096         if ( $attr == "description" )
00097         {
00098             return  $this->eventDescription();
00099         }
00100         if ( isset( $this->Attributes[$attr] ) )
00101         {
00102             return $this->Attributes[$attr];
00103         }
00104 
00105         eZDebug::writeError( "Attribute '$attr' does not exist", 'eZNotificationEventType::attribute' );
00106         return null;
00107     }
00108 
00109     function eventDescription()
00110     {
00111         return $this->Attributes["name"];
00112     }
00113 
00114     function execute( $event )
00115     {
00116     }
00117 
00118     function eventContent( $event )
00119     {
00120         return "";
00121     }
00122 
00123     static function allowedTypes()
00124     {
00125         $allowedTypes = $GLOBALS["eZNotificationEventTypeAllowedTypes"];
00126         if ( !is_array( $allowedTypes ) )
00127         {
00128             $notificationINI = eZINI::instance( 'notification.ini' );
00129             $eventTypes = $notificationINI->variable( 'NotificationEventTypeSettings', 'AvailableEventTypes' );
00130             $allowedTypes = array_unique( $eventTypes );
00131         }
00132         return $allowedTypes;
00133     }
00134 
00135     static function loadAndRegisterAllTypes()
00136     {
00137         $allowedTypes = eZNotificationEventType::allowedTypes();
00138         foreach( $allowedTypes as $type )
00139         {
00140             eZNotificationEventType::loadAndRegisterType( $type );
00141         }
00142     }
00143 
00144     static function loadAndRegisterType( $type )
00145     {
00146         $types = $GLOBALS["eZNotificationEventTypes"];
00147         if ( isset( $types[$type] ) )
00148         {
00149             eZDebug::writeError( "Notification event type already registered: $type", "eZNotificationEventType::loadAndRegisterType" );
00150             return false;
00151         }
00152 
00153         //include_once( 'lib/ezutils/classes/ezextension.php' );
00154         $baseDirectory = eZExtension::baseDirectory();
00155         $notificationINI = eZINI::instance( 'notification.ini' );
00156         $repositoryDirectories = $notificationINI->variable( 'NotificationEventTypeSettings', 'RepositoryDirectories' );
00157         $extensionDirectories = $notificationINI->variable( 'NotificationEventTypeSettings', 'ExtensionDirectories' );
00158         foreach ( $extensionDirectories as $extensionDirectory )
00159         {
00160             $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/notificationtypes';
00161             if ( file_exists( $extensionPath ) )
00162                 $repositoryDirectories[] = $extensionPath;
00163         }
00164         $foundEventType = false;
00165         foreach ( $repositoryDirectories as $repositoryDirectory )
00166         {
00167             $includeFile = "$repositoryDirectory/$type/" . $type . "type.php";
00168             if ( file_exists( $includeFile ) )
00169             {
00170                 $foundEventType = true;
00171                 break;
00172             }
00173         }
00174         if ( !$foundEventType )
00175         {
00176             eZDebug::writeError( "Notification event type not found: $type, searched in these directories: " . implode( ', ', $repositoryDirectories ), "eZNotificationEventType::loadAndRegisterType" );
00177             return false;
00178         }
00179         include_once( $includeFile );
00180         return true;
00181     }
00182 
00183     static function register( $notificationTypeString, $className )
00184     {
00185         if ( !isset( $GLOBALS["eZNotificationEventTypes"] ) || !is_array( $GLOBALS["eZNotificationEventTypes"] ) )
00186         {
00187             $types = array();
00188         }
00189         $GLOBALS["eZNotificationEventTypes"][$notificationTypeString] = $className;
00190     }
00191 
00192 
00193 
00194 
00195 }
00196 
00197 ?>