<?php

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

/**
 * Description of Slider_tmodel
 *
 * @author CIEXT skeleton
 */
class Slide_tmodel extends \Ciext\Model\AbstractTableModel
{

    protected $table = 'slider_slide';
    protected $pkey = 'id_slider_slide';

    public function fetch_all_by_code($code)
    {
        $this->db->join('slider s', 's.id_slider=t.id_slider', 'left')
            ->order_by('t.view_order')
            ->where('s.code', $code)
            ->where('t.active', true);

        return $this->prepare($this->fetch_all());
    }

    protected function prepare($data)
    {
        $this->config->load('slider/config');
        foreach ($data as &$item) {
            if (!empty($item['image'])) {
                $item['image'] = $this->config->item('slider_image_path') . $item['image'];
            }

        }
        unset($item);

        return $data;
    }
}
