Skip to content
Snippets Groups Projects
Commit e34cbce1 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #44328 : fix multi_input display with empty values

parent f86491b8
Branches
Tags
2 merge requests!1681Hotline master,!1678Hotline#44328 cosmogramme problemes types de documents
- ticket #44328 : Cosmogramme : correction de l'affichage de la configuration des types de documents des profils de données.
\ No newline at end of file
......@@ -995,13 +995,13 @@ class Cosmo_DataProfileControllerAutoFormatPostTest extends Cosmo_DataProfileCon
class Cosmo_DataProfileControllerRecordsProfileTest extends Cosmo_DataProfileControllerTestCase {
class Cosmo_DataProfileControllerMultiValuesTest extends Cosmo_DataProfileControllerTestCase {
public function setUp() {
parent::setUp();
$type_doc = [['code' => '0', 'label' => '', 'zone_995' => 'IND' ],
['code' => '1', 'label' => 'am;na', 'zone_995' => 'LIV;LIVJ;LIVA;DOC;MANUEL' ],
['code' => '1', 'label' => 'am;;bm;;em;mm;;;;;;;;', 'zone_995' => 'BDA;;BDJ;LFA;LFJ;LDA;LDJ;LCDA;LCDJ;PATIMP;PATMS;PERIP;PATINC;' ],
['code' => '2', 'label' => 'as', 'zone_995' => 'REV;REVA;REVJ;'],
['code' => '3', 'label' => 'i;j', 'zone_995' => 'CD'],
['code' => '4', 'label' => 'g', 'zone_995' => 'DVD;JDVD;DVDA;DVDJ;VID'],
......@@ -1067,4 +1067,11 @@ class Cosmo_DataProfileControllerRecordsProfileTest extends Cosmo_DataProfileCon
public function itemUrlShouldBe995AndI() {
$this->assertXPathContentContains('//script', 'values:{"url_zone":["995"],"url_champ":["i"]}');
}
/** @test */
public function docTypeWithLabelSkipsShouldHaveAllItsValues() {
$this->assertXPathContentContains('//script', 'values:{"1_label":["am","bm","","em","mm","","","","","","",""],"1_zone":["BDA","BDJ","LFA","LFJ","LDA","LDJ","LCDA","LCDJ","PATIMP","PATMS","PERIP","PATINC"]}',
$this->_response->getBody());
}
}
\ No newline at end of file
......@@ -165,16 +165,15 @@ class Class_ProfilePrefs extends Class_Entity {
public function getItemDocTypeSettings($id, $mapping) {
$empty = [];
foreach ($mapping as $key => $value) {
foreach ($mapping as $key => $value)
$empty[$id . '_' . $key] = [];
}
if(!$all_doc_types = $this->getDocTypesPrefs())
if (!$all_doc_types = $this->getDocTypesPrefs())
return $empty;
foreach($all_doc_types as $doc_type_pref) {
if($id == $doc_type_pref['code'])
foreach ($all_doc_types as $doc_type_pref)
if ($id == $doc_type_pref['code'])
return $this->_buildDocTypeForMultiInput($doc_type_pref, $mapping);
}
return $empty;
}
......@@ -182,10 +181,49 @@ class Class_ProfilePrefs extends Class_Entity {
protected function _buildDocTypeForMultiInput($pref, $mapping) {
$doctype = [];
foreach ($mapping as $form_doc_type_input_name => $save_key) {
$doctype[$pref['code'] . '_' . $form_doc_type_input_name] = array_filter(explode(';', $pref[$save_key]));
foreach ($mapping as $name => $save_key)
$doctype[$pref['code'] . '_' . $name] = explode(';', $pref[$save_key]);
return $this->_stripEmptyLinesFrom($doctype);
}
protected function _stripEmptyLinesFrom($datas) {
if (!$datas
|| (!$empties = $this->_emptyPositionsFrom($datas))
|| (!$to_strip = call_user_func_array('array_intersect', $empties)))
return $datas;
foreach($datas as $type => $values)
$datas[$type] = $this->_stripPositionsFrom($to_strip, $values);
return $datas;
}
protected function _emptyPositionsFrom($datas) {
$empties = [];
foreach ($datas as $lines) {
$empty = [];
foreach ($lines as $k => $v)
if (!$v)
$empty[] = $k;
$empties[] = $empty;
}
return $doctype;
return $empties;
}
protected function _stripPositionsFrom($positions, $values) {
$new = [];
foreach ($values as $k => $value)
if (!in_array($k, $positions))
$new[] = $value;
return $new;
}
......@@ -247,5 +285,4 @@ class Class_ProfilePrefs extends Class_Entity {
public function getPrefs() {
return unserialize($this->getDatas()['attributs']);
}
}
?>
\ No newline at end of file
}
\ No newline at end of file
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