Skip to content

Commit 16d940b

Browse files
SRJ9michield
authored andcommitted
Add listSubscribersCount method (API1) (phpList#51)
1 parent b8fb389 commit 16d940b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

plugins/restapi/includes/lists.php

+33
Original file line numberDiff line numberDiff line change
@@ -363,5 +363,38 @@ public static function listSubscribers($list_id = 0)
363363
die(0);
364364
}
365365

366+
/**
367+
* Get num of subscribers from a list
368+
*
369+
* <p><strong>Parameters:</strong><br/>
370+
* [*list_id] {integer} the List-ID.
371+
* <p><strong>Returns:</strong><br/>
372+
* List_id and count of subscriber.
373+
* </p>
374+
*/
375+
public static function listSubscribersCount($list_id = 0)
376+
{
377+
$response = new Response();
378+
if($list_id == 0) {
379+
$list_id = sprintf('%d', $_REQUEST['list_id']);
380+
}
381+
$sql = 'SELECT listid, COUNT(*) AS count FROM '.$GLOBALS['tables']['listuser'].' WHERE listid=:list_id;';
382+
if(!is_numeric($list_id) || empty($list_id)){
383+
Response::outputErrorMessage('invalid call');
384+
}
385+
try {
386+
$db = PDO::getConnection();
387+
$stmt = $db->prepare($sql);
388+
$stmt->bindParam('list_id', $list_id, PDO::PARAM_INT);
389+
$stmt->execute();
390+
$result = $stmt->fetch(PDO::FETCH_OBJ);
391+
$db = null;
392+
$response->setData('SubscribersCount', $result);
393+
$response->output();
394+
} catch(\Exception $e) {
395+
Response::outputError($e);
396+
}
397+
}
398+
366399

367400
}

0 commit comments

Comments
 (0)