⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

callback_column con set_relation



Alejandro Morales Sanchez

Alejandro Morales Sanchez
  • profile picture
  • Member

Posted 21 March 2014 - 22:15 PM

tengo un problema espero que me puedan ayudar si tengo dos tablas "promociones" y "producto" y creo una relación entre ambas tablas set_ralation para traer datos de la tabla producto "nombre_producto" , e implemento un callback_column para que me muestre una alerta de una promocion que se en cuentra activa o inactiva.
 
el problema en el que me encuentro es que cuando yo omito el callback_column el set_ralation me funciona perfectamente pero no me muestra la alerta y cuando omito el set_ralation si me muestra la alerta pero no me muestra la relación entre las tablas.
 
load->helper(‘url’);
 
$this->load->helper(‘date’);
 
/* Inicializamos la base de datos */
$this->load->database();
 
/* Cargamos la libreria groceru_crud */
$this->load->library(‘grocery_crud’);
 
/* Obtenemos la fecha actual */
$timestamp = now();
$timezone = ‘UM8′;
$daylight_saving = FALSE;
 
$now = gmt_to_local($timestamp, $timezone, $daylight_saving);
$datestring = “%Y-%m-%d %h:%i:%s”;
 
$this->now = mdate($datestring, $now);
}
 
public function index()
{
/* Redirigimos a la funcion promociones() */
redirect(‘admin/promociones’);
/*redirect(‘admin/respuestas’);*/
}
 
public function promociones()
{
try{
$crud = new grocery_CRUD();
 
$crud->set_theme(‘datatables’);
$crud->set_table(‘promociones’);
 
$crud->columns(
‘nombre_promocion’,
‘mensaje_promocion’,
‘fecha_inicio’,
‘fecha_vencimiento’,
‘nombre_producto’,
 
‘estatus’
);
 
$crud->display_as(‘numprod’,'producto nombre_producto’)
->display_as(‘fecha_vencimiento’)
->display_as(‘fecha_inicio’)
->display_as(‘estatus’);
$crud->set_subject(‘promociones’);
 
/* Establecemos español como el lenguaje predeterminado */
$crud->set_language(‘spanish’);
 
//$crud->set_relation(‘numalar’,'promociones’,'nombre_promocion’,'mensaje_promocion’);
$crud->set_relation(‘numprod’,'producto’,'nombre_producto’);
 
/* Añadimos una funcionalidad extra a las columnas */
$crud->callback_column(‘estatus’,array($this,’_GC_Estatus’));
 
//$crud->columns(‘nombre_producto’,'descripcion_producto’,'nombre_promocion’,'mensaje_promocion’,'fecha_inicio’);
/* $crud->required_fields(
‘nombre_promocion’,
‘mensaje_promocion’,
‘fecha_inicio’,
‘fecha_vencimiento’,
‘nombre_producto’,
‘descripcion_producto’
);*/
 
$output = $crud->render();
 
$this->load->view(‘admin/promociones’, $output);
 
}
catch(Exception $e){
show_error($e->getMessage().’ — ‘.$e->getTraceAsString());
}
}
 
public function _GC_Estatus($value, $row) {
 
/* Si la fecha actual es mayor o igual a la del inicio de la promocion y es menor
* a la de la fecha de vencimiento, la promocion esta activa.
*/
 
$fechaVencimiento = ($row->fecha_vencimiento);
$arrStr = explode(“-”, $fechaVencimiento);
$arrStr = explode(“/”, $arrStr[0] );
$fechaVencimiento = $arrStr[1] . “/” . $arrStr[ 0 ] . “/” . $arrStr[2];
$fechaVencimiento = strtotime( $fechaVencimiento );
 
$fechaInicio = ($row->fecha_inicio);
$arrStr = explode(“-”, $fechaInicio);
$arrStr = explode(“/”, $arrStr[0] );
$fechaInicio = $arrStr[1] . “/” . $arrStr[ 0 ] . “/” . $arrStr[2];
$fechaInicio = strtotime( $fechaInicio );
 
if( $fechaVencimiento > time() && $fechaInicio < time())
 
{
return 'Activa’;
 
} else {
 
return ‘Inactiva’;
}
}
 
}

 


james0070

james0070
  • profile picture
  • Member

Posted 10 April 2018 - 00:38 AM

Alguien podría responder esto? necesito algo parecido

Could someone answer this? I need something similar

 

necesito sumar la fecha con un integer y dar alerta
 

I need to sum (add) the date with an integer and give warning (alert)