}
/**
- * Filters pages that are a direct relation to another item.
+ * Add conditions to a query to filter the selection to related entities
+ * where permissions are granted.
+ * @param $entityType
* @param $query
* @param $tableName
* @param $entityIdColumn
* @return mixed
*/
- public function filterRelatedPages($query, $tableName, $entityIdColumn)
+ public function filterRelatedEntity($entityType, $query, $tableName, $entityIdColumn)
{
$this->currentAction = 'view';
$tableDetails = ['tableName' => $tableName, 'entityIdColumn' => $entityIdColumn];
- $pageMorphClass = $this->entityProvider->page->getMorphClass();
+ $pageMorphClass = $this->entityProvider->get($entityType)->getMorphClass();
+
$q = $query->where(function ($query) use ($tableDetails, $pageMorphClass) {
$query->where(function ($query) use (&$tableDetails, $pageMorphClass) {
$query->whereExists(function ($permissionQuery) use (&$tableDetails, $pageMorphClass) {
});
})->orWhere($tableDetails['entityIdColumn'], '=', 0);
});
+
$this->clean();
+
return $q;
}