ultimix
change_history_access.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 
27 
38  var $NativeTable = '`umx_change_history`';
39 
50  var $Database = false;
51  var $Link = false;
52  var $LinkDictionary = false;
53  var $Security = false;
54  var $UserAlgorithms = false;
55 
70  function __construct()
71  {
72  try
73  {
74  $this->Database = get_package( 'database' , 'last' , __FILE__ );
75  $this->Link = get_package( 'link' , 'last' , __FILE__ );
76  $this->LinkDictionary = get_package( 'link::link_dictionary' , 'last' , __FILE__ );
77  $this->Security = get_package( 'security' , 'last' , __FILE__ );
78  $this->UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
79  }
80  catch( Exception $e )
81  {
82  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
83  }
84  }
85 
116  private function get_entry( $id , $ObjectType , $Name )
117  {
118  try
119  {
120  $this->Database->query_as( DB_OBJECT );
121 
122  $Entry = $this->Database->select(
123  $this->NativeTable.'.field_value' ,
124  $this->NativeTable ,
125  $this->NativeTable.".object_id = $id AND ".$this->NativeTable.".object_type = $ObjectType AND ".
126  $this->NativeTable.".field_name LIKE '".$Name."' ORDER BY id DESC LIMIT 1"
127  );
128 
129  return( $Entry );
130  }
131  catch( Exception $e )
132  {
133  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
134  }
135  }
136 
167  function get_last_field_vlue( $id , $ObjectType , $Name )
168  {
169  try
170  {
171  $id = $this->Security->get( $id , 'integer' );
172  $ObjectType = $this->Security->get( $ObjectType , 'integer' );;
173  $Name = $this->Security->get( $Name , 'command' );
174 
175  $Entry = $this->get_entry( $id , $ObjectType , $Name );
176 
177  if( isset( $Entry[ 0 ] ) )
178  {
179  return( get_field( $Entry[ 0 ] , 'field_value' ) );
180  }
181 
182  return( false );
183  }
184  catch( Exception $e )
185  {
186  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
187  }
188  }
189 
224  function need_save_field( $id , $ObjectType , $Name , $NewValue )
225  {
226  try
227  {
228  $Value = $this->get_last_field_vlue( $id , $ObjectType , $Name );
229 
230  return( $Value === false || ( $Value == $NewValue ? false : true ) );
231  }
232  catch( Exception $e )
233  {
234  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
235  }
236  }
237 
256  function get_author()
257  {
258  try
259  {
260  $User = $this->UserAlgorithms->get_user();
261 
262  return( get_field( $User , 'id' ) );
263  }
264  catch( Exception $e )
265  {
266  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
267  }
268  }
269 
296  function add_to_history( $id , $ObjectType , $Record )
297  {
298  try
299  {
300  $id = $this->Security->get( $id , 'integer' );
301  $Record = $this->Security->get( $Record , 'string' );
302  $ObjectType = $this->LinkDictionary->get_link_type( 'history' , $ObjectType );
303  $Author = $this->get_author();
304 
305  foreach( $Record as $Name => $Value )
306  {
307  if( $this->need_save_field( $id , $ObjectType , $Name , $Value ) )
308  {
309  $this->Database->insert( $this->NativeTable ,
310  'object_id , object_type , field_name , field_value , creation_date , author' ,
311  "$id , $ObjectType , '$Name' , '$Value' , NOW() , $Author"
312  );
313 
314  $this->Database->commit();
315  }
316  }
317  }
318  catch( Exception $e )
319  {
320  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
321  }
322  }
323 
350  function get_history( $id , $ObjectType )
351  {
352  try
353  {
354  $id = $this->Security->get( $id , 'integer' );
355  $ObjectType = $this->LinkDictionary->get_link_type( 'history' , $ObjectType );
356 
357  $this->Database->query_as( DB_OBJECT );
358 
359  return(
360  $this->Database->select(
361  $this->NativeTable.'.* , umx_user.login AS author_name' ,
362  $this->NativeTable.' , umx_user' ,
363  $this->NativeTable.".author = umx_user.id AND ".$this->NativeTable.".object_id = $id AND ".
364  $this->NativeTable.".object_type = $ObjectType ORDER BY id ASC"
365  )
366  );
367  }
368  catch( Exception $e )
369  {
370  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
371  }
372  }
373  }
374 
375 ?>