Using jquery ui autocomplete to get names when they search for them.
Output only the first date if the search by name. This keeps it from
giving the default date range with one event.
eventForm = $('#glm-member-event-search');
eventForm.attr('action', '../wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=pdfOutput&glm-event-pdf=1');
});
+ var cache = {};
+ $("#glm-event-name").autocomplete({
+ minLength: 2,
+ source: function(request, response) {
+ var term = request.term;
+ if ( term in cache ) {
+ response( cache[term]);
+ return;
+ }
+ var url = '../wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=nameSearch';
+ $.getJSON( url, request, function(data, status, xhr){
+ //cache[term] = data;
+ response( data );
+ });
+ }
+ });
}).call(this);
--- /dev/null
+<?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
+ */
+
+require_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/front/events/list.php';
+/**
+ * Steve Note...
+ *
+ * You can get to this using the following URL.
+ *
+ * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=pdfOutput&mystuff=THIS
+ *
+ * You should be able to do this as POST or GET and should be able to add and read additional parameters.
+ * I added a "mystuff" parameter to the URL above and it does output from the code in the
+ * modelAction() function below.
+ *
+ * To add another model under models/admin/ajax all you need to do is create it and add it to the
+ * setup/validActions.php file.
+ *
+ */
+
+// Load Members data abstract
+// require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.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_nameSearch extends GlmMembersFront_events_list
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+}
public function getModelEventsData($categoryId = null, $limit = null)
{
$this->postAddTimes = true;
- if ($categoryId) {
- $events = $this->getEventsByCategory( $categoryId, $limit );
+ if ($catId = filter_var( $categoryId, FILTER_VALIDATE_INT )) {
+ $events = $this->getEventsByCategory( $catId, $limit );
+ } else if ($term = filter_var( $categoryId, FILTER_SANITIZE_STRING )) {
+ $searchTerm = $this->wpdb->esc_like( $term );
+ $where = "T.name like '%" . $searchTerm . "%'
+ AND 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 " . $this->dateRange . "
+ )
+ ";
+ $order = "T.id";
+ $order .= " LIMIT 2 OFFSET 0";
+ $events = $this->getList($where, $order);
} else {
$where = "T.status = " . $this->config['status_numb']['Active'] . "
AND T.id IN (
AND " . $this->dateRange . "
)
";
- //echo '<pre>$where: ' . print_r($where, true) . '</pre>';
$events = $this->getList($where);
}
//echo '<pre>$events: ' . print_r($events, true) . '</pre>';
public function modelAction($actionData = false)
{
//$allEvents = $this->getList();
- $status = $categoryId = null;
- $action = '';
+ $status = $categoryId = null;
+ $action = '';
$settings = $events = $event = $categoryEvents = array();
if (isset($_REQUEST['eventId']) && $eventId = filter_var($_REQUEST['eventId'], FILTER_VALIDATE_INT)) {
$search = true;
$search = true;
$action = 'pdf';
}
+ if (isset($_REQUEST['term']) && $term = filter_var($_REQUEST['term'], FILTER_SANITIZE_STRING) ) {
+ $search = true;
+ $action = 'nameSearch';
+ }
if ( isset($_REQUEST['glm_event_from']) ) {
//$fromDate = filter_var($_REQUEST['glm_event_from'], FILTER_SANITIZE_STRING);
$fromDate = filter_var(
if (isset($_REQUEST['event_name']) && $eventNameSearch = filter_var($_REQUEST['event_name'], FILTER_SANITIZE_STRING)) {
$search = true;
- $action = 'event-list';
+ $action = 'event-list-name';
} else {
$eventNameSearch = false;
}
wp_register_script(
'event-dashboard-js',
GLM_MEMBERS_EVENTS_PLUGIN_BASE_URL . '/js/dashboard.js',
- 'jquery-datepicker',
+ array('jquery-ui-datepicker','jquery-ui-autocomplete'),
GLM_MEMBERS_EVENTS_PLUGIN_VERSION,
true
);
switch ($action) {
+ case 'event-list-name':
+ $events = $this->getModelEventsData($eventNameSearch);
+ $view = 'agenda.html';
+ break;
case 'event-list':
$events = $this->getModelEventsData($categoryId);
$view = 'agenda.html';
break;
+ case 'nameSearch':
+ // get list of names based on term
+ if ($term) {
+ $searchResults = array();
+ $searchTerm = $this->wpdb->esc_like( $term );
+ $sql = "
+ SELECT name
+ FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "events
+ WHERE name like '%" . $searchTerm . "%'";
+ $results = $this->wpdb->get_results( $sql, ARRAY_A );
+ if ( !empty( $results ) ) {
+ foreach ( $results as $result ) {
+ $searchResults[] = array(
+ 'id' => $result['name'],
+ 'label' => $result['name'],
+ 'value' => $result['name'],
+ );
+ }
+ }
+ echo json_encode( $searchResults );
+ return 1;
+ exit;
+ }
+ break;
case 'pdf':
include_once '/var/www/localhost/Setasign/SetaPDF-Core_2.18.0.817_Ioncubed-PHP5.4/library/SetaPDF/Autoload.php';
$this->postAddLocations = true;
);
$totalEvents = count($events);
+ var_dump($totalEvents);
$index = 0;
foreach ( $events as $eventId => $event ) {
$event['ending_date'] = $eventTime['end_time']['timestamp'];
$event['hasSameTimes'] = ($event['starting_date'] == $event['ending_date']) ? 1 : 0;
$eventsByDate[$eventDateTime][$eventTime['start_time']['timestamp']] = $event;
+ // if there's a name search stop for the first occurrence of that event
+ if ( $action == 'event-list-name' ) {
+ break;
+ }
}
}
ksort($eventsByDate);
$glmMembersEventsAddOnValidActions = array(
'adminActions' => array(
'ajax' => array(
- 'pdfOutputs' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG
+ 'pdfOutputs' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
+ 'nameSearch' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG
),
'member' => array(
'events' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,