/** * Lists all Project models. * @return mixed */ public function actionIndex() { $dataProvider1 = null; $dataProvider2 = null; if (Yii::$app->user->can('editProject')) { $searchModel1 = new ProjectSearch(); $dataProvider1 = $searchModel1->search(Yii::$app->request->queryParams, Project::find()->andWhere(['not', ['projectmanager_id' => null]])); $searchModel2 = new ProjectSearch(); $dataProvider2 = $searchModel2->search(Yii::$app->request->queryParams, Project::find()->andWhere(['projectmanager_id' => null])); } else { if ($customer = Customer::findOne(['user_id' => Yii::$app->user->id])) { $dataProvider1 = new ActiveDataProvider(['query' => Project::find()->andWhere(['or', ['creator_id' => Yii::$app->user->id], ['client_id' => $customer->customer_id], ['projectmanager_id' => Yii::$app->user->id]])->andWhere(['status' => 1])->with('creator', 'client', 'projectmanager', 'updater')]); $searchModel1 = new ProjectSearch(); $dataProvider1 = $searchModel1->search(Yii::$app->request->queryParams, Project::find()->andWhere(['or', ['creator_id' => Yii::$app->user->id], ['client_id' => $customer->customer_id], ['projectmanager_id' => Yii::$app->user->id]])->andWhere(['status' => 1])->with('creator', 'client', 'projectmanager', 'updater')); } else { $searchModel1 = new ProjectSearch(); $dataProvider1 = $searchModel1->search(Yii::$app->request->queryParams, Project::find()->andWhere(['or', ['creator_id' => Yii::$app->user->id], ['projectmanager_id' => Yii::$app->user->id]])->with('creator', 'client', 'projectmanager', 'updater')); } } return $this->render('index', ['dataProvider1' => $dataProvider1, 'dataProvider2' => $dataProvider2, 'searchModel1' => $searchModel1, 'searchModel2' => $searchModel2]); }
public function actionIndexWithRelationships() { // 1. Check what parameter of detail has been passed $room_id = Yii::$app->request->get('room_id', null); $reservation_id = Yii::$app->request->get('reservation_id', null); $customer_id = Yii::$app->request->get('customer_id', null); // 2. Fill three models: roomSelected, reservationSelected and customerSelected and // Fill three arrays of models: rooms, reservations and customer; $roomSelected = null; $reservationSelected = null; $customerSelected = null; if ($room_id != null) { $roomSelected = Room::findOne($room_id); $rooms = array($roomSelected); $reservations = $roomSelected->reservations; $customers = $roomSelected->customers; } else { if ($reservation_id != null) { $reservationSelected = Reservation::findOne($reservation_id); $rooms = array($reservationSelected->room); $reservations = array($reservationSelected); $customers = array($reservationSelected->customer); } else { if ($customer_id != null) { $customerSelected = Customer::findOne($customer_id); $rooms = $customerSelected->rooms; $reservations = $customerSelected->reservations; $customers = array($customerSelected); } else { $rooms = Room::find()->all(); $reservations = Reservation::find()->all(); $customers = Customer::find()->all(); } } } return $this->render('index-with-relationships', ['roomSelected' => $roomSelected, 'reservationSelected' => $reservationSelected, 'customerSelected' => $customerSelected, 'rooms' => $rooms, 'reservations' => $reservations, 'customers' => $customers]); }
/** * Finds the Customer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Customer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Customer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }