<?php
class ControllerModuleManufactured extends Controller {
	protected function index($setting) {
		$this->language->load('module/manufactured');
    $this->language->load('common/extra_oc_lang');
    $this->load->type('tipocomum');

		$this->data['heading_title'] = ($this->config->get('manufactured_title')) ? $this->config->get('manufactured_title') :$this->language->get('heading_title');
		$this->load->model('catalog/manufacturer');
		$this->load->dmodel('tool/image');
		$this->data['manufactureds'] = array();
		$this->data['efeitoimg'] = $this->config->get('wg24_prod_efec_img');
        $this->data['product_list_title_style'] =  $this->config->get('product_list_title_style');

        $manufactures = explode(',', $this->config->get('manufactured_id'));
		$this->data['ver_produtos'] = $this->language->get('ver_produtos');

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

        $this->data['productListTitle'] = array(
            'heading_title' => ($this->config->get('manufactured_title')) ? $this->config->get('manufactured_title') :$this->language->get('heading_title'),
			'heading_subtitle' => $this->config->get('manufactured_subtitle') ? $this->config->get('manufactured_subtitle') : ''
        );

        $this->productlistitle->setProductListTitle($this->data['productListTitle']);


		if (empty($setting['limit'])) {
			$setting['limit'] = 5;
		}
		$cont = 0 ;
		foreach ($manufactures as $manufacturer_id) {

			if($cont < $setting['limit']) {
				$manufactured_info = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);

				if ($manufactured_info) {

					if ($manufactured_info['image']) {
						$image = $this->dmodel_tool_image->resize($manufactured_info['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
					} else {
						$image = $this->dmodel_tool_image->resize('data/sem-imagem.png', $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
          }

					$this->data['manufactureds'][] = array(
						'manufacturer_id' => $manufactured_info['manufacturer_id'],
						'name'       			=> (strlen($manufactured_info['name'])>50)? utf8_substr(strip_tags(html_entity_decode($manufactured_info['name'], ENT_QUOTES, 'UTF-8')), 0, 50).'...' : $manufactured_info['name'],
						'thumb'						=> $image,
						'image_extra'			=> $image,
						'href'						=> $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $manufactured_info['manufacturer_id'])
					);
				}

				$cont++;
			}

		}

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/manufactured.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/manufactured.tpl';
		} else {
			$this->template = 'default/template/module/manufactured.tpl';
		}

		$this->children = array(
            'common/product_list_title',
        );

		$this->render('module/manufactured');

	}


}
