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

hotline #59488 : create single nanook dedicated user double finder

parent 5592d986
Branches
Tags
2 merge requests!2334Master,!2129hotline #59488 : create single nanook dedicated user double finder
Pipeline #1265 passed with stage
in 18 minutes and 7 seconds
- ticket #59488 : Nanook : correction de l'authentification des abonnés après un chamgement de site dans le SIGB
\ No newline at end of file
......@@ -21,6 +21,26 @@
class Class_User_DoubleFinder extends Class_Entity {
public function __construct($patron) {
$this->setStrategy((Class_IntBib::isSingleNanook())
? new Class_User_DoubleFinder_NanookStrategy($patron)
: new Class_User_DoubleFinder_DefaultStrategy($patron));
}
public function find() {
return $this->getStrategy()->find();
}
public function getDouble() {
return $this->getStrategy()->getDouble();
}
}
class Class_User_DoubleFinder_DefaultStrategy extends Class_Entity {
public function __construct($patron) {
$this->setPatron($patron);
}
......@@ -44,19 +64,22 @@ class Class_User_DoubleFinder extends Class_Entity {
if (!$id_int_bib = $this->getPatronIdIntBib())
return false;
foreach(['_matchByLoginAndOrder',
'_matchByLoginAndIdSigb',
'_matchByLoginAndLibrary',
'_matchByIdSigb']
as $method) {
foreach($this->_matchers() as $method)
if (call_user_func([$this, $method]))
return true;
}
return false;
}
protected function _matchers() {
return ['_matchByLoginAndOrder',
'_matchByLoginAndIdSigb',
'_matchByLoginAndLibrary',
'_matchByIdSigb'];
}
protected function _matchByLoginAndOrder() {
if (!$ordreabon = $this->getPatronOrdreabon())
return false;
......@@ -87,8 +110,7 @@ class Class_User_DoubleFinder extends Class_Entity {
protected function _matchByParams($params) {
$params = array_merge(['id_int_bib' => $this->getPatronIdIntBib()],
$params);
$params = $this->_restrictToIntegration($params);
if (!$user = Class_Users::findFirstBy($params))
return false;
......@@ -96,4 +118,51 @@ class Class_User_DoubleFinder extends Class_Entity {
$this->setDouble($user);
return true;
}
protected function _restrictToIntegration($params) {
return array_merge(['id_int_bib' => $this->getPatronIdIntBib()],
$params);
}
}
class Class_User_DoubleFinder_NanookStrategy
extends Class_User_DoubleFinder_DefaultStrategy {
protected function _matchers() {
return ['_matchByLoginAndOrderAndLibrary',
'_matchByLoginAndIdSigbAndLibrary',
'_matchByLoginAndOrder',
'_matchByLoginAndIdSigb',
'_matchByLoginAndLibrary',
'_matchByIdSigb'];
}
protected function _matchByLoginAndOrderAndLibrary() {
if (!$ordreabon = $this->getPatronOrdreabon())
return false;
return $this->_matchRestrictedToSite(['login' => $this->getPatronLogin(),
'ordreabon' => $ordreabon]);
}
protected function _matchByLoginAndIdSigbAndIdSite() {
return $this->_matchRestrictedToSite(['login' => $this->getPatronLogin(),
'id_sigb' => $this->getPatronIdSigb()]);
}
protected function _matchRestrictedToSite($params) {
$params['id_site'] = $this->getPatronIdSite();
return $this->_matchByParams($params);
}
protected function _restrictToIntegration($params) {
return $params;
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2017, 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 UserDoubleFinderWithSingleNanookTest extends ModelTestCase {
protected
$_storm_default_to_volatile = true,
$_result,
$_double;
public function setUp() {
parent::setUp();
$library_commons = ['mail' => null,
'qualite' => 5,
'dernier_ajout' => '0000-00-00',
'ecart_ajouts' => 0,
'date_mail' => '',
'sigb' => 13,
'planif_mode' => 'r',
'planif_jours' => '1111111',
'planif_fois' => 0,
'planif_par' => null,
'comm_sigb' => 7,
'comm_params' => 'a:1:{s:11:"url_serveur";s:53:"http://nanookws.afi-sa.net/afi_NanookWs/ilsdi/meylan/";}',
'pas_exporter' => 0];
$this->fixture('Class_IntBib',
array_merge($library_commons,
['id' => 7,
'nom' => 'Magasin',
'nom_court' => 'Magasin']));
$this->fixture('Class_IntBib',
array_merge($library_commons,
['id' => 2,
'nom' => 'Béalières',
'nom_court' => 'meylan']));
$this->fixture('Class_IntBib',
array_merge($library_commons,
['id' => 3,
'nom' => 'Grand-Pré',
'nom_court' => 'Grand-Pré']));
$user_commons = ['NOM' => 'testing',
'PRENOM' => 'test',
'NAISSANCE' => '1984-04-18',
'LOGIN' => '0046158',
'PASSWORD' => '1984',
'ROLE' => 'abonne_sigb',
'ROLE_LEVEL' => 2,
'IDABON' => '0046158',
'ORDREABON' => 1,
'pseudo' => '',
'DATE_DEBUT' => '',
'ID_SIGB' => '6308',
'CIVILITE' => 0,
'ID_PANIER_COURANT' => 0];
$this->fixture('Class_Users',
array_merge($user_commons,
['id' => 41632,
'ID_SITE' => 2,
'STATUT' => 1,
'DATE_FIN' => '2016-11-24',
'DATE_MAJ' => '2016-11-28',
'SETTINGS' => 'a:1:{s:11:"library_ids";i:60;}',
'id_int_bib' => 2]));
$this->fixture('Class_Users',
array_merge($user_commons,
['id' => 45012,
'ID_SITE' => 3,
'STATUT' => 0,
'DATE_FIN' => '2017-11-29',
'DATE_MAJ' => '2017-04-18',
'SETTINGS' => 'a:1:{s:11:"library_ids";s:0:"";}',
'id_int_bib' => 3]));
$patron = (new Class_Entity())
->setLogin('0046158')
->setPassword('1984')
->setIdabon('0046158')
->setOrdreabon(1)
->setIdSigb('6308')
->setIdSite(3)
->setIdIntBib(7);
$finder = new Class_User_DoubleFinder($patron);
if ($this->_result = $finder->find())
$this->_double = $finder->getDouble();
}
/** @test */
public function shouldFindDouble() {
$this->assertTrue($this->_result);
}
/** @test */
public function doubleLibraryShouldBe3() {
$this->assertEquals(3, $this->_double->getIdSite());
}
}
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