Skip to content

Commit

Permalink
Fix shared events obtaining.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvaganov committed Jun 6, 2016
1 parent 190f471 commit 633ff99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 1 addition & 3 deletions controllers/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
1 change: 0 additions & 1 deletion models/query/CalendarQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 13 additions & 0 deletions models/search/CalendarSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,34 @@ 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);
return new ActiveDataProvider(['query' => $query]);
}

/**
* 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]);
}
}

0 comments on commit 633ff99

Please sign in to comment.