Add json output for events
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 26 Aug 2019 17:22:19 +0000 (13:22 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 26 Aug 2019 17:22:19 +0000 (13:22 -0400)
Get all current events in json

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

diff --git a/models/admin/ajax/eventsListJson.php b/models/admin/ajax/eventsListJson.php
new file mode 100644 (file)
index 0000000..f068e68
--- /dev/null
@@ -0,0 +1,138 @@
+<?php
+
+/**
+ * Gaslight Media Events Database
+ * Events List Export by AJAX
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmEventsDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+
+// Load Event Info data abstract
+require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataEvents.php';
+require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataCategories.php';
+require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataEventCategories.php';
+
+/**
+ *
+ * This class exports the currently selected events list
+ * to a printable HTML file, to a CSV file, or otherwise.
+ */
+class GlmMembersAdmin_ajax_eventsListJson extends GlmDataEvents
+{
+
+    /**
+     * 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;
+
+        parent::__construct( false, false );
+
+    }
+
+    /**
+     * Perform Model Action
+     *
+     * This modelAction takes an AJAX image upload and stores the image in the
+     * media/images directory of the plugin.
+     *
+     * This model action does not return, it simply does it's work then calls die();
+     *
+     * @param $actionData
+     *
+     * Echos JSON string as response and does not return
+     */
+    public function modelAction ( $actionData = false )
+    {
+        // Initialize Events Array
+        $events         = array();
+        $where          = false;
+        $whereParts     = array();
+        $categories     = false;
+        $haveEvents     = false;
+        $list           = false;
+        $success        = false;
+
+        $from           = date( 'Y-m-d' );
+        $dateRange      = "id IN (
+            SELECT id
+              FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
+             WHERE DATE(start_time) >= '{$from}')";
+
+        // Build $whereParts
+        $whereParts[] = "T.status = " . $this->config['status_numb']['Active'] . "
+            AND T.id IN (
+                    SELECT event
+                      FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
+                     WHERE active
+                       AND " . $dateRange . "
+                )
+            ";
+
+        $where = implode( ' AND ', $whereParts );
+
+        // Get a list of event categories
+        $sql = "
+        SELECT C.id,C.name,C.parent,
+            COALESCE ((SELECT name
+                   FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "categories
+                  WHERE id = C.parent), '') AS parent_name
+          FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "categories C
+        ORDER BY C.parent,C.name";
+        $category_data = $this->wpdb->get_results( $sql, ARRAY_A );
+
+        // Get a current list of events without paging
+        $orderBy                  = "(select min(start_time) FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE T.id = event),name";
+        $this->postCategories     = true;
+        $this->postAddLocations   = true;
+        $this->postAddTimes       = true;
+        $this->postAddRecurrences = true;
+
+        $list = $this->getList( $where, $orderBy, true );
+
+        $eventIndex = 0;
+        foreach ( $list as $event ) {
+            $events[$eventIndex] = $event;
+            $eventIndex++;
+        }
+
+        header( 'Content-Type: application/json' );
+        echo json_encode( $events );
+
+    }
+
+}
index a0cf12c..3125f1b 100644 (file)
@@ -41,6 +41,7 @@ $glmMembersEventsAddOnValidActions = array(
             'eventsCalMonthAJAX' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
             'icalFeedImport'     => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
             'eventsListExport'   => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
+            'eventsListJson'     => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
         ),
         'dashboard' => array(
             'events' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,