Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Comptoir
Comptoir-srv
Commits
258e4b19
Commit
258e4b19
authored
Jun 08, 2022
by
Fabrice Gangler
🎨
Browse files
REFACTOR(mapping): improve user controller
parent
aea40d24
Pipeline
#27593
passed with stage
in 4 minutes and 28 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/Controller/Api/V1/UsersController.php
View file @
258e4b19
...
...
@@ -404,9 +404,73 @@ class UsersController extends AppController
/**
* Load mapping data if available for given user ID and populate view data
* @param
int
$user
Id
* @param
User
$user
*/
protected
function
commonMappingForUser
(
User
$user
)
{
$data
=
$this
->
getMappingForUser
(
$user
);
$taxonomiesSoftware
=
$data
[
'taxonomiesSoftware'
];
$usedSoftwareKeys
=
$data
[
'usedSoftwareKeys'
];
$mappingFirstLevels
=
$data
[
'mappingFirstLevels'
];
$mappingTaxons
=
$data
[
'mappingTaxons'
];
// Populate view data
$this
->
set
(
compact
([
'mappingFirstLevels'
]));
$this
->
set
(
compact
([
'mappingTaxons'
]));
$this
->
set
(
compact
([
'usedSoftwareKeys'
]));
$this
->
set
(
compact
([
'taxonomiesSoftware'
]));
$this
->
set
(
'_serialize'
,
[
'taxonomiesSoftware'
,
'usedSoftwareKeys'
,
'mappingTaxons'
,
'mappingFirstLevels'
]);
}
/**
* Load mapping data if available for given user ID
* and return a array of all software declared by user for one or multiple taxon
*
* @param User $user
* @return array example: [
* 'LibreOffice' => ['softwareName' => 'LibreOffice',
* 'softwareId' => 33,
* 'modified' => '2022-06-01T11:05:53+00:00',
* 'mappingTaxons' => [['slug' => 'bureautique', 'title' => 'Bureautique],]]
*/
protected
function
getSofwareMappingForUser
(
User
$user
)
{
$mappingData
=
$this
->
getMappingForUser
(
$user
);
$softwareDeclaredInTaxonomy
=
[];
if
(
count
(
$mappingData
[
'taxonomiesSoftware'
])
>
0
)
{
foreach
(
$mappingData
[
'taxonomiesSoftware'
]
as
$taxon
)
{
foreach
(
$taxon
as
$softwareName
=>
$taxonData
)
{
$taxonomyId
=
$taxonData
->
taxonomy_id
;
$mappingTaxons
=
$mappingData
[
'mappingTaxons'
][
$taxonomyId
];
$softwareDeclaredInTaxonomy
[
$softwareName
][
'softwareName'
]
=
$softwareName
;
$softwareDeclaredInTaxonomy
[
$softwareName
][
'softwareId'
]
=
$taxonData
->
software_id
;
$softwareDeclaredInTaxonomy
[
$softwareName
][
'mappingTaxons'
][
$taxonomyId
]
=
$mappingTaxons
;
$modified
=
$taxonData
[
'modified'
];
// Cake\I18n\Time
if
(
!
isset
(
$softwareDeclaredInTaxonomy
[
$softwareName
][
'modified'
]))
{
$softwareDeclaredInTaxonomy
[
$softwareName
][
'modified'
]
=
$modified
;
// Cake\I18n\Time
}
elseif
(
$softwareDeclaredInTaxonomy
[
$softwareName
][
'modified'
]
<
$modified
)
{
$softwareDeclaredInTaxonomy
[
$softwareName
][
'modified'
]
=
$modified
;
// Cake\I18n\Time
}
}
}
}
return
$softwareDeclaredInTaxonomy
;
}
/**
* Load mapping data if available for given user ID
*
* @param User $user
* @return array
*/
protected
function
getMappingForUser
(
User
$user
)
{
$taxonomiesSoftware
=
[];
$usedSoftwareKeys
=
[];
...
...
@@ -449,23 +513,16 @@ class UsersController extends AppController
}
}
}
// Populate view data
$this
->
set
(
compact
([
'mappingFirstLevels'
]));
$this
->
set
(
compact
([
'mappingTaxons'
]));
$this
->
set
(
compact
([
'usedSoftwareKeys'
]));
$this
->
set
(
compact
([
'taxonomiesSoftware'
]));
$this
->
set
(
'_serialize'
,
[
'taxonomiesSoftware'
,
'usedSoftwareKeys'
,
'mappingTaxons'
,
'mappingFirstLevels'
]);
return
[
'taxonomiesSoftware'
=>
$taxonomiesSoftware
,
'usedSoftwareKeys'
=>
$usedSoftwareKeys
,
'mappingFirstLevels'
=>
$mappingFirstLevels
,
'mappingTaxons'
=>
$mappingTaxons
,
];
}
/**
* Tooling for "add" method: create anti-spam tokens
* - create anti-spam tokens (get, post, form)
...
...
Write
Preview
Supports
Markdown
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