From ba4691196bc20bd4efe202b347eafede164e729e Mon Sep 17 00:00:00 2001 From: Alexandre Norman Date: Mon, 2 May 2016 00:26:59 +0200 Subject: [PATCH] Add new API function listSubscribers which returns all subscribers from a list --- plugins/restapi/includes/lists.php | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/plugins/restapi/includes/lists.php b/plugins/restapi/includes/lists.php index 6d0a88c..523b6b9 100644 --- a/plugins/restapi/includes/lists.php +++ b/plugins/restapi/includes/lists.php @@ -328,4 +328,40 @@ public static function listCampaignDelete($list_id = 0, $campaign_id = 0) } die(0); } + /** + * Get all subscribers from a list + * + *

Parameters:
+ * [*list_id] {integer} the List-ID. + *

Returns:
+ * Array of subscribers assigned to the list. + *

+ */ + public static function listSubscribers($list_id = 0) + { + $response = new Response(); + if ($list_id == 0) { + $list_id = sprintf('%d',$_REQUEST['list_id']); + } + $sql = 'SELECT * FROM '.$GLOBALS['tables']['user'].' WHERE id IN + (SELECT userid FROM '.$GLOBALS['tables']['listuser'].' WHERE listid=:list_id) ORDER BY id;'; + if (!is_numeric($list_id) || empty($list_id)) { + Response::outputErrorMessage('invalid call'); + } + try { + $db = PDO::getConnection(); + $stmt = $db->prepare($sql); + $stmt->bindParam('list_id', $list_id, PDO::PARAM_INT); + $stmt->execute(); + $result = $stmt->fetchAll(PDO::FETCH_OBJ); + $db = null; + $response->setData('Subscribers', $result); + $response->output(); + } catch (\Exception $e) { + Response::outputError($e); + } + die(0); + } + + }