eZ Publish  [4.0]
ezsubtreesubscriptiontype.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZSubtreeSubscriptionType class
00004 //
00005 // Created on: <20-May-2003 11:35:43 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 ezsubtreesubscriptiontype.php
00032 */
00033 
00034 /*!
00035   \class eZSubtreeSubscriptionType ezsubtreesubscriptiontype.php
00036   \ingroup eZDatatype
00037   \brief The class eZSubtreeSubscriptionType does
00038 
00039 */
00040 //include_once( "kernel/classes/ezdatatype.php" );
00041 
00042 class eZSubtreeSubscriptionType extends eZDataType
00043 {
00044     const DATA_TYPE_STRING = "ezsubtreesubscription";
00045 
00046     /*!
00047      Constructor
00048     */
00049     function eZSubtreeSubscriptionType()
00050     {
00051         $this->eZDataType(  self::DATA_TYPE_STRING, 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      Store content
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 ( $publishedNodes as $node )
00073             {
00074                 if ( !in_array( $node->attribute( 'node_id' ), $nodeIDList ) )
00075                 {
00076                     $newSubscriptions[] = $node->attribute( 'node_id' );
00077                 }
00078             }
00079 
00080             foreach ( $newSubscriptions as $nodeID )
00081             {
00082 
00083                 $rule = eZSubtreeNotificationRule::create( $nodeID, $userID );
00084                 $rule->store();
00085             }
00086         }
00087         else
00088         {
00089             foreach ( $publishedNodes as $node )
00090             {
00091                 if ( in_array( $node->attribute( 'node_id' ), $nodeIDList ) )
00092                 {
00093                     eZSubtreeNotificationRule::removeByNodeAndUserID( $user->attribute( 'contentobject_id' ), $node->attribute( 'node_id' ) );
00094                 }
00095             }
00096         }
00097         return true;
00098     }
00099 
00100     /*!
00101      Fetches the http post var integer input and stores it in the data instance.
00102     */
00103     function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
00104     {
00105         if ( $http->hasPostVariable( $base . "_data_subtreesubscription_" . $contentObjectAttribute->attribute( "id" ) ))
00106         {
00107             $data = $http->postVariable( $base . "_data_subtreesubscription_" . $contentObjectAttribute->attribute( "id" ) );
00108             if ( isset( $data ) )
00109                 $data = 1;
00110         }
00111         else
00112         {
00113             $data = 0;
00114         }
00115         $contentObjectAttribute->setAttribute( "data_int", $data );
00116         return true;
00117     }
00118 
00119     function hasObjectAttributeContent( $contentObjectAttribute )
00120     {
00121         return true;
00122     }
00123 
00124     function toString( $contentObjectAttribute )
00125     {
00126         return $contentObjectAttribute->attribute( 'data_int' );
00127     }
00128 
00129 
00130     function fromString( $contentObjectAttribute, $string )
00131     {
00132         if ( $string == '' )
00133             return true;
00134         if ( ! is_numeric( $string ) )
00135             return false;
00136 
00137         $contentObjectAttribute->setAttribute( 'data_int', $string );
00138         return true;
00139     }
00140 
00141     /*!
00142      \reimp
00143     */
00144     function serializeContentObjectAttribute( $package, $objectAttribute )
00145     {
00146         $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
00147         $dom = $node->ownerDocument;
00148 
00149         $value = $objectAttribute->attribute( 'data_int' );
00150         $valueNode = $dom->createElement( 'value' );
00151         $valueNode->appendChild( $dom->createTextNode( $value ) );
00152         $node->appendChild( $valueNode );
00153 
00154         return $node;
00155     }
00156 
00157     /*!
00158      \reimp
00159     */
00160     function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
00161     {
00162         $valueNode = $attributeNode->getElementsByTagName( 'value' )->item( 0 );
00163         $value = $valueNode ? $valueNode->textContent : 0;
00164         $objectAttribute->setAttribute( 'data_int', $value );
00165     }
00166 
00167     /*!
00168       \reimp
00169     */
00170     function diff( $old, $new, $options = false )
00171     {
00172         return null;
00173     }
00174 }
00175 
00176 eZDataType::register( eZSubtreeSubscriptionType::DATA_TYPE_STRING, "eZSubtreeSubscriptionType" );
00177 
00178 ?>