ultimix
default_controllers.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 $ContextSetUtilities = false;
39  var $GUI = false;
40  var $SecurityParser = false;
41 
52  var $Prefix = false;
53 
64  var $Provider = false;
65 
80  function __construct()
81  {
82  try
83  {
84  $this->ContextSetUtilities = get_package(
85  'gui::context_set::context_set_utilities' , 'last' , __FILE__
86  );
87  $this->GUI = get_package( 'gui' , 'last' , __FILE__ );
88  $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
89  }
90  catch( Exception $e )
91  {
92  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
93  }
94  }
95 
118  function set_constants( &$ContextSet , &$Options )
119  {
120  try
121  {
122  $this->Prefix = $ContextSet->Prefix;
123  $this->Provider = $ContextSet->Provider;
124  }
125  catch( Exception $e )
126  {
127  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
128  }
129  }
130 
149  function delete( &$Options )
150  {
151  try
152  {
153  $Provider = $this->ContextSetUtilities->get_data_provider( $Options , $this->Provider );
154  $FunctionName = $Options->get_setting( 'delete_func' , 'delete' );
155  $Ids = $this->ContextSetUtilities->get_posted_ids( $this->Prefix );
156 
157  if( method_exists( $Provider , $FunctionName ) === true )
158  {
159  call_user_func( array( $Provider , $FunctionName ) , implode( ',' , $Ids ) , $Options );
160  }
161  else
162  {
163  $ClassName = $Provider ? get_class( $Provider ) : 'undefined_class';
164  throw( new Exception( "Method \"$FunctionName\" was not found in the class \"$ClassName.\"" ) );
165  }
166  }
167  catch( Exception $e )
168  {
169  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
170  }
171  }
172 
191  function multy_call( &$Options )
192  {
193  try
194  {
195  $Ids = $this->ContextSetUtilities->get_posted_ids( $this->Prefix );
196  $Provider = $this->ContextSetUtilities->get_data_provider( $Options , $this->Provider );
197 
198  if( $Options->get_setting( 'id_list_accept' , 1 ) == '1' )
199  {
200  call_user_func(
201  array( $Provider , $Options->get_setting( 'func_name' ) ) , implode( $Ids ) , $Options
202  );
203  }
204  else
205  {
206  foreach( $Ids as $id )
207  {
208  call_user_func( array( $Provider , $Options->get_setting( 'func_name' ) ) , $id , $Options );
209  }
210  }
211  }
212  catch( Exception $e )
213  {
214  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
215  }
216  }
217 
240  private function get_creation_data( &$Options )
241  {
242  try
243  {
244  $ExtractionScript = $Options->get_setting( 'get_post_extraction_script' );
245  $Record = $this->SecurityParser->parse_http_parameters( $ExtractionScript );
246 
247  $FunctionName = $Options->get_setting( 'create_func' , 'create' );
248  $Provider = $this->ContextSetUtilities->get_data_provider( $Options , $this->Provider );
249 
250  return( array( $Record , $FunctionName , $Provider ) );
251  }
252  catch( Exception $e )
253  {
254  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
255  }
256  }
257 
276  function create( &$Options )
277  {
278  try
279  {
280  list( $Record , $FunctionName , $Provider ) = $this->get_creation_data( $Options );
281 
282  if( method_exists( $Provider , $FunctionName ) === true )
283  {
284  $id = call_user_func( array( $Provider , $FunctionName ) , $Record , $Options );
285  $this->GUI->set_var( 'record_id' , $id );
286  }
287  else
288  {
289  $ClassName = $Provider ? get_class( $Provider ) : 'undefined_class';
290  throw( new Exception( "Method \"$FunctionName\" was not found in the class \"$ClassName.\"" ) );
291  }
292  }
293  catch( Exception $e )
294  {
295  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
296  }
297  }
298 
325  private function compile_update_record( $RecordNew , $RecordOriginal )
326  {
327  try
328  {
329  $UpdateRecord = array();
330 
331  foreach( $RecordNew as $Field => $NewValue )
332  {
333  $Field = str_replace( $this->Prefix.'_' , '' , $Field );
334 
335  if( @$RecordOriginal->$Field != $NewValue )
336  {
337  @$UpdateRecord[ $Field ] = $NewValue;
338  }
339  }
340 
341  return( $UpdateRecord );
342  }
343  catch( Exception $e )
344  {
345  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
346  }
347  }
348 
379  function get_update_record( &$Options , $Ids , $RecordOriginal )
380  {
381  try
382  {
383  $GetPostValidation = $Options->get_setting( 'get_post_validation' , false );
384  $ValidationScript = $Options->get_setting( 'custom_get_post_validation' , $GetPostValidation );
385 
386  if( $ValidationScript === false )
387  {
388  throw( new Exception( 'There is no script to extract data from http headers' ) );
389  }
390 
391  $RecordNew = $this->SecurityParser->parse_http_parameters( $ValidationScript );
392 
393  return( $this->compile_update_record( $RecordNew , $RecordOriginal ) );
394  }
395  catch( Exception $e )
396  {
397  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
398  }
399  }
400 
423  private function get_update_data( &$Options )
424  {
425  try
426  {
427  $Ids = $this->ContextSetUtilities->get_posted_ids( $this->Prefix );
428 
431  $RecordOriginal = $this->ContextSetUtilities->get_data_record( $Options , $Ids );
432 
433  $UpdateRecord = $this->get_update_record( $Options , $Ids , $RecordOriginal );
434 
435  return( array( $Ids , $UpdateRecord ) );
436  }
437  catch( Exception $e )
438  {
439  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
440  }
441  }
442 
461  function update( &$Options )
462  {
463  try
464  {
465  list( $Ids , $UpdateRecord ) = $this->get_update_data( $Options );
466 
467  $Provider = $this->ContextSetUtilities->get_data_provider( $Options , $this->Provider );
468 
469  $FunctionName = $Options->get_setting( 'update_func' , 'update' );
470 
471  if( method_exists( $Provider , $FunctionName ) === true )
472  {
473  $Func = array( $Provider , $FunctionName );
474 
475  call_user_func( $Func , implode( ',' , $Ids ) , $UpdateRecord , $Options );
476  }
477  else
478  {
479  $ClassName = $Provider ? get_class( $Provider ) : 'undefined_class';
480 
481  throw( new Exception( "Method \"$FunctionName\" was not found in the class \"$ClassName.\"" ) );
482  }
483  }
484  catch( Exception $e )
485  {
486  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
487  }
488  }
489 
508  function copy( &$Options )
509  {
510  try
511  {
512  $Options->set_setting( 'create_func' , $Options->get_setting( 'copy_func' ) );
513  $this->create( $Options );
514  }
515  catch( Exception $e )
516  {
517  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
518  }
519  }
520  }
521 
522 ?>