Minor improvements of Space visibility query

This commit is contained in:
Lucas Bartholemy 2021-10-11 22:20:48 +02:00
parent 1820a734fd
commit a9e4998b75

View File

@ -52,18 +52,17 @@ class ActiveQuerySpace extends ActiveQuery
} }
if ($user !== null) { if ($user !== null) {
$spaceIds = array_map(function (Membership $membership) {
return $membership->space_id;
}, Membership::findAll(['user_id' => $user->id]));
$this->andWhere(['OR', $this->andWhere(['OR',
['!=', 'space.visibility', Space::VISIBILITY_NONE], ['IN', 'space.visibility', [Space::VISIBILITY_ALL, Space::VISIBILITY_REGISTERED_ONLY]],
['IN', 'space.id', $spaceIds] ['AND',
['=', 'space.visibility', Space::VISIBILITY_NONE],
['IN', 'space.id', Membership::find()->select('id')->where(['user_id' => $user->id])]
]
]); ]);
} else { } else {
$this->andWhere(['space.visibility' => Space::VISIBILITY_ALL]); $this->andWhere(['!=', 'space.visibility', Space::VISIBILITY_NONE]);
} }
return $this; return $this;
} }