<?php

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

class Translate_crud extends \CI_Model
{

    protected $crud;

    public function __construct()
    {
        parent::__construct();
        $this->load->library('rtgrid/rtgrid_api');
        $this->crud = new rtgrid_api();
    }

    public function render()
    {
        $this->crud->set_table('translate');
        $this->crud->columns('line');
        $this->crud->fields('line');
        $this->crud->unique_fields('line');
        $this->crud->required_fields('line');

        $this->callbacks()->display_as()->observers();

        return $this->crud->render();
    }

    protected function callbacks()
    {
        $this->crud->callback('line', 'rtgc_textarea');

        return $this;
    }

    protected function display_as()
    {
        $this->crud->display_as('line', $this->lang->line('Translation key'));

        return $this;
    }

    protected function observers()
    {
        $this->load->helper('rtgrid/rtgrid_obs');
        $action = 'translate_manager';
        $moreBtn = ' <a href="{link}">>>></a>';

        $this->crud->attach(make_rtgrid_add_obs('system', $action, $this->lang->line('Translate key was added') . $moreBtn));
        $this->crud->attach(make_rtgrid_edit_obs('system', $action, $this->lang->line('Translate key was edited') . $moreBtn));
        $this->crud->attach(make_rtgrid_delete_obs('system', $action, $this->lang->line('Translate key was deleted')));

        return $this;
    }

}
