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

FEAT #16063 TIME 0:30 Chart + fixes

parent a6689489
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ use Respect\Validation\Validator; ...@@ -24,6 +24,7 @@ use Respect\Validation\Validator;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
use SrcCore\controllers\PreparedClauseController; use SrcCore\controllers\PreparedClauseController;
use Status\models\StatusModel;
use User\models\UserModel; use User\models\UserModel;
class TileController class TileController
...@@ -214,9 +215,13 @@ class TileController ...@@ -214,9 +215,13 @@ class TileController
} elseif (!Validator::intVal()->validate($args['parameters']['groupId'] ?? null)) { } elseif (!Validator::intVal()->validate($args['parameters']['groupId'] ?? null)) {
return ['errors' => 'Body[parameters] groupId is empty or not an integer']; return ['errors' => 'Body[parameters] groupId is empty or not an integer'];
} }
if (!BasketModel::hasGroup(['id' => $args['parameters']['basketId'], 'groupId' => $args['parameters']['groupId']])) { $basket = BasketModel::getById(['select' => ['basket_id'], 'id' => $args['parameters']['basketId']]);
$group = GroupModel::getById(['select' => ['group_id'], 'id' => $args['parameters']['groupId']]);
if (empty($basket) || empty($group)) {
return ['errors' => 'Basket or group do not exist'];
} elseif (!BasketModel::hasGroup(['id' => $basket['basket_id'], 'groupId' => $group['group_id']])) {
return ['errors' => 'Basket is not linked to this group']; return ['errors' => 'Basket is not linked to this group'];
} elseif (!UserModel::hasGroup(['id' => $GLOBALS['id'], 'groupId' => $args['parameters']['groupId']])) { } elseif (!UserModel::hasGroup(['id' => $GLOBALS['id'], 'groupId' => $group['group_id']])) {
return ['errors' => 'User is not linked to this group']; return ['errors' => 'User is not linked to this group'];
} }
} }
...@@ -227,14 +232,14 @@ class TileController ...@@ -227,14 +232,14 @@ class TileController
private static function getDetails(array &$tile) private static function getDetails(array &$tile)
{ {
if ($tile['type'] == 'basket') { if ($tile['type'] == 'basket') {
if (!BasketModel::hasGroup(['id' => $tile['parameters']['basketId'], 'groupId' => $tile['parameters']['groupId']])) { $basket = BasketModel::getById(['select' => ['basket_clause', 'basket_name', 'basket_id'], 'id' => $tile['parameters']['basketId']]);
$group = GroupModel::getById(['select' => ['group_desc', 'group_id'], 'id' => $tile['parameters']['groupId']]);
if (!BasketModel::hasGroup(['id' => $basket['basket_id'], 'groupId' => $group['group_id']])) {
return ['errors' => 'Basket is not linked to this group']; return ['errors' => 'Basket is not linked to this group'];
} elseif (!UserModel::hasGroup(['id' => $GLOBALS['id'], 'groupId' => $tile['parameters']['groupId']])) { } elseif (!UserModel::hasGroup(['id' => $GLOBALS['id'], 'groupId' => $group['group_id']])) {
return ['errors' => 'User is not linked to this group']; return ['errors' => 'User is not linked to this group'];
} }
$basket = BasketModel::getById(['select' => ['basket_clause', 'basket_name'], 'id' => $tile['parameters']['basketId']]);
$group = GroupModel::getById(['select' => ['group_desc'], 'id' => $tile['parameters']['groupId']]);
$tile['basketName'] = $basket['basket_name']; $tile['basketName'] = $basket['basket_name'];
$tile['groupName'] = $group['group_desc']; $tile['groupName'] = $group['group_desc'];
if ($tile['view'] == 'resume') { if ($tile['view'] == 'resume') {
...@@ -242,15 +247,28 @@ class TileController ...@@ -242,15 +247,28 @@ class TileController
} elseif ($tile['view'] == 'list') { } elseif ($tile['view'] == 'list') {
//TODO WIP //TODO WIP
} elseif ($tile['view'] == 'chart') { } elseif ($tile['view'] == 'chart') {
if (!empty($tile['parameters']['chartMode']) && $tile['parameters']['chartMode'] == 'status') {
$type = 'status';
} else {
$type = 'type_id';
}
$resources = ResModel::getOnView([ $resources = ResModel::getOnView([
'select' => ['COUNT(type_id)'], 'select' => ["COUNT({$type}), {$type}"],
'where' => [PreparedClauseController::getPreparedClause(['userId' => $GLOBALS['id'], 'clause' => $basket['basket_clause']])], 'where' => [PreparedClauseController::getPreparedClause(['userId' => $GLOBALS['id'], 'clause' => $basket['basket_clause']])],
'groupBy' => ['type_id'] 'groupBy' => [$type]
]); ]);
$tile['resources'] = []; $tile['resources'] = [];
foreach ($resources as $resource) { foreach ($resources as $resource) {
$doctype = DoctypeModel::getById(['select' => ['description'], 'id' => $resource['type_id']]); if ($type == 'status') {
$tile['resources'][] = ['name' => $doctype['description'], 'value' => $resource['count']]; $status['label_status'] = null;
if (!empty($resource['status'])) {
$status = StatusModel::getById(['select' => ['label_status'], 'id' => $resource['status']]);
}
$tile['resources'][] = ['name' => $status['label_status'], 'value' => $resource['count']];
} else {
$doctype = DoctypeModel::getById(['select' => ['description'], 'id' => $resource['type_id']]);
$tile['resources'][] = ['name' => $doctype['description'], 'value' => $resource['count']];
}
} }
} }
} }
......
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