ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

default_views.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
26 class default_views_1_0_0{
27
38 var $AutoMarkup = false;
39 var $CachedMultyFS = false;
40 var $ContextSetUtilities = false;
41 var $DefaultViewsUtilities = false;
42 var $Security = false;
43 var $String = false;
44 var $UserAlgorithms = false;
45
56 var $Prefix = false;
57
68 var $Provider = false;
69
80 var $ContextSet = false;
81
96 function __construct()
97 {
98 try
99 {
100 $this->AutoMarkup = get_package( 'page::auto_markup' , 'last' , __FILE__ );
101 $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
102 $this->ContextSetUtilities = get_package(
103 'gui::context_set::context_set_utilities' , 'last' , __FILE__
104 );
105 $this->DefaultViewsUtilities = get_package(
106 'gui::context_set::default_views::default_views_utilities' , 'last' , __FILE__
107 );
108 $this->Security = get_package( 'security' , 'last' , __FILE__ );
109 $this->String = get_package( 'string' , 'last' , __FILE__ );
110 }
111 catch( Exception $e )
112 {
113 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
114 }
115 }
116
139 function set_constants( &$ContextSet , &$Options )
140 {
141 try
142 {
143 $this->Prefix = $ContextSet->Prefix;
144 $this->Provider = $ContextSet->Provider;
145 $this->ContextSet = &$ContextSet;
146
147 $this->DefaultViewsUtilities->set_constants( $ContextSet , $Options );
148 }
149 catch( Exception $e )
150 {
151 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
152 }
153 }
154
173 function list_form( &$Options )
174 {
175 try
176 {
177 $Paging = get_package( 'gui::paging' , 'last' , __FILE__ );
178
179 $this->DefaultViewsUtilities->construct_paging( $Options , $Paging );
180
181 $this->Provider->Output = $Paging->draw( false , $Options );
182
183 $this->Provider->Output = $this->DefaultViewsUtilities->compile_form(
184 $Options , $this->Provider->Output
185 );
186
187 $this->Provider->Output = $this->AutoMarkup->compile_string( $this->Provider->Output );
188 }
189 catch( Exception $e )
190 {
191 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
192 }
193 }
194
213 function create_form( &$Options )
214 {
215 try
216 {
217 if( $Options->get_setting( 'default_form' , 1 ) == 0 )
218 {
219 call_user_func( array( $this->Provider , 'create_form' ) , $Options );
220 }
221 else
222 {
223 $this->Provider->Output = $this->ContextSetUtilities->get_form(
224 $Options , array() , 'create_form' , $this->Prefix , 'create_record'
225 );
226 }
227
228 $this->Provider->Output = $this->DefaultViewsUtilities->apply_posted_data_for_create_form(
229 $Options , $this->Provider->Output
230 );
231
232 $this->DefaultViewsUtilities->compile_form( $Options , $this->Provider->Output );
233 }
234 catch( Exception $e )
235 {
236 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
237 }
238 }
239
258 function update_form( &$Options )
259 {
260 try
261 {
262 $IdList = $this->ContextSetUtilities->get_posted_ids( $this->Prefix );
263
264 if( $Options->get_setting( 'default_form' , 1 ) == 0 )
265 {
266 call_user_func( array( $this->Provider , 'update_form' ) , $Options );
267 }
268 else
269 {
270 $this->Provider->Output = $this->ContextSetUtilities->get_form(
271 $Options , $IdList , 'update_form' , $this->Prefix , 'update_record'
272 );
273 }
274
275 $this->Provider->Output = $this->DefaultViewsUtilities->compile_form(
276 $Options , $this->Provider->Output , $IdList
277 );
278 }
279 catch( Exception $e )
280 {
281 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
282 }
283 }
284
307 private function get_copy_form( &$Options )
308 {
309 try
310 {
311 if( $this->Security->get_gp( $this->Prefix.'_action' , 'command' , '' ) !== '' )
312 {
313 $Record = $IdList = array();
314 }
315 else
316 {
317 $IdList = $this->ContextSetUtilities->get_posted_ids( $this->Prefix );
318
319 $Record = $this->ContextSetUtilities->get_data_record( $Options , $IdList );
320 }
321
322 $Record = $this->ContextSetUtilities->extract_data_from_request(
323 $Options , $Record , 'get_post_extraction_script' , $this->Prefix
324 );
325
326 $Form = $this->ContextSetUtilities->get_form(
327 $Options , $IdList , 'copy_form' , $this->Prefix , 'create_record'
328 );
329
330 return( $Form );
331 }
332 catch( Exception $e )
333 {
334 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
335 }
336 }
337
356 function copy_form( &$Options )
357 {
358 try
359 {
360 $Form = $this->get_copy_form( $Options );
361
362 $this->Provider->Output = $this->ContextSetUtilities->set_form_data( $Form , $Record );
363
364 $this->DefaultViewsUtilities->compile_form( $Options , $this->Provider->Output );
365 }
366 catch( Exception $e )
367 {
368 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
369 }
370 }
371
394 function get_grid_templates( &$Options )
395 {
396 try
397 {
398 $Header = $this->DefaultViewsUtilities->get_template( $Options , 'header' );
399
400 $Item = $Options->get_setting( 'item' );
401 $Item = dirname( $Options->get_setting( 'file_path' ) )."/res/templates/$Item.tpl";
402 $Item = $this->CachedMultyFS->file_get_contents( $Item );
403
404 $Footer = $this->DefaultViewsUtilities->get_template( $Options , 'footer' );
405
406 return( array( $Header , $Item , $Footer ) );
407 }
408 catch( Exception $e )
409 {
410 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
411 }
412 }
413
432 function last_records_form( &$Options )
433 {
434 try
435 {
436 $DataProvider = $this->ContextSetUtilities->get_data_provider( $Options , $this->Provider );
437
438 $FunctionName = $Options->get_setting( 'select_func' , 'select' );
439
440 $Limit = $Options->get_setting( 'records_count' , 3 );
441
442 $Records = call_user_func( array( $DataProvider , $FunctionName ) , 0 , $Limit , 'id' , 'DESC' );
443
444 list( $Header , $Item , $Footer ) = $this->get_grid_templates( $Options );
445
446 $Items = '';
447
448 foreach( $Records as $i => $Record )
449 {
450 $Items .= $this->String->print_record( $Item , $Record );
451 }
452
453 $this->Provider->Output = $Header.$Items.$Footer;
454 }
455 catch( Exception $e )
456 {
457 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
458 }
459 }
460
483 function get_select_condition( &$Options )
484 {
485 try
486 {
487 $MasterType = $Options->get_setting( 'master_type' , 'user' );
488
489 if( $MasterType == 'user' && $MasterId == false )
490 {
491 if( $this->UserAlgorithms === false )
492 {
493 $this->UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
494 }
495
496 return( "owner = ".$this->UserAlgorithms->get_id() );
497 }
498 else
499 {
500 throw( new Exception( "Illegal parameters of dependent records detection" ) );
501 }
502 }
503 catch( Exception $e )
504 {
505 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
506 }
507 }
508
527 function dependent_records_form( &$Options )
528 {
529 try
530 {
531 $DataProvider = $this->ContextSetUtilities->get_data_provider( $Options , $this->Provider );
532
533 $FunctionName = $Options->get_setting( 'select_func' , 'select' );
534
535 $Condition = $this->get_select_condition( $Options );
536
537 $Records = call_user_func(
538 array( $DataProvider , $FunctionName ) , false , false , false , false , $Condition
539 );
540
541 list( $Header , $Item , $Footer ) = $this->get_grid_templates( $Options );
542
543 $Items = '';
544
545 foreach( $Records as $i => $Record )
546 {
547 $Items .= $this->String->print_record( $Item , $Record );
548 }
549
550 $this->Provider->Output = $Header.$Items.$Footer;
551 }
552 catch( Exception $e )
553 {
554 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
555 }
556 }
557
576 function record_view_form( &$Options )
577 {
578 try
579 {
580 $TemplateName = $Options->get_setting( 'form_template' , $this->ContextSet->Prefix.'_view_form.tpl' );
581 $ComponentPath = dirname( $Options->get_setting( 'file_path' ) ).'/unexisting_script';
582 $Template = $this->CachedMultyFS->get_template( $ComponentPath , $TemplateName );
583
584 $Provider = $this->ContextSetUtilities->get_data_provider( $Options , $this->Provider );
585
586 $id = $this->Security->get_gp( $this->Prefix.'_record_id' , 'integer' );
587 $Records = call_user_func( array( $Provider , 'select_list' ) , $id );
588
589 $Template = $this->String->print_record( $Template , $Records[ 0 ] );
590 $this->Provider->Output = $Template;
591 }
592 catch( Exception $e )
593 {
594 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
595 }
596 }
597
616 function simple_form( &$Options )
617 {
618 try
619 {
620 $FormTemplateFileName = $Options->get_setting( 'form_template' );
621 $FilePath = $Options->get_setting( 'file_path' );
622
623 $Form = $this->CachedMultyFS->get_template( $FilePath , "$FormTemplateFileName.tpl" );
624
625 $Changed = false;
626
627 $Form = $this->ContextSet->compile_special_macro( $Options , $Form , $Changed );
628
629 list( $Form , $Changed ) = $this->ContextSet->compile_prefix( $Form , $Changed );
630
631 $this->Provider->Output = $Form;
632 }
633 catch( Exception $e )
634 {
635 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
636 }
637 }
638
661 private function set_list_view_custom_buttons( &$Options , $Paging )
662 {
663 try
664 {
665 $HeaderFields =
666 '<input type="hidden" name="{prefix}_context_action" id="{prefix}_context_action" value="">
667 <input type="hidden" name="{prefix}_action" id="{prefix}_action" value="">
668 <input type="hidden" name="{prefix}_record_id" id="{prefix}_record_id" value="">';
669 $Paging->set( 'CustomButtons' , $HeaderFields );
670 }
671 catch( Exception $e )
672 {
673 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
674 }
675 }
676
699 private function set_list_view_parts( &$Options , $Paging )
700 {
701 try
702 {
703 $this->set_list_view_custom_buttons( $Options , $Paging );
704 $this->ContextSetUtilities->set_header_template( $Options , $Paging , $this->Prefix );
705 $this->ContextSetUtilities->set_item_template( $Options , $Paging , $this->Prefix );
706 $this->ContextSetUtilities->set_no_data_found_message( $Options , $Paging , $this->Prefix );
707 $this->ContextSetUtilities->set_footer_template( $Options , $Paging , $this->Prefix );
708 $this->ContextSetUtilities->set_main_settings( $Options , $Paging );
709 $this->ContextSetUtilities->set_grid_data( $Options , $Paging );
710 }
711 catch( Exception $e )
712 {
713 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
714 }
715 }
716
735 function list_view( &$Options )
736 {
737 try
738 {
739 $Paging = get_package( 'gui::paging' , 'last' , __FILE__ );
740 $Paging->set( 'FormId' , $this->Prefix.'_form' );
741 $Paging->set( 'Prefix' , $this->Prefix );
742
743 $this->set_list_view_parts( $Options , $Paging );
744
745 $Str = $Paging->draw( false , $Options );
746
747 $Str = $this->ContextSet->compile_special_macro( $Options , $Str , $Changed );
748 list( $this->Provider->Output , $Changed ) = $this->ContextSet->compile_prefix( $Str , $Changed );
749 }
750 catch( Exception $e )
751 {
752 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
753 }
754 }
755 }
756
757 ?>