Allow users to see their own organisation pages
This commit is contained in:
85
src/Sprunje/UserSprunje.php
Normal file
85
src/Sprunje/UserSprunje.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* AVSDev UF Organisations (https://avsdev.uk)
|
||||
*
|
||||
* @link https://git.avsdev.uk/avsdev/sprinkle-organisations
|
||||
* @license https://git.avsdev.uk/avsdev/sprinkle-organisations/blob/master/LICENSE.md (LGPL-3.0 License)
|
||||
*/
|
||||
|
||||
namespace UserFrosting\Sprinkle\Organisations\Sprunje;
|
||||
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
use UserFrosting\Sprinkle\Core\Facades\Translator;
|
||||
use UserFrosting\Sprinkle\Core\Sprunje\Sprunje;
|
||||
use UserFrosting\Sprinkle\Admin\Sprunje\UserSprunje as UFUserSprunje;
|
||||
|
||||
/**
|
||||
* UserSprunje.
|
||||
*
|
||||
* Extends Sprunje for the users API.
|
||||
*
|
||||
* @author Craig Williams (https://avsdev.uk)
|
||||
*/
|
||||
class UserSprunje extends UFUserSprunje
|
||||
{
|
||||
protected $filterable = [
|
||||
'name',
|
||||
'organisations',
|
||||
'last_activity',
|
||||
'status',
|
||||
];
|
||||
protected $sortable = [
|
||||
'name',
|
||||
'organisations',
|
||||
'last_activity',
|
||||
'status',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function baseQuery()
|
||||
{
|
||||
$query = parent::baseQuery();
|
||||
|
||||
// Join user's organisations
|
||||
return $query->joinOrganisations()->with('organisations');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort based on organisations names.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function sortOrganisations($query, $direction)
|
||||
{
|
||||
$query->orderBy('organisations.name', $direction);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter LIKE the last activity description.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function filterOrganisations($query, $value)
|
||||
{
|
||||
// Split value on separator for OR queries
|
||||
$values = explode($this->orSeparator, $value);
|
||||
$query->where(function ($query) use ($values) {
|
||||
foreach ($values as $value) {
|
||||
$query->orLike('organisations.name', $value);
|
||||
}
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user