<?php
class ControllerInformationSitemap extends Controller {
	public function index() {
		$this->language->load('information/sitemap');
		$this->load->helper('ftr_geral');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home','','NONSSL','false'),
			'separator' => false
		);

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('information/sitemap'),
			'separator' => $this->language->get('text_separator')
		);

		$this->breadcrumbs->setbreadcumbs($this->data['breadcrumbs']);

		$this->data['heading_title']     = $this->language->get('heading_title');
		$this->data['text_special']      = $this->language->get('text_special');
		$this->data['text_account']      = $this->language->get('text_account');
		$this->data['text_edit']         = $this->language->get('text_edit');
		$this->data['text_password']     = $this->language->get('text_password');
		$this->data['text_address']      = $this->language->get('text_address');
		$this->data['text_history']      = $this->language->get('text_history');
		$this->data['text_cart']         = $this->language->get('text_cart');
		$this->data['text_checkout']     = $this->language->get('text_checkout');
		$this->data['text_search']       = $this->language->get('text_search');
		$this->data['text_information']  = $this->language->get('text_information');
		$this->data['text_contact']      = $this->language->get('text_contact');

		$this->data['validate_manufacturer'] = (ftr_geral::isIsset($this->config->get('wg24_linkFabricantes')) && $this->config->get('wg24_linkFabricantes')) ? true : false ;
		$this->data['text_manufacturer']     = $this->language->get('text_manufacturer');
		$this->data['link_manufacturer']     = $this->url->link('product/manufacturer');

		$this->data['validate_gift'] = (ftr_geral::isIsset($this->config->get('listapresente_status')) &&  $this->config->get('listapresente_status')) ? true : false ;
		$this->data['text_gift']     = $this->language->get('text_gift');
		$this->data['link_gift']     = $this->url->link('listapresente/listapresente/buscalista');

		$this->load->model('catalog/category');
		$this->load->model('catalog/product');

		$this->data['categories'] = array();

		$categories_1 = $this->model_catalog_category->getCategories(0);

		foreach ($categories_1 as $category_1) {
			$level_2_data = array();

			$categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']);

			foreach ($categories_2 as $category_2) {

				$level_3_data = array();
				$categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']);

				foreach ($categories_3 as $categorie_3) {
					$level_3_data[] = array(
						'name'     => $categorie_3['name'],
						'href'     => $this->url->link('product/category', 'path=' . $category_1['category_id'] . '_' . $category_2['category_id'] . '_' .$categorie_3['category_id'])
					);
				}
				$level_2_data[] = array(
					'name'     => $category_2['name'],
					'children' => $level_3_data,
					'href'     => $this->url->link('product/category', 'path=' . $category_1['category_id'] . '_' . $category_2['category_id'])
				);

			}

			$this->data['categories'][] = array(
				'name'     => $category_1['name'],
				'children' => $level_2_data,
				'href'     => $this->url->link('product/category', 'path=' . $category_1['category_id'])
			);
		}

		$qtdporcolunaCat	 				= ceil(count($this->data['categories']) / 3);
		$this->data['categories'] = array_chunk($this->data['categories'], $qtdporcolunaCat);

		$this->data['link_special']      = $this->url->link('product/special');
		$this->data['link_account']      = $this->url->link('account/account', '', 'SSL');
		$this->data['link_edit']         = $this->url->link('account/edit', '', 'SSL');
		$this->data['link_password']     = $this->url->link('account/password', '', 'SSL');
		$this->data['link_address']      = $this->url->link('account/address', '', 'SSL');
		$this->data['link_history']      = $this->url->link('account/order', '', 'SSL');
		$this->data['link_cart']         = $this->url->link('checkout/cart');
		$this->data['link_checkout']     = $this->url->link('checkout/checkout', '', 'SSL');
		$this->data['link_search']       = $this->url->link('product/search');
		$this->data['link_contact']      = $this->url->link('information/contact');

		$this->load->model('catalog/information');

		$this->data['informations'] = array();
    $informationList 						= $this->model_catalog_information->getInformations();
		$qtdporcolunaInfo 	 				= ceil(count($informationList) / 3);

		foreach ($informationList as $key => $result) {
			$this->data['informations'][] = array(
				'title' => $result['title'],
				'href'  => $this->url->link('information/information', 'information_id=' . $result['information_id'])
			);
		}
		$this->data['informations'] = array_chunk($this->data['informations'], $qtdporcolunaInfo);

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/sitemap.twig')) {
			$this->template = $this->config->get('config_template') . '/template/information/sitemap.twig';
		} else {
			$this->template = 'default/template/information/sitemap.twig';
		}

		$this->children = array(
			'common/breadcrumbs',
			'common/column_left',
			'common/column_right',
			'common/content_top',
			'common/content_bottom',
			'common/footer',
			'common/header'
		);

		$this->response->setOutput($this->render());
	}
}
