ultimix
common_state_startup.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 $ContextSetMarkup = false;
39  var $PermitAlgorithms = false;
40  var $Security = false;
41  var $StartupUtilities = false;
42  var $Trace = false;
43 
54  var $Prefix = false;
55 
70  function __construct()
71  {
72  try
73  {
74  $this->ContextSetMarkup = get_package( 'gui::context_set::context_set_markup' , 'last' , __FILE__ );
75  $this->PermitAlgorithms = get_package( 'permit::permit_algorithms' , 'last' , __FILE__ );
76  $this->Security = get_package( 'security' , 'last' , __FILE__ );
77  $PackageName = 'gui::context_set::common_state_startup::common_state_startup_utilities';
78  $this->StartupUtilities = get_package( $PackageName , 'last' , __FILE__ );
79  $this->Trace = get_package( 'trace' , 'last' , __FILE__ );
80  }
81  catch( Exception $e )
82  {
83  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
84  }
85  }
86 
109  function set_constants( &$ContextSet , $Options )
110  {
111  try
112  {
113  $this->Prefix = $ContextSet->Prefix;
114  $this->StartupUtilities->DefaultControllers->set_constants( $ContextSet , $Options );
115  $this->StartupUtilities->DefaultViews->set_constants( $ContextSet , $Options );
116  }
117  catch( Exception $e )
118  {
119  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
120  }
121  }
122 
149  private function not_processed( &$ContextSet , $Str1 , $Str2 )
150  {
151  try
152  {
153  $this->StartupUtilities->trace_no_need_to_run_state_message( $Str1 , $this->Prefix , $Str2 );
154  }
155  catch( Exception $e )
156  {
157  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
158  }
159  }
160 
161  //TODO: store page permits in db
162 
189  private function run_it( &$Options , $State )
190  {
191  try
192  {
193  $HintedContext = $Options->get_setting( 'common_context' , false );
194 
195  if( $HintedContext === false )
196  {
197  return( true );
198  }
199 
200  return( $HintedContext == $State );
201  }
202  catch( Exception $e )
203  {
204  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
205  }
206  }
207 
238  private function controller_state_startup( &$ContextSet , &$Options , $State )
239  {
240  try
241  {
242  $ContextSet->Trace->start_group( '{lang:'.$State.'_state}' );
243 
244  $Action = $this->Security->get_gp( $this->Prefix.'_action' , 'command' , '' );
245  $Direct = $Options->get_setting( 'direct_'.$State , 0 );
246 
247  if( $Action == $State.'_record' || $Direct != 0 )
248  {
249  $Result = $this->StartupUtilities->try_run_controller_state( $ContextSet , $Options , $State );
250  }
251  else
252  {
253  $Result = false;
254  $this->not_processed( $ContextSet , $State , $State.'_record' );
255  }
256 
257  $ContextSet->Trace->end_group();
258  return( $Result );
259  }
260  catch( Exception $e )
261  {
262  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
263  }
264  }
265 
292  function run_controller_states( &$ContextSet , &$Options )
293  {
294  try
295  {
296  $Next = true;
297 
298  $States = array( 'delete' , 'create' , 'update' , 'copy' );
299 
300  foreach( $States as $i => $State )
301  {
302  if( $this->run_it( $Options , $State ) )
303  {
304  if( $this->controller_state_startup( $ContextSet , $Options , $State ) )
305  {
306  return( true );
307  }
308  }
309  }
310 
311  return( false );
312  }
313  catch( Exception $e )
314  {
315  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
316  }
317  }
318 
349  private function view_state_startup( &$ContextSet , &$Options , $State )
350  {
351  try
352  {
353  $ContextSet->Trace->start_group( '{lang:'.$State.'_form_state}' );
354 
355  $Action = $this->Security->get_gp( $this->Prefix.'_context_action' , 'command' , '' );
356  $Direct = $Options->get_setting( 'direct_'.$State , 0 );
357 
358  $IsList = ( $State == 'list' && $Action == '' );
359 
360  if( $IsList || $Action == $State.'_record_form' || $Direct != 0 )
361  {
362  $Result = $this->StartupUtilities->try_run_view_state( $ContextSet , $Options , $State );
363  }
364  else
365  {
366  $Result = false;
367  $this->not_processed( $ContextSet , $State , $State.'_form' );
368  }
369 
370  $ContextSet->Trace->end_group();
371  return( $Result );
372  }
373  catch( Exception $e )
374  {
375  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
376  }
377  }
378 
405  function run_view_states( &$ContextSet , &$Options )
406  {
407  try
408  {
409  $Next = true;
410 
411  $States = array( 'list' , 'create' , 'update' , 'copy' , 'record_view' );
412 
413  foreach( $States as $i => $State )
414  {
415  if( $this->run_it( $Options , $State ) )
416  {
417  if( $this->view_state_startup( $ContextSet , $Options , $State ) )
418  {
419  return( true );
420  }
421  }
422  }
423 
424  return( false );
425  }
426  catch( Exception $e )
427  {
428  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
429  }
430  }
431 
458  function run_common_states( &$ContextSet , &$Options )
459  {
460  try
461  {
462  $this->Trace->start_group( "common_configs_processing" , COMMON );
463  $Result = false;
464  $this->set_constants( $ContextSet , $Options );
465  if( $Options->get_setting( 'controller' , 0 ) != 0 )
466  {
467  $Result = $this->run_controller_states( $ContextSet , $Options );
468  }
469  else
470  {
471  $this->Trace->add_trace_string( "no_controllers" , COMMON );
472  }
473  if( $Options->get_setting( 'view' , 0 ) != 0 )
474  {
475  $Result = $this->run_view_states( $ContextSet , $Options );
476  }
477  else
478  {
479  $this->Trace->add_trace_string( "no_views" , COMMON );
480  }
481  $this->Trace->end_group();
482  return( $Result );
483  }
484  catch( Exception $e )
485  {
486  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
487  }
488  }
489  }
490 
491 ?>