WIP Show members by using ajax call to only get members.
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 19 Nov 2018 13:46:03 +0000 (08:46 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 19 Nov 2018 13:46:03 +0000 (08:46 -0500)
Setting up needed variables for the smarty view file so it can be used
by ajax.

models/admin/ajax/membersList.php [new file with mode: 0644]
models/front/members/list.php
setup/frontHooks.php
setup/shortcodes.php
setup/validActions.php

diff --git a/models/admin/ajax/membersList.php b/models/admin/ajax/membersList.php
new file mode 100644 (file)
index 0000000..0e4c643
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Members List Export by 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 Member Info data abstract
+require_once GLM_MEMBERS_PLUGIN_PATH.'/models/front/members/list.php';
+define( 'GLM_MEMBER_LIST_AJAX_LOADER', true );
+/**
+ *
+ * This class exports the currently selected members list
+ * to a printable HTML file, to a CSV file, or otherwise.
+ */
+class GlmMembersAdmin_ajax_membersList extends GlmMembersFront_members_list
+{
+
+    /**
+     * 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( $wpdb, $config );
+
+    }
+
+    // public function modelAction( $actionData = false ) {
+    //
+    //     if ( isset( $_REQUEST['limit'] ) && filter_var( $_REQUEST['limit'], FILTER_VALIDATE_INT ) ) {
+    //         $limit = filter_var( $_REQUEST['limit'], FILTER_VALIDATE_INT );
+    //     }
+    //
+    //     if ( isset( $_REQUEST['pageSelect'] ) && filter_var( $_REQUEST['pageSelect'], FILTER_SANITIZE_STRING ) ) {
+    //         $pageSelect = filter_var( $_REQUEST['pageSelect'], FILTER_SANITIZE_STRING );
+    //     }
+    //     if ( isset( $_REQUEST['nextStart'] ) && filter_var( $_REQUEST['nextStart'], FILTER_VALIDATE_INT ) ) {
+    //         $nextStart = filter_var( $_REQUEST['nextStart'], FILTER_VALIDATE_INT );
+    //     }
+    //     if ( $_SESSION['search_query'] ) {
+    //         // $actionData             = $_SESSION['actionData'];
+    //         // $_REQUEST               = $_SESSION['search_query'];
+    //         // $_REQUEST['limit']      = $limit;
+    //         // $_REQUEST['pageSelect'] = $pageSelect;
+    //         // $_REQUEST['nextStart']  = $nextStart;
+    //     }
+    //
+    //     return parent::modelAction( $actionData );
+    //
+    // }
+
+}
index bcaaadf..8f1599f 100755 (executable)
@@ -199,6 +199,13 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
         $start         = 1;
         $limit         = $this->config['settings']['list_pagination_count']; // Now this is in management
 
+        if ( isset( $_REQUEST['limit'] ) && filter_var( $_REQUEST['limit'], FILTER_VALIDATE_INT ) ) {
+            $limit = filter_var( $_REQUEST['limit'], FILTER_VALIDATE_INT );
+        }
+        if ( isset( $actionData['request']['limit'] ) && filter_var( $actionData['request']['limit'], FILTER_VALIDATE_INT ) ) {
+            $limit = filter_var( $actionData['request']['limit'], FILTER_VALIDATE_INT );
+        }
+
         // Check if a multi-select for categories is being submitted. If so, assign that to the category selection
         if (isset($_REQUEST['categorySearchMultiple']) && is_array($_REQUEST['categorySearchMultiple'])) {
             $actionData['request']['category'] = implode(',', $_REQUEST['categorySearchMultiple']);
@@ -860,6 +867,9 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
         if (isset($actionData['request']['view']) && $actionData['request']['view'] != "" ) {
             $view = strtolower($actionData['request']['view']);
         }
+        if ( isset( $_REQUEST['view'] ) && $_REQUEST['view'] ) {
+            $view = $_REQUEST['view'];
+        }
 
         /*
          * Check for a blank start - No members selected, just search form
@@ -931,6 +941,8 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
                     '',                 // prohibitListOptions
                     $appendSelect
                 );
+                // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+                // echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
             } else {
                 // Get member list sorted as specified
                 switch ($this->config['settings']['list_order_list']) {
@@ -1000,6 +1012,42 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             $singleCategory = true;
         }
 
+        // Setup ajax Request
+        $ajaxRequest = '';
+        if ( $memberType ) {
+            $ajaxRequest .= "&memberType=$memberType";
+        }
+        if ( $categorySearch ) {
+            $ajaxRequest .= "&categorySearch=$categorySearch";
+        }
+        if ( $citySearch ) {
+            $ajaxRequest .= "&citySearch=$citySearch";
+        }
+        if ( $ajaxRequest ) {
+            $ajaxRequest .= "&ajaxRequest=$ajaxRequest";
+        }
+        if ( $view ) {
+            $ajaxRequest .= "&view=$view";
+        }
+        if ( $blankStart ) {
+            $ajaxRequest .= "&blankStart=$blankStart";
+        }
+        if ( $catSelected ) {
+            $ajaxRequest .= "&catSelected=$catSelected";
+        }
+        if (isset($_REQUEST['textSearch'])) {
+            $ajaxRequest .= "&textSearch=" . urlencode( stripslashes( $textSearch ) );
+        }
+        if ( isset( $actionData['request']['category'] ) ) {
+            $catsRequested = explode( ',', $actionData['request']['category'] );
+            if ( $catsRequested ) {
+                foreach ( $catsRequested as $cats ) {
+                    $ajaxRequest .= "&categorySearchMultiple[]=" . $cats;
+                }
+            }
+            // echo '<pre>$catsRequested: ' . print_r( $catsRequested, true ) . '</pre>';
+        }
+
         // Compile template data
         $templateData = array(
             'haveMembers'          => $haveMembers,
@@ -1039,6 +1087,16 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             'start'                => $start,
             'limit'                => $limit,
 
+            // Add for ajax
+            'memberType'           => $memberType,
+            'categorySearch'       => $categorySearch,
+            'amenitySearch'        => $amenitySearch,
+            'citySearch'           => $citySearch,
+            'ajaxRequest'          => $ajaxRequest,
+
+            'ajaxLoader'           => ( defined( 'GLM_MEMBER_LIST_AJAX_LOADER' ) && GLM_MEMBER_LIST_AJAX_LOADER ) ? true : false,
+            'ajaxNext'             => ( isset( $_REQUEST['ajaxNext'] ) ) ? true : false,
+
         );
 
         if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
@@ -1047,12 +1105,18 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             trigger_error($membListTime." seconds ---", E_USER_NOTICE);
         }
 
+        $viewFile = 'front/members/list.html';
+
+        if ( defined( 'GLM_MEMBER_LIST_AJAX_LOADER' ) && GLM_MEMBER_LIST_AJAX_LOADER ) {
+            $viewFile = 'front/members/listContainer.html';
+        }
+
         // Return status, suggested view, and data to controller - also return any modified settings
         return array(
             'status'           => $success,
             'menuItemRedirect' => false,
             'modelRedirect'    => false,
-            'view'             => "front/members/list.html",
+            'view'             => $viewFile,
             'data'             => $templateData,
             'settings'         => $settings
         );
index 0fd861b..1abbd1b 100644 (file)
@@ -669,3 +669,10 @@ add_filter(
     10,
     2
 );
+
+// If no session then start one.
+add_action( 'init', function(){
+    if ( !session_id() ) {
+        session_start();
+    }
+});
index 350d72a..139b190 100644 (file)
@@ -93,6 +93,7 @@ if ( isset( $config['settings'] ) && $config['settings']['enable_members'] ) {
                 'blank-start'           => false,
                 'show'                  => false,
                 'view'                  => false,
+                'limit'                 => false,
                 'map'                   => 'list_show_map',
                 'map-opened'            => 'list_map_show_opened',
                 'map-name-link'         => 'list_map_show_detaillink',
index ef985fc..33cf8b9 100644 (file)
@@ -48,6 +48,7 @@ $glmMembersValidActions = array(
             'membersMapData'      => 'glm-member-db',
             'citiesMapData'       => 'glm-member-db',
             'countiesMapData'     => 'glm-member-db',
+            'membersList'         => 'glm-member-db',
         ),
         'dashboard' => array(
             'index'   => 'glm-member-db',