ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

chronological.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
26 class chronological_1_0_0{
27
38 var $Database = false;
39 var $Security = false;
40
55 function __construct()
56 {
57 try
58 {
59 $this->Database = get_package( 'database' , 'last' , __FILE__ );
60 $this->Security = get_package( 'security' , 'last' , __FILE__ );
61 }
62 catch( Exception $e )
63 {
64 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
65 }
66 }
67
90 function create_record( $MasterId , $DataAccess )
91 {
92 try
93 {
94 $MasterId = $this->Security->get( $MasterId , 'integer' );
95
96 $Time = time();
97
98 $this->Database->update(
99 $DataAccess->NativeTable ,
100 array( 'date_from' , 'date_to' , 'group_id' ) ,
101 array( $Time , $Time + 100 * 365 * 24 * 60 * 60 , $MasterId ) ,
102 "id = $MasterId"
103 );
104
105 $this->Database->commit();
106 }
107 catch( Exception $e )
108 {
109 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
110 }
111 }
112
139 private function close_old_version( $MasterId , $Changes , $DataAccess )
140 {
141 try
142 {
143 $MasterId = $this->Security->get( $MasterId , 'integer' );
144 $Time = time();
145
146 $Records = $this->Database->select( 'MIN( id ) AS min_id' , $DataAccess->NativeTable );
147 $MinId = get_field( $Records[ 0 ] , 'min_id' , 0 ) - 1;
148 $this->Database->update(
149 $DataAccess->NativeTable , array( 'id' , 'date_to' ) ,
150 array( $MinId , $Time - 1 ) , "id = $MasterId"
151 );
152 $this->Database->commit();
153 }
154 catch( Exception $e )
155 {
156 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
157 }
158 }
159
186 private function create_new_version( $MasterId , $Changes , $DataAccess )
187 {
188 try
189 {
190 $OriginalRecord = $DataAccess->unsafe_select( "id = $MasterId" );
191 $ChangedRecord = extend( $OriginalRecord[ 0 ] , $Changes );
192 $NewId = $DataAccess->create( $ChangedRecord );
193 $this->Database->update(
194 $DataAccess->NativeTable , array( 'id' , 'date_from' , 'date_to' , 'group_id' ) ,
195 array( $MasterId , $Time , $Time + 100 * 365 * 24 * 60 * 60 , $MasterId ) , "id = $NewId"
196 );
197 $this->Database->commit();
198 }
199 catch( Exception $e )
200 {
201 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
202 }
203 }
204
231 function update_record( $MasterId , $Changes , $DataAccess )
232 {
233 try
234 {
235 $this->Database->lock( array( $DataAccess->NativeTable ) , array( 'WRITE' ) );
236
237 $this->close_old_version( $MasterId , $Changes , $DataAccess );
238
239 $this->create_new_version( $MasterId , $Changes , $DataAccess );
240
241 $this->Database->unlock();
242 }
243 catch( Exception $e )
244 {
245 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
246 }
247 }
248
271 function close_record( $MasterId , $DataAccess )
272 {
273 try
274 {
275 $MasterId = $this->Security->get( $MasterId , 'integer_list' );
276
277 $this->Database->update(
278 $DataAccess->NativeTable , array( 'date_to' ) , array( time() ) ,
279 "id IN ( $MasterId ) AND ( ".$DataAccess->AddLimitations." )"
280 );
281
282 $this->Database->commit();
283 }
284 catch( Exception $e )
285 {
286 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
287 }
288 }
289 }
290
291 ?>