From: Steve Sutton Date: Mon, 26 Aug 2019 17:22:19 +0000 (-0400) Subject: Add json output for events X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=cdea988cac9f019f91d7d0c306e8a12899b9e90f;p=WP-Plugins%2Fglm-member-db-events.git Add json output for events Get all current events in json --- diff --git a/models/admin/ajax/eventsListJson.php b/models/admin/ajax/eventsListJson.php new file mode 100644 index 0000000..f068e68 --- /dev/null +++ b/models/admin/ajax/eventsListJson.php @@ -0,0 +1,138 @@ + + * @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 ); + + } + +} diff --git a/setup/validActions.php b/setup/validActions.php index a0cf12c..3125f1b 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -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,