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 include_once( "kernel/classes/ezdatatype.php" );
00041
00042 define( "EZ_DATATYPESTRING_SUBTREESUBSCRIPTION", "ezsubtreesubscription" );
00043
00044 class eZSubtreeSubscriptionType extends eZDataType
00045 {
00046
00047
00048
00049 function eZSubtreeSubscriptionType()
00050 {
00051 $this->eZDataType( EZ_DATATYPESTRING_SUBTREESUBSCRIPTION, ezi18n( 'kernel/classes/datatypes', "Subtree subscription", 'Datatype name' ),
00052 array( 'serialize_supported' => true,
00053 'object_serialize_map' => array( 'data_int' => 'value' ) ) );
00054 }
00055
00056
00057
00058
00059
00060 function onPublish( &$attribute, &$contentObject, &$publishedNodes )
00061 {
00062 include_once( 'kernel/classes/notification/handler/ezsubtree/ezsubtreenotificationrule.php' );
00063 $user =& eZUser::currentUser();
00064 $address = $user->attribute( 'email' );
00065 $userID = $user->attribute( 'contentobject_id' );
00066
00067 $nodeIDList = eZSubtreeNotificationRule::fetchNodesForUserID( $user->attribute( 'contentobject_id' ), false );
00068
00069 if ( $attribute->attribute( 'data_int' ) == '1' )
00070 {
00071 $newSubscriptions = array();
00072 foreach ( array_keys( $publishedNodes ) as $key )
00073 {
00074 $node =& $publishedNodes[$key];
00075 if ( !in_array( $node->attribute( 'node_id' ), $nodeIDList ) )
00076 {
00077 $newSubscriptions[] = $node->attribute( 'node_id' );
00078 }
00079 }
00080
00081
00082 foreach ( $newSubscriptions as $nodeID )
00083 {
00084
00085 $rule = eZSubtreeNotificationRule::create( $nodeID, $userID );
00086 $rule->store();
00087 }
00088 }
00089 else
00090 {
00091 foreach ( array_keys( $publishedNodes ) as $key )
00092 {
00093 $node =& $publishedNodes[$key];
00094 if ( in_array( $node->attribute( 'node_id' ), $nodeIDList ) )
00095 {
00096 eZSubtreeNotificationRule::removeByNodeAndUserID( $user->attribute( 'contentobject_id' ), $node->attribute( 'node_id' ) );
00097 }
00098 }
00099 }
00100 return true;
00101 }
00102
00103
00104
00105
00106 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00107 {
00108 if ( $http->hasPostVariable( $base . "_data_subtreesubscription_" . $contentObjectAttribute->attribute( "id" ) ))
00109 {
00110 $data = $http->postVariable( $base . "_data_subtreesubscription_" . $contentObjectAttribute->attribute( "id" ) );
00111 if ( isset( $data ) )
00112 $data = 1;
00113 }
00114 else
00115 {
00116 $data = 0;
00117 }
00118 $contentObjectAttribute->setAttribute( "data_int", $data );
00119 return true;
00120 }
00121
00122 function hasObjectAttributeContent( &$contentObjectAttribute )
00123 {
00124 return true;
00125 }
00126
00127 function toString( $contentObjectAttribute )
00128 {
00129 return $contentObjectAttribute->attribute( 'data_int' );
00130 }
00131
00132
00133 function fromString( &$contentObjectAttribute, $string )
00134 {
00135 if ( $string == '' )
00136 return true;
00137 if ( ! is_numeric( $string ) )
00138 return false;
00139
00140 $contentObjectAttribute->setAttribute( 'data_int', $string );
00141 return true;
00142 }
00143
00144
00145
00146
00147 function serializeContentObjectAttribute( &$package, &$objectAttribute )
00148 {
00149 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
00150 $value = $objectAttribute->attribute( 'data_int' );
00151 $node->appendChild( eZDOMDocument::createElementTextNode( 'value', $value ) );
00152
00153 return $node;
00154 }
00155
00156
00157
00158
00159 function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode )
00160 {
00161 $value = $attributeNode->elementTextContentByName( 'value' );
00162
00163 if ( $value === false )
00164 $value = 0;
00165
00166 $objectAttribute->setAttribute( 'data_int', $value );
00167 }
00168
00169
00170
00171
00172 function diff( $old, $new )
00173 {
00174 return null;
00175 }
00176 }
00177
00178 eZDataType::register( EZ_DATATYPESTRING_SUBTREESUBSCRIPTION, "ezsubtreesubscriptiontype" );
00179
00180 ?>