diff --git a/docs/sdk/client/setOrder.md b/docs/sdk/client/setOrder.md new file mode 100644 index 0000000..c233238 --- /dev/null +++ b/docs/sdk/client/setOrder.md @@ -0,0 +1,26 @@ +### setOrder(int $sortBy, string $sortDirection = null) + +Permet de définir le critère de tri et l'ordre. + +#### Paramètres + +| Param | Type | Description | +| --- | --- | --- | +| $sortBy | int | Critère de tri | +| $sortDirection | string | Optionnel, sens du tri, accepte 'asc' ou 'desc' | + + +#### Constantes + + - Client::SORT_BY_PRICE + - Client::SORT_BY_ROOMS + - Client::SORT_BY_SURFACE + - Client::SORT_BY_CREATED_AT + +#### Exemple + +```php +$Client->setSort(Client::SORT_BY_PRICE); + +$Client->setSort(Client::SORT_BY_PRICE, 'asc'); +``` diff --git a/docs/sdk/client/setId.md b/docs/sdk/client/setReference.md similarity index 73% rename from docs/sdk/client/setId.md rename to docs/sdk/client/setReference.md index 2261290..530b3fa 100644 --- a/docs/sdk/client/setId.md +++ b/docs/sdk/client/setReference.md @@ -1,4 +1,4 @@ -### setId(mixed $ref) +### setReference($ref) Définit l'identifiant Publimmo ou la référence agence de l'objet à chercher. @@ -13,6 +13,6 @@ Définit l'identifiant Publimmo ou la référence agence de l'objet à chercher. #### Exemple ```php -$Client->setId(54589); -$Client->setId('Villa 34'); +$Client->setReference(54589); +$Client->setReference('Villa 34'); ``` diff --git a/docs/sdk/client/setSort.md b/docs/sdk/client/setSort.md deleted file mode 100644 index 0e5c01f..0000000 --- a/docs/sdk/client/setSort.md +++ /dev/null @@ -1,23 +0,0 @@ -### setSort(int $sortBy) - -Permet de définir le critère de tri. - -#### Paramètres - -| Param | Type | Description | -| --- | --- | --- | -| $sortB- | int | Critère de tri | - - -#### Constantes - - - Client::SORT_BY_PRICE - - Client::SORT_BY_ROOMS - - Client::SORT_BY_SURFACE - - Client::SORT_BY_CREATED_AT - -#### Exemple - -```php -$Client->setSort(Client::SORT_BY_PRICE); -``` diff --git a/docs/sdk/recherche.md b/docs/sdk/recherche.md index b87ff58..714b9d8 100644 --- a/docs/sdk/recherche.md +++ b/docs/sdk/recherche.md @@ -61,7 +61,7 @@ $PublimmoClient = new Client(99999, 'key'); --- -[filename](client/setId.md ':include') +[filename](client/setReference.md ':include') --- @@ -109,11 +109,7 @@ $PublimmoClient = new Client(99999, 'key'); --- -[filename](client/setSort.md ':include') - ---- - -[filename](client/setSortDirection.md ':include') +[filename](client/setOrder.md ':include') --- diff --git a/src/PublimmoPro/Client.php b/src/PublimmoPro/Client.php index cb47d8a..c3259c1 100644 --- a/src/PublimmoPro/Client.php +++ b/src/PublimmoPro/Client.php @@ -62,6 +62,15 @@ class Client /** @var int LOCATION_TYPE_YEAR Internal number for yearly location type */ public const LOCATION_TYPE_YEAR = 3; + /** @var int PROMOTION_TYPE_NOT_PROMOTION Internal number all objects but promotion */ + public const PROMOTION_TYPE_NOT_PROMOTION = 0; + + /** @var int PROMOTION_TYPE_NEW Internal number for new objects type */ + public const PROMOTION_TYPE_NEW = 1; + + /** @var int PROMOTION_TYPE_PROMOTION Internal number for promotion type */ + public const PROMOTION_TYPE_PROMOTION = 2; + /** @var string API_URL holds the api URL */ private const API_URL = 'http://syn.publimmo.ch/api/v1'; @@ -259,7 +268,7 @@ public function setRegion(int $region) return $this; } - public function setId(mixed $ref) + public function setReference($ref) { $this->id = $ref; @@ -309,27 +318,22 @@ public function setSelfOnly() return $this; } - public function setSort(int $sortBy) + public function setOrder(int $sortBy, string $sortDirection = null) { if (!in_array($sortBy, [self::SORT_BY_PRICE, self::SORT_BY_ROOMS, self::SORT_BY_SURFACE, self::SORT_BY_CREATED_AT])) { throw new \InvalidArgumentException('Sort criterion should be one of '.self::SORT_BY_PRICE. '(Client::SORT_BY_PRICE), '.self::SORT_BY_ROOMS. '(Client::SORT_BY_ROOMS), '.self::SORT_BY_SURFACE. '(Client::SORT_BY_SURFACE), '.self::SORT_BY_CREATED_AT. '(Client::SORT_BY_CREATED_AT)'); } - $this->tri = $sortBy; - - return $this; - } - - public function setSortDirection(string $sortDirection) - { if ($sortDirection == 'asc') { $this->triSens = 2; } elseif ($sortDirection == 'desc') { $this->triSens = 1; - } else { + } elseif (!empty($sortDirection)) { throw new \InvalidArgumentException('Sort direction should be either "asc" or "desc"'); } + $this->tri = $sortBy; + return $this; } diff --git a/tests/Client.php b/tests/Client.php index 7a26385..2063b04 100644 --- a/tests/Client.php +++ b/tests/Client.php @@ -143,7 +143,7 @@ public function testRegionCanBeSet(): void public function testIdCanBeSet(): void { - $queryUrl = $this->Client->setId(8989)->getQueryURL(); + $queryUrl = $this->Client->setReference(8989)->getQueryURL(); $this->assertTrue(strpos($queryUrl, 'id=8989') !== false); } @@ -194,38 +194,38 @@ public function testSelfOnlyCanBeSet(): void public function testSortCanBeSet(): void { - $queryUrl = $this->Client->setSort(Client::SORT_BY_PRICE)->getQueryURL(); + $queryUrl = $this->Client->setOrder(Client::SORT_BY_PRICE)->getQueryURL(); $this->assertTrue(strpos($queryUrl, 'tri='.Client::SORT_BY_PRICE) !== false); - $queryUrl = $this->Client->setSort(Client::SORT_BY_ROOMS)->getQueryURL(); + $queryUrl = $this->Client->setOrder(Client::SORT_BY_ROOMS)->getQueryURL(); $this->assertTrue(strpos($queryUrl, 'tri='.Client::SORT_BY_ROOMS) !== false); - $queryUrl = $this->Client->setSort(Client::SORT_BY_SURFACE)->getQueryURL(); + $queryUrl = $this->Client->setOrder(Client::SORT_BY_SURFACE)->getQueryURL(); $this->assertTrue(strpos($queryUrl, 'tri='.Client::SORT_BY_SURFACE) !== false); - $queryUrl = $this->Client->setSort(Client::SORT_BY_CREATED_AT)->getQueryURL(); + $queryUrl = $this->Client->setOrder(Client::SORT_BY_CREATED_AT)->getQueryURL(); $this->assertTrue(strpos($queryUrl, 'tri='.Client::SORT_BY_CREATED_AT) !== false); } public function testSortCanOnlyBeOfPredefinedTypes(): void { $this->expectException(InvalidArgumentException::class); - $queryUrl = $this->Client->setSort(6)->getQueryURL(); + $queryUrl = $this->Client->setOrder(6)->getQueryURL(); } - public function testTriSensCanBeSet(): void + public function testSortDirectionCanBeSet(): void { - $queryUrl = $this->Client->setTriSens('asc')->getQueryURL(); + $queryUrl = $this->Client->setOrder(Client::SORT_BY_CREATED_AT, 'asc')->getQueryURL(); $this->assertTrue(strpos($queryUrl, 'triSens=2') !== false); - $queryUrl = $this->Client->setTriSens('desc')->getQueryURL(); + $queryUrl = $this->Client->setOrder(Client::SORT_BY_CREATED_AT, 'desc')->getQueryURL(); $this->assertTrue(strpos($queryUrl, 'triSens=1') !== false); } - public function testTriSensCanOnlyBeOfPredefinedType(): void + public function testSortDirectionCanOnlyBeOfPredefinedType(): void { $this->expectException(InvalidArgumentException::class); - $queryUrl = $this->Client->setTriSens('asc,desc')->getQueryURL(); + $queryUrl = $this->Client->setOrder(Client::SORT_BY_CREATED_AT, 'asc,desc')->getQueryURL(); } public function testLanguageCanBeSet(): void