71 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
72 $this->CategoryAccess =
get_package(
'category::category_access' ,
'last' , __FILE__ );
73 $this->CategoryAlgorithms =
get_package(
'category::category_algorithms' ,
'last' , __FILE__ );
75 'category::category_view::category_view_templates' ,
'last' , __FILE__
77 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
78 $this->String =
get_package(
'string' ,
'last' , __FILE__ );
110 $Lang->include_strings_js(
'category::category_view' );
112 catch( Exception $e )
144 $DirectCategoryName =
false;
146 if( $Options->get_setting(
'direct_category_name' ,
false ) !== false )
148 $DirectCategoryName = $Options->get_setting(
'direct_category_name' );
150 elseif( $Options->get_setting(
'category_name' ,
false ) !== false )
152 $DirectCategoryName = $Options->get_setting(
'category_name' );
155 if( $DirectCategoryName ===
false )
157 return( $Options->get_setting(
'direct_category' , 0 ) );
161 return( $this->CategoryAccess->get_category_id( $DirectCategoryName ) );
164 catch( Exception $e )
204 private function draw_categories_catalogue_subtree( $Records , $RetCode , $Record , $DisplayTemplates )
208 $RetCode .=
get_field( $DisplayTemplates ,
'start_item_tag' );
209 $RetCode = $this->String->print_record( $RetCode , $Record );
211 $Records ,
get_field( $Record ,
'id' ) , $DisplayTemplates
213 $RetCode .=
get_field( $DisplayTemplates ,
'end_item_tag' );
214 $RetCode = $this->String->print_record( $RetCode , $Record );
218 catch( Exception $e )
258 $Templates = $this->CategoryViewTemplates->get_categories_catalogue_templates( $Templates );
259 $Children = $this->CategoryAlgorithms->get_children( $RootId , $Records );
261 if( isset( $Children[ 0 ] ) )
263 $RetCode =
get_field( $Templates ,
'start_tag' );
265 foreach( $Children as $k => $v )
267 $RetCode = $this->draw_categories_catalogue_subtree( $Records , $RetCode , $v , $Templates );
270 $RetCode .=
get_field( $Templates ,
'end_tag' );
276 catch( Exception $e )
312 $id = $this->CategoryAccess->get_category_id( $Name );
314 $Items = $this->CategoryAccess->select_categories_list( $id );
318 catch( Exception $e )
348 $Items = $this->CategoryAccess->select_categories_list( $id );
352 catch( Exception $e )
392 $DisplayTemplates = $this->CategoryViewTemplates->get_categories_catalogue_part_templates(
393 $Options , $Templates
398 foreach( $Records as $k => $v )
400 $SubcategoriesCount = $this->CategoryAccess->get_children_count(
get_field( $v ,
'id' ) );
401 if( $SubcategoriesCount )
403 $RetCode .=
get_field( $DisplayTemplates ,
'item' );
407 $RetCode .=
get_field( $DisplayTemplates ,
'leaf' );
409 $RetCode = $this->String->print_record( $RetCode , $v );
414 catch( Exception $e )
442 if( $this->Security->get_gp(
'cid' ,
'set' ) )
444 $id = $this->Security->get_gp(
'cid' ,
'integer' );
451 $Items = $this->CategoryAccess->get_children( $id );
455 catch( Exception $e )
483 $Items = $this->CategoryAccess->select_categories_list( $id = $this->
get_category_id( $Options ) );
484 $cid = $this->Security->get_gp(
'cid' ,
'integer' , $id );
485 $Path = $this->CategoryAlgorithms->get_previous_items( $Items , $cid );
489 foreach( $Path as $i => $Item )
491 $Template = $this->CachedMultyFS->get_template( __FILE__ ,
'categories_path.tpl' );
492 $PlaceHolders = array(
'{id}' ,
'{title}' );
493 $Template = str_replace( $PlaceHolders , array( $Item->id , $Item->title ) , $Template );
496 $RetCode = implode(
' > ' , $RetCode );
498 $this->Output = $RetCode;
500 catch( Exception $e )
536 private function draw_categories_structure_subtree( $RetCode , $Record , $DisplayTemplates )
542 $RetCode .= $SubTree ===
'' ?
get_field( $DisplayTemplates ,
'start_leaf_tag' ) :
543 get_field( $DisplayTemplates ,
'start_item_tag' );
544 $RetCode = $this->String->print_record( $RetCode , $Record );
545 $RetCode .= $SubTree;
546 $RetCode .=
get_field( $DisplayTemplates ,
'end_item_tag' );
550 catch( Exception $e )
586 $Children = $this->CategoryAccess->get_children( $RootId );
590 if( isset( $Children[ 0 ] ) )
592 $RetCode .=
get_field( $DisplayTemplates ,
'start_tag' );
594 foreach( $Children as $k => $v )
596 $RetCode = $this->draw_categories_structure_subtree( $RetCode , $v , $DisplayTemplates );
599 $RetCode .=
get_field( $DisplayTemplates ,
'end_tag' );
604 catch( Exception $e )
632 private function output_root( &$Options , $id )
636 if( $Options->get_setting(
'output_root' , 1 ) )
638 $TreeRoot = $this->CachedMultyFS->get_template( __FILE__ ,
'tree_root.tpl' );
640 $PlaceHolders = array(
'{id}' ,
'{output}' );
642 $this->Output = str_replace( $PlaceHolders , array( $id , $this->Output ) , $TreeRoot );
646 $NoTreeRoot = $this->CachedMultyFS->get_template( __FILE__ ,
'no_tree_root.tpl' );
648 $this->Output = str_replace(
'{output}' , $this->Output , $NoTreeRoot );
651 catch( Exception $e )
681 $DisplayTemplates = $this->CategoryViewTemplates->get_default_category_structure_templates( $Options );
685 $this->output_root( $Options , $id );
687 catch( Exception $e )
721 $PackagePath = dirname( __FILE__ );
723 $ContextSet->add_context( $PackagePath.
'/conf/cfcx_categories_tree' );
725 $ContextSet->add_context( $PackagePath.
'/conf/cfcx_categories_catalogue' );
727 $ContextSet->add_context( $PackagePath.
'/conf/cfcx_categories_catalogue_part' );
729 $ContextSet->add_context( $PackagePath.
'/conf/cfcx_categories_path' );
731 $ContextSet->execute( $Options , $this , __FILE__ );
733 return( $this->Output );
735 catch( Exception $e )