Skip to content

Commit 171a057

Browse files
committed
feat: Improvement 'searchEtablissement' function for pagination
1 parent c09e894 commit 171a057

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Sirene est une librairie php vous permettant d'utiliser l'[API Sirene](https://a
99
## TODO
1010
- [x] Recherche par siren
1111
- [x] Recherche par siret
12-
- [ ] Système de pagination
1312
- [x] Recherche d'établissement via paramètres
1413
- [x] Ville
1514
- [x] Code Postal
1615
- [x] Raison sociale
1716
- [x] Sigle
1817
- [x] Code APE
1918
- [x] Catégorie Juridique
20-
19+
- [x] Système de pagination
20+
- [x] Ordre d'affichage par champ
2121

2222
La [documentation](https://simondevelop.github.io/sirene/) est encore en cours de rédaction.
2323

src/Sirene.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function siren(string $siren)
193193
* @param array $params Parameters of search
194194
* @return array|bool
195195
*/
196-
public function searchEtablissement(array $params)
196+
public function searchEtablissement(array $params, string $tri = "siren", int $page = 1, int $nombre = 20)
197197
{
198198
$list = [
199199
"city" => "libelleCommuneEtablissement",
@@ -214,7 +214,8 @@ public function searchEtablissement(array $params)
214214
}
215215
$data = urlencode(substr($data, 0, -5));
216216
$ch = curl_init();
217-
curl_setopt($ch, CURLOPT_URL, $this->urlApi."/siret/?q=".$data);
217+
$paramsTri = "&debut=".$page."&nombre=".$nombre."&tri=".$tri;
218+
curl_setopt($ch, CURLOPT_URL, $this->urlApi."/siret/?q=".$data.$paramsTri);
218219
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
219220
$headers = [
220221
"Accept: application/json",

tests/SireneTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,21 @@ public function testSearchEtablissement($Sirene)
9191
$this->assertEquals(is_array($result["etablissements"]), true);
9292
$this->assertEquals(!empty($result["etablissements"]), true);
9393
}
94+
95+
/**
96+
* searchEtablissement function test with pagination
97+
* @depends testInitConstructor
98+
*/
99+
public function testSearchEtablissementPagination($Sirene)
100+
{
101+
// City list (5 result)
102+
$result = $Sirene->searchEtablissement([
103+
"city" => "BORDEAUX"
104+
], "siren", 1, 5);
105+
$this->assertEquals($result["header"]["statut"], 200);
106+
$this->assertEquals($result["header"]["message"], "OK");
107+
$this->assertEquals(is_array($result["etablissements"]), true);
108+
$this->assertEquals(!empty($result["etablissements"]), true);
109+
$this->assertEquals(count($result["etablissements"]), 5);
110+
}
94111
}

0 commit comments

Comments
 (0)