diff --git a/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php b/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php index 2a8e9df5da5f2e008717dfdc10a74cf6c0c1ed40..b715bf6c710778678e816b5a09781a56118853c2 100644 --- a/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php +++ b/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php @@ -50,8 +50,6 @@ class Cosmo_DataProfileController extends ZendAfi_Controller_Action { $attributes_values = $this->_extractAttributesFrom($values); $model->updateAttributes($attributes_values); - $values = $this->_cleansFieldsValues($values, $model); - $profile_prefs = $this->_extractProfilePrefsFrom($values); $model->setAttributs($profile_prefs); @@ -72,29 +70,10 @@ class Cosmo_DataProfileController extends ZendAfi_Controller_Action { protected function _extractProfilePrefsFrom($values) { - $prefs = array_diff_key($values, Class_IntProfilDonnees::getClassVar('_default_attribute_values')); - return (new Class_ProfileSerializer($prefs))->serializeDatas(); + return (new Class_ProfileSerializer($values))->serializeDatas(); } - protected function _cleansFieldsValues($values, $model) { - $file_type = $model->getTypeFichier(); - - if(Class_IntProfilDonnees::FT_RECORDS != $file_type) - unset($values['light_records']); - - if(Class_IntProfilDonnees::FT_HOLDS != $file_type) - unset($values['holds']); - - if(Class_IntProfilDonnees::FT_BASKETS != $file_type) - unset($values['carts']); - - if(Class_IntProfilDonnees::FT_LOANS != $file_type) - unset($values['loans']); - - return $values; - } - protected function _getEditUrl($model) { return sprintf('/cosmo/%s/edit/id/%s', diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php index 01aab41e5ccda621b772592eed0bf0c157cd1aeb..0fd4755f1a27026ccd43521c3e4bcd8ca7a87f0f 100644 --- a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php @@ -99,7 +99,7 @@ class Cosmo_DataProfileControllerIndexTest extends Cosmo_DataProfileControllerTe /** @test */ public function secondTrShouldContainsLinkEditKohaProfile() { - $this->assertXPath('//table//tr[2]/td/a[contains(@href, "/cosmo/data-profile/edit/id/56")]', $this->_response->getBody()); + $this->assertXPath('//table//tr[2]/td/a[contains(@href, "/cosmo/data-profile/edit/id/56")]'); } @@ -129,26 +129,58 @@ class Cosmo_DataProfileControllerIndexTest extends Cosmo_DataProfileControllerTe -class Cosmo_DataProfileControllerEditUnimarcKohaFileFormatTest extends Cosmo_DataProfileControllerTestCase { +class Cosmo_DataProfileControllerEditPatronsTest extends Cosmo_DataProfileControllerTestCase { public function setUp() { parent::setUp(); - $this->dispatch('cosmo/data-profile/edit/id/56', true); + + $this->fixture('Class_IntProfilDonnees', + [ + 'id' => 57, + 'libelle' => 'Some patrons', + 'accents' => Class_IntProfilDonnees::ENCODING_WINDOWS_ANSI, + 'rejet_periodiques' => 1, + 'id_article_periodique' => Class_IntProfilDonnees::SERIAL_FORMAT_NONE, + 'type_fichier' => Class_IntProfilDonnees::FT_PATRONS, + 'format' => Class_IntProfilDonnees::FORMAT_PIPED_ASCII, + 'attributs' => + [ + [Class_IntProfilDonnees::FIELD_TYPE_DOC_RECOGNITION => [ ], + Class_IntProfilDonnees::FIELD_ITEM_BARCODE => '996', + Class_IntProfilDonnees::FIELD_ITEM_GENRE => '', + Class_IntProfilDonnees::FIELD_ITEM_SECTION => 'x', + Class_IntProfilDonnees::FIELD_ITEM_EMPLACEMENT => '', + Class_IntProfilDonnees::FIELD_ITEM_ANNEXE => 'a' + ], + ['champs' => 'PRENOM;NOM;PRENOM'], + ['champs' => 'PRENOM;NOM;PRENOM'], + ['champs' => 'PRENOM;NOM;PRENOM'] + ] + ]); + $this->dispatch('cosmo/data-profile/edit/id/57', true); } /** @test */ public function subscriberSelectedFieldsShouldContainsTwoPrenom() { - $this->assertXPathCount('//div[@id="input_subscribers_light"]/div[1]/ul/li[@data-value="PRENOM"]', 2); + $this->assertXPathCount('//div[@id="input_patron_fields"]/div[1]/ul/li[@data-value="PRENOM"]', 2, + $this->_response->getBody()); } /** @test */ public function subscriberAvailableFieldsShouldContainsPrenom() { - $this->assertXPathCount('//div[@id="input_subscribers_light"]/div[2]/ul/li[@data-value="PRENOM"]', 1); + $this->assertXPathCount('//div[@id="input_patron_fields"]/div[2]/ul/li[@data-value="PRENOM"]', 1); } +} +class Cosmo_DataProfileControllerEditUnimarcKohaTest extends Cosmo_DataProfileControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('cosmo/data-profile/edit/id/56', true); + } + /** @test */ public function labelShouldBePresent() { $this->assertXPath('//form//input[@type="text"][@name="libelle"][@value= "Unimarc Koha"]'); @@ -199,7 +231,7 @@ class Cosmo_DataProfileControllerEditUnimarcKohaFileFormatTest extends Cosmo_Dat /** @test */ public function subscribersShouldBePrenomAndNaissance() { - $this->assertXPath('//form//input[@name="subscribers_light"][@value="PRENOM; NAISSANCE; PRENOM"]'); + $this->assertXPath('//form//input[@name="patron_fields"][@value="PRENOM; NAISSANCE; PRENOM"]'); } @@ -223,7 +255,7 @@ class Cosmo_DataProfileControllerEditUnimarcKohaFileFormatTest extends Cosmo_Dat /** @test */ public function fieldIdLightRecordsShouldBeEmpty() { - $this->assertXPath('//form//input[@id="light_records"][@value="PRENOM; NAISSANCE; PRENOM"]'); + $this->assertXPath('//form//input[@id="csv_item_fields"][@value="PRENOM; NAISSANCE; PRENOM"]'); } @@ -381,8 +413,8 @@ class Cosmo_DataProfileControllerPostEditUnimarcKohaFileFormatTest extends Cosmo $post = ['libelle' => 'New Koha', 'accents' => Class_IntProfilDonnees::ENCODING_ISO2709, - 'type_fichier' => Class_IntProfilDonnees::FT_PATRONS, - 'format' => Class_IntProfilDonnees::FORMAT_CSV, + 'type_fichier' => Class_IntProfilDonnees::FT_RECORDS, + 'format' => Class_IntProfilDonnees::FORMAT_UNIMARC, 'xml_balise_abonne' => 'subscribers', 'xml_abonne_IDABON' => 'id', 'champ_code_barres'=> 'f', @@ -407,9 +439,9 @@ class Cosmo_DataProfileControllerPostEditUnimarcKohaFileFormatTest extends Cosmo 'interest_champ' => [0 => '7'], 'holds' => 'SUPPORT; SUPPORT', 'carts' => 'LIBELLE; ROLE', - 'light_records' => 'ean;ean', + 'csv_item_fields' => 'ean;ean', 'loans' => 'ID_PERGAME; ID_PERGAME', - 'subscribers_light' => 'ORDREABON; ORDREABON']; + 'patron_fields' => 'ORDREABON; ORDREABON']; $this->postDispatch('cosmo/data-profile/edit/id/56', $post, true); @@ -435,18 +467,6 @@ class Cosmo_DataProfileControllerPostEditUnimarcKohaFileFormatTest extends Cosmo } - /** @test */ - public function xmlBaliseAbonneShouldBeSubscribers() { - $this->assertEquals('subscribers', $this->_koha->getXmlSubscriberField()); - } - - - /** @test */ - public function xmlAbonneIdShouldBeId() { - $this->assertEquals('id', $this->_koha->getXmlSubscriberFieldsAt('IDABON')); - } - - /** @test */ public function champsCodeBarresShouldBeF() { $this->assertEquals('f', $this->_koha->getBarCode()); @@ -517,30 +537,39 @@ class Cosmo_DataProfileControllerPostEditUnimarcKohaFileFormatTest extends Cosmo public function interestFieldShouldBe7() { $this->assertEquals('7', $this->_koha->getInterestField()); } +} - /** @test */ - public function subscribersFieldsShouldContainsOrdreabon() { - $this->assertEquals('ORDREABON; ORDREABON', $this->_koha->getSubscriberFieldsValues()); - } +class Cosmo_DataProfileControllerPostEditFieldsTest extends Cosmo_DataProfileControllerTestCase { + protected + $_nanook_profile; - /** @test */ - public function loansFieldsShouldBeNull() { - $this->assertNull($this->_koha->getLoansFieldsValues()); + public function setUp() { + parent::setUp(); + $this->_nanook_profile = Class_IntProfilDonnees::find(105); } -} + /** @test */ + public function patronsFieldsShouldContainsIdPergame() { + $this->postDispatch('cosmo/data-profile/edit/id/105', + [Class_IntProfilDonnees::PROFILE_FILE_TYPE => Class_IntProfilDonnees::FT_PATRONS, + Class_IntProfilDonnees::PROFILE_FILE_FORMAT => Class_IntProfilDonnees::FORMAT_CSV, + 'carts' => 'ID_ABO', + Class_IntProfilDonnees::PROFILE_PATRON_FIELDS => 'ID_PERGAME; ID_PERGAME'], true); + $this->assertEquals('ID_PERGAME; ID_PERGAME', $this->_nanook_profile->getPatronsFieldsValues()); + } -class Cosmo_DataProfileControllerPostEditFieldsTest extends Cosmo_DataProfileControllerTestCase { /** @test */ public function loansFieldsShouldContainsIdPergame() { $this->postDispatch('cosmo/data-profile/edit/id/105', [Class_IntProfilDonnees::PROFILE_FILE_TYPE => Class_IntProfilDonnees::FT_LOANS, - 'loans' => 'ID_PERGAME; ID_PERGAME'], true); - $this->assertEquals('ID_PERGAME; ID_PERGAME', Class_IntProfilDonnees::find(105)->getLoansFieldsValues()); + Class_IntProfilDonnees::PROFILE_FILE_FORMAT => Class_IntProfilDonnees::FORMAT_CSV, + 'carts' => 'ID_ABO', + Class_IntProfilDonnees::PROFILE_LOANS_FIELDS => 'ID_PERGAME; ID_PERGAME'], true); + $this->assertEquals('ID_PERGAME; ID_PERGAME', $this->_nanook_profile->getLoansFieldsValues()); } @@ -548,16 +577,18 @@ class Cosmo_DataProfileControllerPostEditFieldsTest extends Cosmo_DataProfileCon public function lightRecordsFieldsShouldContainsEan() { $this->postDispatch('cosmo/data-profile/edit/id/105', [Class_IntProfilDonnees::PROFILE_FILE_TYPE => Class_IntProfilDonnees::FT_RECORDS, - 'light_records' => 'ean;ean'], true); - $this->assertEquals('ean;ean', Class_IntProfilDonnees::find(105)->getLightRecordsFieldsValues()); + Class_IntProfilDonnees::PROFILE_FILE_FORMAT => Class_IntProfilDonnees::FORMAT_CSV, + Class_IntProfilDonnees::PROFILE_ITEM_FIELDS => 'ean;ean'], true); + $this->assertEquals('ean;ean', $this->_nanook_profile->getLightRecordsFieldsValues()); } /** @test */ public function holdsFieldsShouldContainsSupport() { $this->postDispatch('cosmo/data-profile/edit/id/105', [Class_IntProfilDonnees::PROFILE_FILE_TYPE => Class_IntProfilDonnees::FT_HOLDS, + Class_IntProfilDonnees::PROFILE_FILE_FORMAT => Class_IntProfilDonnees::FORMAT_CSV, 'holds' => 'SUPPORT; SUPPORT'], true); - $this->assertEquals('SUPPORT; SUPPORT', Class_IntProfilDonnees::find(105)->getHoldsFieldsValues()); + $this->assertEquals('SUPPORT; SUPPORT', $this->_nanook_profile->getHoldsFieldsValues()); } @@ -565,8 +596,9 @@ class Cosmo_DataProfileControllerPostEditFieldsTest extends Cosmo_DataProfileCon public function cartsFieldsShouldContainsLibelleAndRole() { $this->postDispatch('cosmo/data-profile/edit/id/105', [Class_IntProfilDonnees::PROFILE_FILE_TYPE => Class_IntProfilDonnees::FT_BASKETS, + Class_IntProfilDonnees::PROFILE_FILE_FORMAT => Class_IntProfilDonnees::FORMAT_CSV, 'carts' => 'LIBELLE; ROLE'], true); - $this->assertEquals('LIBELLE; ROLE', Class_IntProfilDonnees::find(105)->getCartsFieldsValues()); + $this->assertEquals('LIBELLE; ROLE', $this->_nanook_profile->getCartsFieldsValues()); } @@ -577,14 +609,62 @@ class Cosmo_DataProfileControllerPostEditFieldsTest extends Cosmo_DataProfileCon 'bb'], '1_zone' => ['z', 't', - 'u']]; + 'u'], + Class_IntProfilDonnees::PROFILE_FILE_TYPE => Class_IntProfilDonnees::FT_RECORDS, + Class_IntProfilDonnees::PROFILE_FILE_FORMAT => Class_IntProfilDonnees::FORMAT_UNIMARC]; $this->postDispatch('cosmo/data-profile/edit/id/105', $doc_type, true); - $this->assertEquals(['code' => '1', 'label' => 'am;af;bb', 'zone_995' => 'z;t;u'], Class_IntProfilDonnees::find(105)->getItemDocTypesPrefs()[1]); + $this->assertEquals(['code' => '1', 'label' => 'am;af;bb', 'zone_995' => 'z;t;u'], + $this->_nanook_profile->getItemDocTypesPrefs()[1]); + } + + + + /** @test */ + public function postXMLPatronsShouldFillXmlPatronField() { + $this->postDispatch('cosmo/data-profile/edit/id/105', + [Class_IntProfilDonnees::PROFILE_FILE_TYPE => Class_IntProfilDonnees::FT_PATRONS, + Class_IntProfilDonnees::PROFILE_FILE_FORMAT => Class_IntProfilDonnees::FORMAT_XML, + 'xml_balise_abonne' => 'items', + 'xml_abonne_IDABON'=> 'id', + 'xml_abonne_DATE_DEBUT' => 'start', + 'xml_abonne_DATE_FIN' => 'end', + ], true); + $this->assertEquals('items', $this->_nanook_profile->getXmlPatronField()); + return $this->_nanook_profile; + } + + + /** + * @depends postXMLPatronsShouldFillXmlPatronField + * @test + */ + public function postXMLPatronsShouldFillXmlPatronFieldForIDABON($profile) { + $this->assertEquals($profile->getXmlPatronFieldsAt('IDABON'), 'id'); + } + + + /** + * @depends postXMLPatronsShouldFillXmlPatronField + * @test + */ + public function postXMLPatronsShouldFillXmlPatronFieldForDATEFIN($profile) { + $this->assertEquals($profile->getXmlPatronFieldsAt('DATE_FIN'), 'end'); + } + + + /** @test */ + public function subscribersFieldsShouldContainsOrdreabon() { + $this->postDispatch('cosmo/data-profile/edit/id/105', + [Class_IntProfilDonnees::PROFILE_FILE_TYPE => Class_IntProfilDonnees::FT_PATRONS, + Class_IntProfilDonnees::PROFILE_FILE_FORMAT => Class_IntProfilDonnees::FORMAT_PIPED_ASCII, + 'patron_fields' => 'ORDREABON; ORDREABON'], true); + $this->assertEquals('ORDREABON; ORDREABON', $this->_nanook_profile->getPatronsFieldsValues()); } } + class Cosmo_DataProfileControllerAddActionTest extends Cosmo_DataProfileControllerTestCase { public function setUp() { @@ -633,6 +713,6 @@ class Cosmo_DataProfileControllerEditPergamePatronsTest extends Cosmo_DataProfil /** @test */ public function inputSubscribersLightShouldContainsFieldsIDABON_ORDREABON_etc() { - $this->assertXPath('//input[@name="subscribers_light"][@value="IDABON;ORDREABON;NOM;PRENOM;NAISSANCE;DATE_DEBUT;DATE_FIN;MAIL"]'); + $this->assertXPath('//input[@name="patron_fields"][@value="IDABON;ORDREABON;NOM;PRENOM;NAISSANCE;DATE_DEBUT;DATE_FIN;MAIL"]'); } } \ No newline at end of file diff --git a/library/Class/IntProfilDonnees.php b/library/Class/IntProfilDonnees.php index 848f8947ba3fb426877d7db7282c5b6e5a194a09..2ee15b9a905d285a5fa9daef6064e65c0be2ad41 100644 --- a/library/Class/IntProfilDonnees.php +++ b/library/Class/IntProfilDonnees.php @@ -66,12 +66,21 @@ class IntProfilDonneesLoader extends Storm_Model_Loader { } + public function isFormatCSV($format) { + return in_array($format, [Class_IntProfilDonnees::FORMAT_CSV, + Class_IntProfilDonnees::FORMAT_TABBED_ASCII, + Class_IntProfilDonnees::FORMAT_SEMI_COLON_ASCII, + Class_IntProfilDonnees::FORMAT_PIPED_ASCII, + Class_IntProfilDonnees::FORMAT_AVENIO]); + } + + public function getLoanFields() { return Class_CosmoVar::getList('champs_pret'); } - public function getSubscriberFields() { + public function getPatronFields() { return Class_CosmoVar::getList('champs_abonne'); } @@ -180,12 +189,18 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { PROFILE_DOC_TYPES = 'type_doc', PROFILE_NOVELTY = 'jours', PROFILE_FILE_TYPE = 'type_fichier', + PROFILE_FILE_FORMAT = 'format', + PROFILE_PATRON_FIELDS = 'patron_fields', + PROFILE_LOANS_FIELDS = 'loans', + PROFILE_ITEM_FIELDS = 'csv_item_fields', + PROFILE_HOLD_FIELDS = 'holds', + PROFILE_CART_FIELDS = 'carts', NOVELTY_ZONE = 'zone', NOVELTY_FIELD = 'champ', NOVELTY_FORMAT = 'format', NOVELTY_VALUES = 'valeurs', - XML_SUBSCRIBER_FIELD = 'xml_balise_abonne', - XML_SUBSCRIBER_FIELDS = 'xml_champs_abonne'; + XML_PATRON_FIELD = 'xml_balise_abonne', + XML_PATRON_FIELDS = 'xml_champs_abonne'; protected $_table_name = 'profil_donnees', @@ -403,6 +418,9 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { 'xml_champs_abonne' => ['IDABON' => 'id_abon', 'DATE_DEBUT' => 'subscription_date'], 'champs' => 'PRENOM; NAISSANCE; PRENOM'], + [], + [], + [], ['zone' => '995', 'champ' => 'z'] ] @@ -658,7 +676,7 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { self::FIELD_ITEM_SECTION => 'x', self::FIELD_ITEM_EMPLACEMENT => '', self::FIELD_ITEM_ANNEXE => 'a' - ], + ], ['champs' => 'IDABON;ORDREABON;NOM;PRENOM;NAISSANCE;DATE_DEBUT;DATE_FIN;MAIL'], ['champs' => 'IDABON;ORDREABON;NOM;PRENOM;NAISSANCE;DATE_DEBUT;DATE_FIN;MAIL'], ['champs' => 'IDABON;ORDREABON;NOM;PRENOM;NAISSANCE;DATE_DEBUT;DATE_FIN;MAIL'] @@ -746,13 +764,13 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { } - public function getXmlSubscriberField() { - return $this->getProfilePrefs()->getSubscriberXmlField(); + public function getXmlPatronField() { + return $this->getProfilePrefs()->getPatronXmlField(); } - public function getXmlSubscriberFieldsAt($key) { - return $this->getProfilePrefs()->getSubscriberXmlFieldValue($key); + public function getXmlPatronFieldsAt($key) { + return $this->getProfilePrefs()->getPatronXmlFieldValue($key); } @@ -811,13 +829,13 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { } - public function getSubscriberFieldsValues() { - return $this->getProfilePrefs()->getSubscriberFields(); + public function getPatronsFieldsValues() { + return $this->getProfilePrefs()->getFieldsForFormat($this->getFormat()); } public function getLoansFieldsValues() { - return $this->getProfilePrefs()->getUnknownFields(); + return $this->getProfilePrefs()->getFieldsForFormat($this->getFormat()); } diff --git a/library/Class/ProfilePrefs.php b/library/Class/ProfilePrefs.php index e515a24ac07d9714afbb42876ec7b84367fd4e8f..ac43e3dbf1c97c92e0344b1fd2be0f862ead74c1 100644 --- a/library/Class/ProfilePrefs.php +++ b/library/Class/ProfilePrefs.php @@ -62,24 +62,23 @@ class Class_ProfilePrefs extends Class_Entity { } - public function getSubscriberXmlField() { - return $this->getPrefsXml()[Class_IntProfilDonnees::XML_SUBSCRIBER_FIELD]; + public function getPatronXmlField() { + return $this->getPrefsXml()[Class_IntProfilDonnees::XML_PATRON_FIELD]; } - public function getSubscriberFields() { - $prefs = $this->getPrefsFor(Class_IntProfilDonnees::PROFILE_FIELDS); - return $prefs[Class_IntProfilDonnees::PROFILE_FIELDS]; + public function getPatronFields() { + return $this->getUnknownFields(); } - public function getSubscriberXmlFieldValue($key) { + public function getPatronXmlFieldValue($key) { return $this->getPrefsXmlFields()[$key]; } public function getPrefsXmlFields() { - return $this->getPrefsXml()[Class_IntProfilDonnees::XML_SUBSCRIBER_FIELDS]; + return $this->getPrefsXml()[Class_IntProfilDonnees::XML_PATRON_FIELDS]; } @@ -103,7 +102,7 @@ class Class_ProfilePrefs extends Class_Entity { public function getInterests() { - $interet_prefs = $this->getInterestPrefs(); + $interet_prefs = $this->getPrefs()[6]; $interet_zone = $interet_prefs['zone']; $interet_champ = $interet_prefs['champ']; @@ -112,20 +111,6 @@ class Class_ProfilePrefs extends Class_Entity { } - public function getInterestPrefs() { - if(!$prefs = $this->getPrefs()) - return []; - - foreach($prefs as $pref) { - if((!$pref) || (!is_array($pref))) - return []; - - if(array_key_exists('zone', $pref) && array_key_exists('champ', $pref) && (2 == count($pref))) - return $pref; - } - } - - public function getItemUrl() { $url_zone = $this->getItemUrlZone(); $url_champ = $this->getItemUrlChamp(); @@ -185,6 +170,11 @@ class Class_ProfilePrefs extends Class_Entity { } + public function getFieldsForFormat($format) { + return $this->getPrefs()[$format][Class_IntProfilDonnees::PROFILE_FIELDS]; + } + + public function getDocTypesPrefs() { return $this->getItemPrefs()[Class_IntProfilDonnees::PROFILE_DOC_TYPES]; } @@ -196,12 +186,12 @@ class Class_ProfilePrefs extends Class_Entity { public function getPrefsXML() { - return $this->getPrefsFor(Class_IntProfilDonnees::XML_SUBSCRIBER_FIELD); + return $this->getPrefsFor(Class_IntProfilDonnees::XML_PATRON_FIELD); } public function getItemPrefs() { - return $this->getPrefsFor(Class_IntProfilDonnees::PROFILE_DOC_TYPES); + return $this->getPrefs()[0]; } diff --git a/library/Class/ProfileSerializer.php b/library/Class/ProfileSerializer.php index 7b7e0848d9bbff67066f5baa50e6bf9aa5dce208..0ce9b1ed37b2622264e9d125458256e42b1ef21f 100644 --- a/library/Class/ProfileSerializer.php +++ b/library/Class/ProfileSerializer.php @@ -21,133 +21,54 @@ class Class_ProfileSerializer { - const XML_PREFIX = 'xml_abonne_'; protected $_datas; - public function __construct($datas) { $this->_datas = $datas; - } - - public function serializeDatas() { - $datas = [$this->_extractRecords(), - $this->_extractNovelty(), - $this->_extractProfileFields(), - $this->_extractSubscribers(), - $this->_extractInterests()]; - - return serialize($datas); - } - - - protected function _extractInterests() { - return ['zone' => $this->_datas['interest_zone'][0], - 'champ' => $this->_datas['interest_champ'][0]]; - } - - - protected function _extractRecords() { - return array_merge($this->_extractDocTypes(), $this->_extractItemFields(), $this->_extractItemUrl()); - } - - - protected function _extractDocTypes() { - $doc_types_prefs = []; - $doc_types = Class_TypeDoc::findAll(); - foreach($doc_types as $doc_type) { - $doc_type_id = $doc_type->getId(); - $doc_types_prefs[$doc_type_id] = ['code' => $doc_type_id, - 'label' => $this->_extractDocTypeLabel($doc_type_id), - 'zone_995' => $this->_extractDocTypeZone($doc_type_id)]; - } - - return [Class_IntProfilDonnees::PROFILE_DOC_TYPES => $doc_types_prefs]; + $this->_strategy = $this->_buildStrategy(); + $this->_strategy->setDatas($this->_datas); } - protected function _extractDocTypeLabel($id) { - return $this->_extractDocTypeData($id . '_label'); - } + protected function _buildStrategy() { + $is_csv = Class_IntProfilDonnees::isFormatCSV($this->_datas[Class_IntProfilDonnees::PROFILE_FILE_FORMAT]); + if($this->_datas[Class_IntProfilDonnees::PROFILE_FILE_TYPE] === Class_IntProfilDonnees::FT_RECORDS + && $this->_datas[Class_IntProfilDonnees::PROFILE_FILE_FORMAT] === Class_IntProfilDonnees::FORMAT_UNIMARC ) + return new Class_ProfileSerializer_UnimarcRecord(); - protected function _extractDocTypeZone($id) { - return $this->_extractDocTypeData($id . '_zone'); - } + if($this->_datas[Class_IntProfilDonnees::PROFILE_FILE_TYPE] === Class_IntProfilDonnees::FT_RECORDS + && $is_csv) + return new Class_ProfileSerializer_CSVItem(); + if($this->_datas[Class_IntProfilDonnees::PROFILE_FILE_TYPE] === Class_IntProfilDonnees::FT_PATRONS + && $this->_datas[Class_IntProfilDonnees::PROFILE_FILE_FORMAT] === Class_IntProfilDonnees::FORMAT_XML) + return new Class_ProfileSerializer_XMLPatrons(); - protected function _extractDocTypeData($key) { - if(!isset($this->_datas[$key])) - return ''; + if($this->_datas[Class_IntProfilDonnees::PROFILE_FILE_TYPE] === Class_IntProfilDonnees::FT_PATRONS + && $is_csv) + return new Class_ProfileSerializer_CSVPatrons(); - if(!is_array($this->_datas[$key])) - return ''; + if($this->_datas[Class_IntProfilDonnees::PROFILE_FILE_TYPE] === Class_IntProfilDonnees::FT_LOANS + && $is_csv) + return new Class_ProfileSerializer_CSVLoans(); - return implode(';', $this->_datas[$key]); - } + if($this->_datas[Class_IntProfilDonnees::PROFILE_FILE_TYPE] === Class_IntProfilDonnees::FT_HOLDS + && $is_csv) + return new Class_ProfileSerializer_CSVHolds(); + if($this->_datas[Class_IntProfilDonnees::PROFILE_FILE_TYPE] === Class_IntProfilDonnees::FT_BASKETS + && $is_csv) + return new Class_ProfileSerializer_CSVBaskets(); - protected function _extractItemUrl() { - return [Class_IntProfilDonnees::FIELD_ITEM_URL => ['zone' => $this->_datas['url_zone'][0], - 'champ' => $this->_datas['url_champ'][0]]]; - } - + return new Class_ProfileSerializer_Unsupported(); - protected function _extractItemFields() { - return array_intersect_key($this->_datas, Class_IntProfilDonnees::getItemFields()); } - protected function _extractNovelty() { - return [Class_IntProfilDonnees::PROFILE_NOVELTY => $this->_datas['nouveaute_jours'], - Class_IntProfilDonnees::NOVELTY_ZONE => $this->_datas['nouveaute_zone'][0], - Class_IntProfilDonnees::NOVELTY_FIELD => $this->_datas['nouveaute_champ'][0], - Class_IntProfilDonnees::NOVELTY_FORMAT => $this->_datas['nouveaute_format'], - Class_IntProfilDonnees::NOVELTY_VALUES => $this->_extractNoveltyValues()]; - } - - - protected function _extractNoveltyValues() { - if(!isset($this->_datas['nouveaute_valeurs'])) - return []; - - if(!is_array($this->_datas['nouveaute_valeurs'])) - return []; - - return implode(';', $this->_datas['nouveaute_valeurs']); - } - - - protected function _extractSubscribers() { - return [Class_IntProfilDonnees::XML_SUBSCRIBER_FIELD => $this->_extractXmlSubscriber(), - Class_IntProfilDonnees::XML_SUBSCRIBER_FIELDS => $this->_extractSubscriberFields(), - Class_IntProfilDonnees::PROFILE_FIELDS => $this->_datas['subscribers_light']]; - } - - - protected function _extractProfileFields() { - $fields = array_filter(array_intersect_key($this->_datas, ['loans' => '', - 'holds' => '', - 'light_records' => '', - 'carts' => ''])); - - return [Class_IntProfilDonnees::PROFILE_FIELDS => array_shift($fields)]; - } - - - protected function _extractXmlSubscriber() { - return $this->_datas[Class_IntProfilDonnees::XML_SUBSCRIBER_FIELD]; + public function serializeDatas() { + return serialize($this->_strategy->getDatas()); } - - protected function _extractSubscriberFields() { - $xml_fields = Class_IntProfilDonnees::getSubscriberFields(); - $subscriber_fields = []; - foreach($xml_fields as $key => $field) { - $key = trim(strtoupper($key)); - $subscriber_fields[$key] = $this->_datas[static::XML_PREFIX . $key]; - } - - return $subscriber_fields; - } } ?> \ No newline at end of file diff --git a/library/Class/ProfileSerializer/Abstract.php b/library/Class/ProfileSerializer/Abstract.php new file mode 100644 index 0000000000000000000000000000000000000000..36d5968b02f924627890819f2dcf7e3811f624f6 --- /dev/null +++ b/library/Class/ProfileSerializer/Abstract.php @@ -0,0 +1,58 @@ +<?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 + */ + + +abstract class Class_ProfileSerializer_Abstract { + protected $_datas = []; + + public function setDatas($datas) { + $this->_datas = $datas; + return $this; + } + + + protected function _extractProfileFields() { + + /* return [ */ + /* Class_IntProfilDonnees::FORMAT_TABBED_ASCII = 1, */ + /* Class_IntProfilDonnees::FORMAT_SEMI_COLON_ASCII = 2, */ + /* Class_IntProfilDonnees::FORMAT_PIPED_ASCII = 3, */ + /* Class_IntProfilDonnees::FORMAT_XML = 4, */ + /* Class_IntProfilDonnees::FORMAT_CSV = 5, */ + /* Class_IntProfilDonnees::FORMAT_MARC21 = 6, */ + /* Class_IntProfilDonnees::FORMAT_UNIMARC_XML = 7, */ + /* Class_IntProfilDonnees::FORMAT_AVENIO = 8, */ + + + /* [Class_Intprofildonnees:: => [Class_IntProfilDonnees::PROFILE_FIELDS => ] */ + + /* $fields = array_filter(array_intersect_key($this->_datas, ['loans' => '', */ + /* 'holds' => '', */ + /* 'light_records' => '', */ + /* 'carts' => ''])); */ + + /* return [Class_IntProfilDonnees::PROFILE_FIELDS => array_shift($fields)]; */ + } + + + +} +?> \ No newline at end of file diff --git a/library/Class/ProfileSerializer/CSVAbstract.php b/library/Class/ProfileSerializer/CSVAbstract.php new file mode 100644 index 0000000000000000000000000000000000000000..e2c1d3f808f2f07927e94a2a1deef10c6e67e7b3 --- /dev/null +++ b/library/Class/ProfileSerializer/CSVAbstract.php @@ -0,0 +1,37 @@ +<?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 + */ + + +abstract class Class_ProfileSerializer_CSVAbstract extends Class_ProfileSerializer_Abstract { + + protected $_form_profile_fields; + + public function getDatas() { + return [0 => [], + 1 => [Class_IntProfilDonnees::PROFILE_FIELDS => $this->_datas[$this->_form_profile_fields]], + 2 => [Class_IntProfilDonnees::PROFILE_FIELDS => $this->_datas[$this->_form_profile_fields]], + 3 => [Class_IntProfilDonnees::PROFILE_FIELDS => $this->_datas[$this->_form_profile_fields]], + 4 => [], + 5 => [Class_IntProfilDonnees::PROFILE_FIELDS => $this->_datas[$this->_form_profile_fields]], + 6 => []]; + } +} +?> \ No newline at end of file diff --git a/library/Class/ProfileSerializer/CSVBaskets.php b/library/Class/ProfileSerializer/CSVBaskets.php new file mode 100644 index 0000000000000000000000000000000000000000..c26b14853ed9739bc187f513278f2f013bb001f1 --- /dev/null +++ b/library/Class/ProfileSerializer/CSVBaskets.php @@ -0,0 +1,26 @@ +<?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_ProfileSerializer_CSVBaskets extends Class_ProfileSerializer_CSVAbstract { + protected $_form_profile_fields = Class_IntProfilDonnees::PROFILE_CART_FIELDS; +} +?> \ No newline at end of file diff --git a/library/Class/ProfileSerializer/CSVHolds.php b/library/Class/ProfileSerializer/CSVHolds.php new file mode 100644 index 0000000000000000000000000000000000000000..8e2133de0220289e1139237c9f1d6071f5ec3bd7 --- /dev/null +++ b/library/Class/ProfileSerializer/CSVHolds.php @@ -0,0 +1,26 @@ +<?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_ProfileSerializer_CSVHolds extends Class_ProfileSerializer_CSVAbstract { + protected $_form_profile_fields = Class_IntProfilDonnees::PROFILE_HOLD_FIELDS; +} +?> \ No newline at end of file diff --git a/library/Class/ProfileSerializer/CSVItem.php b/library/Class/ProfileSerializer/CSVItem.php new file mode 100644 index 0000000000000000000000000000000000000000..ee476bf11eb79ed340e6ca60bbdcca03608af670 --- /dev/null +++ b/library/Class/ProfileSerializer/CSVItem.php @@ -0,0 +1,26 @@ +<?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_ProfileSerializer_CSVItem extends Class_ProfileSerializer_CSVAbstract { + protected $_form_profile_fields = Class_IntProfilDonnees::PROFILE_ITEM_FIELDS; +} +?> \ No newline at end of file diff --git a/library/Class/ProfileSerializer/CSVLoans.php b/library/Class/ProfileSerializer/CSVLoans.php new file mode 100644 index 0000000000000000000000000000000000000000..a015ed66e5e4a371895874b8ac6d7964f8862e36 --- /dev/null +++ b/library/Class/ProfileSerializer/CSVLoans.php @@ -0,0 +1,26 @@ +<?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_ProfileSerializer_CSVLoans extends Class_ProfileSerializer_CSVAbstract { + protected $_form_profile_fields = Class_IntProfilDonnees::PROFILE_LOANS_FIELDS; +} +?> \ No newline at end of file diff --git a/library/Class/ProfileSerializer/CSVPatrons.php b/library/Class/ProfileSerializer/CSVPatrons.php new file mode 100644 index 0000000000000000000000000000000000000000..d124a515dbbb146bd377d70720cee8d6220f0f77 --- /dev/null +++ b/library/Class/ProfileSerializer/CSVPatrons.php @@ -0,0 +1,26 @@ +<?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_ProfileSerializer_CSVPatrons extends Class_ProfileSerializer_CSVAbstract { + protected $_form_profile_fields = Class_IntProfilDonnees::PROFILE_PATRON_FIELDS; +} +?> \ No newline at end of file diff --git a/library/Class/ProfileSerializer/UnimarcRecord.php b/library/Class/ProfileSerializer/UnimarcRecord.php new file mode 100644 index 0000000000000000000000000000000000000000..293276bac12e36c9a0f6527aa5406e997d9e473c --- /dev/null +++ b/library/Class/ProfileSerializer/UnimarcRecord.php @@ -0,0 +1,111 @@ +<?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_ProfileSerializer_UnimarcRecord extends Class_ProfileSerializer_Abstract { + public function getDatas() { + return [0 => $this->_extractRecords(), + 1 => [], + 2 => [], + 3 => [], + 4 => $this->_extractNovelty(), + 5 => [], + 6 => $this->_extractInterests()]; + } + + protected function _extractInterests() { + return ['zone' => $this->_datas['interest_zone'][0], + 'champ' => $this->_datas['interest_champ'][0]]; + } + + + protected function _extractRecords() { + return array_merge($this->_extractDocTypes(), $this->_extractItemFields(), $this->_extractItemUrl()); + } + + + protected function _extractDocTypes() { + $doc_types_prefs = []; + $doc_types = Class_TypeDoc::findAll(); + foreach($doc_types as $doc_type) { + $doc_type_id = $doc_type->getId(); + $doc_types_prefs[$doc_type_id] = ['code' => $doc_type_id, + 'label' => $this->_extractDocTypeLabel($doc_type_id), + 'zone_995' => $this->_extractDocTypeZone($doc_type_id)]; + } + + return [Class_IntProfilDonnees::PROFILE_DOC_TYPES => $doc_types_prefs]; + } + + + protected function _extractDocTypeLabel($id) { + return $this->_extractDocTypeData($id . '_label'); + } + + + protected function _extractDocTypeZone($id) { + return $this->_extractDocTypeData($id . '_zone'); + } + + + protected function _extractDocTypeData($key) { + if(!isset($this->_datas[$key])) + return ''; + + if(!is_array($this->_datas[$key])) + return ''; + + return implode(';', $this->_datas[$key]); + } + + + protected function _extractItemUrl() { + return [Class_IntProfilDonnees::FIELD_ITEM_URL => ['zone' => $this->_datas['url_zone'][0], + 'champ' => $this->_datas['url_champ'][0]]]; + } + + + protected function _extractItemFields() { + return array_intersect_key($this->_datas, Class_IntProfilDonnees::getItemFields()); + } + + + protected function _extractNovelty() { + return [Class_IntProfilDonnees::PROFILE_NOVELTY => $this->_datas['nouveaute_jours'], + Class_IntProfilDonnees::NOVELTY_ZONE => $this->_datas['nouveaute_zone'][0], + Class_IntProfilDonnees::NOVELTY_FIELD => $this->_datas['nouveaute_champ'][0], + Class_IntProfilDonnees::NOVELTY_FORMAT => $this->_datas['nouveaute_format'], + Class_IntProfilDonnees::NOVELTY_VALUES => $this->_extractNoveltyValues()]; + } + + + protected function _extractNoveltyValues() { + if(!isset($this->_datas['nouveaute_valeurs'])) + return []; + + if(!is_array($this->_datas['nouveaute_valeurs'])) + return []; + + return implode(';', $this->_datas['nouveaute_valeurs']); + } + +} +?> \ No newline at end of file diff --git a/library/Class/ProfileSerializer/Unsupported.php b/library/Class/ProfileSerializer/Unsupported.php new file mode 100644 index 0000000000000000000000000000000000000000..4c24971142db343f10f3e72f042c909238627758 --- /dev/null +++ b/library/Class/ProfileSerializer/Unsupported.php @@ -0,0 +1,29 @@ +<?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_ProfileSerializer_Unsupported extends Class_ProfileSerializer_Abstract { + public function getDatas() { + throw new RunTimeException('Unsupported format'); + return []; + } +} +?> \ No newline at end of file diff --git a/library/Class/ProfileSerializer/XMLPatrons.php b/library/Class/ProfileSerializer/XMLPatrons.php new file mode 100644 index 0000000000000000000000000000000000000000..74b3dcaa336c5bdc8101a2b5442acfe339619af6 --- /dev/null +++ b/library/Class/ProfileSerializer/XMLPatrons.php @@ -0,0 +1,54 @@ +<?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_ProfileSerializer_XMLPatrons extends Class_ProfileSerializer_Abstract { + const XML_PREFIX = 'xml_abonne_'; + + public function getDatas() { + return [0 => [], + 1 => [], + 2 => [], + 3 => [], + 4 => [], + 5 => [ + Class_IntProfilDonnees::XML_PATRON_FIELD => $this->_extractXmlPatron(), + Class_IntProfilDonnees::XML_PATRON_FIELDS => $this->_extractPatronFields()], + 6 => []]; + } + + + protected function _extractXmlPatron() { + return $this->_datas[Class_IntProfilDonnees::XML_PATRON_FIELD]; + } + + + protected function _extractPatronFields() { + $xml_fields = Class_IntProfilDonnees::getPatronFields(); + $patron_fields = []; + foreach($xml_fields as $key => $field) { + $key = trim(strtoupper($key)); + $patron_fields[$key] = $this->_datas[static::XML_PREFIX . $key]; + } + + return $patron_fields; + } +} \ No newline at end of file diff --git a/library/ZendAfi/Form/Cosmo/DataProfile.php b/library/ZendAfi/Form/Cosmo/DataProfile.php index e750777d60055008681e1227d6222fc8c92b4e8c..c9bf6490908b63e0ee4ce5906eb094e886b617d4 100644 --- a/library/ZendAfi/Form/Cosmo/DataProfile.php +++ b/library/ZendAfi/Form/Cosmo/DataProfile.php @@ -64,7 +64,7 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { 'general', ['legend' => $this->_('Généralités')]) - ->_addSubscribersSettings() + ->_addPatronsSettings() ->_addLoansSettings() ->_addHoldsSettings() ->_addRecordsSettings() @@ -94,10 +94,10 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { } - protected function _addSubscribersSettings() { + protected function _addPatronsSettings() { $xml_fields = []; - $fields = Class_IntProfilDonnees::getSubscriberFields(); + $fields = Class_IntProfilDonnees::getPatronFields(); foreach($fields as $key => $field) { $id = 'xml_abonne_' . trim(strtoupper($key)); @@ -112,13 +112,13 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { 'xml_balise_abonne', ['label' => $this->_('Balise abonné (sans les crochets)')]) - ->_draggableGroup('subscribers_light', - Class_IntProfilDonnees::getSubscriberFields(), + ->_draggableGroup(Class_IntProfilDonnees::PROFILE_PATRON_FIELDS, + Class_IntProfilDonnees::getPatronFields(), $this->_('des abonnés')) ->addDisplayGroup(array_merge(['xml_balise_abonne'], $xml_fields), - 'subscribers_xml_group', + 'patrons_xml_group', ['legend' => $this->_('Configuration des champs pour le fichier des abonnés'), 'style' => 'display: none']); } @@ -135,7 +135,7 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { protected function _addRecordsSettings() { - $this->_draggableGroup('light_records', Class_IntProfilDonnees::getLightRecordsFields(), $this->_('des notices')); + $this->_draggableGroup('csv_item_fields', Class_IntProfilDonnees::getLightRecordsFields(), $this->_('des notices')); return $this->_recordsGroup(); } @@ -386,15 +386,15 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { public function populateXmlSubribers() { - $this->xml_balise_abonne->setValue($this->_profile_prefs->getSubscriberXmlField()); - $this->subscribers_light->setValue($this->_profile_prefs->getSubscriberFields()); + $this->xml_balise_abonne->setValue($this->_profile_prefs->getPatronXmlField()); + $this->patron_fields->setValue($this->_profile_prefs->getPatronFields()); - $xml_fields = Class_IntProfilDonnees::getSubscriberFields(); + $xml_fields = Class_IntProfilDonnees::getPatronFields(); foreach($xml_fields as $key => $field) { $key = trim(strtoupper($key)); $element_id = 'xml_abonne_' . $key; - $this->$element_id->setValue($this->_profile_prefs->getSubscriberXmlFieldValue($key)); + $this->$element_id->setValue($this->_profile_prefs->getPatronXmlFieldValue($key)); } return $this; @@ -405,7 +405,7 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { $unknown_fields = $this->_profile_prefs->getUnknownFields(); $this->loans->setValue($unknown_fields); $this->holds->setValue($unknown_fields);; - $this->light_records->setValue($unknown_fields); + $this->csv_item_fields->setValue($unknown_fields); $this->carts->setValue($unknown_fields); return $this; } @@ -476,17 +476,17 @@ class ZendAfi_Form_Cosmo_DataProfile extends ZendAfi_Form { if(Class_IntProfilDonnees::FT_RECORDS === $current_data_type && Class_IntProfilDonnees::FORMAT_XML !== $current_format) - return sprintf($show, 'light_records'); + return sprintf($show, Class_IntProfilDonnees::PROFILE_ITEM_FIELDS); if(Class_IntProfilDonnees::FT_PATRONS === $current_data_type && Class_IntProfilDonnees::FORMAT_XML === $current_format) - return sprintf($show, 'subscribers_xml'); + return sprintf($show, 'patrons_xml'); if(Class_IntProfilDonnees::FT_PATRONS === $current_data_type && (Class_IntProfilDonnees::FORMAT_UNIMARC !== $current_format && Class_IntProfilDonnees::FORMAT_MARC21 !== $current_format && Class_IntProfilDonnees::FORMAT_UNIMARC_XML !== $current_format)) - return sprintf($show, 'subscribers_light'); + return sprintf($show, Class_IntProfilDonnees::PROFILE_PATRON_FIELDS); if(Class_IntProfilDonnees::FT_LOANS === $current_data_type && (Class_IntProfilDonnees::FORMAT_UNIMARC !== $current_format