Какая версия Yii? если вторая, то проще сделать наверное так.
<?php
public static function getFullInfo($id)
{
$driverCar = DriverCar::findOne([
'mifar_card_id' => $id
]);
if (empty( $driverCar ) ) return false;
//Если тут одна сущность то делаем так
// Но у объекта дожны быть методы getCar и getDriver в которых используется $this->hasOne()
$car = $driverCar->сar;
$driver = $driverCar->driver;
$object = array();
if ($driverCar->сar->use_group_tariff && $driverCar->сar->group_tariff_id)
{
$groupTariff = GroupTariff::findOne([
'id' => $driverCar->сar->group_tariff_id
]);
$object = [
'town' => $groupTariff->town,
'town_center' => $groupTariff->town_center,
'km_price' => $groupTariff->km_price,
]
}
else
{
$driverTariff = DriverTariff::findOne([
'driver_id' => $driverCar->driver->id
]);
$object = [
'town' => $driverTariff->town,
'town_center' => $driverTariff->town_center,
'km_price' => $driverTariff->km_price,
]
}
$object = array(
'company' => $driverCar->сar->getCarBrand();
'model' => $driverCar->сar->model;
'color' => $driverCar->сar->color;
'object' = $driverCar->сar->number;
'full_name' = $driverCar->driver->getFullName();
'serial_number' = $driverCar->driver->serial_number;
);
return (object)$object;
}
//Или так от структуры зависит и логики
class Driver extends ActiveRecord{
public function getCar()
{
return $this->hasOne(Car::className(),['mifar_card_id' => 'id' ])
->viaTable('{{%driverCar}}',['driver_id' => 'id']);
}
public function getTariff(){
return $this->hasOne(DriverTariff::className(),['driver_id' => 'id'])
}
}
class Car extends ActiveRecord{
public function getTariff(){
return $this->hasOne(GroupTariff::className(), ['id' => 'driver_id'])
}
}
interface IGetTariff{
public function getTown();
public function getTownCenter();
public function getKmPrice();
}
class GroupTariff extends ActiveRecord implements GetTariff{}
class DriverTariff extends ActiveRecord implements GetTariff{}
class FullDriverCarInfo extends Model{
public static function getFullInfo( $driverId ){
$driver = Driver::findOne('id'=>$driverId);
if( empty($driver) ) return;
/** @var $tariff IGetTariff */
if( $driver->сar->use_group_tariff && $driver->сar->group_tariff_id ){
$tariff = $driver->car->getTariff();
}else{
$tariff = $driver->getTariff();
}
$result = array(
'town' => $tariff->getTown(),
'town_center' => $tariff->getTownCenter(),
'km_price' => $tariff->getKmPrice(),
'company' => $driver->сar->getCarBrand();
'model' => $driver->сar->model;
'color' => $driver->сar->color;
'object' = $driver->сar->number;
'full_name' = $driver->getFullName();
'serial_number' = $driver->serial_number;
);
//Так если это отдельная модель
$this->setAttributes( $result );
return $this;
//Или
return (object)$result;
}
}
Это так, примерно. Можно намного лучше написать, но идею надеюсь донёс.