Skip to content

Commit 38c0ed4

Browse files
Merge pull request #17 from SlicingDice/feature/update-count_total-method
Update countEntityTotal function and README example
2 parents f575d82 + 9ff76fd commit 38c0ed4

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ print_r($client->existsEntity($ids));
293293
```
294294

295295
### `countEntityTotal()`
296-
Count the number of inserted entities. This method corresponds to a [GET request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
296+
Count the number of inserted entities in the whole database. This method corresponds to a [POST request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
297297

298298
#### Request example
299299

@@ -302,6 +302,7 @@ Count the number of inserted entities. This method corresponds to a [GET request
302302
use Slicer\SlicingDice;
303303
$usesTestEndpoint = true;
304304
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);
305+
305306
print_r($client->countEntityTotal());
306307
?>
307308
```
@@ -318,6 +319,35 @@ print_r($client->countEntityTotal());
318319
}
319320
```
320321

322+
### `countEntityTotal($tables)`
323+
Count the total number of inserted entities in the given tables. This method corresponds to a [POST request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
324+
325+
#### Request example
326+
327+
```php
328+
<?php
329+
use Slicer\SlicingDice;
330+
$usesTestEndpoint = true;
331+
$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);
332+
333+
$tables = array("default");
334+
335+
print_r($client->countEntityTotal($tables));
336+
?>
337+
```
338+
339+
#### Output example
340+
341+
```json
342+
{
343+
"status": "success",
344+
"result": {
345+
"total": 42
346+
},
347+
"took": 0.103
348+
}
349+
```
350+
321351
### `countEntity($jsonData)`
322352
Count the number of entities matching the given query. This method corresponds to a [POST request at /query/count/entity](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-query-count-entity).
323353

src/SlicingDice.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,13 @@ public function insert($data){
231231

232232
/**
233233
* Get count entity total queries
234+
* @param array $tables An array containing the tables in which
235+
* the total query will be performed
234236
*/
235-
public function countEntityTotal() {
237+
public function countEntityTotal($tables=array()) {
238+
$query = array("tables" => $tables);
236239
$url = $this->testWrapper() . URLResources::QUERY_COUNT_ENTITY_TOTAL;
237-
return $this->makeRequest($url, "GET", 0);
240+
return $this->makeRequest($url, "POST", 0, $query);
238241
}
239242

240243
/**

0 commit comments

Comments
 (0)