eZ Publish  [4.0]
ezoperationmemento.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZOperationMemento class
00004 //
00005 // Created on: <06-ξΟΡ-2002 16:19:18 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 ezoperationmemento.php
00032 */
00033 
00034 /*!
00035   \class eZOperationMemento ezoperationmemento.php
00036   \brief The class eZOperationMemento does
00037 
00038 */
00039 
00040 //include_once( 'kernel/classes/ezpersistentobject.php' );
00041 
00042 class eZOperationMemento extends eZPersistentObject
00043 {
00044     /*!
00045      Constructor
00046     */
00047     function eZOperationMemento( $row )
00048     {
00049         $this->eZPersistentObject( $row );
00050     }
00051 
00052     static function definition()
00053     {
00054         return array( 'fields' => array( 'id' => array( 'name' => 'ID',
00055                                                         'datatype' => 'integer',
00056                                                         'default' => 0,
00057                                                         'required' => true ),
00058                                          'main' => array( 'name' => 'Main',
00059                                                           'datatype' => 'integer',
00060                                                           'default' => 0,
00061                                                           'required' => true ),
00062                                          'memento_key' => array( 'name' => 'MementoKey',
00063                                                                  'datatype' => 'string',
00064                                                                  'default' => '',
00065                                                                  'required' => true ),
00066                                          'main_key' => array( 'name' => 'MainKey',
00067                                                               'datatype' => 'string',
00068                                                               'default' => '',
00069                                                               'required' => true ),
00070                                          'memento_data' => array( 'name' => 'MementoData',
00071                                                                   'datatype' => 'text',
00072                                                                   'default' => '',
00073                                                                   'required' => true ) ),
00074                       'function_attributes' => array( 'main_memento' => 'mainMemento' ),
00075                       'keys' => array( 'id' ),
00076                       "increment_key" => "id",
00077                       'class_name' => 'eZOperationMemento',
00078                       'name' => 'ezoperation_memento' );
00079     }
00080 
00081     function &mainMemento()
00082     {
00083         if ( !isset( $this->MainMemento ) )
00084         {
00085             $this->MainMemento = eZOperationMemento::fetchMain( $this->attribute( 'main_key' ) );
00086         }
00087         return $this->MainMemento;
00088     }
00089 
00090     static function fetch( $mementoKey, $asObject = true )
00091     {
00092         if ( is_array( $mementoKey ) )
00093         {
00094             $mementoKey = eZOperationMemento::createKey( $mementoKey );
00095         }
00096 
00097         return eZPersistentObject::fetchObject( eZOperationMemento::definition(),
00098                                                 null,
00099                                                 array( 'memento_key' => $mementoKey ),
00100                                                 $asObject );
00101     }
00102 
00103     static function fetchChild( $mementoKey, $asObject = true )
00104     {
00105         if ( is_array( $mementoKey ) )
00106         {
00107             $mementoKey = eZOperationMemento::createKey( $mementoKey );
00108         }
00109 
00110         return eZPersistentObject::fetchObject( eZOperationMemento::definition(),
00111                                                 null,
00112                                                 array( 'memento_key' => $mementoKey,
00113                                                        'main' => 0 ),
00114                                                 $asObject );
00115     }
00116 
00117     static function fetchMain( $mementoKey, $asObject = true )
00118     {
00119         if ( is_array( $mementoKey ) )
00120         {
00121             $mementoKey = eZOperationMemento::createKey( $mementoKey );
00122         }
00123 
00124         return eZPersistentObject::fetchObject( eZOperationMemento::definition(),
00125                                                 null,
00126                                                 array( 'memento_key' => $mementoKey,
00127                                                        'main' => 1 ),
00128                                                 $asObject );
00129     }
00130 
00131     static function fetchList( $mementoKey, $asObject = true )
00132     {
00133         if ( is_array( $mementoKey ) )
00134         {
00135             $mementoKey = eZOperationMemento::createKey( $mementoKey );
00136         }
00137 
00138         return eZPersistentObject::fetchObjectList( eZOperationMemento::definition(),
00139                                                     null,
00140                                                     array( 'memento_key' => $mementoKey,
00141                                                            'main' => 0 ),
00142                                                     null,
00143                                                     null,
00144                                                     $asObject );
00145     }
00146 
00147     function setData( $data = array() )
00148     {
00149         $this->MementoData = serialize( $data );
00150     }
00151 
00152     function data()
00153     {
00154         return unserialize( $this->MementoData );
00155     }
00156 
00157     static function create( $mementoKey, $data = array(), $isMainKey = false, $mainKey = null )
00158     {
00159         if( is_array( $mementoKey ) )
00160         {
00161             $mementoKey = eZOperationMemento::createKey( $mementoKey );
00162         }
00163 
00164         $serializedData = serialize( $data );
00165         return new eZOperationMemento( array( 'id' => null,
00166                                               'main' => ( $isMainKey ? 1 : 0 ),
00167                                               'memento_key' => $mementoKey,
00168                                               'main_key' => ( $isMainKey ? $mementoKey : $mainKey ),
00169                                               'memento_data' => $serializedData ) );
00170     }
00171 
00172     static function createKey( $parameters )
00173     {
00174         $string = '';
00175         foreach ( $parameters as $key => $value )
00176         {
00177             $string .= $key . $value;
00178         }
00179         return md5( $string );
00180     }
00181 
00182     /*!
00183      \static
00184      Removes all active operation mementos.
00185     */
00186     static function cleanup()
00187     {
00188         $db = eZDB::instance();
00189         $db->query( "DELETE FROM ezoperation_memento" );
00190     }
00191 
00192 }
00193 
00194 ?>