use map to find assets from inventory

parent 225b1ac3
<?php return [ <?php return [
'inventory' => [ 'inventory' => [
'base_uri' => '', 'base_uri' => '',
'category_map' => [
// form inventory => in database
'ACCESS POINT' => 'ACCESS POINT',
'LAPTOP' => 'LAPTOP',
'MODEM / ROUTER' => 'MODEM / ROUTER',
'PATCH PANEL' => 'PATCH PANEL',
'PRINTER' => 'PRINTER',
'RACK' => 'RACK',
'SCANNER' => 'SCANNER',
'SERVER' => 'SERVER',
'SWITCH/ HUB' => 'SWITCH/ HUB',
'TABLET' => 'TABLET',
'WEBCAM' => 'WEBCAM',
'WORKSTATION' => 'ΣΤΑΘΜΟΣ ΕΡΓΑΣΙΑΣ',
'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ' => 'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ',
'ΔΙΑΔΡΑΣΤΙΚΟ ΣΥΣΤΗΜΑ' => 'ΔΙΑΔΡΑΣΤΙΚΟ ΣΥΣΤΗΜΑ',
'ΕΠΕΞΕΡΓΑΣΤΗΣ (CPU)' => 'ΕΠΕΞΕΡΓΑΣΤΗΣ (CPU)',
'ΚΙΝΗΤΟ ΕΡΓΑΣΤΗΡΙΟ' => 'ΚΙΝΗΤΟ ΕΡΓΑΣΤΗΡΙΟ',
'ΜΝΗΜΗ RAM' => 'ΜΝΗΜΗ RAM',
'ΟΘΟΝΗ' => 'ΟΘΟΝΗ',
'ΣΚΛΗΡΟΣ ΔΙΣΚΟΣ' => 'ΣΚΛΗΡΟΣ ΔΙΣΚΟΣ',
],
], ],
]; ];
\ No newline at end of file
...@@ -51,13 +51,18 @@ return function (App $app) { ...@@ -51,13 +51,18 @@ return function (App $app) {
); );
}; };
$container[CreateLabs::class] = function ($c) { $container[CreateLabs::class] = function ($c) {
$settings = $c->get('settings');
$categoryMap = isset($settings['inventory']['category_map'])
? $settings['inventory']['category_map'] : [];
return new CreateLabs( return new CreateLabs(
$c->get(LabServiceInterface::class), $c->get(LabServiceInterface::class),
$c->get(AssetServiceInterface::class), $c->get(AssetServiceInterface::class),
$c->get('SchInventory\\Service'), $c->get('SchInventory\\Service'),
$c->get(SchoolServiceInterface::class), $c->get(SchoolServiceInterface::class),
$c->get('authentication_service'), $c->get('authentication_service'),
$c->get('logger') $c->get('logger'),
$categoryMap
); );
}; };
}); });
......
...@@ -58,13 +58,20 @@ class CreateLabs ...@@ -58,13 +58,20 @@ class CreateLabs
*/ */
private $logger; private $logger;
/**
*
* @var array
*/
private $categoryMap;
public function __construct( public function __construct(
LabServiceInterface $labService, LabServiceInterface $labService,
AssetServiceInterface $assetService, AssetServiceInterface $assetService,
InventoryService $inventoryService, InventoryService $inventoryService,
SchoolServiceInterface $schoolService, SchoolServiceInterface $schoolService,
AuthenticationServiceInterface $authService, AuthenticationServiceInterface $authService,
LoggerInterface $logger LoggerInterface $logger,
array $categoryMap = []
) { ) {
$this->labService = $labService; $this->labService = $labService;
$this->assetService = $assetService; $this->assetService = $assetService;
...@@ -72,6 +79,7 @@ class CreateLabs ...@@ -72,6 +79,7 @@ class CreateLabs
$this->schoolService = $schoolService; $this->schoolService = $schoolService;
$this->authService = $authService; $this->authService = $authService;
$this->logger = $logger; $this->logger = $logger;
$this->categoryMap = $categoryMap;
} }
public function __invoke(Request $req, Response $res, callable $next) public function __invoke(Request $req, Response $res, callable $next)
...@@ -134,10 +142,10 @@ class CreateLabs ...@@ -134,10 +142,10 @@ class CreateLabs
$categoryName = $item['item_template.category.name']; $categoryName = $item['item_template.category.name'];
$type = reset(array_filter(array_keys($assetTypes), function ($type) use ($categoryName) { $type = reset(array_filter(array_keys($this->categoryMap), function ($type) use ($categoryName) {
return $type == $categoryName; return $type == $categoryName;
})); }));
$type = ($type) ? $assetTypes[$type] : false; $type = ($type) ? $assetTypes[$this->categoryMap[$type]] : false;
if ($type !== false) { if ($type !== false) {
if (!isset($uniq[$item['location.id']]->ownSchoolAsset[$type])) { if (!isset($uniq[$item['location.id']]->ownSchoolAsset[$type])) {
......
...@@ -108,7 +108,7 @@ CREATE TABLE `itemcategory` ( ...@@ -108,7 +108,7 @@ CREATE TABLE `itemcategory` (
LOCK TABLES `itemcategory` WRITE; LOCK TABLES `itemcategory` WRITE;
/*!40000 ALTER TABLE `itemcategory` DISABLE KEYS */; /*!40000 ALTER TABLE `itemcategory` DISABLE KEYS */;
INSERT INTO `itemcategory` VALUES (8,'ACCESS POINT'),(26,'LAPTOP'),(6,'MODEM / ROUTER '),(5,'PATCH PANEL'),(14,'PRINTER'),(3,'RACK'),(13,'SCANNER'),(24,'SERVER'),(2,'SWITCH/ HUB'),(23,'TABLET'),(11,'WEBCAM'),(22,'WORKSTATION'),(41,'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ'),(40,'ΔΙΑΔΡΑΣΤΙΚΟ ΣΥΣΤΗΜΑ'),(38,'ΕΠΕΞΕΡΓΑΣΤΗΣ (CPU)'),(34,'ΚΙΝΗΤΟ ΕΡΓΑΣΤΗΡΙΟ'),(32,'ΜΝΗΜΗ RAM'),(30,'ΟΘΟΝΗ'),(29,'ΣΚΛΗΡΟΣ ΔΙΣΚΟΣ'); INSERT INTO `itemcategory` VALUES (8,'ACCESS POINT'),(26,'LAPTOP'),(6,'MODEM / ROUTER '),(5,'PATCH PANEL'),(14,'PRINTER'),(3,'RACK'),(13,'SCANNER'),(24,'SERVER'),(2,'SWITCH/ HUB'),(23,'TABLET'),(11,'WEBCAM'),(22,'ΣΤΑΘΜΟΣ ΕΡΓΑΣΙΑΣ'),(41,'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ'),(40,'ΔΙΑΔΡΑΣΤΙΚΟ ΣΥΣΤΗΜΑ'),(38,'ΕΠΕΞΕΡΓΑΣΤΗΣ (CPU)'),(34,'ΚΙΝΗΤΟ ΕΡΓΑΣΤΗΡΙΟ'),(32,'ΜΝΗΜΗ RAM'),(30,'ΟΘΟΝΗ'),(29,'ΣΚΛΗΡΟΣ ΔΙΣΚΟΣ'),(42,'ΤΡΙΣΔΙΑΣΤΑΤΟΣ ΕΚΤΥΠΩΤΗΣ'),(43,'ΤΡΙΣΔΙΑΣΤΑΤΟΣ ΣΑΡΩΤΗΣ'),(44,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ - ΑΙΣΘΗΤΗΡΩΝ'),(45,'ΔΟΜΗΜΕΝΗ ΚΑΛΩΔΙΩΣΗ');
/*!40000 ALTER TABLE `itemcategory` ENABLE KEYS */; /*!40000 ALTER TABLE `itemcategory` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment