BookStack\Services\PermissionService::filterRelatedPages PHP Method

filterRelatedPages() public method

Filters pages that are a direct relation to another item.
public filterRelatedPages ( $query, $tableName, $entityIdColumn ) : mixed
$query
$tableName
$entityIdColumn
return mixed
    public function filterRelatedPages($query, $tableName, $entityIdColumn)
    {
        if ($this->isAdmin()) {
            $this->clean();
            return $query;
        }
        $this->currentAction = 'view';
        $tableDetails = ['tableName' => $tableName, 'entityIdColumn' => $entityIdColumn];
        $q = $query->where(function ($query) use($tableDetails) {
            $query->where(function ($query) use(&$tableDetails) {
                $query->whereExists(function ($permissionQuery) use(&$tableDetails) {
                    $permissionQuery->select('id')->from('joint_permissions')->whereRaw('joint_permissions.entity_id=' . $tableDetails['tableName'] . '.' . $tableDetails['entityIdColumn'])->where('entity_type', '=', 'Bookstack\\Page')->where('action', '=', $this->currentAction)->whereIn('role_id', $this->getRoles())->where(function ($query) {
                        $query->where('has_permission', '=', true)->orWhere(function ($query) {
                            $query->where('has_permission_own', '=', true)->where('created_by', '=', $this->currentUser()->id);
                        });
                    });
                });
            })->orWhere($tableDetails['entityIdColumn'], '=', 0);
        });
        $this->clean();
        return $q;
    }