ultimix
category_view.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 $Output;
39 
50  var $CachedMultyFS = false;
51  var $CategoryAccess = false;
52  var $CategoryAlgorithms = false;
54  var $Security = false;
55  var $String = false;
56 
67  function __construct()
68  {
69  try
70  {
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__ );
74  $this->CategoryViewTemplates = get_package(
75  'category::category_view::category_view_templates' , 'last' , __FILE__
76  );
77  $this->Security = get_package( 'security' , 'last' , __FILE__ );
78  $this->String = get_package( 'string' , 'last' , __FILE__ );
79  }
80  catch( Exception $e )
81  {
82  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
83  }
84  }
85 
104  function pre_generation( $Options )
105  {
106  try
107  {
108  $Lang = get_package( 'lang' , 'last' , __FILE__ );
109 
110  $Lang->include_strings_js( 'category::category_view' );
111  }
112  catch( Exception $e )
113  {
114  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
115  }
116  }
117 
140  function get_category_id( $Options )
141  {
142  try
143  {
144  $DirectCategoryName = false;
145 
146  if( $Options->get_setting( 'direct_category_name' , false ) !== false )
147  {
148  $DirectCategoryName = $Options->get_setting( 'direct_category_name' );
149  }
150  elseif( $Options->get_setting( 'category_name' , false ) !== false )
151  {
152  $DirectCategoryName = $Options->get_setting( 'category_name' );
153  }
154 
155  if( $DirectCategoryName === false )
156  {
157  return( $Options->get_setting( 'direct_category' , 0 ) );
158  }
159  else
160  {
161  return( $this->CategoryAccess->get_category_id( $DirectCategoryName ) );
162  }
163  }
164  catch( Exception $e )
165  {
166  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
167  }
168  }
169 
204  private function draw_categories_catalogue_subtree( $Records , $RetCode , $Record , $DisplayTemplates )
205  {
206  try
207  {
208  $RetCode .= get_field( $DisplayTemplates , 'start_item_tag' );
209  $RetCode = $this->String->print_record( $RetCode , $Record );
210  $RetCode .= $this->draw_categories_catalogue_rec(
211  $Records , get_field( $Record , 'id' ) , $DisplayTemplates
212  );
213  $RetCode .= get_field( $DisplayTemplates , 'end_item_tag' );
214  $RetCode = $this->String->print_record( $RetCode , $Record );
215 
216  return( $RetCode );
217  }
218  catch( Exception $e )
219  {
220  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
221  }
222  }
223 
254  function draw_categories_catalogue_rec( $Records , $RootId , $Templates = false )
255  {
256  try
257  {
258  $Templates = $this->CategoryViewTemplates->get_categories_catalogue_templates( $Templates );
259  $Children = $this->CategoryAlgorithms->get_children( $RootId , $Records );
260 
261  if( isset( $Children[ 0 ] ) )
262  {
263  $RetCode = get_field( $Templates , 'start_tag' );
264 
265  foreach( $Children as $k => $v )
266  {
267  $RetCode = $this->draw_categories_catalogue_subtree( $Records , $RetCode , $v , $Templates );
268  }
269 
270  $RetCode .= get_field( $Templates , 'end_tag' );
271  return( $RetCode );
272  }
273 
274  return( '' );
275  }
276  catch( Exception $e )
277  {
278  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
279  }
280  }
281 
308  function draw_categories_catalogue( $Name , $Templates = false )
309  {
310  try
311  {
312  $id = $this->CategoryAccess->get_category_id( $Name );
313 
314  $Items = $this->CategoryAccess->select_categories_list( $id );
315 
316  return( $this->draw_categories_catalogue_rec( $Items , $id , $Templates ) );
317  }
318  catch( Exception $e )
319  {
320  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
321  }
322  }
323 
342  function draw_categories_catalogue_view( $Options )
343  {
344  try
345  {
346  $id = $this->get_category_id( $Options );
347 
348  $Items = $this->CategoryAccess->select_categories_list( $id );
349 
350  $this->Output = $this->draw_categories_catalogue_rec( $Items , $id );
351  }
352  catch( Exception $e )
353  {
354  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
355  }
356  }
357 
388  function draw_categories_catalogue_part( $Options , $Records , $Templates = false )
389  {
390  try
391  {
392  $DisplayTemplates = $this->CategoryViewTemplates->get_categories_catalogue_part_templates(
393  $Options , $Templates
394  );
395 
396  $RetCode = '';
397 
398  foreach( $Records as $k => $v )
399  {
400  $SubcategoriesCount = $this->CategoryAccess->get_children_count( get_field( $v , 'id' ) );
401  if( $SubcategoriesCount )
402  {
403  $RetCode .= get_field( $DisplayTemplates , 'item' );
404  }
405  else
406  {
407  $RetCode .= get_field( $DisplayTemplates , 'leaf' );
408  }
409  $RetCode = $this->String->print_record( $RetCode , $v );
410  }
411 
412  return( $RetCode );
413  }
414  catch( Exception $e )
415  {
416  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
417  }
418  }
419 
439  {
440  try
441  {
442  if( $this->Security->get_gp( 'cid' , 'set' ) )
443  {
444  $id = $this->Security->get_gp( 'cid' , 'integer' );
445  }
446  else
447  {
448  $id = $this->get_category_id( $Options );
449  }
450 
451  $Items = $this->CategoryAccess->get_children( $id );
452 
453  $this->Output = $this->draw_categories_catalogue_part( $Options , $Items );
454  }
455  catch( Exception $e )
456  {
457  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
458  }
459  }
460 
479  function draw_categories_path( $Options )
480  {
481  try
482  {
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 );
486 
487  $RetCode = array();
488 
489  foreach( $Path as $i => $Item )
490  {
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 );
494  }
495 
496  $RetCode = implode( '&nbsp;&gt;&nbsp;' , $RetCode );
497 
498  $this->Output = $RetCode;
499  }
500  catch( Exception $e )
501  {
502  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
503  }
504  }
505 
536  private function draw_categories_structure_subtree( $RetCode , $Record , $DisplayTemplates )
537  {
538  try
539  {
540  $SubTree = $this->draw_categories_structure_rec( get_field( $Record , 'id' ) , $DisplayTemplates );
541 
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' );
547 
548  return( $RetCode );
549  }
550  catch( Exception $e )
551  {
552  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
553  }
554  }
555 
582  function draw_categories_structure_rec( $RootId , $DisplayTemplates = false )
583  {
584  try
585  {
586  $Children = $this->CategoryAccess->get_children( $RootId );
587 
588  $RetCode = '';
589 
590  if( isset( $Children[ 0 ] ) )
591  {
592  $RetCode .= get_field( $DisplayTemplates , 'start_tag' );
593 
594  foreach( $Children as $k => $v )
595  {
596  $RetCode = $this->draw_categories_structure_subtree( $RetCode , $v , $DisplayTemplates );
597  }
598 
599  $RetCode .= get_field( $DisplayTemplates , 'end_tag' );
600  }
601 
602  return( $RetCode );
603  }
604  catch( Exception $e )
605  {
606  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
607  }
608  }
609 
632  private function output_root( &$Options , $id )
633  {
634  try
635  {
636  if( $Options->get_setting( 'output_root' , 1 ) )
637  {
638  $TreeRoot = $this->CachedMultyFS->get_template( __FILE__ , 'tree_root.tpl' );
639 
640  $PlaceHolders = array( '{id}' , '{output}' );
641 
642  $this->Output = str_replace( $PlaceHolders , array( $id , $this->Output ) , $TreeRoot );
643  }
644  else
645  {
646  $NoTreeRoot = $this->CachedMultyFS->get_template( __FILE__ , 'no_tree_root.tpl' );
647 
648  $this->Output = str_replace( '{output}' , $this->Output , $NoTreeRoot );
649  }
650  }
651  catch( Exception $e )
652  {
653  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
654  }
655  }
656 
675  function draw_categories_tree( &$Options )
676  {
677  try
678  {
679  $id = $this->get_category_id( $Options );
680 
681  $DisplayTemplates = $this->CategoryViewTemplates->get_default_category_structure_templates( $Options );
682 
683  $this->Output = $this->draw_categories_structure_rec( $id , $DisplayTemplates );
684 
685  $this->output_root( $Options , $id );
686  }
687  catch( Exception $e )
688  {
689  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
690  }
691  }
692 
715  function view( $Options )
716  {
717  try
718  {
719  $ContextSet = get_package_object( 'gui::context_set' , 'last' , __FILE__ );
720 
721  $PackagePath = dirname( __FILE__ );
722 
723  $ContextSet->add_context( $PackagePath.'/conf/cfcx_categories_tree' );
724 
725  $ContextSet->add_context( $PackagePath.'/conf/cfcx_categories_catalogue' );
726 
727  $ContextSet->add_context( $PackagePath.'/conf/cfcx_categories_catalogue_part' );
728 
729  $ContextSet->add_context( $PackagePath.'/conf/cfcx_categories_path' );
730 
731  $ContextSet->execute( $Options , $this , __FILE__ );
732 
733  return( $this->Output );
734  }
735  catch( Exception $e )
736  {
737  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
738  }
739  }
740  }
741 ?>