Skip to content
Snippets Groups Projects
Verified Commit 30cfc0ef authored by Damien's avatar Damien
Browse files

FEAT #55 reorder data

parent 7e94edbb
No related branches found
No related tags found
No related merge requests found
...@@ -156,6 +156,13 @@ class BasketControllerTest extends TestCase ...@@ -156,6 +156,13 @@ class BasketControllerTest extends TestCase
$this->assertSame('', $responseBody->groups[0]->groupActions[0]->redirects[0]->entity_id); $this->assertSame('', $responseBody->groups[0]->groupActions[0]->redirects[0]->entity_id);
$this->assertSame('MY_ENTITIES', $responseBody->groups[0]->groupActions[0]->redirects[0]->keyword); $this->assertSame('MY_ENTITIES', $responseBody->groups[0]->groupActions[0]->redirects[0]->keyword);
$this->assertSame('ENTITY', $responseBody->groups[0]->groupActions[0]->redirects[0]->redirect_mode); $this->assertSame('ENTITY', $responseBody->groups[0]->groupActions[0]->redirects[0]->redirect_mode);
$this->assertInternalType('array', $responseBody->allGroups);
$this->assertNotNull($responseBody->allGroups);
$this->assertInternalType('array', $responseBody->pages);
$this->assertNotNull($responseBody->pages);
$this->assertInternalType('array', $responseBody->actions);
$this->assertNotNull($responseBody->actions);
} }
public function testUpdateGroup() public function testUpdateGroup()
...@@ -284,24 +291,6 @@ class BasketControllerTest extends TestCase ...@@ -284,24 +291,6 @@ class BasketControllerTest extends TestCase
$this->assertEmpty($responseBody->groups); $this->assertEmpty($responseBody->groups);
} }
public function testGetDataForGroup()
{
$basketController = new \Basket\controllers\BasketController();
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $basketController->getDataForGroupById($request, new \Slim\Http\Response(), ['id' => 'TEST-BASKET123']);
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody->groups);
$this->assertNotNull($responseBody->groups);
$this->assertInternalType('array', $responseBody->pages);
$this->assertNotNull($responseBody->pages);
$this->assertInternalType('array', $responseBody->actions);
$this->assertNotNull($responseBody->actions);
}
public function testGet() public function testGet()
{ {
$basketController = new \Basket\controllers\BasketController(); $basketController = new \Basket\controllers\BasketController();
......
...@@ -277,7 +277,11 @@ class BasketController ...@@ -277,7 +277,11 @@ class BasketController
$groups[$key]['groupActions'] = $actions; $groups[$key]['groupActions'] = $actions;
} }
return $response->withJson(['groups' => $groups]); $allGroups = GroupModel::get(['select' => ['group_id', 'group_desc']]);
$basketPages = BasketModel::getBasketPages();
$allActions = ActionModel::get();
return $response->withJson(['groups' => $groups, 'allGroups' => $allGroups, 'pages' => $basketPages, 'actions' => $allActions]);
} }
public function createGroup(Request $request, Response $response, array $aArgs) public function createGroup(Request $request, Response $response, array $aArgs)
...@@ -415,40 +419,6 @@ class BasketController ...@@ -415,40 +419,6 @@ class BasketController
return $response->withJson(['success' => 'success']); return $response->withJson(['success' => 'success']);
} }
public function getDataForGroupById(Request $request, Response $response, $aArgs)
{
if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$basket = BasketModel::getById(['id' => $aArgs['id']]);
if (empty($basket)) {
return $response->withStatus(400)->withJson(['errors' => 'Basket not found']);
}
$basketGroups = BasketModel::getGroups(['id' => $aArgs['id']]);
$groups = GroupModel::get(['select' => ['group_id', 'group_desc']]);
foreach ($groups as $key => $group) {
$found = false;
foreach ($basketGroups as $basketGroup) {
if ($basketGroup['group_id'] == $group['group_id']) {
$found = true;
break;
}
}
if ($found) {
unset($groups[$key]);
}
}
$groups = array_values($groups);
$basketPages = BasketModel::getBasketPages();
$actions = ActionModel::get();
return $response->withJson(['groups' => $groups, 'pages' => $basketPages, 'actions' => $actions]);
}
public function deleteGroup(Request $request, Response $response, array $aArgs) public function deleteGroup(Request $request, Response $response, array $aArgs)
{ {
if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment