ultimix
ad_campaign_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_ad_campaign`';
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  return( $Records );
162  }
163  catch( Exception $e )
164  {
165  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
166  }
167  }
168 
207  function select( $Start = false , $Limit = false , $Field = false ,
208  $Order = false , $Condition = '1 = 1' )
209  {
210  try
211  {
212  $Condition = $this->DatabaseAlgorithms->select_condition(
213  $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
214  );
215 
216  return( $this->unsafe_select( $Condition ) );
217  }
218  catch( Exception $e )
219  {
220  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
221  }
222  }
223 
246  function create( $Record )
247  {
248  try
249  {
250  $Record = $this->SecurityParser->parse_parameters( $Record , 'title:string' );
251 
252  list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
253 
254  $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
255 
256  $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
257  $EventManager->trigger_event( 'on_after_create_ad_campaign' , array( 'id' => $id ) );
258 
259  return( $id );
260  }
261  catch( Exception $e )
262  {
263  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
264  }
265  }
266 
285  function delete( $id )
286  {
287  try
288  {
289  $id = $this->Security->get( $id , 'integer_list' );
290 
293  $this->Database->delete( $this->NativeTable , "( $this->AddLimitations ) AND id IN ( $id )" );
294  $this->Database->commit();
295  }
296  catch( Exception $e )
297  {
298  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
299  }
300  }
301 
324  function select_list( $id )
325  {
326  try
327  {
328  $id = $this->Security->get( $id , 'integer_list' );
329 
330  return( $this->unsafe_select( $this->NativeTable.".id IN ( $id )" ) );
331  }
332  catch( Exception $e )
333  {
334  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
335  }
336  }
337 
356  function simple_select()
357  {
358  try
359  {
360  $Records = $this->unsafe_select( '1 = 1' );
361 
362  foreach( $Records as $k => $v )
363  {
364  $Records[ $k ]->title = '{lang:ad_title} '.$v->title;
365  }
366 
367  return( $Records );
368  }
369  catch( Exception $e )
370  {
371  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
372  }
373  }
374 
397  function update( $id , $Record )
398  {
399  try
400  {
401  $id = $this->Security->get( $id , 'integer_list' );
402  $Record = $this->SecurityParser->parse_parameters( $Record , 'title:string' , 'allow_not_set' );
403 
404  list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
405 
406  if( isset( $Fields[ 0 ] ) )
407  {
408  $this->Database->update(
409  $this->NativeTable , $Fields , $Values , "( $this->AddLimitations ) AND id IN ( $id )"
410  );
411  $this->Database->commit();
412  }
413  }
414  catch( Exception $e )
415  {
416  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
417  }
418  }
419  }
420 
421 ?>