Add ajax functions
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 8 Jun 2018 20:59:31 +0000 (16:59 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 8 Jun 2018 20:59:31 +0000 (16:59 -0400)
Adding ajax function for getting all messages.

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

diff --git a/models/admin/ajax/relay.php b/models/admin/ajax/relay.php
new file mode 100644 (file)
index 0000000..047241e
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * PDF Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+// Load Members data abstract
+require_once GLM_MEMBERS_RELAY_PLUGIN_CLASS_PATH . '/data/dataMessages.php';
+
+/**
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_relay extends GlmDataMessages
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This constructor 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 data class
+        parent::__construct(false, false);
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This model checks to see if the credentials passed in are correct.
+     *
+     * This model action does not return, it simply does it's work then calls die();
+     *
+     * @param $actionData
+     *
+     * Output JSON string as response and does not return
+     */
+    public function modelAction( $actionData = false )
+    {
+        $return  = false;
+        $success =  true;
+
+        $option = isset($_REQUEST['option']) ? filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING ) : '';
+        trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
+
+        switch ( $option ) {
+        case 'list':
+        default:
+            $messages = $this->getList( '', "T.updated desc" );
+
+            $results = $messages;
+            break;
+        }
+
+        header('Content-type:application/json;charset=utf-8', true);
+        echo json_encode( $results );
+        exit;
+
+    }
+}
index fe019c2..6a26b5b 100644 (file)
@@ -59,6 +59,9 @@
 
 $glmMembersRelayAddOnValidActions = array(
     'adminActions' => array(
+        'ajax' => array(
+            'relay' => GLM_MEMBERS_RELAY_PLUGIN_SLUG,
+        ),
         'relay' => array(
             'index' => GLM_MEMBERS_RELAY_PLUGIN_SLUG,
         )