From 633ff99d07973bb1dfb57670946c2fbe583dc411 Mon Sep 17 00:00:00 2001 From: dvaganov Date: Mon, 6 Jun 2016 10:37:06 +0300 Subject: [PATCH] Fix shared events obtaining. --- controllers/CalendarController.php | 4 +--- models/query/CalendarQuery.php | 1 - models/search/CalendarSearch.php | 13 +++++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/controllers/CalendarController.php b/controllers/CalendarController.php index fc1628a..a06e722 100644 --- a/controllers/CalendarController.php +++ b/controllers/CalendarController.php @@ -37,11 +37,9 @@ public function behaviors() public function actionIndex() { $searchModel = new CalendarSearch(); - - $dataProviderMy = $searchModel->byOwner(\Yii::$app->user->id); - $access = Access::find()->whereGuest(\Yii::$app->user->id)->all(); + $dataProviderMy = $searchModel->byOwner(\Yii::$app->user->id); $dataProviderShared = $searchModel->searchShared($access); return $this->render('index', [ diff --git a/models/query/CalendarQuery.php b/models/query/CalendarQuery.php index d043b66..fb292ba 100644 --- a/models/query/CalendarQuery.php +++ b/models/query/CalendarQuery.php @@ -52,7 +52,6 @@ public function whereOwner($userID) public function withUserAndDate($userID, $date) { - echo $userID . $date; return $this->orWhere([ 'and', 'creatorID = :userID', ['like', 'dateEvent', $date] diff --git a/models/search/CalendarSearch.php b/models/search/CalendarSearch.php index 1e23a91..7a516ee 100644 --- a/models/search/CalendarSearch.php +++ b/models/search/CalendarSearch.php @@ -68,6 +68,11 @@ public function search($params) return $dataProvider; } + /** + * Creates data provider instance with own events + * @param int $ownerID + * @return ActiveDataProvider + */ public function byOwner($ownerID) { $query = Calendar::find()->whereOwner($ownerID); @@ -75,14 +80,22 @@ public function byOwner($ownerID) } /** + * Creates data provider instance with shared events * @param \app\models\Access $accesses + * @return ActiveDataProvider */ public function searchShared($accesses) { $query = Calendar::find(); + foreach($accesses as $access) { $query->withUserAndDate($access->ownerID, $access->date); } + + if (is_null($query->sql)) { + $query->where('0 = 1'); + } + return new ActiveDataProvider(['query' => $query]); } }