From: Laury GvR Date: Wed, 7 Aug 2019 23:43:01 +0000 (-0400) Subject: POI route: add packaging & coupons queries X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fdevelop;p=WP-Plugins%2Fglm-member-db-rest-api.git POI route: add packaging & coupons queries --- 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;