Add json list for packages
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 26 Aug 2019 18:00:47 +0000 (14:00 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 26 Aug 2019 18:00:47 +0000 (14:00 -0400)
Add admin ajax json output.

models/admin/ajax/packagesListJson.php [new file with mode: 0644]
setup/validActions.php

diff --git a/models/admin/ajax/packagesListJson.php b/models/admin/ajax/packagesListJson.php
new file mode 100644 (file)
index 0000000..260bf3f
--- /dev/null
@@ -0,0 +1,126 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Front Package List
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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 );
+
+    }
+
+
+}
index 69e636d..dfd931e 100644 (file)
@@ -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'
         )
     )
 );
-
-?>