Hello every1! Have a problem! Need show clients in gridView with their last activity.
public function relations()
{
return array(
'clientsInfoProgram' => array(self::HAS_MANY, 'ClientsInfoProgram', 'client_id', 'order'=>'clientsInfoProgram.date_begin DESC'),
);
}
GridView
array(
'name' => 'clientsInfoProgram.date_begin',
'value' => 'CModelHelper::getObjLastValue($data->clientsInfoProgram, "date_begin")',
'filterHtmlOptions' => array('class' => 'FilterDate','style'=>'width:95px'),
'filter' => CHtml::textField(get_class($model).'[clients_date_begin]', $model->clients_date_begin),
),
CModelHelper::getObjLastValue
public static function getObjLastValue($arr, $key){
if(count($arr)){
foreach($arr as $i => $val){
if(!empty($val->$key)){
$rval = $val->$key;
break;
}
}
return $rval;
}
}
But this select first activity record!