hola forum, en el admin de mi modelo principal(Anexo1) quiero mostrar dos clumnas que no pertenecen al mismo, pero la puedo calcular, es una diferencia entre fechas.
en mi model tengo:
public $fdfo;// declarando las variables
public $frfd;//
public function dateDiff($start, $end)
{
$start = strtotime($this->fecha_ocu_a1);
$end = strtotime($this->fecha_det_a1);
$diff = $end - $start;
return round($diff / 86400);
}
public function dateDiff1($start, $end)
{
$start = strtotime($this->fecha_det_a1);
$end = strtotime($this->fecha_rep_a1);
$diff = $end - $start;
return round($diff / 86400);
}
public function rules()
{
return array(
.
.
array('...,fdfo,frfd,..., 'safe', 'on'=>'search'),
);
}
public function attributeLabels()
{
return array(
.
.
'fdfo'=>'FD-FO',
'frfd'=>'FR-FD',
);
}
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->with =array('entidadhcFk','fuenteDetFk','temahcFk','modoOperarFk','causasCondFk','cargoFk','entidadhcFk.orgaFk','entidadhcFk.provinciaFk');
.
.
$criteria->compare('fecha_ocu_a1',$this->fecha_ocu_a1,true);
$criteria->compare('fecha_det_a1',$this->fecha_det_a1,true);
$criteria->addSearchCondition('dateDiff(fecha_ocu_a1, fecha_det_a1)', $this->fdfo);
$criteria->addSearchCondition('dateDiff1(fecha_det_a1, fecha_rep_a1)', $this->frfd);
.
.
$sort= new CSort();
if((isset($this->date_first1) && trim($this->date_first1) != "") && (isset($this->date_last1) && trim($this->date_last1) != ""))
$criteria->addBetweenCondition('fecha_ocu_a1', ''.$this->date_first1.'', ''.$this->date_last1.'');
if((isset($this->date_first2) && trim($this->date_first2) != "") && (isset($this->date_last2) && trim($this->date_last2) != ""))
$criteria->addBetweenCondition('fecha_det_a1', ''.$this->date_first2.'', ''.$this->date_last2.'');
if((isset($this->date_first3) && trim($this->date_first3) != "") && (isset($this->date_last3) && trim($this->date_last3) != ""))
$criteria->addBetweenCondition('fecha_rep_a1', ''.$this->date_first3.'', ''.$this->date_last3.'');
if((isset($this->date_first4) && trim($this->date_first4) != "") && (isset($this->date_last4) && trim($this->date_last4) != ""))
$criteria->addBetweenCondition('fecha_reg_a1', ''.$this->date_first4.'', ''.$this->date_last4.'');
$_SESSION['Anexo1'] = new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>$sort,
'pagination'=>false,
));
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
y en el admin tengo:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'anexo1-grid',
'itemsCssClass'=>"table table-striped",
'dataProvider'=>$model->search(),
'afterAjaxUpdate'=>"function() {
jQuery('#date_first1').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['es'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));
jQuery('#date_last1').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['es'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));
}",
'afterAjaxUpdate'=>"function() {
jQuery('#date_first2').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['es'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));
jQuery('#date_last2').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['es'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));
}",
'afterAjaxUpdate'=>"function() {
jQuery('#date_first3').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['es'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));
jQuery('#date_last3').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['es'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));
}",
'afterAjaxUpdate'=>"function() {
jQuery('#date_first4').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['es'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));
jQuery('#date_last4').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['es'], {'showAnim':'fold','dateFormat':'yy-mm-dd','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));
}",
'filter'=>$model,
'pager'=>array("htmlOptions"=>array("class"=>"pagination")),
'columns'=>array(
'id',
array('name'=>'no_hc_a1','value'=>'$data->no_hc_a1'),
array('name'=>'entidadhc_fk','value'=>'$data->entidadhcFk->enthc_nombre'),
array('name'=>'prov_desc','value'=>'$data->entidadhcFk->provinciaFk->prov_desc'),
array('name'=>'orga_hc_siglas','value'=>'$data->entidadhcFk->orgaFk->orga_hc_siglas'),
array('name'=>'fuente_det_fk','value'=>'$data->fuenteDetFk->fuente_det_siglas'),
array('name'=>'fecha_ocu_a1','filter'=>$dateisOn1,'value'=>'$data->fecha_ocu_a1'),
array('name'=>'fecha_det_a1','filter'=>$dateisOn2,'value'=>'$data->fecha_det_a1'),
array('name'=>'fdfo','value'=>'$data->dateDiff($data->fecha_ocu_a1,$data->fecha_det_a1)'),// aqui es donde devuelvo la diferencia
array('name'=>'frfd','value'=>'$data->dateDiff1($data->fecha_det_a1,$data->fecha_rep_a1)'),// aqui es donde devuelvo la diferencia
array('name'=>'temahc_fk','value'=>'$data->temahcFk->temahc_desc'),
array('name'=>'modo_operar_fk','value'=>'$data->modoOperarFk->modo_op_desc'),
//'resumen_a1',
array('name'=>'causas_cond_fk','value'=>'$data->causasCondFk->causas_cond_desc'),
'reportado_por_a1',
//'cargo_fk',
'tiene_a2',
//'anexo2id',
'afect_mn',
'recup_mn',
'afect_mlc',
'recup_mlc',
'obsevaciones_a1',
array('name'=>'fecha_rep_a1','filter'=>$dateisOn3,'value'=>'$data->fecha_rep_a1'),
array('name'=>'fecha_reg_a1','filter'=>$dateisOn4,'value'=>'$data->fecha_reg_a1'),
'cant_impl',
'cant_col',
'registrado_por',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
la columna me muestra los datos, me permite filtrar si pongo un valor exacto y me los ordena, pero a la hora de usar operadores(<, <=, >, >=, <> o =), no devuelve nada, que podría ser?? Gracias de antemano