add shipping rules
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\UserClient;
|
||||
use App\Models\Core\Auth\User;
|
||||
|
||||
use App\Models\Core\Auth\UserClient;
|
||||
use App\Repositories\Clients;
|
||||
|
||||
class UserClients
|
||||
@@ -12,7 +11,7 @@ class UserClients
|
||||
public static function associate($user_id, $clients_list)
|
||||
{
|
||||
$clients_existing = self::getClientsByUser($user_id)->toArray();
|
||||
$clients_list = is_array($clients_list) ? $clients_list : array();
|
||||
$clients_list = is_array($clients_list) ? $clients_list : [];
|
||||
|
||||
if (is_array($clients_existing)) {
|
||||
$clients_new = array_diff($clients_list, $clients_existing);
|
||||
@@ -22,9 +21,9 @@ class UserClients
|
||||
$clients_to_delete = $clients_existing;
|
||||
}
|
||||
|
||||
$history_element_infos = (!empty($clients_new)) ? self::associateClients($user_id, $clients_new) : false;
|
||||
$history_element_infos2 = (!empty($clients_to_delete)) ? self::dissociateClients($user_id, $clients_to_delete) : false;
|
||||
|
||||
$history_element_infos = (! empty($clients_new)) ? self::associateClients($user_id, $clients_new) : false;
|
||||
$history_element_infos2 = (! empty($clients_to_delete)) ? self::dissociateClients($user_id, $clients_to_delete) : false;
|
||||
|
||||
// $history_element = $old_translated_name['name'];
|
||||
// $history_element_id = $documentation_category_id;
|
||||
// Histories::insert(190, $history_element_id, $history_element);
|
||||
@@ -41,20 +40,22 @@ class UserClients
|
||||
|
||||
public static function associateClients($user_id, $clients)
|
||||
{
|
||||
$history = "";
|
||||
$history = '';
|
||||
foreach ($clients as $key => $client_id) {
|
||||
$client = Clients::get($client_id);
|
||||
if ($client) {
|
||||
self::associate_client($user_id, $client_id);
|
||||
$history .= $client['name'] . "| ";
|
||||
$history .= $client['name'].'| ';
|
||||
}
|
||||
}
|
||||
|
||||
return $history;
|
||||
}
|
||||
|
||||
public static function associate_client($user_id, $client_id)
|
||||
{
|
||||
self::copyUser($user_id, $client_id);
|
||||
|
||||
return UserClient::create(['user_id' => $user_id, 'client_id' => $client_id]);
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ class UserClients
|
||||
$password = $user->password;
|
||||
Clients::switchClient($client_id);
|
||||
$client_user = User::on($connection->tenantName())->withTrashed()->where('username', $user->username)->first();
|
||||
if (!$client_user) {
|
||||
if (! $client_user) {
|
||||
$user = $user->toArray();
|
||||
$user['password'] = $password;
|
||||
unset($user['id']);
|
||||
@@ -106,17 +107,19 @@ class UserClients
|
||||
|
||||
public static function dissociateClients($user_id, $clients)
|
||||
{
|
||||
$history = "";
|
||||
$history = '';
|
||||
foreach ($clients as $key => $client_id) {
|
||||
self::dissociate_client($user_id, $client_id);
|
||||
$history .= $client['name'] . "| ";
|
||||
$history .= $client['name'].'| ';
|
||||
}
|
||||
|
||||
return $history;
|
||||
}
|
||||
|
||||
public static function dissociate_client($user_id, $client_id)
|
||||
{
|
||||
self::deleteUser($user_id, $client_id);
|
||||
|
||||
return UserClient::byUser($user_id)->byClient($client_id)->delete();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user