69 lines
2.0 KiB
PHP
69 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class WorkspaceInvitationModel extends Model
|
|
{
|
|
protected $table = 'workspace_invitations';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
protected $protectFields = true;
|
|
protected $allowedFields = [
|
|
'workspace_id',
|
|
'invited_by',
|
|
'email',
|
|
'role',
|
|
'token',
|
|
'accepted',
|
|
'expires_at',
|
|
];
|
|
|
|
protected bool $allowEmptyInserts = false;
|
|
protected bool $updateOnlyChanged = true;
|
|
|
|
protected array $casts = [];
|
|
protected array $castHandlers = [];
|
|
|
|
// Dates
|
|
protected $useTimestamps = false;
|
|
protected $dateFormat = 'datetime';
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
protected $deletedField = 'deleted_at';
|
|
|
|
// Validation
|
|
protected $validationRules = [
|
|
'workspace_id' => 'required|integer',
|
|
'email' => 'required|valid_email|max_length[255]',
|
|
'role' => 'required|in_list[admin,editor,viewer]',
|
|
'token' => 'required|max_length[255]',
|
|
'expires_at' => 'required',
|
|
];
|
|
protected $validationMessages = [];
|
|
protected $skipValidation = false;
|
|
protected $cleanValidationRules = true;
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = [];
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = [];
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = [];
|
|
protected $afterFind = [];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
|
|
public function getPendingByWorkspace(int $workspaceId): array
|
|
{
|
|
return $this->where('workspace_id', $workspaceId)
|
|
->where('accepted', 0)
|
|
->orderBy('created_at', 'DESC')
|
|
->findAll();
|
|
}
|
|
}
|