ultimix
menu_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_menu`';
39 
50  var $DatabaseAlgorithms = false;
51  var $SecurityParser = false;
52 
63  function __construct()
64  {
65  try
66  {
67  $this->DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
68  $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
69  }
70  catch( Exception $e )
71  {
72  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
73  }
74  }
75 
86  var $AddLimitations = '1 = 1';
87 
106  function set_add_limitations( $theAddLimitation )
107  {
108  try
109  {
110  if( $this->AddLimitations === '1 = 1' )
111  {
112  $this->AddLimitations = $theAddLimitation;
113  }
114  else
115  {
116  throw( new Exception( '"AddLimitations" was already set' ) );
117  }
118  }
119  catch( Exception $e )
120  {
121  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
122  }
123  }
124 
147  function unsafe_select( $Condition )
148  {
149  try
150  {
151  $Database = get_package( 'database' , 'last' , __FILE__ );
152  $Database->query_as( DB_OBJECT );
153 
154  $Records = $Database->select( '*' , $this->NativeTable , "( $this->AddLimitations ) AND $Condition" );
155 
156  return( $Records );
157  }
158  catch( Exception $e )
159  {
160  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
161  }
162  }
163 
202  function select( $Start , $Limit , $Field = false , $Order = false , $Condition = '1 = 1' )
203  {
204  try
205  {
206  $Condition = $this->DatabaseAlgorithms->select_condition(
207  $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
208  );
209 
210  return( $this->unsafe_select( $Condition ) );
211  }
212  catch( Exception $e )
213  {
214  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
215  }
216  }
217 
240  function get_by_id( $id )
241  {
242  try
243  {
244  $Security = get_package( 'security' , 'last' , __FILE__ );
245  $id = $Security->get( $id , 'integer' );
246 
247  $Records = $this->unsafe_select( $this->NativeTable.".id = $id" );
248 
249  if( count( $Records ) == 0 )
250  {
251  throw( new Exception( 'Record was not found' ) );
252  }
253 
254  return( $Records[ 0 ] );
255  }
256  catch( Exception $e )
257  {
258  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
259  }
260  }
261 
280  function create( $Record )
281  {
282  try
283  {
284  $Record = $this->SecurityParser->parse_parameters( $Record , 'name:string' );
285 
286  list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
287 
288  $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
289 
290  return( $id );
291  }
292  catch( Exception $e )
293  {
294  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
295  }
296  }
297 
329  function get_menu_list( $Start , $Limit )
330  {
331  try
332  {
333  $Security = get_package( 'security' , 'last' , __FILE__ );
334  $Start = $Security->get( $Start , 'integer' );
335  $Limit = $Security->get( $Limit , 'integer' );
336 
337  $Databse = get_package( 'database' , 'last' , __FILE__ );
338  $Result = $Databse->select( '*' , 'umx_menu' , "$this->AddLimitations LIMIT $Start , $Limit" );
339  foreach( $Result as $i => $r )
340  {
341  $Result[ $i ] = array_merge( array( 'n' => $i + 1 ) , $Result );
342  }
343 
344  return( $Result );
345  }
346  catch( Exception $e )
347  {
348  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
349  }
350  }
351 
374  function get_menu_items( $Menu )
375  {
376  try
377  {
378  $Security = get_package( 'security' , 'last' , __FILE__ );
379  $Menu = $Security->get( $Menu , 'command' );
380 
381  $Counter = 0;
382 
383  $MenuItemAccess = get_package( 'menu::menu_item_access' , 'last' , __FILE__ );
384  $Result = $MenuItemAccess->select(
385  false , false , false , false , "( $this->AddLimitations ) AND menu LIKE '$Menu'"
386  );
387 
388  return( $Result );
389  }
390  catch( Exception $e )
391  {
392  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
393  }
394  }
395 
418  function get_menu( $Menu )
419  {
420  try
421  {
422  $Security = & get_package( 'security' , 'last' , __FILE__ );
423  $Menu = $Security->get( $Menu , 'command' );
424 
425  $Databse = get_package( 'database' , 'last' , __FILE__ );
426  $Result = $Databse->select( '*' , 'umx_menu' , "( $this->AddLimitations ) AND name LIKE '$Menu'" );
427  if( count( $Result ) !== 1 )
428  {
429  throw( new Exception( "An error occured while selecting menu" ) );
430  }
431  else
432  {
433  return( $Result[ 0 ] );
434  }
435  }
436  catch( Exception $e )
437  {
438  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
439  }
440  }
441 
464  function update_menu( $OldMenuLocator , $NewMenuLocator )
465  {
466  try
467  {
468  $Security = get_package( 'security' , 'last' , __FILE__ );
469  $OldMenuLocator = $Security->get( $OldMenuLocator , 'command' );
470  $NewMenuLocator = $Security->get( $NewMenuLocator , 'command' );
471 
472  $Databse = get_package( 'database' , 'last' , __FILE__ );
473  $Databse->update(
474  'umx_menu' , array( 'name' ) , array( $NewMenuLocator ) ,
475  "( $this->AddLimitations ) AND name LIKE '$OldMenuLocator'"
476  );
477  $Databse->commit();
478  }
479  catch( Exception $e )
480  {
481  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
482  }
483  }
484 
503  function delete_menu( $Menu )
504  {
505  try
506  {
507  $Security = get_package( 'security' , 'last' , __FILE__ );
508  $Menu = $Security->get( $Menu , 'command' );
509 
510  $Database = get_package( 'database' , 'last' , __FILE__ );
511  $Database->delete( 'umx_menu' , "( $this->AddLimitations ) AND name LIKE '$Menu'" );
512  $Database->commit();
513  }
514  catch( Exception $e )
515  {
516  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
517  }
518  }
519  }
520 
521 ?>