<?php

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

/**
 * Default callbacks for rtgrid
 *
 * @author Igor Ratsun
 */
class rtgrid_column_callback {

    public function active($value = TRUE) {
        // Prepare data
        $active = ((is_string($value) && ($value == 't' || $value == '1')) || (!is_string($value) && $value == TRUE)) ? TRUE : FALSE;

        return '<i class="icon-' . ($active ? 'ok' : 'remove') . '"></i>';
    }

    public function strip_128($value = '') {

        return $this->_strip_text($value, 0, 128);
    }

    public function date($value = '') {
        if (empty($value)) {
            
            return '';
        }
        
        return date('d.m.Y', strtotime($value));
    }
    
    public function datetime($value = '') {

        if (empty($value)) {
            
            return '';
        }
        
        return date('d.m.Y H:i:s', strtotime($value));
    }
    
    public function textarea($value = '') {
        
        return $this->strip_128($value);
    }
    
    public function texteditor($value = '') {
        
        return $this->strip_128($value);
    }

    protected function _strip_text($value = '', $start = 0, $length = 8) {
        // Prepare data
        $value = trim(strip_tags($value));
        $dots = (mb_strlen($value) > $length) ? ' ... ' : '';

        return mb_substr($value, $start, $length) . $dots;
    }

    protected function _price($value = '') {
        
        return number_format($value, 2, '.', '');
    }
    
    public function price_uah($value = '') {
        
        return $this->_price($value);
    }
    
    public function price_usd($value = '') {
        
        return $this->_price($value);
    }
}

