<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of alphagallery_site
 *
 * @author Igor Ratsun
 */
class alphagallery_site extends MX_Controller {

    public function index() {
        $this->load->config('alphagallery/config');
        $this->load->model('alphagallery/alphagallery_admin_model', 'alphagalmod');
        $this->load->library('ciext/ciext');
        $this->ciext->load_jquery();
        $this->js_css->add_js('/assets/js/flexslider/jquery.flexslider.js');
        $this->js_css->add_css('/assets/js/flexslider/flexslider.css');

        $this->alphagalmod->set_table($this->config->item('main_table'));
        $this->alphagalmod->set_pkey($this->config->item('alphagallery_photo_pkey'));
        $this->alphagalmod->set_lang_table($this->config->item('lang_table'));

        $content = array(
            'items' => array()
        );

        $items = $this->alphagalmod->fetch_by_fields(array('id_alphagallery' => 1));
        foreach ($items as $item) {
            $alt = $item->get_lang_string('name');
            $content['items'][] = array(
                'src' => $this->config->item('photo_path') . '/' . $item->get_photo(),
                'alt' => (!empty($alt)) ? $alt : $item->get_string('name')
            );
        }

        return $this->parser->parse('alphagallery/site_template', $content, TRUE);
    }

}

