ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

menu_item_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
26 class menu_item_access_1_0_0{
27
38 var $NativeTable = '`umx_menu_item`';
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 )
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 ]->href = htmlspecialchars_decode( $Records[ $k ]->href , ENT_QUOTES );
164 }
165
166 return( $Records );
167 }
168 catch( Exception $e )
169 {
170 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
171 }
172 }
173
212 function select( $Start , $Limit , $Field = false , $Order = false , $Condition = '1 = 1' )
213 {
214 try
215 {
216 $Condition = $this->DatabaseAlgorithms->select_condition(
217 $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
218 );
219
220 return( $this->unsafe_select( $Condition ) );
221 }
222 catch( Exception $e )
223 {
224 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
225 }
226 }
227
250 function get_by_id( $id )
251 {
252 try
253 {
254 $id = $this->Security->get( $id , 'integer' );
255
256 $Records = $this->unsafe_select( $this->NativeTable.".id = $id" );
257
258 if( count( $Records ) == 0 )
259 {
260 throw( new Exception( 'Record was not found' ) );
261 }
262
263 return( $Records[ 0 ] );
264 }
265 catch( Exception $e )
266 {
267 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
268 }
269 }
270
289 function create( $Record )
290 {
291 try
292 {
293 $Record = $this->SecurityParser->parse_parameters( $Record , 'name:string;menu:string;href:string' );
294
295 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
296
297 $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
298
299 return( $id );
300 }
301 catch( Exception $e )
302 {
303 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
304 }
305 }
306
329 function select_list( $id )
330 {
331 try
332 {
333 $id = $this->Security->get( $id , 'integer_list' );
334
335 return( $this->unsafe_select( $this->NativeTable.".id IN ( $id )" ) );
336 }
337 catch( Exception $e )
338 {
339 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
340 }
341 }
342
365 function update( $id , $Record )
366 {
367 try
368 {
369 $id = $this->Security->get( $id , 'integer_list' );
370 $Record = $this->SecurityParser->parse_parameters(
371 $Record , 'name:string;menu:string;href:string' , 'allow_not_set'
372 );
373
374 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
375
376 if( isset( $Fields[ 0 ] ) )
377 {
378 $this->Database->update(
379 $this->NativeTable , $Fields , $Values , "( $this->AddLimitations ) AND id IN ( $id )"
380 );
381 $this->Database->commit();
382 }
383 }
384 catch( Exception $e )
385 {
386 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
387 }
388 }
389
408 function delete( $id )
409 {
410 try
411 {
412 $id = $this->Security->get( $id , 'integer_list' );
413
416 $this->Database->delete( $this->NativeTable , "( $this->AddLimitations ) AND id IN ( $id )" );
417 $this->Database->commit();
418 }
419 catch( Exception $e )
420 {
421 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
422 }
423 }
424 }
425
426 ?>