ultimix
ad_banner_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_banner`';
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  '* , code AS preview , IF( shows , ( 100 * clicks / shows ) , 0 ) AS ctr' ,
159  $this->NativeTable ,
160  "( $this->AddLimitations ) AND $Condition"
161  );
162 
163  foreach( $Records as $k => $v )
164  {
165  set_field(
166  $Records[ $k ] , 'preview' , $this->Security->get( get_field( $v , 'code' ) , 'unsafe_string' )
167  );
168  }
169 
170  return( $Records );
171  }
172  catch( Exception $e )
173  {
174  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
175  }
176  }
177 
216  function select( $Start = false , $Limit = false , $Field = false , $Order = false ,
217  $Condition = '1 = 1' )
218  {
219  try
220  {
221  $Condition = $this->DatabaseAlgorithms->select_condition(
222  $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
223  );
224 
225  return( $this->unsafe_select( $Condition ) );
226  }
227  catch( Exception $e )
228  {
229  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
230  }
231  }
232 
255  function create( $Record )
256  {
257  try
258  {
259  $Record = $this->SecurityParser->parse_parameters(
260  $Record , 'campaign_id:integer,allow_not_set,default_0;code:string'
261  );
262 
263  list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
264 
265  $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
266 
267  $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
268  $EventManager->trigger_event( 'on_after_create_ad_banner' , array( 'id' => $id ) );
269 
270  return( $id );
271  }
272  catch( Exception $e )
273  {
274  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
275  }
276  }
277 
296  function delete( $id )
297  {
298  try
299  {
300  $id = $this->Security->get( $id , 'integer_list' );
301 
304  $this->Database->delete( $this->NativeTable , "( $this->AddLimitations ) AND id IN ( $id )" );
305  $this->Database->commit();
306  }
307  catch( Exception $e )
308  {
309  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
310  }
311  }
312 
335  function select_list( $id )
336  {
337  try
338  {
339  $id = $this->Security->get( $id , 'integer_list' );
340 
341  return( $this->unsafe_select( $this->NativeTable.".id IN ( $id )" ) );
342  }
343  catch( Exception $e )
344  {
345  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
346  }
347  }
348 
367  function simple_select()
368  {
369  try
370  {
371  $Records = $this->unsafe_select( '1 = 1' );
372 
373  foreach( $Records as $k => $v )
374  {
375  $Records[ $k ]->title = '{lang:ad_code} '.$v->code;
376  }
377 
378  return( $Records );
379  }
380  catch( Exception $e )
381  {
382  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
383  }
384  }
385 
408  function update( $id , $Record )
409  {
410  try
411  {
412  $id = $this->Security->get( $id , 'integer_list' );
413  $Record = $this->SecurityParser->parse_parameters(
414  $Record , 'campaign_id:integer,default_0;code:string' , 'allow_not_set'
415  );
416 
417  list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
418 
419  if( isset( $Fields[ 0 ] ) )
420  {
421  $this->Database->update(
422  $this->NativeTable , $Fields , $Values , "( $this->AddLimitations ) AND id IN ( $id )"
423  );
424  $this->Database->commit();
425  }
426  }
427  catch( Exception $e )
428  {
429  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
430  }
431  }
432  }
433 
434 ?>