<?php
//	сигнатура :
//	розділи			П.теги			І.теги					сортування			особливості
//	philips+lenovo/ size:44+48+50/ [prozorist:800-8000]/ sort=price-increase/ features=bestseller+novelty
//------------------------------------------------------------------
//	PTSE_Data::$request_data->self_children_table_name.'$'											--таблиця типорозмірів
//	----------------------------------------------------------------
//	$_REQUEST['entity_list_small_uri_id_array']						= array('philips', 'lenovo')	--Розділи (активні)
//------------------------------------------------------------------
//
// створений об'єкт		Tag_Cloud_Section_List
// передається в клас	Entity_Filter_Result
//				
// Масиви, які використовуються у класі		
//		->filter_section_list									список активних розділів
//		->full_section_list_according_uri_id_with_table_name	відповідність: [uri_id] = назві таблиці розділу
//		->inner_section_list_info_array							опис всіх розділів (структура нижче)

class Tag_Cloud_Section_List // used for GoodsCardListCategory /EntityListSection/ with assigned tag_list_group_id
{
 function Tag_Cloud_Section_List( $entity_list_section_id )
 {
	$this->section_data = new PTSE_Data($entity_list_section_id);
	$this->section_type = $this->section_data->Get_Value('type');

	$this->full_section_list_according_uri_id_with_table_name = array();
	$this->filter_section_list = array();
	$this->inner_category_list = array();

	$this->Init();
 }
//-----------------------------------------------------------------------
//									 $inner_section_small_uri_id = ... ,philips ,lenovo ,...
//
//	->inner_section_list_info_array[ $inner_section_small_uri_id ]['key']				-- ключ (не підряд: 0,2,5,...)
//	->inner_section_list_info_array[ $inner_section_small_uri_id ]['name']				-- назва розділу
//	->inner_section_list_info_array[ $inner_section_small_uri_id ]['filtered_count']	-- кількість товарів (заповнюється в Entity_Filter_Result)
//
 function Init()
 {
	if( $this->section_type == 'PTSE_AnimalDistributionPage')	// Категорія тварин, технічно - як група товарів
	{
		$inner_section_small_uri_id = $this->section_data->Get_Value($_REQUEST['ptse_lang'].'uri_id');

		$this->inner_section_list_info_array[$inner_section_small_uri_id]['key'] = 0;
		$this->inner_section_list_info_array[$inner_section_small_uri_id]['name']= $this->section_data->Get_Value($_REQUEST['ptse_lang'].'name');

		$this->full_section_list_according_uri_id_with_table_name[$inner_section_small_uri_id] = $this->section_data->self_children_table_name;
	}
	else
	{	$inner_section_data_list_by_type = $this->section_data->Get_Data_List('*');

		foreach($inner_section_data_list_by_type['GoodsCardListCategory'] as $data)			// Категорії товарів
		{
			$category_name = $data->Get_Value($_REQUEST['ptse_lang'].'name');
			$category_href = PTSE_SITE_WEB_ADDRESS.'/'.$data->Get_Uri_Id_By_Id( $data->id, $_REQUEST['ptse_lang'] );
			$this->inner_category_list[] = '<a href="'.$category_href.'">'.$category_name.'</a>';
		}

		foreach($inner_section_data_list_by_type['GoodsCardList'] as $key => $inner_section_data)	// Групи товарів
		{
			$inner_section_small_uri_id = $inner_section_data->Get_Value($_REQUEST['ptse_lang'].'uri_id');
	
			$this->inner_section_list_info_array[$inner_section_small_uri_id]['key'] = $key;
			$this->inner_section_list_info_array[$inner_section_small_uri_id]['name'] = $inner_section_data->Get_Value($_REQUEST['ptse_lang'].'name');
	
			$this->full_section_list_according_uri_id_with_table_name[$inner_section_small_uri_id] = $inner_section_data->self_children_table_name;
		}
	}

	if($_REQUEST['entity_list_small_uri_id_array'])
	{
		$array_keys = array_keys($_REQUEST['entity_list_small_uri_id_array']);
		foreach( $array_keys as $key )
		{
			$small_uri_id = $_REQUEST['entity_list_small_uri_id_array'][$key];
			unset($_REQUEST['entity_list_small_uri_id_array'][$key]);
			
			$_REQUEST['entity_list_small_uri_id_array'][$this->inner_section_list_info_array[$small_uri_id]['key']] = $small_uri_id;
			$this->filter_section_list[] = $this->full_section_list_according_uri_id_with_table_name[$small_uri_id];
		}
	}
	else
		$this->filter_section_list = array_values($this->full_section_list_according_uri_id_with_table_name);

	$this->full_section_list_according_uri_id_with_table_name = array_flip(
	$this->full_section_list_according_uri_id_with_table_name);
 }
//-----------------------------------------------------------------------
 function Sending_To_Output_Init()
 {
	$key = 0;
	foreach($this->inner_section_list_info_array as $inner_section_small_uri_id => $inner_section_info)	// Розділи
	{
		if( $filtered_count = $inner_section_info['filtered_count'])	// якщо розділ не пустий
		{
			$inner_section_name = $inner_section_info['name'].' ('.$filtered_count.')';

			$inner_section_link = new PTSE_Link( PTSE_REQUESTED_NODE::$uri_id );

			if($_REQUEST['entity_list_small_uri_id_array'][$key])
			{
				$inner_section_link->Set_Class('active-filter-link');	
				$inner_section_link->Add('<i class="fas fa-check-square"></i>');

				$temp = $_REQUEST['entity_list_small_uri_id_array'][$key];
				unset($_REQUEST['entity_list_small_uri_id_array'][$key]);
				$inner_section_link->Set_Options_String( Get_Filter_Options_String() );
				$_REQUEST['entity_list_small_uri_id_array'][$key] = $temp;
			}	
			else
			{	$inner_section_link->Set_Class('unactive-filter-link');	
				$inner_section_link->Add('<i class="far fa-square"></i>');

				$_REQUEST['entity_list_small_uri_id_array'][$key] = $inner_section_small_uri_id;
				$inner_section_link->Set_Options_String( Get_Filter_Options_String() );
				unset($_REQUEST['entity_list_small_uri_id_array'][$key]);
			}
			$inner_section_link->Add('<div>'.$inner_section_name.'</div>');
			$this->inner_section_link_list[] = $inner_section_link;
		}
		$key++;
	}
 }
//-----------------------------------------------------------------------
 function Send_To_Output()
 {
	$this->Sending_To_Output_Init();

	if( count($this->inner_category_list))
	{
		print('<div class="tag-list-wrapper">');
		print'<div class="tag-list-name">Додаткові підрозділи</div>';

		foreach($this->inner_category_list as $category)
			print'<div>'.$category.'</div>';

		print('</div>');
		print('<div class="tag-list-separator"></div>');
	}

	if( count($this->inner_section_link_list)
	and PTSE_REQUESTED_NODE::$type !='PTSE_AnimalDistributionPage')
	{
		print('<div class="tag-list-wrapper">');
		print'<div class="tag-list-name">Розділи</div>';

		foreach($this->inner_section_link_list as $inner_section_link )
				$inner_section_link->Send_To_Output();

		print('</div>');
		print('<div class="tag-list-separator"></div>');
	}
 }
}
?>