From 3d6ca083e726a2c3fce70b67b317c701674b1462 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 26 Aug 2019 14:00:47 -0400 Subject: [PATCH] Add json list for packages Add admin ajax json output. --- models/admin/ajax/packagesListJson.php | 126 +++++++++++++++++++++++++ setup/validActions.php | 7 +- 2 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 models/admin/ajax/packagesListJson.php diff --git a/models/admin/ajax/packagesListJson.php b/models/admin/ajax/packagesListJson.php new file mode 100644 index 0000000..260bf3f --- /dev/null +++ b/models/admin/ajax/packagesListJson.php @@ -0,0 +1,126 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +// Load packages data abstract +require_once GLM_MEMBERS_PACKAGING_PLUGIN_CLASS_PATH.'/data/dataPackages.php'; + +/* + * This class performs the work for displaying members packages. + */ +class GlmMembersAdmin_ajax_packagesListJson extends GlmDataPackages +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /** + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ( $wpdb, $config ) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for members data class + parent::__construct( false, false ); + + } + + /** + * Perform Model Action + * + * This method does the work for this model and returns any resulting data + * + * @return array Status and data array + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'menuItemRedirect' + * + * If not false, provides a menu item the controller should + * execute after this one. Normally if this is used, there would also be a + * modelRedirect value supplied as well. + * + * 'modelRedirect' + * + * If not false, provides an action the controller should execute after + * this one. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + */ + public function modelAction( $actionData = false ) + { + + $havePackages = false; + $packages = []; // Used if sorting by package + $where = false; + $whereParts = array(); + $noMemberWithPackage = true; + + // Build $whereParts + $whereParts[] = "CURDATE() BETWEEN T.start_date AND T.end_date AND T.status = 10"; + + // Setup $where + $where = implode( ' AND ', $whereParts ); + $orderBy = 'position ASC'; + + $list = $this->getPackageList( $where, $orderBy, $noMemberWithPackage ); + + $packageIndex = 0; + foreach ( $list as $package ) { + $packages[$packageIndex] = $package; + $packageIndex++; + } + + header( 'Content-Type: application/json' ); + echo json_encode( $packages ); + + } + + +} diff --git a/setup/validActions.php b/setup/validActions.php index 69e636d..dfd931e 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -32,6 +32,9 @@ $glmMembersPackagingAddOnValidActions = array( 'adminActions' => array( + 'ajax' => array( + 'packagesListJson' => GLM_MEMBERS_PACKAGING_PLUGIN_SLUG, + ), 'dashboard' => array( 'packaging' => GLM_MEMBERS_PACKAGING_PLUGIN_SLUG, ), @@ -50,10 +53,8 @@ $glmMembersPackagingAddOnValidActions = array( ), 'frontActions' => array( 'packaging' => array( - 'list' => 'glm-member-db-packaging', + 'list' => 'glm-member-db-packaging', 'detail' => 'glm-member-db-packaging' ) ) ); - -?> -- 2.17.1