00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class eZNotificationEventType
00041 {
00042
00043
00044
00045 function eZNotificationEventType( $notificationEventTypeString )
00046 {
00047 $this->NotificationEventTypeString = $notificationEventTypeString;
00048 }
00049
00050 function initializeEvent( &$event, $params )
00051 {
00052 }
00053
00054
00055
00056
00057
00058
00059 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 ( 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 $retValue =& $this->eventDescription();
00098 if ( isset( $this->Attributes[$attr] ) )
00099 return $this->Attributes[$attr];
00100 else
00101 {
00102 eZDebug::writeError( "Attribute '$attr' does not exist", 'eZNotificationEventType::attribute' );
00103 $retValue = null;
00104 }
00105 return $retValue;
00106 }
00107
00108 function &eventDescription()
00109 {
00110 return $this->Attributes["name"];
00111 }
00112
00113 function execute( &$event )
00114 {
00115 }
00116
00117 function eventContent()
00118 {
00119 return "";
00120 }
00121
00122 function allowedTypes()
00123 {
00124 $allowedTypes =& $GLOBALS["eZNotificationEventTypeAllowedTypes"];
00125 if ( !is_array( $allowedTypes ) )
00126 {
00127 $notificationINI =& eZINI::instance( 'notification.ini' );
00128 $eventTypes = $notificationINI->variable( 'NotificationEventTypeSettings', 'AvailableEventTypes' );
00129 $allowedTypes = array_unique( $eventTypes );
00130 }
00131 return $allowedTypes;
00132 }
00133
00134 function loadAndRegisterAllTypes()
00135 {
00136 $allowedTypes = eZNotificationEventType::allowedTypes();
00137 foreach( $allowedTypes as $type )
00138 {
00139 eZNotificationEventType::loadAndRegisterType( $type );
00140 }
00141 }
00142
00143 function loadAndRegisterType( $type )
00144 {
00145 $types =& $GLOBALS["eZNotificationEventTypes"];
00146 if ( isset( $types[$type] ) )
00147 {
00148 eZDebug::writeError( "Notification event type already registered: $type", "eZNotificationEventType::loadAndRegisterType" );
00149 return false;
00150 }
00151
00152 include_once( 'lib/ezutils/classes/ezextension.php' );
00153 $baseDirectory = eZExtension::baseDirectory();
00154 $notificationINI =& eZINI::instance( 'notification.ini' );
00155 $repositoryDirectories = $notificationINI->variable( 'NotificationEventTypeSettings', 'RepositoryDirectories' );
00156 $extensionDirectories = $notificationINI->variable( 'NotificationEventTypeSettings', 'ExtensionDirectories' );
00157 foreach ( $extensionDirectories as $extensionDirectory )
00158 {
00159 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/notificationtypes';
00160 if ( file_exists( $extensionPath ) )
00161 $repositoryDirectories[] = $extensionPath;
00162 }
00163 $foundEventType = false;
00164 foreach ( $repositoryDirectories as $repositoryDirectory )
00165 {
00166 $includeFile = "$repositoryDirectory/$type/" . $type . "type.php";
00167 if ( file_exists( $includeFile ) )
00168 {
00169 $foundEventType = true;
00170 break;
00171 }
00172 }
00173 if ( !$foundEventType )
00174 {
00175 eZDebug::writeError( "Notification event type not found: $type, searched in these directories: " . implode( ', ', $repositoryDirectories ), "eZNotificationEventType::loadAndRegisterType" );
00176 return false;
00177 }
00178 include_once( $includeFile );
00179 return true;
00180 }
00181
00182 function register( $notificationTypeString, $className )
00183 {
00184 $types =& $GLOBALS["eZNotificationEventTypes"];
00185 if ( !is_array( $types ) )
00186 $types = array();
00187 $types[$notificationTypeString] = $className;
00188 }
00189
00190
00191
00192
00193 }
00194
00195 ?>