From 737afc7e8e2bde79f6ab12e1b25436a7392fd38e Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Wed, 7 Aug 2019 19:43:01 -0400 Subject: [PATCH] POI route: add packaging & coupons queries --- setup/routes/pointsOfInterest.php | 49 +++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/setup/routes/pointsOfInterest.php b/setup/routes/pointsOfInterest.php index 5e90390..5582941 100644 --- a/setup/routes/pointsOfInterest.php +++ b/setup/routes/pointsOfInterest.php @@ -208,20 +208,63 @@ class GLMA_POI_Rest_Controller } if ( in_array( 'coupons', $addons ) ) { - if ( !defined( "GLM_MEMBERS_COUPONS_PLUGIN_PATH" ) ) { $coupons['error'] = "ERR: coupons addon requested but not found"; } else { - $coupons = "o"; + $coupons_fields = " + C.id, + C.name, + C.name_slug, + C.descr, + C.image, + C.start_date, + C.end_date, + C.expire"; + $coupons_table = GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."coupons C"; + $coupons_where = " + status IN (".$this->config['status_numb']['Active'].") + AND start_date <= CURDATE() + AND end_date >= CURDATE()"; + $coupons_limit = $limit; + + $coupons_sql = " + SELECT $coupons_fields + FROM $coupons_table + WHERE $coupons_where + LIMIT $coupons_limit; + "; + + $coupons = $this->wpdb->get_results($coupons_sql, ARRAY_A); + if (!$coupons) { + $coupons['error'] = "ERR: no coupons found"; + } } //$summary['coupons'] = $this->get_coupons_summary(); $response['coupons'] = $coupons; } + if ( in_array( 'packaging', $addons ) ) { if ( !defined( "GLM_MEMBERS_PACKAGING_PLUGIN_PATH" ) ) { $packages['error'] = "ERR: packaging addon requested but not found"; } else { - $packages = "o"; + $packaging_fields = " + P.id, + P.title"; + $packaging_table = GLM_MEMBERS_PACKAGING_PLUGIN_DB_PREFIX."packages P"; + $packaging_where = "P.status = 10"; + $packaging_limit = $limit; + + $packaging_sql = " + SELECT $packaging_fields + FROM $packaging_table + WHERE $packaging_where + LIMIT $packaging_limit + "; + + $packages = $this->wpdb->get_results($packaging_sql, ARRAY_A); + if (!$packages) { + $packages['error'] = "ERR: no packages found"; + } } //$summary['packaging'] = $this->get_packaging_summary(); $response['packaging'] = $packages; -- 2.17.1