/** * Lists all models. */ public function actionIndex() { $model = new Favorite('search'); $model->unsetAttributes(); // clear any default values if (isset($_REQUEST['Favorite'])) { $model->attributes = $_GET['Favorite']; } // $favorites = Favorite::model()->findAll('modelName LIKE :t ',array(':t' => '%'.$model->modelName.'%')); $favorites = Favorite::model()->findAllBySql(' select f.* FROM Favorite `f` LEFT JOIN Tender ON tenderId = modelId AND modelName=\'Tender\' LEFT JOIN Transport ON transportId = modelId AND modelName=\'Transport\' LEFT JOIN Cargo ON cargoId = modelId AND modelName=\'Cargo\' LEFT JOIN User ON User.userId = modelId AND modelName=\'User\' where f.userId = :u AND modelName LIKE :t AND ( NOT ISNULL( tenderId ) OR NOT ISNULL( cargoId ) OR NOT ISNULL( User.userId ) OR NOT ISNULL( transportId ) )', array(':t' => '%' . $model->modelName . '%', ':u' => Yii::app()->user->id)); $ids = array(); foreach ($favorites as $it) { $ids[$it['modelName']][] = Yii::app()->db->quoteValue($it['modelId']); } /** * Disable all defaults scopes */ Cargo::disableDefaultScope(); Transport::disableDefaultScope(); Tender::disableDefaultScope(); User::disableDefaultScope(); $cargoes = new CActiveDataProvider('Cargo', array('criteria' => array('condition' => 'cargo.cargoId in (' . ($ids['Cargo'] ? implode(',', $ids['Cargo']) : 0) . ')'), 'pagination' => false)); $transports = new CActiveDataProvider('Transport', array('criteria' => array('condition' => 'transport.type = ' . Transport::TRANSPORT . ' AND transport.transportId in (' . ($ids['Transport'] ? implode(',', $ids['Transport']) : 0) . ')'), 'pagination' => false)); $tenders = new CActiveDataProvider('Tender', array('criteria' => array('condition' => 'tender.tenderId in (' . ($ids['Tender'] ? implode(',', $ids['Tender']) : -1) . ')'), 'pagination' => false)); $users = new CActiveDataProvider('User', array('criteria' => array('condition' => 'User.userId in (' . ($ids['User'] ? implode(',', $ids['User']) : -1) . ')'), 'pagination' => false)); $this->render('index', array('cargoes' => $cargoes, 'transports' => $transports, 'tenders' => $tenders, 'users' => $users, 'model' => $model)); }