Commit c6e7f6f4 authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

FEAT(mapping): prepare diplay for user page

Refs: #917
parent a7d5c0c6
......@@ -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->commonMappingForCurrentUser($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 commonMappingForCurrentUser(int $userId)
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'
]);
}
......
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