<?php
class CLMAccion extends AppColumna{
	
	protected $ordenable = false;
	protected $agrupable = false;
	protected $_controller = null;
	protected $_acciones = array();
	protected $_clases = array('btn-xs ');
	
	
	public function __construct($name, $controller = CONTROLLER, $valor = null, $cabecera = ''){
		$this->_controller = $controller;
		parent::__construct($name, $valor, $cabecera);
		$this->tipo = 'accion';
		
	
	}
	
	public function addAccion($texto, $title ,$clase_icono, $parametros, $vista, $controller = null , $mensajeConfirmacion = null, $modal = false){
		$url = '/'.($controller?$controller:$this->_controller).'/'.$vista;
		foreach ($parametros as $key => $value){
			$url .= '/'.$key.'/'.$value;
		}
		
		$icono = new VstIcono($clase_icono);
		$accion = new Boton($url, BASEURL , $title, $texto, $icono, $mensajeConfirmacion);
		$accion->setModal($modal);
		$accion->setClase(implode(' ',$this->_clases));
		$this->_acciones[] = $accion;
	}
	public function addAccionEditar($parametros, $vista = 'editar', $controller = null, $modal = false){
		
		$url = '/'.($controller?$controller:$this->_controller).'/'.$vista;
		
		foreach ($parametros as $key => $value){
			$url .= '/'.$key.'/'.$value;
		}
		
		$icono = new VstIcono(VstIcono::APP_icon_pencil);
		$accion = new Boton($url, BASEURL , 'Editar', '', $icono);
		$accion->setClase(implode(' ',$this->_clases));
		$accion->setModal($modal);
		$this->_acciones[] = $accion;
	}
	
	
	public function addAccionVer($parametros, $vista = 'ver', $controller = null, $modal= false){
		
		$url = '/'.($controller?$controller:$this->_controller).'/'.$vista;
		
		foreach ($parametros as $key => $value){
			$url .= '/'.$key.'/'.$value;
		}
		
		$icono = new VstIcono(VstIcono::APP_icon_search);
		$accion = new Boton($url, BASEURL , '', '', $icono);
		$accion->setClase(implode(' ',$this->_clases));
		$accion->setModal($modal);
		$this->_acciones[] = $accion;
	}
	
	
	
	
	public function addAccionEliminar($parametros, $mensajeConfirmacion, $vista = 'eliminar', $controller = null){
	
		$url = '/'.($controller?$controller:$this->_controller).'/'.$vista;
	
		foreach ($parametros as $key => $value){
			$url .= '/'.$key.'/'.$value;
		}
	
		$icono = new VstIcono(VstIcono::APP_icon_trash, true);
		$accion = new Boton($url, BASEURL , 'Eliminar', '', $icono, $mensajeConfirmacion, true);
		$accion->setClase(implode(' ',$this->_clases).' '.'btn-danger');
		
		$this->_acciones[] = $accion;
	}
	

	public function getAncho(){
		if($this->_ancho){
			return $this->_ancho;
		}else{
			return 50 * count($this->_acciones);
		}
	}
	
	protected function getValorCelda(){
		
		$acciones = '';
		foreach ($this->_acciones as $accion){
			$acciones .= $accion->render();
		}
		$valor = '<div class="btn-group">' . $acciones. '</div>';
		return $valor;
	}
	
	
}