[WIP] Fix ergonomics rules
This commit is contained in:
136
app/Repositories/Core/Auth/Users.php
Normal file
136
app/Repositories/Core/Auth/Users.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
use App\Models\Core\Auth\User;
|
||||
use App\Models\Core\Auth\RoleUser;
|
||||
|
||||
class Users
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
|
||||
public static function isAdmin()
|
||||
{
|
||||
return (self::hasRole('admin')) ? true : false;
|
||||
}
|
||||
|
||||
public static function getInfo($id = false)
|
||||
{
|
||||
return self::getWithDetail($id);
|
||||
}
|
||||
|
||||
public static function getWithDetail($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
return User::where('id', $id)->with(['user_detail'])->first();
|
||||
}
|
||||
|
||||
public static function getEmailsByRole($role) {
|
||||
return User::select('id','email')->whereRoleIs($role)->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getIdsByRole($role) {
|
||||
return User::select('id')->whereRoleIs($role)->get()->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getListByRole($role)
|
||||
{
|
||||
return self::selectOptions()->orderBy('nom', 'asc')->whereRoleIs($role)->get();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return self::selectOptions()->get();
|
||||
}
|
||||
|
||||
public static function selectOptions()
|
||||
{
|
||||
return User::select('id', DB::raw("concat(last_name,' ',first_name) as nom"));
|
||||
}
|
||||
|
||||
public static function hasRole($role)
|
||||
{
|
||||
$user = self::get();
|
||||
return $user ? $user->hasRole($role) : false;
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
return self::getUser()->id;
|
||||
}
|
||||
|
||||
public static function get($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
return User::find($id);
|
||||
}
|
||||
|
||||
public static function getUser()
|
||||
{
|
||||
return Auth::user();
|
||||
}
|
||||
|
||||
public static function isConnected()
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
$t = RoleUser::byUser($id)->delete();
|
||||
return User::destroy($id);
|
||||
}
|
||||
|
||||
public static function getByTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->get();
|
||||
}
|
||||
|
||||
public static function getByUniqueTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->byUniqueTeam()->get();
|
||||
}
|
||||
|
||||
public static function destroyByUniqueTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->byUniqueTeam()->delete();
|
||||
}
|
||||
|
||||
// récupère les champs de la table
|
||||
public static function get_field_table()
|
||||
{
|
||||
return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
|
||||
}
|
||||
|
||||
// ajoute un utilisateur
|
||||
public static function insert($data)
|
||||
{
|
||||
return User::create($data);
|
||||
}
|
||||
|
||||
// récupère tous les utilisateurs
|
||||
public static function select_all()
|
||||
{
|
||||
return User::all()->toArray();
|
||||
}
|
||||
|
||||
|
||||
// met à jour les informations d'un utilisateur
|
||||
public static function update(Request $request)
|
||||
{
|
||||
return User::find($data['id'])->update($data);
|
||||
}
|
||||
|
||||
// met à jour le mot de passe d'un utilisateur
|
||||
public static function update_password($id, $password)
|
||||
{
|
||||
$user = User::find($id);
|
||||
$user->password = Hash::make($password);
|
||||
return $user->save();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user