ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

category_widgets.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 category_widgets_1_0_0{
27
38 var $BlockSettings = false;
39 var $CachedMultyFS = false;
40 var $CategoryAccess = false;
41 var $CategoryAlgorithms = false;
42 var $CategoryView = false;
43 var $String = false;
44
55 function __construct()
56 {
57 try
58 {
59 $this->BlockSettings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
60 $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
61 $this->CategoryAccess = get_package( 'category::category_access' , 'last' , __FILE__ );
62 $this->CategoryAlgorithms = get_package( 'category::category_algorithms' , 'last' , __FILE__ );
63 $this->CategoryView = get_package( 'category::category_view' , 'last' , __FILE__ );
64 $this->String = get_package( 'string' , 'last' , __FILE__ );
65 }
66 catch( Exception $e )
67 {
68 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
69 }
70 }
71
94 function compile_category_tree( &$BlockSettings )
95 {
96 try
97 {
98 $this->CategoryView->draw_categories_tree( $BlockSettings );
99
100 return( $this->CategoryVie->Output );
101 }
102 catch( Exception $e )
103 {
104 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
105 }
106 }
107
130 function compile_categories_list_type_list( &$Categories )
131 {
132 try
133 {
134 $Titles = get_field_ex( $Categories , 'title' );
135
136 $Template = $this->CachedMultyFS->get_template( __FILE__ , 'categories_list_type_list.tpl' );
137
138 $TitleTemplate = $this->CachedMultyFS->get_template( __FILE__ , 'title_item.tpl' );
139
140 return( str_replace( '{titles}' , implode( $TitleTemplate , $Titles ) , $Template ) );
141 }
142 catch( Exception $e )
143 {
144 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
145 }
146 }
147
174 private function compile_active_list_code( &$AllCategories , &$Categories )
175 {
176 try
177 {
178 $ids = get_field_ex( $Categories , 'id' );
179
180 $Code = '';
181 foreach( $AllCategories as $i => $Category )
182 {
183 $id = get_field( $Category , 'id' );
184 $Title = get_field( $Category , 'title' );
185
186 $Checked = in_array( $id , $ids ) ? 'on' : 'off';
187
188 $Code .= $this->CachedMultyFS->get_template( __FILE__ , 'category_active_list.tpl' );
189 $PlaceHolders = array( '{id}' , '{checked}' , '{title}' );
190
191 $Code = str_replace( $PlaceHolders , array( $id , $Checked , $Title ) , $Code );
192 }
193 }
194 catch( Exception $e )
195 {
196 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
197 }
198 }
199
234 function compile_categories_list_type_active_list( &$AllCategories , &$Categories ,
235 $MasterId , $MasterType )
236 {
237 try
238 {
239 $Code = $this->compile_active_list_code( $AllCategories , $Categories );
240
241 $ActiveListTemplate = $this->CachedMultyFS->get_template( __FILE__ , 'active_list.tpl' );
242
243 $PlaceHolders = array( '{code}' , '{master_id}' , '{master_type}' );
244
245 return( str_replace( $PlaceHolders , array( $Code , $MasterId , $MasterType ) , $ActiveListTemplate ) );
246 }
247 catch( Exception $e )
248 {
249 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
250 }
251 }
252
283 private function redefine_type( $MasterId , $MasterType , $Type )
284 {
285 try
286 {
287 if( $this->OwnershipAccess->owner_was_registered( $MasterId , $MasterType ) === false )
288 {
289 $Type = 'list';
290 }
291
292 return( $Type );
293 }
294 catch( Exception $e )
295 {
296 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
297 }
298 }
299
326 private function categories_list( &$AllCategories , $Type )
327 {
328 try
329 {
330 list( $MasterId , $MasterType ) = $this->BlockSettings->get_settings( 'master_id,master_type' );
331
332 $Type = $this->redefine_type( $MasterId , $MasterType , $Type );
333
334 $Categories = $this->CategoryAlgorithms->get_object_categories( $MasterId , $MasterType );
335
336 switch( $Type )
337 {
338 case( 'list' ):return( $this->compile_categories_list_type_list( $Categories ) );
339 case( 'active_list' ):
340 $Code = $this->compile_categories_list_type_active_list(
341 $AllCategories , $Categories , $MasterId , $MasterType );
342 return( $Code );
343 default:return( '{lang:illegal_list_type}' );
344 }
345 }
346 catch( Exception $e )
347 {
348 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
349 }
350 }
351
374 private function compile_category_list( &$BlockSettings )
375 {
376 try
377 {
378 $Type = $BlockSettings->get_setting( 'type' , 'list' );
379 $CategoryName = $BlockSettings->get_setting( 'category_name' );
380
381 if( $Type == 'checkbox_list' )
382 {
383 $ids = implode( ' , ' , $this->CategoryAlgorithms->get_category_ids( $CategoryName ) );
384 $Code = "{checkboxset:cols=1;query=SELECT id , title FROM umx_category WHERE ".
385 "direct_category IN ( $ids ) AND id <> direct_category;checked_all=1}";
386 }
387 else
388 {
389 $AllCategories = $this->CategoryAccess->get_children_by_name( $CategoryName );
390 $Code = $this->categories_list( $AllCategories , $Type );
391 }
392
393 return( $Code );
394 }
395 catch( Exception $e )
396 {
397 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
398 }
399 }
400
427 private function get_dialog_parameters( &$BlockSettings , $CategoryName )
428 {
429 try
430 {
431 $CategoryId = $this->CategoryAccess->get_category_id( $CategoryName );
432
433 $id = $BlockSettings->get_setting( 'id' , "select_category_from_tree_$CategoryId" );
434
435 $Value = $BlockSettings->get_setting( 'value' , $CategoryId );
436
437 $VisibleValue = $BlockSettings->get_setting(
438 'visible_value' ,
439 "{record_field:access_package_name=category::category_algorithms;field=title;id=$Value}"
440 );
441
442 return( array( $id , $Value , $VisibleValue ) );
443 }
444 catch( Exception $e )
445 {
446 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
447 }
448 }
449
472 function get_select_category_from_tree_data( &$BlockSettings )
473 {
474 try
475 {
476 $CategoryName = $BlockSettings->get_setting( 'category_name' );
477 $Name = $BlockSettings->get_setting( 'name' , 'category' );
478 $Title = $BlockSettings->get_setting( 'title' , 'category_selection' );
479 $Class = $BlockSettings->get_setting( 'class' , 'width_160 flat' );
480
481 list( $id , $Value , $VisibleValue ) = $this->get_dialog_parameters( $BlockSettings , $CategoryName );
482
483 return(
484 array(
485 'category_name' => $CategoryName , 'name' => $Name , 'title' => $Title ,
486 'class' => $Class , 'value' => $Value , 'visible_value' => $VisibleValue , 'id' => $id
487 )
488 );
489 }
490 catch( Exception $e )
491 {
492 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
493 }
494 }
495
518 function compile_select_category_from_tree( &$BlockSettings )
519 {
520 try
521 {
522 $Data = $this->get_select_category_from_tree_data( $BlockSettings );
523
524 $Code = $this->CachedMultyFS->get_template( __FILE__ , 'select_category_from_tree.tpl' );
525
526 $Code = $this->String->print_record( $Code , $Data );
527
528 return( $Code );
529 }
530 catch( Exception $e )
531 {
532 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
533 }
534 }
535 }
536
537 ?>