<?php

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

/**
 * Set url input
 *
 * @author Igor Ratsun
 */
class Rtgc_url extends \Abstract_rtgc_callback
{

    public function column($value = '', $data = array())
    {
        return $value;
    }

    public function field($name = '', $value = NULL)
    {
        return '<input type="text" name="' . $name . '" value="' . $value . '" />';
    }

    public function __construct($options = array())
    {
        if (empty($options['crud']) || empty($options['field'])) {
            show_error('rtgc_url: Empty crud or field option');
        }
        
        $crud = & $options['crud'];
        $filed = $options['field'];
        $crud->callback_before_edit(function($post) use ($filed) {
            $ci = & get_instance();
            $ci->load->helper('url');
            $post[$filed] = url_title($post[$filed], 'dash', TRUE);
            
            return $post;
        });
    }

}
