From 63c2709a5b161b8acb117984dd83f64c2668426b Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Thu, 24 Mar 2016 17:12:33 +0100 Subject: [PATCH] dev #35088 add elements to dataProfile form --- .../opac/controllers/AbonneController.php | 2 - .../controllers/DataProfileController.php | 2 +- .../controllers/DataProfileControllerTest.php | 55 ++++++-- library/Class/IntProfilDonnees.php | 14 +- library/Class/ProfilePrefs.php | 108 +++++++++++++++ library/ZendAfi/Controller/Action.php | 1 - library/ZendAfi/Form/Cosmo/DataProfile.php | 124 +++++++++++++++--- 7 files changed, 268 insertions(+), 38 deletions(-) create mode 100644 library/Class/ProfilePrefs.php diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 027e3426e86..4066f42d338 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -311,8 +311,6 @@ class AbonneController extends ZendAfi_Controller_Action { public function tagnoticeAction() { - xdebug_break(); - if (!$this->_request->isPost()) { $this->view->titre = $this->_('Proposer des tags pour cette notice'); $this->view->id = $this->_request->getParam('id_notice', 0); diff --git a/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php b/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php index 11327ef49ce..9a349512ec4 100644 --- a/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php +++ b/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php @@ -34,7 +34,7 @@ class Cosmo_DataProfileController extends ZendAfi_Controller_Action { 'edit' => ['title' => $this->_('Modifier un profil de données')], 'index' => ['title' => $this->_('Profils de données')]], - 'form' => (new ZendAfi_Form_Cosmo_DataProfile())]; + 'form_class_name' => 'ZendAfi_Form_Cosmo_DataProfile']; } } ?> \ No newline at end of file diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php index 64eec6ea5e1..e0ed045cf44 100644 --- a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php @@ -41,6 +41,21 @@ abstract class Cosmo_DataProfileControllerTestCase extends CosmoControllerTestCa ['id' => 'types_docs', 'valeur' => null, 'liste' => "0:non identifié\r\n1:Livres\r\n"]); + + $this->fixture('Class_CosmoVar', + ['id' => 'id_article_periodique', + 'valeur' => null, + 'liste' => "0:aucun\r\n1:pergame\r\n2:opsys indexpresse\r\n3:Koha\r\n4:Orphée"]); + + $this->fixture('Class_CosmoVar', + ['id' => 'champ_code_barres', + 'valeur' => null, + 'liste' => "f:995$f\r\nh:995$h\r\nb:995$b\r\n997:997$a\r\n852:852$g\r\na:995$a\r\n999:999$i\r\n996:996$f"]); + + $this->fixture('Class_CosmoVar', + ['id' => 'champ_cote', + 'valeur' => null, + 'liste' => "k:995$k\r\nf:995$f"]); } } @@ -60,7 +75,7 @@ class Cosmo_DataProfileControllerIndexTest extends Cosmo_DataProfileControllerTe } -/** @test */ + /** @test */ public function firstTrShouldContainsRecordsFileType() { $this->assertXPathContentContains('//table//tr[1]/td[2]', 'Notices'); } @@ -98,7 +113,7 @@ class Cosmo_DataProfileControllerIndexTest extends Cosmo_DataProfileControllerTe -class Cosmo_DataProfileControllerEditUnimarcFileFormatTest extends Cosmo_DataProfileControllerTestCase { +class Cosmo_DataProfileControllerEditUnimarcKohaFileFormatTest extends Cosmo_DataProfileControllerTestCase { public function setUp() { parent::setUp(); $this->dispatch('cosmo/data-profile/edit/id/1', true); @@ -107,7 +122,7 @@ class Cosmo_DataProfileControllerEditUnimarcFileFormatTest extends Cosmo_DataPro /** @test */ public function labelShouldBePresent() { - $this->assertXPath('//form//input[@type="text"][@name="libelle"][contains(@value, "Koha")]'); + $this->assertXPath('//form//input[@type="text"][@name="libelle"][@value= "Unimarc Koha"]'); } @@ -195,9 +210,15 @@ class Cosmo_DataProfileControllerEditUnimarcFileFormatTest extends Cosmo_DataPro } + /** @test */ + public function nouveauteZoneAndChampShouldBe801AndC() { + $this->assertXPathContentContains('//script', 'values:{"nouveaute_zone":["801"],"nouveaute_champ":["c"]}'); + } + + /** @test */ public function selectNouveauteFormatShouldBePresent() { - $this->assertXPath('//form//select[@id="nouveaute_format"]'); + $this->assertXPath('//form//select[@id="nouveaute_format"]/option[@value="' . Class_IntProfilDonnees::NOVELTY_DATE_FORMAT_AAAA_MM_JJ . '"][@selected]'); } @@ -207,51 +228,57 @@ class Cosmo_DataProfileControllerEditUnimarcFileFormatTest extends Cosmo_DataPro } + /** @test */ + public function nouveauteValeursShouldBeNouveauAndNew() { + $this->assertXPathContentContains('//script', 'values:["nouveau","new"]'); + } + + /** @test */ public function itemCodebarreShouldBePresent() { - $this->assertXPath('//form//select[@id="champ_code_barres"]'); + $this->assertXPath('//form//select[@id="champ_code_barres"]/option[@value="f"][@selected]'); } /** @test */ public function itemCoteShouldBePresent() { - $this->assertXPath('//form//select[@id="champ_cote"]'); + $this->assertXPath('//form//select[@id="champ_cote"]/option[@value="k"][@selected]'); } /** @test */ public function itemTypeDocShouldBePresent() { - $this->assertXPath('//form//select[@id="champ_type_doc"]'); + $this->assertXPath('//form//select[@id="champ_type_doc"]/option[@value="r"][@selected]'); } /** @test */ public function itemSectionShouldBePresent() { - $this->assertXPath('//form//select[@id="champ_section"]'); + $this->assertXPath('//form//select[@id="champ_section"]/option[@value="q"][@selected]'); } /** @test */ public function itemGenreShouldBePresent() { - $this->assertXPath('//form//select[@id="champ_genre"]'); + $this->assertXPath('//form//select[@id="champ_genre"]/option[@value=""]'); } /** @test */ public function itemEmplacementShouldBePresent() { - $this->assertXPath('//form//select[@id="champ_emplacement"]'); + $this->assertXPath('//form//select[@id="champ_emplacement"]/option[@value="e"][@selected]'); } /** @test */ public function itemAnnexeShouldBePresent() { - $this->assertXPath('//form//select[@id="champ_annexe"]'); + $this->assertXPath('//form//select[@id="champ_annexe"]/option[@value="b"][@selected]'); } /** @test */ public function itemDisponibiliteShouldBePresent() { - $this->assertXPath('//form//select[@id="champ_availability"]'); + $this->assertXPath('//form//select[@id="champ_availability"]/option[@value=""]'); } @@ -269,13 +296,13 @@ class Cosmo_DataProfileControllerEditUnimarcFileFormatTest extends Cosmo_DataPro /** @test */ public function selectRejetPeriodiquesShoudBePresent() { - $this->assertXPath('//form//select[@id="rejet_periodiques"]'); + $this->assertXPath('//form//select[@id="rejet_periodiques"]/option[@value="0"][@selected]'); } /** @test */ public function selectIdArticlePeriodiqueShouldBePresent() { - $this->assertXPath('//form//select[@id="id_article_periodique"]'); + $this->assertXPath('//form//select[@id="id_article_periodique"]/option[@value="' . Class_IntProfilDonnees::SERIAL_FORMAT_KOHA . '"][@selected]'); } diff --git a/library/Class/IntProfilDonnees.php b/library/Class/IntProfilDonnees.php index 1a06c4bcbbc..488be00eff8 100644 --- a/library/Class/IntProfilDonnees.php +++ b/library/Class/IntProfilDonnees.php @@ -161,7 +161,13 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { FIELD_ITEM_EMPLACEMENT = 'champ_emplacement', FIELD_ITEM_ANNEXE = 'champ_annexe', FIELD_ITEM_AVAILABILITY = 'champ_availability', - FIELD_ITEM_URL = 'champ_url'; + FIELD_ITEM_URL = 'champ_url', + PROFILE_PREFS_ITEMS = 0, + PROFILE_PREFS_ITEMS_NEWS_DATE = 1, + NEWS_ZONE = 'zone', + NEWS_FIELD = 'champ', + NEWS_FORMAT = 'format', + NEWS_VALEURS = 'valeurs'; protected $_table_name = 'profil_donnees', @@ -364,7 +370,7 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { 'champ' => 'c', 'format' => self::NOVELTY_DATE_FORMAT_AAAA_MM_JJ, 'jours' => '90', - 'valeurs' => ''] + 'valeurs' => 'nouveau;new'] ] ] ); @@ -612,7 +618,7 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { public function setTypeDocRecognition($type_doc, $label, $zone_995) { $config = unserialize($this->getAttributs()); - $config[self::FT_RECORDS]['type_doc'][$type_doc] = ['code' => $type_doc, + $config[self::PROFILE_PREFS_ITEMS]['type_doc'][$type_doc] = ['code' => $type_doc, 'label' => $label, 'zone_995' => $zone_995]; return $this->setAttributs($config); @@ -621,7 +627,7 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { public function setItemField($name, $value) { $config = unserialize($this->getAttributs()); - $config[self::FT_RECORDS][$name] = $value; + $config[self::PROFILE_PREFS_ITEMS][$name] = $value; return $this->setAttributs($config); } diff --git a/library/Class/ProfilePrefs.php b/library/Class/ProfilePrefs.php new file mode 100644 index 00000000000..0d566acc68a --- /dev/null +++ b/library/Class/ProfilePrefs.php @@ -0,0 +1,108 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_ProfilePrefs extends Class_Entity { + public function getItemBarCode() { + return $this->getItemPrefs()[Class_IntProfilDonnees::FIELD_ITEM_BARCODE]; + } + + + public function getItemCote() { + return $this->getItemPrefs()[Class_IntProfilDonnees::FIELD_ITEM_COTE]; + } + + + public function getItemDocType() { + return $this->getItemPrefs()[Class_IntProfilDonnees::FIELD_ITEM_TYPE_DOC]; + } + + + public function getItemGenre() { + return $this->getItemPrefs()[Class_IntProfilDonnees::FIELD_ITEM_GENRE]; + } + + + public function getItemSection() { + return $this->getItemPrefs()[Class_IntProfilDonnees::FIELD_ITEM_SECTION]; + } + + + public function getItemEmplacement() { + return $this->getItemPrefs()[Class_IntProfilDonnees::FIELD_ITEM_EMPLACEMENT]; + } + + + public function getItemAnnexe() { + return $this->getItemPrefs()[Class_IntProfilDonnees::FIELD_ITEM_ANNEXE]; + } + + + public function getItemAvailability() { + return $this->getItemPrefs()[Class_IntProfilDonnees::FIELD_ITEM_AVAILABILITY]; + } + + + public function getItemNewsZoneAndField() { + $zone_value = $this->getItemNewsZone(); + $champ_value = $this->getItemNewsField(); + + return ['nouveaute_zone' => [$zone_value], + 'nouveaute_champ' => [$champ_value]]; + } + + + public function getItemNewsZone() { + return $this->getItemNewsPrefs()[Class_IntProfilDonnees::NEWS_ZONE]; + } + + + public function getItemNewsField() { + return $this->getItemNewsPrefs()[Class_IntProfilDonnees::NEWS_FIELD]; + } + + + public function getItemNewsPrefs() { + return $this->getPrefs()[Class_IntProfilDonnees::PROFILE_PREFS_ITEMS_NEWS_DATE]; + } + + + public function getItemNewsFormat() { + return $this->getItemNewsPrefs()[Class_IntProfilDonnees::NEWS_FORMAT]; + } + + + public function getItemNewsValeurs() { + $valeurs = $this->getItemNewsPrefs()[Class_IntProfilDonnees::NEWS_VALEURS]; + return explode(';', $valeurs); + } + + + public function getItemPrefs() { + return $this->getPrefs()[Class_IntProfilDonnees::PROFILE_PREFS_ITEMS]; + } + + + public function getPrefs() { + return unserialize($this->getDatas()['attributs']); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index 81d84b725f4..69cf1777c57 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -254,7 +254,6 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { if (!$this->_request->isPost()) return false; - // for multicheckboxes, if none is checked nothing is posted, default to empty $defaults = []; foreach ($form->getMulticheckboxNames() as $checkbox_name) diff --git a/library/ZendAfi/Form/Cosmo/DataProfile.php b/library/ZendAfi/Form/Cosmo/DataProfile.php index 4d9ef9253ed..cc044c3582e 100644 --- a/library/ZendAfi/Form/Cosmo/DataProfile.php +++ b/library/ZendAfi/Form/Cosmo/DataProfile.php @@ -21,6 +21,28 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { + protected $_profile_prefs; + + public static function newWith($datas = [], $custom_form = null) { + $form = parent::newWith($datas, $custom_form); + $form->setProfilePrefs((new Class_ProfilePrefs())->setDatas($datas)); + $form + ->populateItemBarCode() + ->populateItemCote() + ->populateItemDocType() + ->populateItemGenre() + ->populateItemSection() + ->populateItemEmplacement() + ->populateItemAnnexe() + ->populateItemAvailability() + ->populateItemNewsZoneAndField() + ->populateItemNewsFormat() + ->populateItemNewsValeurs(); + + return $form; + } + + public function init() { parent::init(); @@ -94,17 +116,17 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { } return $this - ->addElement('text', - 'xml_balise_abonne', - ['label' => $this->_('Balise abonné (sans les crochets')]) + ->addElement('text', + 'xml_balise_abonne', + ['label' => $this->_('Balise abonné (sans les crochets')]) - ->_addDraggable('subscribers', Class_IntProfilDonnees::getSubscriberFields()) + ->_addDraggable('subscribers', Class_IntProfilDonnees::getSubscriberFields()) - ->addDisplayGroup(array_merge(['xml_balise_abonne'], - $xml_fields, - ['subscribers']), - 'subscribers_group', - ['legend' => $this->_('Configuration des champs pour le fichier des abonnés')]); + ->addDisplayGroup(array_merge(['xml_balise_abonne'], + $xml_fields, + ['subscribers']), + 'subscribers_group', + ['legend' => $this->_('Configuration des champs pour le fichier des abonnés')]); } @@ -189,8 +211,8 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { 'fixed' => true]) ->addDisplayGroup(['interet_zone'], - 'item_interest_group', - ['legend' => $this->_('Indexation')]); + 'item_interest_group', + ['legend' => $this->_('Indexation')]); } @@ -203,9 +225,9 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { 'champ_availability' => $this->_('disponilité')]; return $this->addElement('select', - 'champ_code_barres', - ['label' => $this->_('Prendre le champ code-barres en'), - 'multiOptions' => Class_IntProfilDonnees::getItemBarCodes()]) + 'champ_code_barres', + ['label' => $this->_('Prendre le champ code-barres en'), + 'multiOptions' => Class_IntProfilDonnees::getItemBarCodes()]) ->addElement('select', 'champ_cote', @@ -224,7 +246,7 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { ->addDisplayGroup(array_merge(['champ_code_barres', 'champ_cote'], array_keys($elements_with_all_fields), - ['item_url']), + ['item_url']), 'item_group', ['legend' => $this->_('Champs exemplaires')]); } @@ -280,5 +302,75 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { return $this; } + + public function populateItemBarCode() { + $this->champ_code_barres->setValue($this->_profile_prefs->getItemBarCode()); + return $this; + } + + + public function populateItemCote() { + $this->champ_cote->setValue($this->_profile_prefs->getItemCote()); + return $this; + } + + + public function populateItemDocType() { + $this->champ_type_doc->setValue($this->_profile_prefs->getItemDocType()); + return $this; + } + + + public function populateItemGenre() { + $this->champ_genre->setValue($this->_profile_prefs->getItemGenre()); + return $this; + } + + + public function populateItemSection() { + $this->champ_section->setValue($this->_profile_prefs->getItemSection()); + return $this; + } + + + public function populateItemEmplacement() { + $this->champ_emplacement->setValue($this->_profile_prefs->getItemEmplacement()); + return $this; + } + + + public function populateItemAnnexe() { + $this->champ_annexe->setValue($this->_profile_prefs->getItemAnnexe()); + return $this; + } + + + public function populateItemAvailability() { + $this->champ_availability->setValue($this->_profile_prefs->getItemAvailability()); + return $this; + } + + + public function populateItemNewsZoneAndField() { + $this->nouveaute_zone_champ->setValues($this->_profile_prefs->getItemNewsZoneAndField()); + return $this; + } + + + public function populateItemNewsFormat() { + $this->nouveaute_format->setValue($this->_profile_prefs->getItemNewsFormat()); + return $this; + } + + + public function populateItemNewsValeurs() { + $this->nouveaute_valeurs->setValues($this->_profile_prefs->getItemNewsValeurs()); + return $this; + } + + + public function setProfilePrefs($preferences) { + $this->_profile_prefs = $preferences; + } } -?> +?> \ No newline at end of file -- GitLab