92 lines
2.3 KiB
PHP
92 lines
2.3 KiB
PHP
<?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\UFTweaks\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');
|
|
}
|
|
}
|