Removed many redundant functions from User::class

This commit is contained in:
Deon George
2022-04-21 16:25:29 +10:00
parent 796c72dd09
commit d53643ef55
25 changed files with 87 additions and 625 deletions

View File

@@ -49,17 +49,6 @@ class Service extends Model implements IDs
{
use HasFactory,ScopeServiceUserAuthorised;
protected $appends = [
'account_name',
'admin_service_id_url',
'billing_price',
'name_short',
'next_invoice',
'service_id',
'service_id_url',
'status',
];
protected $casts = [
'order_info'=>AsCollection::class,
];
@@ -71,35 +60,12 @@ class Service extends Model implements IDs
'stop_at',
];
protected $visible = [
'account_name',
'admin_service_id_url',
'active',
'billing_price',
'data_orig',
'id',
'name_short',
'next_invoice',
'product_category',
'product_name',
'service_id',
'service_id_url',
'status',
];
protected $with = [
'invoice_items',
'product.type.supplied',
'type',
];
// @todo Change to self::INACTIVE_STATUS
private $inactive_status = [
'CANCELLED',
'ORDER-REJECTED',
'ORDER-CANCELLED',
];
public const INACTIVE_STATUS = [
'CANCELLED',
'ORDER-REJECTED',
@@ -406,7 +372,7 @@ class Service extends Model implements IDs
{
return $query->where(function () use ($query) {
$query->where($this->getTable().'.active',TRUE)
->orWhereNotIn('order_status',$this->inactive_status);
->orWhereNotIn('order_status',self::INACTIVE_STATUS);
});
}
@@ -420,7 +386,7 @@ class Service extends Model implements IDs
{
return $query->where(function () use ($query) {
$query->where($this->getTable().'.active',FALSE)
->orWhereIn('order_status',$this->inactive_status);
->orWhereIn('order_status',self::INACTIVE_STATUS);
});
}
@@ -459,14 +425,6 @@ class Service extends Model implements IDs
return $this->account->name;
}
/**
* @deprecated Use getUrlAdminAttribute()
*/
public function getAdminServiceIdUrlAttribute()
{
return $this->getUrlAdminAttribute();
}
/**
* Return the auto billing details
*
@@ -1170,7 +1128,7 @@ class Service extends Model implements IDs
public function getStageParameters(string $stage): Collection
{
$result = Arr::get(self::ACTION_PROGRESS,$stage);
$myrole = array_search(Auth::user()->role(),User::$role_order);
$myrole = array_search(Auth::user()->role(),User::role_order);
// If we have no valid next stage, return an empty collection.
if (($myrole === FALSE) || (! $result))
@@ -1185,7 +1143,7 @@ class Service extends Model implements IDs
$cando = FALSE;
foreach ($roles as $role) {
if ($myrole <= array_search($role,User::$role_order)) {
if ($myrole <= array_search($role,User::role_order)) {
$cando = TRUE;
break;
@@ -1234,14 +1192,14 @@ class Service extends Model implements IDs
}
/**
* Determine if a service is active. It is active, if active=1, or the order_status is not in inactive_status[]
* Determine if a service is active. It is active, if active=1, or the order_status is not in self::INACTIVE_STATUS[]
*
* @return bool
* @todo Remove active and have order_status reflect whether active or not
*/
public function isActive(): bool
{
return $this->active OR ($this->order_status AND ! in_array($this->order_status,$this->inactive_status));
return $this->active OR ($this->order_status AND ! in_array($this->order_status,self::INACTIVE_STATUS));
}
/**
@@ -1323,7 +1281,7 @@ class Service extends Model implements IDs
{
return ! $this->active
AND ! is_null($this->order_status)
AND ! in_array($this->order_status,array_merge($this->inactive_status,['INACTIVE']));
AND ! in_array($this->order_status,array_merge(self::INACTIVE_STATUS,['INACTIVE']));
}
/**
@@ -1464,6 +1422,6 @@ class Service extends Model implements IDs
*/
public function wasCancelled(): bool
{
return in_array($this->order_status,$this->inactive_status);
return in_array($this->order_status,self::INACTIVE_STATUS);
}
}