ultimix
system_structure_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_system_structure`';
39 
50  var $Database = false;
51  var $DatabaseAlgorithms = false;
52  var $Security = false;
53  var $SecurityParser = false;
54 
65  function __construct()
66  {
67  try
68  {
69  $this->Database = get_package( 'database' , 'last' , __FILE__ );
70  $this->DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
71  $this->Security = get_package( 'security' , 'last' , __FILE__ );
72  $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
73  }
74  catch( Exception $e )
75  {
76  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
77  }
78  }
79 
90  var $AddLimitations = '1 = 1';
91 
110  function set_add_limitations( $theAddLimitation )
111  {
112  try
113  {
114  if( $this->AddLimitations === '1 = 1' )
115  {
116  $this->AddLimitations = $theAddLimitation;
117  }
118  else
119  {
120  throw( new Exception( '"AddLimitations" was already set' ) );
121  }
122  }
123  catch( Exception $e )
124  {
125  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
126  }
127  }
128 
151  function unsafe_select( $Condition = " 1 = 1 " )
152  {
153  try
154  {
155  $this->Database->query_as( DB_OBJECT );
156 
157  $Records = $this->Database->select(
158  '*' , $this->NativeTable , "( $this->AddLimitations ) AND $Condition"
159  );
160 
161  foreach( $Records as $k => $v )
162  {
163  $Records[ $k ]->page = htmlspecialchars_decode( $Records[ $k ]->page , ENT_QUOTES );
164  $Records[ $k ]->root_page = htmlspecialchars_decode( $Records[ $k ]->root_page , ENT_QUOTES );
165  $Records[ $k ]->navigation = htmlspecialchars_decode( $Records[ $k ]->navigation , ENT_QUOTES );
166  $Records[ $k ]->navigation = htmlspecialchars_decode( $Records[ $k ]->navigation , ENT_QUOTES );
167  }
168 
169  return( $Records );
170  }
171  catch( Exception $e )
172  {
173  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
174  }
175  }
176 
215  function select( $Start , $Limit , $Field = false , $Order = false , $Condition = '1 = 1' )
216  {
217  try
218  {
219  $Condition = $this->DatabaseAlgorithms->select_condition(
220  $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
221  );
222 
223  $Items = $this->unsafe_select( $Condition );
224 
225  foreach( $Items as $k => $i )
226  {
227  $Items[ $k ]->navigation = str_replace( '{' , '[lfb]' , $Items[ $k ]->navigation );
228  $Items[ $k ]->navigation = str_replace( '}' , '[rfb]' , $Items[ $k ]->navigation );
229  }
230 
231  return( $Items );
232  }
233  catch( Exception $e )
234  {
235  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
236  }
237  }
238 
261  function get_by_id( $id )
262  {
263  try
264  {
265  $id = $this->Security->get( $id , 'integer' );
266 
267  $Records = $this->unsafe_select( $this->NativeTable.".id = $id" );
268 
269  if( count( $Records ) == 0 )
270  {
271  throw( new Exception( 'Record was not found' ) );
272  }
273 
274  return( $Records[ 0 ] );
275  }
276  catch( Exception $e )
277  {
278  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
279  }
280  }
281 
308  function create_system_structure( $Page , $RootPage , $Navigation )
309  {
310  try
311  {
312  $Params = $this->SecurityParser->parse_parameters(
313  func_get_args() , '0:string,alias_page;1:string,alias_root_page;2:string,alias_navigation'
314  );
315 
316  $this->Database->insert(
317  $this->NativeTable ,
318  'page , root_page , navigation' ,
319  "'".$Params->page."' , '".$Params->root_page."' , '".$Params->navigation."'"
320  );
321  $this->Database->commit();
322  }
323  catch( Exception $e )
324  {
325  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
326  }
327  }
328 
347  function delete( $id )
348  {
349  try
350  {
351  $id = $this->Security->get( $id , 'integer_list' );
352 
355  $this->Database->delete( $this->NativeTable , "( $this->AddLimitations ) AND id IN ( $id )" );
356  $this->Database->commit();
357  }
358  catch( Exception $e )
359  {
360  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
361  }
362  }
363 
386  function update( $id , $Record )
387  {
388  try
389  {
390  $id = $this->Security->get( $id , 'integer_list' );
391  $Record = $this->SecurityParser->parse_parameters(
392  $Record , 'page:command;root_page:command;navigation:raw' , 'allow_not_set'
393  );
394 
395  list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
396 
397  if( isset( $Fields[ 0 ] ) )
398  {
399  $this->Database->update(
400  $this->NativeTable , $Fields , $Values , "( $this->AddLimitations ) AND id IN ( $id )"
401  );
402  $this->Database->commit();
403  }
404  }
405  catch( Exception $e )
406  {
407  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
408  }
409  }
410 
433  function select_list( $id )
434  {
435  try
436  {
437  $id = $this->Security->get( $id , 'integer_list' );
438 
439  return( $this->unsafe_select( $this->NativeTable.".id IN ( $id )" ) );
440  }
441  catch( Exception $e )
442  {
443  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
444  }
445  }
446  }
447 
448 ?>