Revamped the organisation approvals process & refactored some files

This commit is contained in:
2022-02-15 15:26:56 +00:00
parent e029728d69
commit cd8a16f4a8
10 changed files with 643 additions and 668 deletions

View File

@@ -13,6 +13,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Capsule\Manager as DB;
use UserFrosting\Sprinkle\Core\Database\Models\Model;
use UserFrosting\Sprinkle\Organisations\Database\Models\Interfaces\OrganisationInterface;
use UserFrosting\Sprinkle\Organisations\Repository\Interfaces\TokenOwnerInterface;
/**
* Organisation Class.
@@ -28,7 +29,7 @@ use UserFrosting\Sprinkle\Organisations\Database\Models\Interfaces\OrganisationI
* @property timestamp $updated_at
* @property timestamp $deleted_at
*/
class Organisation extends Model implements OrganisationInterface
class Organisation extends Model implements OrganisationInterface, TokenOwnerInterface
{
use SoftDeletes;
@@ -46,6 +47,7 @@ class Organisation extends Model implements OrganisationInterface
'slug',
'name',
'description',
'registrant_id',
'flag_approved',
'deleted_at',
];
@@ -82,6 +84,25 @@ class Organisation extends Model implements OrganisationInterface
*/
public $timestamps = true;
/**
* Get the mapping id, as per TokenOwnerInterface
*/
public function getId()
{
return $this->id;
}
/**
* Get the user who registered this organisation
*/
public function registrant()
{
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
$classMapper = static::$ci->classMapper;
return $this->hasOne($classMapper->getClassMapping('user'), 'id', 'registrant_id');
}
/**
* Get a list of members within this organisation.
@@ -93,8 +114,7 @@ class Organisation extends Model implements OrganisationInterface
return $this
->belongsToMany($classMapper->getClassMapping('user'), 'organisation_members', 'organisation_id', 'user_id')
->where('flag_admin', false)
->withTimestamps();
->where('flag_admin', false);
}
/**
@@ -107,8 +127,7 @@ class Organisation extends Model implements OrganisationInterface
return $this
->belongsToMany($classMapper->getClassMapping('user'), 'organisation_members', 'organisation_id', 'user_id')
->where('flag_admin', true)
->withTimestamps();
->where('flag_admin', true);
}
/**
@@ -127,7 +146,7 @@ class Organisation extends Model implements OrganisationInterface
static::$ci->get('organisation.beforeDelete')($this);
// Remove all organisation tokens
$classMapper->getClassMapping('organisation_approval')::where('organisation_id', $this->id)->delete();
$classMapper->getClassMapping('organisation_approval')::where('owner_id', $this->id)->delete();
// Remove all member associations
$this->members()->detach();