Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
gredu_labs
Commits
c633655a
Commit
c633655a
authored
Feb 29, 2016
by
Vassilis Kanellopoulos
Browse files
remove unused inputfilter; add logging; fix schools schema
parent
75f92e2c
Changes
3
Hide whitespace changes
Inline
Side-by-side
module/sch_sync/bootstrap.php
View file @
c633655a
<?php
use
GrEduLabs\Schools\InputFilter\Lab
;
use
GrEduLabs\Schools\InputFilter\School
as
SchoolInputFilter
;
use
GrEduLabs\Schools\Service\AssetServiceInterface
;
use
GrEduLabs\Schools\Service\LabServiceInterface
;
...
...
@@ -58,7 +57,6 @@ return function (App $app) {
$c
->
get
(
'SchInventory\\Service'
),
$c
->
get
(
SchoolServiceInterface
::
class
),
$c
->
get
(
'authentication_service'
),
$c
->
get
(
Lab
::
class
),
$c
->
get
(
'logger'
)
);
};
...
...
module/sch_sync/src/Middleware/CreateLabs.php
View file @
c633655a
...
...
@@ -10,6 +10,7 @@
namespace
SchSync\Middleware
;
use
Exception
;
use
GrEduLabs\Schools\Service\AssetServiceInterface
;
use
GrEduLabs\Schools\Service\LabServiceInterface
;
use
GrEduLabs\Schools\Service\SchoolServiceInterface
;
...
...
@@ -52,12 +53,6 @@ class CreateLabs
*/
protected
$authService
;
/**
*
* @var callable
*/
protected
$inputFilter
;
/**
* @var LoggerInterface
*/
...
...
@@ -69,7 +64,6 @@ class CreateLabs
InventoryService
$inventoryService
,
SchoolServiceInterface
$schoolService
,
AuthenticationServiceInterface
$authService
,
callable
$inputFilter
,
LoggerInterface
$logger
)
{
$this
->
labService
=
$labService
;
...
...
@@ -77,7 +71,6 @@ class CreateLabs
$this
->
inventoryService
=
$inventoryService
;
$this
->
schoolService
=
$schoolService
;
$this
->
authService
=
$authService
;
$this
->
inputFilter
=
$inputFilter
;
$this
->
logger
=
$logger
;
}
...
...
@@ -100,8 +93,14 @@ class CreateLabs
if
(
0
<
count
(
$this
->
labService
->
getLabsBySchoolId
(
$school_id
)))
{
return
$res
;
}
try
{
$equipment
=
$this
->
inventoryService
->
getUnitEquipment
(
$school
[
'registry_no'
]);
}
catch
(
Exception
$e
)
{
$this
->
logger
->
error
(
sprintf
(
'Problem retrieving assets from inventory for school %s'
,
$school_id
));
$this
->
logger
->
debug
(
'Exception'
,
[
$e
->
getMessage
(),
$e
->
getTraceAsString
()]);
$equipment
=
$this
->
inventoryService
->
getUnitEquipment
(
$school
[
'registry_no'
]);
return
$res
;
}
$labTypes
=
array_reduce
(
$this
->
labService
->
getLabTypes
(),
function
(
$map
,
$type
)
{
$map
[
trim
(
$type
[
'name'
])]
=
$type
[
'id'
];
...
...
@@ -113,46 +112,51 @@ class CreateLabs
return
$map
;
},
[]);
try
{
$locations
=
array_reduce
(
$equipment
,
function
(
$uniq
,
$item
)
use
(
$school_id
,
$labTypes
,
$assetTypes
)
{
if
(
!
isset
(
$uniq
[
$item
[
'location.id'
]]))
{
$locationName
=
$item
[
'location.name'
];
$detected
=
reset
(
array_filter
(
array_keys
(
$labTypes
),
function
(
$type
)
use
(
$locationName
)
{
return
false
!==
stripos
(
$locationName
,
$type
)
||
false
!==
stripos
(
$type
,
$locationName
);
}));
$labType
=
$detected
?
$labTypes
[
$detected
]
:
end
(
$labTypes
);
$data
=
[
'school_id'
=>
(
int
)
$school_id
,
'name'
=>
$locationName
,
'labtype_id'
=>
(
int
)
$labType
,
];
$lab
=
R
::
dispense
(
'lab'
);
$lab
->
import
(
$data
);
$uniq
[
$item
[
'location.id'
]]
=
$lab
;
}
$locations
=
array_reduce
(
$equipment
,
function
(
$uniq
,
$item
)
use
(
$school_id
,
$labTypes
,
$assetTypes
)
{
if
(
!
isset
(
$uniq
[
$item
[
'location.id'
]]))
{
$locationName
=
$item
[
'location.name'
];
$detected
=
reset
(
array_filter
(
array_keys
(
$labTypes
),
function
(
$type
)
use
(
$locationName
)
{
$categoryName
=
$item
[
'item_template.category.name'
];
return
false
!==
stripos
(
$locationName
,
$type
)
||
false
!==
stripos
(
$type
,
$location
Name
)
;
$type
=
reset
(
array_filter
(
array_keys
(
$assetTypes
),
function
(
$type
)
use
(
$categoryName
)
{
return
$type
==
$category
Name
;
}));
$labType
=
$detected
?
$labTypes
[
$detected
]
:
end
(
$labTypes
);
$data
=
[
'school_id'
=>
(
int
)
$school_id
,
'name'
=>
$locationName
,
'labtype_id'
=>
(
int
)
$labType
,
];
$lab
=
R
::
dispense
(
'lab'
);
$lab
->
import
(
$data
);
$uniq
[
$item
[
'location.id'
]]
=
$lab
;
}
$categoryName
=
$item
[
'item_template.category.name'
];
$type
=
reset
(
array_filter
(
array_keys
(
$assetTypes
),
function
(
$type
)
use
(
$categoryName
)
{
return
$type
==
$categoryName
;
}));
$type
=
(
$type
)
?
$assetTypes
[
$type
]
:
false
;
if
(
$type
!==
false
)
{
if
(
!
$uniq
[
$item
[
'location.id'
]]
->
ownSchoolAsset
[
$type
])
{
$asset
=
R
::
dispense
(
'schoolasset'
);
$asset
->
school_id
=
(
int
)
$school_id
;
$asset
->
itemcategory_id
=
(
int
)
$type
;
$uniq
[
$item
[
'location.id'
]]
->
ownSchoolAsset
[
$type
]
=
$asset
;
$type
=
(
$type
)
?
$assetTypes
[
$type
]
:
false
;
if
(
$type
!==
false
)
{
if
(
!
isset
(
$uniq
[
$item
[
'location.id'
]]
->
ownSchoolAsset
[
$type
]))
{
$asset
=
R
::
dispense
(
'schoolasset'
);
$asset
->
school_id
=
(
int
)
$school_id
;
$asset
->
itemcategory_id
=
(
int
)
$type
;
$uniq
[
$item
[
'location.id'
]]
->
ownSchoolAsset
[
$type
]
=
$asset
;
}
$uniq
[
$item
[
'location.id'
]]
->
ownSchoolAsset
[
$type
]
->
qty
+=
1
;
}
$uniq
[
$item
[
'location.id'
]]
->
ownSchoolAsset
[
$type
]
->
qty
+=
1
;
}
return
$uniq
;
},
[]);
R
::
storeAll
(
$locations
);
return
$uniq
;
},
[]);
R
::
storeAll
(
$locations
);
$this
->
logger
->
info
(
sprintf
(
'Add assets from inventory for school %s'
,
$school_id
));
}
catch
(
Exception
$e
)
{
$this
->
logger
->
error
(
sprintf
(
'Problem inserting assets for school %s in database'
,
$school_id
));
$this
->
logger
->
debug
(
'Exception'
,
[
$e
->
getMessage
(),
$e
->
getTraceAsString
()]);
}
return
$res
;
}
...
...
module/schools/data/schema.mysql.sql
View file @
c633655a
...
...
@@ -266,7 +266,7 @@ CREATE TABLE `lab` (
KEY
`index_foreignkey_lab_labtype`
(
`labtype_id`
),
KEY
`index_foreignkey_lab_responsible`
(
`responsible_id`
),
CONSTRAINT
`c_fk_lab_labtype_id`
FOREIGN
KEY
(
`labtype_id`
)
REFERENCES
`labtype`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
,
CONSTRAINT
`c_fk_lab_responsible_id`
FOREIGN
KEY
(
`responsible_id`
)
REFERENCES
`teacher`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
,
CONSTRAINT
`c_fk_lab_responsible_id`
FOREIGN
KEY
(
`responsible_id`
)
REFERENCES
`teacher`
(
`id`
)
ON
DELETE
SET
NULL
ON
UPDATE
CASCADE
,
CONSTRAINT
`c_fk_lab_school_id`
FOREIGN
KEY
(
`school_id`
)
REFERENCES
`school`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_ci
;
/*!40101 SET character_set_client = @saved_cs_client */
;
...
...
@@ -358,7 +358,10 @@ CREATE TABLE `schoolasset` (
PRIMARY
KEY
(
`id`
),
KEY
`index_foreignkey_schoolasset_itemcategory`
(
`itemcategory_id`
),
KEY
`index_foreignkey_schoolasset_school`
(
`school_id`
),
KEY
`index_foreignkey_schoolasset_lab`
(
`lab_id`
)
KEY
`index_foreignkey_schoolasset_lab`
(
`lab_id`
),
CONSTRAINT
`c_fk_schoolasset_itemcategory_id`
FOREIGN
KEY
(
`itemcategory_id`
)
REFERENCES
`itemcategory`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
,
CONSTRAINT
`c_fk_schoolasset_school_id`
FOREIGN
KEY
(
`school_id`
)
REFERENCES
`school`
(
`id`
)
ON
DELETE
CASCADE
ON
UPDATE
CASCADE
,
CONSTRAINT
`c_fk_schoolasset_lab_id`
FOREIGN
KEY
(
`lab_id`
)
REFERENCES
`lab`
(
`id`
)
ON
DELETE
CASCADE
ON
UPDATE
CASCADE
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_ci
;
/*!40101 SET character_set_client = @saved_cs_client */
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment