<?php
class Home extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('design/model_layout');
$this->load->model('extension/model_module');
$this->load->model('design/model_banner');
$this->load->model('tool/model_image');
$this->load->library('image_lib');
}
public function index() {
$data['title'] = 'Home';
$data['column_left'] = $this->column_left();
$data['content_top'] = $this->content_top();
$data['page'] = 'common/home';
$this->load->view('common/template', $data);
}
public function column_left() {
if ($this->uri->segment(1)) {
$route = $this->uri->segment(1) .'/'. $this->uri->segment(2);
} else {
$route = 'common/home';
}
$layout_id = $this->model_layout->get_layout($route);
$data['modules'] = array();
$modules = $this->model_layout->get_layout_modules($layout_id, 'column_left');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
$setting_info = $this->model_module->get_module($part[1]);
$data['modules'] = array (
'module' => $this->$part[0]($setting_info),
);
}
return $this->load->view('common/column_left', $data, TRUE);
}
public function content_top() {
if ($this->uri->segment(1)) {
$route = $this->uri->segment(1) .'/'. $this->uri->segment(2);
} else {
$route = 'common/home';
}
$layout_id = $this->model_layout->get_layout($route);
$data['modules'] = array();
$modules = $this->model_layout->get_layout_modules($layout_id, 'content_top');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
$setting_info = $this->model_module->get_module($part[1]);
$data['modules'] = array (
'module' => $this->$part[0]($setting_info),
);
}
return $this->load->view('common/content_top', $data, TRUE);
}
public function slideshow($setting_info) {
static $module = 0;
$data['banners'] = array();
$results = $this->model_banner->get_banner($setting_info['banner_id']);
foreach ($results as $result) {
$data['banners'][] = array(
'banner_image' => $this->model_image->resize($result['banner_image'], $setting_info['width'], $setting_info['height'])
);
}
$data['module'] = $module++;
return $this->load->view('module/slideshow', $data, TRUE);
}
public function category() {
$this->load->model('page/model_page_category');
$uri_3 = $this->uri->segment(3);
if ($uri_3) {
$data['category_id'] = $uri_3;
} else {
$data['category_id'] = 0;
}
$uri_4 = $this->uri->segment(4);
if ($uri_4) {
$data['child_id'] = $uri_4;
} else {
$data['child_id'] = 0;
}
$data['categories'] = array();
$categories = $this->model_page_category->get_categories(0);
foreach ($categories as $category) {
$children_data = array();
if ($category['category_id'] == $data['category_id']) {
$children = $this->model_page_category->get_categories($category['category_id']);
foreach($children as $child) {
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'],
'href' => $this->config->item('url') . 'page/categories/' . $category['category_id'] . '/' . $child['category_id']
);
}
}
$data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'],
'children' => $children_data,
'href' => $this->config->item('url') . 'page/categories/' . $category['category_id']
);
}
$data['page'] = 'module/category';
return $this->load->view('common/template', $data, TRUE);
}
}