ultimix
common_state_startup_utilities.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 $ContextSetConfigs = false;
39  var $DefaultControllers = false;
40  var $DefaultViews = false;
41  var $LocalOptions = false;
42  var $Security = false;
43  var $Trace = false;
44 
59  function __construct()
60  {
61  try
62  {
63  $this->ContextSetConfigs = get_package( 'gui::context_set::context_set_configs' , 'last' , __FILE__ );
64  $this->DefaultControllers = get_package( 'gui::context_set::default_controllers' , 'last' , __FILE__ );
65  $this->DefaultViews = get_package( 'gui::context_set::default_views' , 'last' , __FILE__ );
66  $this->LocalOptions = get_package_object( 'settings::settings' , 'last' , __FILE__ );
67  $this->Security = get_package( 'security' , 'last' , __FILE__ );
68  $this->Trace = get_package( 'trace' , 'last' , __FILE__ );
69  }
70  catch( Exception $e )
71  {
72  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
73  }
74  }
75 
110  function get_common_state_config( &$ContextSet , $Options , $StateName , $Suffix = '' )
111  {
112  try
113  {
114  $FieldName = 'common_state_config_'.$StateName.$Suffix;
115  $FileName = 'cfcxs_'.$StateName.$Suffix;
116 
117  return(
118  $this->ContextSetConfigs->get_common_state_config(
119  $ContextSet->ContextSetSettings , $FieldName , $FileName , $Options->get_setting( 'file_path' )
120  )
121  );
122  }
123  catch( Exception $e )
124  {
125  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
126  }
127  }
128 
155  private function trace_field( $Prefix , $FieldSuffix , $RequiredValue )
156  {
157  try
158  {
159  $Field = $Prefix.'_'.$FieldSuffix;
160 
161  $PostedValue = $this->Security->get_gp( $Field , 'command' , 'not set' );
162 
163  $Message = $Prefix.'_'.$FieldSuffix.': "'.$PostedValue.'"';
164 
165  $this->Trace->add_trace_string( $Message );
166 
167  $this->Trace->add_trace_string( "required_".$FieldSuffix." : \"$RequiredValue\"" );
168  }
169  catch( Exception $e )
170  {
171  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
172  }
173  }
174 
201  function trace_no_need_to_run_state_message( $StateName , $Prefix , $ContextAction )
202  {
203  try
204  {
205  $this->Trace->add_trace_string( '{lang:no_need_to_run_trace_message}' , COMMON );
206 
207  if( strpos( $ContextAction , '_form' ) !== false )
208  {
209  $this->trace_field( $Prefix , 'context_action' , $ContextAction );
210  }
211 
212  if( strpos( $ContextAction , '_form' ) === false )
213  {
214  $this->trace_field( $Prefix , 'action' , $StateName );
215  }
216  }
217  catch( Exception $e )
218  {
219  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
220  }
221  }
222 
241  function trace_config_was_not_found_message( $StateName )
242  {
243  try
244  {
245  $this->Trace->add_trace_string( "State config was not found ( $StateName )" );
246  }
247  catch( Exception $e )
248  {
249  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
250  }
251  }
252 
283  function prepare_config( &$ContextSet , $Config , $StateName )
284  {
285  try
286  {
287  if( strpos( $Config , 'success_message=' ) === false )
288  {
289  $Config .= "\r\nsuccess_message=".$ContextSet->Prefix.'_'.$StateName.'_was_completed';
290  }
291  if( strpos( $Config , 'cleanup_fields=' ) === false )
292  {
293  $Config .= "\r\ncleanup_fields=".$ContextSet->Prefix."_action,".
294  $ContextSet->Prefix."_context_action";
295  }
296  if( strpos( $Config , 'success_func=' ) === false )
297  {
298  $Config .= "\r\nsuccess_func=$StateName";
299  }
300 
301  return( $Config );
302  }
303  catch( Exception $e )
304  {
305  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
306  }
307  }
308 
343  function run_controller_state( &$ContextSet , $Options , $StateName , $Config )
344  {
345  try
346  {
347  $Config = $this->prepare_config( $ContextSet , $Config , $StateName );
348 
349  $this->LocalOptions->clear();
350  $this->LocalOptions->append_settings( $Config );
351  $this->LocalOptions->add_settings_from_object( $Options );
352  $this->LocalOptions->set_undefined( 'access_package_version' , 'last' );
353  $this->LocalOptions->set_undefined( $StateName.'_func' , $StateName == 'copy' ? 'create' : $StateName );
354 
355  $ContextSet->Context->load_raw_config( $Config );
356  if( $ContextSet->run_execution( $this->LocalOptions , $this->DefaultControllers , 1 ) )
357  {
358  return( true );
359  }
360 
361  return( false );
362  }
363  catch( Exception $e )
364  {
365  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
366  }
367  }
368 
399  function prepare_options( $Options , $StateName , $Config )
400  {
401  try
402  {
403  $this->LocalOptions->clear();
404  $this->LocalOptions->append_settings( $Config );
405  $this->LocalOptions->add_settings_from_object( $Options );
406  $this->LocalOptions->set_undefined( 'access_package_version' , 'last' );
407 
408  if( strpos( $Config , 'success_func' ) === false )
409  {
410  $Suffix = '_form';
411  $Config .= "\r\nsuccess_func=".$StateName.$Suffix;
412  $this->LocalOptions->set_undefined( 'success_func' , $StateName.$Suffix );
413  }
414 
415  return( $Config );
416  }
417  catch( Exception $e )
418  {
419  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
420  }
421  }
422 
457  function run_view_state( &$ContextSet , $Options , $StateName , $Config )
458  {
459  try
460  {
461  $this->Trace->add_trace_string( '{lang:run_view_state}' , COMMON );
462 
463  $Config = $this->prepare_options( $Options , $StateName , $Config );
464 
465  $ContextSet->Context->load_raw_config( $Config );
466 
467  if( $ContextSet->Context->execute( $this->LocalOptions , $this->DefaultViews ) )
468  {
469  $this->Trace->add_trace_string( '{lang:run_view_state_true}' , COMMON );
470  return( true );
471  }
472 
473  $this->Trace->add_trace_string( '{lang:run_view_state_false}' , COMMON );
474  return( false );
475  }
476  catch( Exception $e )
477  {
478  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
479  }
480  }
481 
512  function try_run_controller_state( &$ContextSet , $Options , $StateName )
513  {
514  try
515  {
516  $Config = $this->get_common_state_config( $ContextSet , $Options , $StateName );
517 
518  if( $Config !== false )
519  {
520  return( $this->run_controller_state( $ContextSet , $Options , $StateName , $Config ) );
521  }
522  else
523  {
524  $this->trace_config_was_not_found_message( $StateName );
525  }
526 
527  return( false );
528  }
529  catch( Exception $e )
530  {
531  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
532  }
533  }
534 
565  function try_run_view_state( &$ContextSet , $Options , $StateName )
566  {
567  try
568  {
569  $Config = $this->get_common_state_config( $ContextSet , $Options , $StateName , '_form' );
570 
571  if( $Config !== false )
572  {
573  return( $this->run_view_state( $ContextSet , $Options , $StateName , $Config ) );
574  }
575  else
576  {
577  $this->trace_config_was_not_found_message( $StateName );
578  }
579 
580  return( false );
581  }
582  catch( Exception $e )
583  {
584  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
585  }
586  }
587  }
588 
589 ?>