Skip to content
GitLab
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
c6e7f6f4
Commit
c6e7f6f4
authored
Jun 11, 2020
by
Fabrice Gangler
🎨
Browse files
FEAT(mapping): prepare diplay for user page
Refs:
#917
parent
a7d5c0c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Controller/Api/V1/UsersController.php
View file @
c6e7f6f4
...
...
@@ -11,6 +11,7 @@ namespace App\Controller\Api\V1;
use
App\Controller\AppController
;
use
App\Controller\Component\RulesComponent
;
use
App\Model\Entity\User
;
use
App\Model\Table\UsersTable
;
use
Cake\Core\Configure
;
use
Cake\Event\Event
;
...
...
@@ -369,7 +370,7 @@ class UsersController extends AppController
}
// Load mapping data if available for current user and populate view data
$this
->
commonMappingFor
Current
User
(
$user
->
id
);
$this
->
commonMappingForUser
(
$user
);
//For Social MEDIAS => OPENGRAPH
$openGraph
=
[
...
...
@@ -405,26 +406,61 @@ class UsersController extends AppController
* Load mapping data if available for given user ID and populate view data
* @param int $userId
*/
protected
function
commonMappingFor
Current
User
(
int
$user
Id
)
protected
function
commonMappingForUser
(
User
$user
)
{
// Get taxonomy records grouped by taxon ID for this user
$this
->
loadModel
(
"TaxonomysSoftwares"
);
$taxonomiesSoftware
=
$this
->
TaxonomysSoftwares
->
getListByUserId
(
$userId
);
// Load mapping data if necessary
$taxonomiesSoftware
=
[];
$usedSoftwareKeys
=
[];
$mappingFirstLevels
=
[];
$mappingTaxons
=
[];
if
(
count
(
$taxonomiesSoftware
)
>
0
)
{
$taxonIds
=
array_keys
(
$taxonomiesSoftware
);
$mappingFirstLevels
=
$this
->
getMappingFirstLevels
(
$this
->
selectedLanguage
);
$mappingTaxons
=
$this
->
getMappingTaxonsWithTaxonIdsFilter
(
$taxonIds
,
$this
->
selectedLanguage
);
$userId
=
$user
->
id
;
if
(
$user
->
isAdministrationType
()
&&
count
(
$user
->
usedsoftwares
)
>
0
)
{
// Get taxonomy records grouped by taxon ID for this user
$this
->
loadModel
(
"TaxonomysSoftwares"
);
$taxonomiesSoftware
=
$this
->
TaxonomysSoftwares
->
getListByUserId
(
$userId
);
// Load mapping data if necessary
$mappingFirstLevels
=
[];
$mappingTaxons
=
[];
if
(
count
(
$taxonomiesSoftware
)
>
0
)
{
// Load mapping data
$taxonIds
=
array_keys
(
$taxonomiesSoftware
);
$mappingFirstLevels
=
$this
->
getMappingFirstLevels
(
$this
->
selectedLanguage
);
$mappingTaxons
=
$this
->
getMappingTaxonsWithTaxonIdsFilter
(
$taxonIds
,
$this
->
selectedLanguage
);
// Extract used software keys and software names
$softwareNameList
=
[];
foreach
(
$user
->
usedsoftwares
as
$usedSoftwareKey
=>
$usedSoftware
)
{
$softwareId
=
$usedSoftware
->
software
->
id
;
$softwareNameList
[
$softwareId
]
=
$usedSoftware
->
software
->
softwarename
;
$usedSoftwareKeys
[
$softwareId
]
=
$usedSoftwareKey
;
}
// Sort records by software name
foreach
(
$taxonomiesSoftware
as
$taxonId
=>
$taxonData
)
{
$taxonDataSorted
=
[];
foreach
(
$taxonData
as
$item
)
{
$softwareId
=
$item
->
software_id
;
$softwareName
=
$softwareNameList
[
$softwareId
];
$taxonDataSorted
[
$softwareName
]
=
$item
;
}
ksort
(
$taxonDataSorted
);
$taxonomiesSoftware
[
$taxonId
]
=
$taxonDataSorted
;
}
}
}
// Populate view data
$this
->
set
(
compact
([
'mappingFirstLevels'
]));
$this
->
set
(
compact
([
'mappingTaxons'
]));
$this
->
set
(
compact
([
'usedSoftwareKeys'
]));
$this
->
set
(
compact
([
'taxonomiesSoftware'
]));
$this
->
set
(
'_serialize'
,
[
'taxonomiesSoftware'
,
'mappingTaxons'
,
'mappingFirstLevels'
]);
$this
->
set
(
'_serialize'
,
[
'taxonomiesSoftware'
,
'usedSoftwareKeys'
,
'mappingTaxons'
,
'mappingFirstLevels'
]);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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