ultimix
comment_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_comment`';
39 
50  var $Database = false;
51  var $DatabaseAlgorithms = false;
52  var $Security = false;
53  var $SecurityParser = false;
54  var $UserAccess = false;
55  var $UserAlgorithms = false;
56 
67  function __construct()
68  {
69  try
70  {
71  $this->Database = get_package( 'database' , 'last' , __FILE__ );
72  $this->DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
73  $this->Security = get_package( 'security' , 'last' , __FILE__ );
74  $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
75  $this->UserAccess = get_package( 'user::user_access' , 'last' , __FILE__ );
76  $this->UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
77  }
78  catch( Exception $e )
79  {
80  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
81  }
82  }
83 
94  var $AddLimitations = '1 = 1';
95 
114  function set_add_limitations( $theAddLimitation )
115  {
116  try
117  {
118  if( $this->AddLimitations === '1 = 1' )
119  {
120  $this->AddLimitations = $theAddLimitation;
121  }
122  else
123  {
124  throw( new Exception( '"AddLimitations" was already set' ) );
125  }
126  }
127  catch( Exception $e )
128  {
129  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
130  }
131  }
132 
155  function unsafe_select( $Condition )
156  {
157  try
158  {
159  $this->Database->query_as( DB_OBJECT );
160 
161  return(
162  $this->Database->select(
163  $this->UserAccess->NativeTable.'.* , '.$this->NativeTable.'.*' ,
164  $this->NativeTable.' , '.$this->UserAccess->NativeTable ,
165  $this->NativeTable.'.author = '.$this->UserAccess->NativeTable.".id
166  AND ( $this->AddLimitations ) AND $Condition"
167  )
168  );
169  }
170  catch( Exception $e )
171  {
172  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
173  }
174  }
175 
214  function select( $Start = false , $Limit = false , $Field = false ,
215  $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  return( $this->unsafe_select( $Condition ) );
224  }
225  catch( Exception $e )
226  {
227  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
228  }
229  }
230 
253  function delete( $id , $Options = ' 1 = 1' )
254  {
255  try
256  {
257  $Link = get_package( 'link' , 'last' , __FILE__ );
258  $Link->delete_link( false , $id , false , 'comment' );
259 
260  $id = $this->Security->get( $id , 'integer_list' );
261  $this->Database->delete( $this->NativeTable , "( $this->AddLimitations ) AND id IN ( $id )" );
262  $this->Database->commit();
263  }
264  catch( Exception $e )
265  {
266  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
267  }
268  }
269 
292  private function compile_record( &$Record )
293  {
294  try
295  {
296  $MasterLink = $this->SecurityParser->parse_parameters(
297  $Record , 'master_type:command;master_id:integer'
298  );
299 
300  $Record = $this->SecurityParser->parse_parameters( $Record , 'comment:string' );
301  set_field( $Record , 'author' , $this->UserAlgorithms->get_id() );
302  set_field( $Record , 'page' , $this->Security->get_srv( 'REQUEST_URI' , 'string' , './index.html' ) );
303 
304  return( $Record );
305  }
306  catch( Exception $e )
307  {
308  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
309  }
310  }
311 
334  function create( $Record )
335  {
336  try
337  {
338  $Record = $this->compile_record( $Record );
339 
340  list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record , CREATION_DATE );
341 
342  $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
343 
344  $Link = get_package( 'link' , 'last' , __FILE__ );
345  $Link->create_link(
346  get_field( $MasterLink , 'master_id' ) , $id ,
347  get_field( $MasterLink , 'master_type' ) , 'comment'
348  );
349 
350  $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
351  $EventManager->trigger_event( 'on_after_create_comment' , array( 'id' => $id ) );
352 
353  return( $id );
354  }
355  catch( Exception $e )
356  {
357  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
358  }
359  }
360 
383  function update( $id , $Record )
384  {
385  try
386  {
387  $id = $this->Security->get( $id , 'integer_list' );
388  $Record = $this->SecurityParser->parse_parameters( $Record , 'comment:string' , 'allow_not_set' );
389 
390  list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
391 
392  if( isset( $Fields[ 0 ] ) )
393  {
394  $this->Database->update(
395  $this->NativeTable , $Fields , $Values , "( $this->AddLimitations ) AND id IN ( $id )"
396  );
397  $this->Database->commit();
398  }
399  }
400  catch( Exception $e )
401  {
402  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
403  }
404  }
405 
428  function select_list( $id )
429  {
430  try
431  {
432  $id = $this->Security->get( $id , 'integer_list' );
433 
434  return( $this->unsafe_select( $this->NativeTable.".id IN ( $id ) ORDER BY creation_date ASC" ) );
435  }
436  catch( Exception $e )
437  {
438  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
439  }
440  }
441  }
442 
443 ?>