|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZNotificationEventType class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZNotificationEventType eznotificationeventtype.php 00013 \brief The class eZNotificationEventType does 00014 00015 */ 00016 00017 class eZNotificationEventType 00018 { 00019 /*! 00020 Constructor 00021 */ 00022 function eZNotificationEventType( $notificationEventTypeString ) 00023 { 00024 $this->NotificationEventTypeString = $notificationEventTypeString; 00025 } 00026 00027 function initializeEvent( $event, $params ) 00028 { 00029 } 00030 00031 /*! 00032 \static 00033 Crates a datatype instance of the datatype string id \a $dataTypeString. 00034 \note It only creates one instance for each datatype. 00035 */ 00036 static function create( $notificationEventTypeString ) 00037 { 00038 $types =& $GLOBALS["eZNotificationEventTypes"]; 00039 if( !isset( $types[$notificationEventTypeString] ) ) 00040 { 00041 eZDebugSetting::writeDebug( 'kernel-notification', $types, 'notification types' ); 00042 eZNotificationEventType::loadAndRegisterType( $notificationEventTypeString ); 00043 eZDebugSetting::writeDebug( 'kernel-notification', $types, 'notification types 2' ); 00044 } 00045 $def = null; 00046 if ( isset( $types[$notificationEventTypeString] ) ) 00047 { 00048 $className = $types[$notificationEventTypeString]; 00049 $def =& $GLOBALS["eZNotificationEventTypeObjects"][$notificationEventTypeString]; 00050 00051 if ( !is_object( $def ) || strtolower( get_class( $def ) ) != $className ) 00052 { 00053 $def = new $className(); 00054 } 00055 } 00056 return $def; 00057 } 00058 00059 00060 function attributes() 00061 { 00062 return array_merge( array( 'description' ), 00063 array_keys( $this->Attributes ) ); 00064 } 00065 00066 function hasAttribute( $attr ) 00067 { 00068 return in_array( $attr, $this->attributes() ); 00069 } 00070 00071 function attribute( $attr ) 00072 { 00073 if ( $attr == "description" ) 00074 { 00075 return $this->eventDescription(); 00076 } 00077 if ( isset( $this->Attributes[$attr] ) ) 00078 { 00079 return $this->Attributes[$attr]; 00080 } 00081 00082 eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ ); 00083 return null; 00084 } 00085 00086 function eventDescription() 00087 { 00088 return $this->Attributes["name"]; 00089 } 00090 00091 function execute( $event ) 00092 { 00093 } 00094 00095 function eventContent( $event ) 00096 { 00097 return ""; 00098 } 00099 00100 static function allowedTypes() 00101 { 00102 $allowedTypes = $GLOBALS["eZNotificationEventTypeAllowedTypes"]; 00103 if ( !is_array( $allowedTypes ) ) 00104 { 00105 $notificationINI = eZINI::instance( 'notification.ini' ); 00106 $eventTypes = $notificationINI->variable( 'NotificationEventTypeSettings', 'AvailableEventTypes' ); 00107 $allowedTypes = array_unique( $eventTypes ); 00108 } 00109 return $allowedTypes; 00110 } 00111 00112 static function loadAndRegisterAllTypes() 00113 { 00114 $allowedTypes = eZNotificationEventType::allowedTypes(); 00115 foreach( $allowedTypes as $type ) 00116 { 00117 eZNotificationEventType::loadAndRegisterType( $type ); 00118 } 00119 } 00120 00121 static function loadAndRegisterType( $type ) 00122 { 00123 $types = $GLOBALS["eZNotificationEventTypes"]; 00124 if ( isset( $types[$type] ) ) 00125 { 00126 eZDebug::writeError( "Notification event type already registered: $type", __METHOD__ ); 00127 return false; 00128 } 00129 00130 $baseDirectory = eZExtension::baseDirectory(); 00131 $notificationINI = eZINI::instance( 'notification.ini' ); 00132 $repositoryDirectories = $notificationINI->variable( 'NotificationEventTypeSettings', 'RepositoryDirectories' ); 00133 $extensionDirectories = $notificationINI->variable( 'NotificationEventTypeSettings', 'ExtensionDirectories' ); 00134 foreach ( $extensionDirectories as $extensionDirectory ) 00135 { 00136 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/notificationtypes'; 00137 if ( file_exists( $extensionPath ) ) 00138 $repositoryDirectories[] = $extensionPath; 00139 } 00140 $foundEventType = false; 00141 foreach ( $repositoryDirectories as $repositoryDirectory ) 00142 { 00143 $includeFile = "$repositoryDirectory/$type/" . $type . "type.php"; 00144 if ( file_exists( $includeFile ) ) 00145 { 00146 $foundEventType = true; 00147 break; 00148 } 00149 } 00150 if ( !$foundEventType ) 00151 { 00152 eZDebug::writeError( "Notification event type not found: $type, searched in these directories: " . implode( ', ', $repositoryDirectories ), __METHOD__ ); 00153 return false; 00154 } 00155 include_once( $includeFile ); 00156 return true; 00157 } 00158 00159 static function register( $notificationTypeString, $className ) 00160 { 00161 if ( !isset( $GLOBALS["eZNotificationEventTypes"] ) || !is_array( $GLOBALS["eZNotificationEventTypes"] ) ) 00162 { 00163 $types = array(); 00164 } 00165 $GLOBALS["eZNotificationEventTypes"][$notificationTypeString] = $className; 00166 } 00167 00168 00169 00170 00171 } 00172 00173 ?>