<?php

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

/**
 * Language injector
 *
 * @author Igor Ratsun
 */
class Translate_injector
{

    protected $ci;

    public function __construct()
    {
        $this->ci = & get_instance();
        $this->ci->lang->language = array_merge($this->ci->lang->language, $this->load());
    }

    protected function load($id_lan = 0)
    {
        if (empty($id_lan)) {
            $id_lan = $this->ci->load->library('db_lang_lib')->get_current_lang_id();
        }

        $data = $this->ci->db
                        ->select('t.line, tv.value')
                        ->join('translate_value tv', '(tv.id_translate=t.id_translate AND tv.id_lan=' . (int) $id_lan . ')', 'left')
                        ->get('translate t')->result_array();

        return array_column($data, 'value', 'line');
    }

}
