diff --git a/apps/maarch_entreprise/js/angular/app/administration/groups-administration.component.js b/apps/maarch_entreprise/js/angular/app/administration/groups-administration.component.js index 8a4888360825640f385949813b0a65cb0178860f..766bf7b17aae71c2a8bddbf1cf2676948a9531d4 100644 --- a/apps/maarch_entreprise/js/angular/app/administration/groups-administration.component.js +++ b/apps/maarch_entreprise/js/angular/app/administration/groups-administration.component.js @@ -56,7 +56,6 @@ var GroupsAdministrationComponent = (function () { }); } } - console.log(this.groupsForAssign); }; GroupsAdministrationComponent.prototype.reassignUsers = function (group, groupId) { var _this = this; diff --git a/apps/maarch_entreprise/js/angular/app/profile.component.js b/apps/maarch_entreprise/js/angular/app/profile.component.js index a23a45903052710ca625be1ef6cffb1052a327ca..b68831156973044040cfee7760635cbab7283ad7 100755 --- a/apps/maarch_entreprise/js/angular/app/profile.component.js +++ b/apps/maarch_entreprise/js/angular/app/profile.component.js @@ -40,6 +40,7 @@ var ProfileComponent = (function () { title: "", }; this.userAbsenceModel = []; + this.basketsToRedirect = []; this.showPassword = false; this.selectedSignature = -1; this.selectedSignatureLabel = ""; diff --git a/apps/maarch_entreprise/js/angular/app/profile.component.ts b/apps/maarch_entreprise/js/angular/app/profile.component.ts index a6240c5d9c5aff5e64f5157dd602268c979335da..c475cd84fc09e309266b2da85baaac49fbe5eb09 100755 --- a/apps/maarch_entreprise/js/angular/app/profile.component.ts +++ b/apps/maarch_entreprise/js/angular/app/profile.component.ts @@ -41,6 +41,7 @@ export class ProfileComponent implements OnInit { title : "", }; userAbsenceModel : any[] = []; + basketsToRedirect : string[] = []; showPassword : boolean = false; selectedSignature : number = -1; diff --git a/core/Controllers/UserController.php b/core/Controllers/UserController.php index 8ff46c8411d7582f1f8429eba172178c6bfabf0d..25b7f95536205a4a259f3c19cfea10046419e76c 100755 --- a/core/Controllers/UserController.php +++ b/core/Controllers/UserController.php @@ -42,7 +42,8 @@ class UserController $user['groups'] = UserModel::getGroupsByUserId(['userId' => $_SESSION['user']['UserId']]); $user['entities'] = UserModel::getEntitiesById(['userId' => $_SESSION['user']['UserId']]); $user['baskets'] = BasketsModel::getBasketsByUserId(['userId' => $_SESSION['user']['UserId']]); - + $user['redirectedBaskets'] = BasketsModel::getBasketsRedirectedByUserId(['userId' => $_SESSION['user']['UserId']]); + return $response->withJson($user); } @@ -214,7 +215,7 @@ class UserController return $response->withJson(['success' => _UPDATED_PASSWORD]); } - public function setBasketsRedirectionForAbsence(RequestInterface $request, ResponseInterface $response, $aArgs) { + public function setRedirectedBaskets(RequestInterface $request, ResponseInterface $response, $aArgs) { $error = $this->hasUsersRights(['id' => $aArgs['id'], 'himself' => true]); if (!empty($error['error'])) { return $response->withStatus($error['status'])->withJson(['errors' => $error['error']]); @@ -254,6 +255,19 @@ class UserController ]); } + public function deleteRedirectedBaskets(RequestInterface $request, ResponseInterface $response, $aArgs) { + $error = $this->hasUsersRights(['id' => $aArgs['id'], 'himself' => true]); + if (!empty($error['error'])) { + return $response->withStatus($error['status'])->withJson(['errors' => $error['error']]); + } + + $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]); + + BasketsModel::deleteBasketRedirection(['userId' => $user['user_id'], 'basketId' => $aArgs['basketId']]); + + return $response->withJson(['redirectedBaskets' => BasketsModel::getRedirectedBasketsByUserId(['userId' => $user['user_id']])]); + } + public function updateStatus(RequestInterface $request, ResponseInterface $response, $aArgs) { $error = $this->hasUsersRights(['id' => $aArgs['id'], 'himself' => true]); if (!empty($error['error'])) { diff --git a/modules/basket/Models/BasketsModelAbstract.php b/modules/basket/Models/BasketsModelAbstract.php index 7d1f2edc4d189505c1d15a9b2eb01455dfea817e..59098a19ff192bc8863fc3991aefd266814052e1 100755 --- a/modules/basket/Models/BasketsModelAbstract.php +++ b/modules/basket/Models/BasketsModelAbstract.php @@ -168,4 +168,40 @@ class BasketsModelAbstract return true; } + + public static function deleteBasketRedirection(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['userId', 'basketId']); + ValidatorModel::stringType($aArgs, ['userId', 'basketId']); + + DatabaseModel::delete([ + 'table' => 'user_abs', + 'where' => ['(user_abs = ? OR basket_owner = ?)', 'basket_id = ?'], + 'data' => [$aArgs['userId'], $aArgs['userId'], $aArgs['basketId']] + ]); + + return true; + } + + public static function getRedirectedBasketsByUserId(array $aArgs) { + ValidatorModel::notEmpty($aArgs, ['userId']); + ValidatorModel::stringType($aArgs, ['userId']); + + $aBaskets = DatabaseModel::select([ + 'select' => ['ba.basket_id', 'ba.basket_name', 'ua.new_user', 'ua.basket_owner'], + 'table' => ['baskets ba, user_abs ua'], + 'where' => ['ua.user_abs = ?', 'ua.basket_id = ba.basket_id'], + 'data' => [$aArgs['userId']], + 'order_by' => 'ua.system_id' + ]); + + foreach ($aBaskets as $key => $value) { + $user = UserModel::getById(['userId' => $value['new_user'], 'select' => ['firstname', 'lastname']]); + $aBaskets[$key]['userToDisplay'] = "{$user['firstname']} {$user['lastname']} ({$value['new_user']})"; + $aBaskets[$key]['user'] = "{$user['firstname']} {$user['lastname']}"; + } + + return $aBaskets; + } + } \ No newline at end of file diff --git a/modules/basket/display_basket_list.php b/modules/basket/display_basket_list.php index 54b3487193c72038ada3cbd1018e64a7e6f375dc..06dad9cc6270cb4fd5b846e27b175dfb4529ac76 100755 --- a/modules/basket/display_basket_list.php +++ b/modules/basket/display_basket_list.php @@ -75,6 +75,7 @@ if ($core_tools->test_service('display_basket_list','basket', false)) { <h2><?php echo _MY_BASKETS;?> : </h2> <?php + $redirectedBaskets = \Baskets\Models\BasketsModel::getRedirectedBasketsByUserId(['userId' => $_SESSION['user']['UserId']]); $countColl = count($collWithUserBaskets); $currentGroup = ''; for ($cpt=0;$cpt<$countColl;$cpt++) { diff --git a/rest/index.php b/rest/index.php index 85089f5e5dccde38af3e529ac4ee93d29a796c0b..b8bf83a3586bbd311b1367e9efe0e9189cb47ec6 100755 --- a/rest/index.php +++ b/rest/index.php @@ -189,7 +189,9 @@ $app->put('/users/{id}/status', \Core\Controllers\UserController::class . ':upda $app->post('/users/{id}/signatures', \Core\Controllers\UserController::class . ':addSignature'); $app->put('/users/{id}/signatures/{signatureId}', \Core\Controllers\UserController::class . ':updateSignature'); $app->delete('/users/{id}/signatures/{signatureId}', \Core\Controllers\UserController::class . ':deleteSignature'); -$app->post('/users/{id}/baskets/absence', \Core\Controllers\UserController::class . ':setBasketsRedirectionForAbsence'); +$app->post('/users/{id}/baskets/absence', \Core\Controllers\UserController::class . ':setRedirectedBaskets'); //TODO penser à une meilleure route +$app->delete('/users/{id}/baskets/{basketId}/absence', \Core\Controllers\UserController::class . ':deleteRedirectedBaskets'); //TODO penser à une meilleure route + //CurrentUser $app->put('/currentUser/password', \Core\Controllers\UserController::class . ':updateCurrentUserPassword');