[WIP] Setup of skeleton
This commit is contained in:
177
app/Repositories/Users.php
Normal file
177
app/Repositories/Users.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
use App\User;
|
||||
use App\Models\RoleUser;
|
||||
use App\Models\Societe;
|
||||
use App\Models\Hestimmo\Partenaire;
|
||||
|
||||
class Users
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
|
||||
public static function isAdmin()
|
||||
{
|
||||
return (self::hasRole('admin')) ? true : false;
|
||||
}
|
||||
|
||||
public static function isPartenaire()
|
||||
{
|
||||
return (self::hasRole('partenaire')) ? self::getPartenaireId() : false;
|
||||
}
|
||||
|
||||
public static function isPromoteur()
|
||||
{
|
||||
return (self::hasRole('promoteur')) ? self::getPromoteurId() : false;
|
||||
}
|
||||
|
||||
public static function isCommercial()
|
||||
{
|
||||
return (self::hasRole('commercial')) ? true : false;
|
||||
}
|
||||
|
||||
public static function getPartenaireId($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : self::getId();
|
||||
$partenaire = Partenaire::byUser($user_id)->first();
|
||||
return $partenaire ? $partenaire->id : null;
|
||||
}
|
||||
|
||||
public static function getPartenaire($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : self::getId();
|
||||
return Societe::partenaireByUser($user_id)->first();
|
||||
}
|
||||
|
||||
public static function getPromoteurId($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : self::getId();
|
||||
return Promoteur::byUser($user_id)->first()->id;
|
||||
}
|
||||
|
||||
public static function getPromoteur($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : self::getId();
|
||||
return Societe::promoteurByUser($user_id)->first();
|
||||
}
|
||||
|
||||
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