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

FIX(software page): display mapping pre-selection

Refs: #937
parent 96dd4b3b
Pipeline #10195 passed with stage
in 5 minutes and 7 seconds
......@@ -375,17 +375,31 @@ class SoftwaresController extends AppController
// Load mapping data if necessary
$mappingFirstLevels = [];
$mappingTaxons = [];
$taxonomiesPreSelection = [];
if (count($taxonomiesSoftware) > 0) {
$taxonIds = array_keys($taxonomiesSoftware);
$mappingFirstLevels = $this->getMappingFirstLevels($this->selectedLanguage);
$mappingTaxons = $this->getMappingTaxonsWithTaxonIdsFilter($taxonIds, $this->selectedLanguage);
} else {
$taxonomiesPreSelection = $this->TaxonomysSoftwares->getPreSelectionBySofwareId($softwareId);
if (count($taxonomiesPreSelection) > 0) {
$taxonIds = array_keys($taxonomiesPreSelection);
$mappingFirstLevels = $this->getMappingFirstLevels($this->selectedLanguage);
$mappingTaxons = $this->getMappingTaxonsWithTaxonIdsFilter($taxonIds, $this->selectedLanguage);
}
}
// Populate view data
$this->set(compact(['mappingFirstLevels']));
$this->set(compact(['mappingTaxons']));
$this->set(compact(['taxonomiesSoftware']));
$this->set('_serialize', ['taxonomiesSoftware','mappingTaxons','mappingFirstLevels']);
$this->set(compact(['taxonomiesPreSelection']));
$this->set('_serialize', [
'taxonomiesSoftware',
'taxonomiesPreSelection',
'mappingTaxons',
'mappingFirstLevels'
]);
}
/**
......
......@@ -131,6 +131,10 @@ msgstr ""
msgid "Taxonomy.softwarePage.sectionNoRecord"
msgstr ""
#: Template/Api/V1/Softwares/view.cpt:68
msgid "Taxonomy.softwarePage.preSelection"
msgstr ""
#: Template/Api/V1/TaxonomysSoftwares/mapping_taxon_users_of.ctp:
msgid "TaxonomySoftware.UserOf.comments.subtitle"
msgstr ""
......
......@@ -142,6 +142,10 @@ msgid "Taxonomy.softwarePage.sectionNoRecord"
msgstr "No use case declared by local governments "
" in <strong>business mapping</strong> for {0} software."
#: Template/Api/V1/Softwares/view.cpt:68
msgid "Taxonomy.softwarePage.preSelection"
msgstr "<em>Adullact</em> pre-fetch for the following use case{0}: "
#: Template/Api/V1/Softwares/view.cpt:98
msgid "Taxonomy.softwarePage.description"
msgstr "<strong>Use case{0}</strong> of libre software <strong>{1}</strong>"
......
......@@ -143,6 +143,10 @@ msgid "Taxonomy.softwarePage.sectionNoRecord"
msgstr "Aucun cas d'usage déclaré par les collectivités et les administrations "
" dans la <strong>cartographie</strong> des <strong>métiers</strong> pour le logiciel {0}."
#: Template/Api/V1/Softwares/view.cpt:68
msgid "Taxonomy.softwarePage.preSelection"
msgstr "Pré-sélection <em>Adullact</em> pour le{0} cas d'usage{0} suivant{0} : "
#: Template/Api/V1/Softwares/view.cpt:98
msgid "Taxonomy.softwarePage.description"
msgstr "<strong>Cas d'usage{0}</strong> déclaré{0} du logiciel libre <strong>{1}</strong> "
......
......@@ -280,6 +280,20 @@ class TaxonomysSoftwaresTable extends Table
}
/**
* Returns a records list (with user ID NULL)
* grouped by Taxon for given software ID
*
* @param int $softwareId
* @return array example: [ <taxonId> => [taxonomySoftware, ...], ]
*/
public function getPreSelectionBySofwareId(int $softwareId)
{
$existingEntries = $this->find()->where(['software_id' => $softwareId, 'user_id IS NULL'])->toArray();
return $this->getRecordsGroupByTaxonId($existingEntries);
}
/**
* Returns a records list (with user ID not NULL)
* grouped by Taxon for given software ID
......
......@@ -49,19 +49,19 @@ $this->assign('title', __d("Softwares", "{0}", $software->softwarename));
"emptyMsg" => __d("Softwares", "No user for {0}", $software->softwarename)
]
); ?>
</section>
<section class="clearfix">
<h2> <?= __d("Taxonomy", "Taxonomy.softwarePage.sectionTitle", $software->softwarename); ?></h2>
<?php
// Mapping display for current software
$mappingNoRecord = __d("Taxonomy", "Taxonomy.softwarePage.sectionNoRecord", $software->softwarename);
if (count($taxonomiesSoftware) > 0) {
echo $this->element("Softwares/mappingOnSoftwarePage");
}
else {
$mappingNoRecord = __d(
"Taxonomy",
"Taxonomy.softwarePage.sectionNoRecord",
$software->softwarename
);
} elseif (count($taxonomiesPreSelection) > 0) {
echo "<p id=\"mappingForSoftware-noRecord\">$mappingNoRecord</p>";
echo $this->element("Softwares/mappingPreSelectionOnSoftwarePage");
} else {
echo "<p id=\"mappingForSoftware-noRecord\">$mappingNoRecord</p>";
}
?>
......
<?php
///////////////////////////////////////////////////////////////
// Preselection mapping display for current software
//
// Used by Softwares/view.ctp
///////////////////////////////////////////////////////////////
// Preselection mapping for current software
$list = [];
$softwareName = $software->softwarename;
$softwareSlug = $software->slugName;
$softwareId = $software->id;
foreach ($mappingFirstLevels as $firsLevelId => $firsLevelName) {
if(isset($mappingTaxons[$firsLevelId]['children'])) {
foreach ($mappingTaxons[$firsLevelId]['children'] as $taxonId => $taxonName) {
if (isset($mappingTaxons[$taxonId]) && $taxonomiesPreSelection[$taxonId]) {
$name = $mappingTaxons[$taxonId]['title'];
$slug = $mappingTaxons[$taxonId]['slug'];
$parentId = $mappingTaxons[$taxonId]['id_parent'];
$parentName = $mappingTaxons[$parentId]['title'];
$parentSlug = $mappingTaxons[$parentId]['slug'];
$url = "$mappingBaseUrl/$parentSlug/$slug/$taxonId";
$linkOptions = [
'id' => "linkMapping-taxon-$taxonId",
'class' => "linkMapping--PreSelectionTaxon",
'escape' => false
];
$list[] = $this->Html->link("$parentName · <strong>$name</strong>", $url, $linkOptions);
}
}
}
}
$nbOfUseCases = count($list);
if ($nbOfUseCases > 0) {
$s = ''; if($nbOfUseCases > 1) { $s = 's'; }
$mappingTxt = __d(
"Taxonomy",
"Taxonomy.softwarePage.preSelection",
[$s, $software->softwarename,]
);
$htmlList = $this->Html->nestedList($list);
echo "<div id=\"mappingForSoftware-PreSelection-$softwareId\">
<p>$mappingTxt</p>
$htmlList
<div>";
}
......@@ -245,6 +245,34 @@ class SoftwaresFixture extends TestFixture
'url_website' => 'http://www.fake-soft5.com',
'web_site_url' => null,
'tag_string' => ''
],
[
// 'id' => 6,
'softwarename' => 'Soft 6',
'url_repository' => 'http://www.fake-repo-soft666.git',
'description' => 'Description 6666 Lorem Ipsum',
'licence_id' => 1,
'created' => 1487084568,
'modified' => 1487084568,
'logo_directory' => TESTS . "TestFiles" . DS . "Softwares/photo/id3/avatar",
'photo' => "correctSoftwareLogo.jpg",
'url_website' => 'http://www.fake-soft6.com',
'web_site_url' => null,
'tag_string' => ''
],
[
// 'id' => 7,
'softwarename' => 'Soft 7',
'url_repository' => 'http://www.fake-repo-soft777.git',
'description' => 'Description 777 Lorem Ipsum',
'licence_id' => 1,
'created' => 1487084568,
'modified' => 1487084568,
'logo_directory' => TESTS . "TestFiles" . DS . "Softwares/photo/id3/avatar",
'photo' => "correctSoftwareLogo.jpg",
'url_website' => 'http://www.fake-sof77.com',
'web_site_url' => null,
'tag_string' => ''
]
];
parent::init();
......
......@@ -128,6 +128,29 @@ class TaxonomysSoftwaresFixture extends TestFixture
'created' => 1581686289,
'modified' => 1581686289
],
[
// 'id' => 10,
'taxonomy_id' => 3,
'software_id' => 6,
'user_id' => null,
'created' => 1581686289,
'modified' => 1581686289
],
[
// 'id' => 11,
'taxonomy_id' => 3,
'software_id' => 7,
'user_id' => null,
'created' => 1581686289,
'modified' => 1581686289
],
[
// 'id' => 12,
'taxonomy_id' => 5,
'software_id' => 7,
'user_id' => null,
'created' => 1581686289,
'modified' => 1581686289
],
];
}
......@@ -414,7 +414,74 @@ class TaxonomysControllerTest extends ApiIntegrationTestCase
/**
* Test mappingTaxon method : a taxon has a software without user (preselected software)
* Test mappingTaxon method :
* a taxon has a software without user (preselected software)
* and this software is only associated with taxons without users (pre-selected software).
*
* URL: /fr/cartographie/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
* /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
*
* ex: /fr/cartographie/metiers/sante-social/14 /en/mapping/business/healthcare-social/14
* /fr/cartographie/generiques/bureautique/20 /en/mapping/generics/office-automation/20
*
* @group public
* @group taxonomy
* @group taxonomy_public
* @group taxonomy_method_mappingTaxon
* @return void
*/
public function testMappingTaxonShouldHaveSoftwareWithoutUsersAssociatedForAnyTaxon()
{
$idTaxon = 3;
$idSoftwareA = 6;
$idSoftwareB = 7;
$url = "/fr/cartographie/metiers/urbanisme-espace-public-environnement/$idTaxon";
$softwareUrlA = "/fr/softwares/$idSoftwareA";
$softwareUrlB = "/fr/softwares/$idSoftwareB";
$htmlTitle = "<title>Urbanisme / Espace public / Environnement";
// Anonymous user
$this->setAnonymousUserSession();
$r = $this->checkUrlOk($url, ['html'], false);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertContains($htmlTitle, $html);
$this->assertContains("id=\"sofwareListForTaxon$idTaxon\"", $html);
$this->assertContains("class=\"item-softwareForTaxon$idTaxon\"", $html);
$this->assertContains("id=\"item-software$idSoftwareA-forTaxon$idTaxon\"", $html);
$this->assertContains("id=\"item-software$idSoftwareB-forTaxon$idTaxon\"", $html);
$this->assertNotContains("id=\"link-software$idSoftwareA-forTaxon$idTaxon\"", $html);
$this->assertNotContains("id=\"link-software$idSoftwareB-forTaxon$idTaxon\"", $html);
// on software page (ID 6): no link for taxon ID 3
$r = $this->checkUrlOk($softwareUrlA, ['html'], false);
$html = $r['html']['data'];
$s = ''; // this software is only associated with one taxonomy in preselection.
$this->assertNotContains("id=\"mappingForSoftware-$idSoftwareA\"", $html);
$this->assertNotContains("class=\"linkMapping-taxonSoftware\"", $html);
$this->assertContains("id=\"mappingForSoftware-noRecord\"", $html);
$this->assertContains("Pré-sélection <em>Adullact</em> pour le$s cas d'usage$s suivant$s : ", $html);
$this->assertContains("class=\"linkMapping--PreSelectionTaxon\"", $html);
$this->assertContains("id=\"linkMapping-taxon-$idTaxon\"", $html);
$this->assertNotContains("id=\"linkMapping-taxon-$idTaxon-Software-$idSoftwareA\"", $html);
// on software page (ID 7): no link for taxon ID 3
$r = $this->checkUrlOk($softwareUrlB, ['html'], false);
$html = $r['html']['data'];
$s = 's'; // this software is associated with two taxonomies in preselection.
$this->assertNotContains("id=\"mappingForSoftware-$idSoftwareB\"", $html);
$this->assertNotContains("class=\"linkMapping-taxonSoftware\"", $html);
$this->assertContains("id=\"mappingForSoftware-noRecord\"", $html);
$this->assertContains("Pré-sélection <em>Adullact</em> pour le$s cas d'usage$s suivant$s : ", $html);
$this->assertContains("class=\"linkMapping--PreSelectionTaxon\"", $html);
$this->assertContains("id=\"linkMapping-taxon-$idTaxon\"", $html);
$this->assertNotContains("id=\"linkMapping-taxon-$idTaxon-Software-$idSoftwareB\"", $html);
}
/**
* Test mappingTaxon method :
* a taxon has a software without user (preselected software),
* but this software is also associated with other taxons with associated users.
*
* URL: /fr/cartographie/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
* /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
......@@ -452,10 +519,15 @@ class TaxonomysControllerTest extends ApiIntegrationTestCase
$html = $r['html']['data'];
$this->assertContains("id=\"mappingForSoftware-$idSoftware\"", $html);
$this->assertContains("class=\"linkMapping-taxonSoftware\"", $html);
$this->assertNotContains("id=\"mappingForSoftware-noRecord\"", $html);
$this->assertNotContains("class=\"linkMapping--PreSelectionTaxon\"", $html);
$this->assertNotContains("id=\"linkMapping-taxon-$idTaxon\"", $html);
$this->assertNotContains("id=\"linkMapping-taxon-$idTaxon-Software-$idSoftware\"", $html);
}
/**
* Test mappingTaxon method : a taxon has no software
*
......
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