From cceb301e0f72d62cacc21f2add220df877ab9944 Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Fri, 25 Oct 2019 18:01:42 +0200
Subject: [PATCH] FEAT #12091 TIME 0:10 Resources list actions with default
 action

---
 .../controllers/ResourceListController.php       | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/app/resource/controllers/ResourceListController.php b/src/app/resource/controllers/ResourceListController.php
index 18495d2bc34..309d42e016a 100644
--- a/src/app/resource/controllers/ResourceListController.php
+++ b/src/app/resource/controllers/ResourceListController.php
@@ -285,9 +285,7 @@ class ResourceListController
 
     public function getActions(Request $request, Response $response, array $aArgs)
     {
-        $currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
-
-        $errors = ResourceListController::listControl(['groupId' => $aArgs['groupId'], 'userId' => $aArgs['userId'], 'basketId' => $aArgs['basketId'], 'currentUserId' => $currentUser['id']]);
+        $errors = ResourceListController::listControl(['groupId' => $aArgs['groupId'], 'userId' => $aArgs['userId'], 'basketId' => $aArgs['basketId'], 'currentUserId' => $GLOBALS['id']]);
         if (!empty($errors['errors'])) {
             return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
         }
@@ -296,18 +294,22 @@ class ResourceListController
         $group = GroupModel::getById(['id' => $aArgs['groupId'], 'select' => ['group_id']]);
 
         $rawActions = ActionGroupBasketModel::get([
-            'select'    => ['id_action'],
-            'where'     => ['basket_id = ?', 'group_id = ?', 'used_in_basketlist = ?', 'default_action_list = ?'],
-            'data'      => [$basket['basket_id'], $group['group_id'], 'Y', 'N']
+            'select'    => ['id_action', 'default_action_list'],
+            'where'     => ['basket_id = ?', 'group_id = ?', 'used_in_basketlist = ?'],
+            'data'      => [$basket['basket_id'], $group['group_id'], 'Y']
         ]);
 
         $actions = [];
+        $defaultAction = 0;
         foreach ($rawActions as $rawAction) {
+            if ($rawAction['default_action_list'] == 'Y') {
+                $defaultAction = $rawAction['id_action'];
+            }
             $actions[] = $rawAction['id_action'];
         }
 
         if (!empty($actions)) {
-            $actions = ActionModel::get(['select' => ['id', 'label_action', 'component'], 'where' => ['id in (?)'], 'data' => [$actions], 'orderBy' => ['label_action']]);
+            $actions = ActionModel::get(['select' => ['id', 'label_action', 'component'], 'where' => ['id in (?)'], 'data' => [$actions], 'orderBy' => ["id = {$defaultAction} DESC",'label_action']]);
             foreach ($actions as $key => $action) {
                 $actions[$key]['label'] = $action['label_action'];
                 unset($actions[$key]['label_action']);
-- 
GitLab