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/ezpersistentobject.php' );
00041
00042 class eZOperationMemento extends eZPersistentObject
00043 {
00044
00045
00046
00047 function eZOperationMemento( $row )
00048 {
00049 $this->eZPersistentObject( $row );
00050 }
00051
00052 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 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 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 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 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 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 function createKey( $parameters )
00173 {
00174 $string = '';
00175 foreach ( array_keys( $parameters ) as $key )
00176 {
00177 $value =& $parameters[$key];
00178 $string .= $key . $value;
00179 }
00180 return md5( $string );
00181 }
00182
00183
00184
00185
00186
00187 function cleanup()
00188 {
00189 $db =& eZDB::instance();
00190 $db->query( "DELETE FROM ezoperation_memento" );
00191 }
00192
00193 }
00194
00195 ?>