More work on ordering
This commit is contained in:
48
app/User.php
48
app/User.php
@@ -9,6 +9,7 @@ use Laravel\Passport\HasApiTokens;
|
||||
use Leenooks\Carbon;
|
||||
use Leenooks\Traits\UserSwitch;
|
||||
use App\Notifications\ResetPasswordNotification;
|
||||
use App\Models\Service;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@@ -159,8 +160,9 @@ class User extends Authenticatable
|
||||
|
||||
public function getServicesActiveAttribute()
|
||||
{
|
||||
return $this->services
|
||||
->where('active',TRUE);
|
||||
return $this->services->filter(function($item) {
|
||||
return $item->isActive();
|
||||
});
|
||||
}
|
||||
|
||||
public function getServicesCountHtmlAttribute()
|
||||
@@ -188,6 +190,11 @@ class User extends Authenticatable
|
||||
return sprintf('<a href="/u/account/view/%s">%s</a>',$this->id,$this->user_id);
|
||||
}
|
||||
|
||||
public function sendPasswordResetNotification($token)
|
||||
{
|
||||
$this->notify(new ResetPasswordNotification($token));
|
||||
}
|
||||
|
||||
/** Scopes **/
|
||||
|
||||
public function scopeActive()
|
||||
@@ -195,6 +202,17 @@ class User extends Authenticatable
|
||||
return $this->where('active',TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is an admin of the account with $id
|
||||
*
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public function isAdmin($id)
|
||||
{
|
||||
return $id AND $this->isReseller() AND in_array($id,$this->all_accounts()->pluck('id')->toArray());
|
||||
}
|
||||
|
||||
/** Functions */
|
||||
|
||||
public function all_accounts()
|
||||
@@ -208,7 +226,6 @@ class User extends Authenticatable
|
||||
|
||||
return $result->flatten();
|
||||
}
|
||||
|
||||
public function all_clients($level=0)
|
||||
{
|
||||
$result = collect();
|
||||
@@ -229,6 +246,16 @@ class User extends Authenticatable
|
||||
return $result->flatten();
|
||||
}
|
||||
|
||||
public function all_client_service_movements()
|
||||
{
|
||||
$s = Service::active()->where('order_status','!=','ACTIVE');
|
||||
$aa = $this->all_accounts()->pluck('id')->unique()->toArray();
|
||||
|
||||
return $s->get()->filter(function($item) use ($aa) {
|
||||
return in_array($item->account_id,$aa);
|
||||
});
|
||||
}
|
||||
|
||||
// List all the agents, including agents of agents
|
||||
public function all_agents($level=0)
|
||||
{
|
||||
@@ -250,17 +277,6 @@ class User extends Authenticatable
|
||||
return $result->flatten();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is an admin of the account with $id
|
||||
*
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public function isAdmin($id)
|
||||
{
|
||||
return $id AND $this->isReseller() AND in_array($id,$this->all_accounts()->pluck('id')->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the logged in user is a reseller or wholesaler
|
||||
*
|
||||
@@ -285,8 +301,4 @@ class User extends Authenticatable
|
||||
elseif (! $this->all_agents()->count() AND ! $this->all_clients()->count())
|
||||
return 'customer';
|
||||
}
|
||||
public function sendPasswordResetNotification($token)
|
||||
{
|
||||
$this->notify(new ResetPasswordNotification($token));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user