Add a mapping model which can be used as an owner for approval tokens

This commit is contained in:
2022-02-15 16:31:09 +00:00
parent 62cc5713f7
commit 6039574d79
2 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
<?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\Database\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Capsule\Manager as DB;
use UserFrosting\Sprinkle\Core\Database\Models\Model;
use UserFrosting\Sprinkle\Organisations\Repository\Interfaces\TokenOwnerInterface;
/**
* OrganisationMember mapping Class.
*
* Represents a mapping of a user to an organisation as stored in the database.
*
* @author Craig Williams (https://avsdev.uk)
*
* @property integer $user_id
* @property integer $organisation_id
* @property boolean $flag_admin
* @property boolean $flag_approved
* @property timestamp $created_at
* @property timestamp $updated_at
*/
class OrganisationMember extends Model implements TokenOwnerInterface
{
/**
* @var string The name of the table for the current model.
*/
protected $table = 'organisation_members';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'map_id';
/**
* Fields that should be mass-assignable when creating a new OrganisationMember.
*
* @var string[]
*/
protected $fillable = [
'user_id',
'organisation_id',
'flag_admin',
'flag_approved',
];
/**
* @var bool Enable timestamps for this class.
*/
public $timestamps = true;
/**
* Get the mapping id, as per TokenOwnerInterface
*/
public function getId()
{
return $this->map_id;
}
/**
* Get the user from this mapping
*/
public function user()
{
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
$classMapper = static::$ci->classMapper;
return $this->belongsTo($classMapper->getClassMapping('user'), 'user_id');
}
/**
* Get the organisation from this mapping
*/
public function organisation()
{
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
$classMapper = static::$ci->classMapper;
return $this->belongsTo($classMapper->getClassMapping('organisation'), 'organisation_id');
}
}