Various preparatory work for other add-ons and minor cleanup.
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 19 Jul 2018 18:21:13 +0000 (14:21 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 19 Jul 2018 18:21:13 +0000 (14:21 -0400)
Started adding code to determine when a member record needs to be re-indexed by the search add-on. Temporarily commented out tell search updates are done.
Removed depreciated code from glmMembersAdminNotices() - Function to be removed later.
Removed some temporary debug code from admin controller.
Added glmMembersConfigArraySetup() array to provide easy expansion of config data in glmPluginSupport.php

classes/glmPluginSupport.php
controllers/admin.php
models/admin/member/memberEdit.php

index cdff7ff..751ca02 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+use net\authorize\api\contract\v1\ProcessorType;
+use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
+
 /**
  * Gaslight Media Members Database
  * Plugin support class
@@ -311,122 +314,81 @@ return; // Off for now ** Need to make this switchable in management
  * Stand alone functions that are needed globally for these plugins/add-ons
  */
 
-/*
- * Function to display admin notices.
+/**
+ * Function to build a more useable array from a config table
  *
- * This function is only called using the add_action('admin_notices','...') function
- * in the code below this function.
+ * @param $configTable array Copy of config table as an array (from $config) to process indexed by numbers - Required
+ * @param $configNubTable array Copy of matching table indexed by names - Optional
+ * @param $configSelected array Simple array of numberic IDs of entries that should be selected (true) by default - Optional
  *
- * @return void
- * @access public
+ * @return array Array of config table entries
+ *
+ * array(
+ *      index => array(
+ *          'id'  => Index number for this entry (key from config array)
+ *          'descr' => Text description of entry,
+ *          'name' => Name of field used to find ID (key from names array)
+ *          'selected' => Selected flag, all initialized to false
+ *      )
+ * )
  */
-function glmMembersAdminNotices($windowed = true)
+function glmMembersConfigArraySetup( $configTable, $configNumbTable = false, $configSelectedArray)
 {
-    // Depreciating debug system
-    return;
-/*
-    $output  = '';
-
-    // If windowed for debug, also include HTML header and stylesheet
-    if ($windowed) {
-
-        $output .= '
-            <html>
-                <head>
-                    <link rel="stylesheet" href="'.GLM_MEMBERS_PLUGIN_URL.'/css/admin.css">
-                <head>
-                <body>
-                    <a name="top"></a>
-                    <div id="glm-debug-timestamp">'.date('m/d/Y G:i:s A').'</div>
-                    <div id="glm-debug-header">'.GLM_MEMBERS_PLUGIN_NAME.' - Debug Data</div>
-        ';
-
-        // Display alerts
-        $alerts = get_option('glmMembersAdminNoticeAlerts');
-        if(is_array($alerts)) {
-           $output .= '<div id="glm-debug-alerts" class="glm-error"><h2>Alerts</h2>';
-            foreach($alerts as $a) {
-                $output .= $a.'<br>';
-            }
-        } else {
-            $output .= '<div id="glm-debug-alerts"><h2>Alerts</h2>';
-        }
-        $output .= '</div><hr>';
-        delete_option('glmMembersAdminNoticeAlerts');
-
-        // Display process messages
-        $process = get_option('glmMembersAdminNoticeProcess');
-        $output .= '<div id="glm-debug-process"><h2>Processing</h2>';
-        if(is_array($process)) {
-            foreach($process as $p) {
-                $output .= $p.'<br>';
-            }
-        }
-        $output .= '</div><hr>';
-        delete_option('glmMembersAdminNoticeProcess');
-
-        // Display data blocks table of contents then the data blocks
-        $dataBlocks = get_option('glmMembersAdminNoticeDataBlocks');
-        $output .= '<div id="glm-debug-contents"><h2>Data Blocks</h2><ul>';
-        $n = 0;
-        if (is_array($dataBlocks)) {
-            foreach($dataBlocks as $d) {
-                $output .= '<li><a href="#'.++$n.'">'.$d['title'].'</a></li>';
+
+    // Check if config table array exits
+    if (!is_array($configTable) || count($configTable) == 0) {
+        return false;
+    }
+
+    // Build base array
+    $conf = array();
+    foreach ($configTable as $key=>$descr) {
+        $conf[$key] = array(
+            'id' => $key,
+            'descr' => $descr,
+            'name' => false,
+            'selected' => false
+        );
+    }
+
+    // If name->number array add that data
+    if (is_array($configNumbTable) && count($configNumbTable) > 0) {
+        foreach ($configNumbTable as $name=>$key) {
+            if (isset($conf[$key])) {
+                $conf[$key]['name'] = $name;
             }
         }
+    }
 
-        $output .= '</ul></div><hr>';
-        if (is_array($dataBlocks)) {
-            reset($dataBlocks);
-            $n = 0;
-            foreach($dataBlocks as $d) {
-                $output .= '
-                    <div  style="margin-top: 2em;">
-                        <div style="float: right;"><a href="#top">[Top]</a></div>
-                        <div class="glm-debug-section-title"><a name="'.++$n.'"><h4>'.$d['title'].'</h4></a></div>
-                        <div class="glm-debug-section-body"><pre>'.print_r($d['data'],1).'</pre></div>
-                    </div>
-                ';
+    // If a selected array is provided, add that data
+    if (is_array($configSelectedArray) && count($configSelectedArray) > 0) {
+        foreach ($configSelectedArray as $key) {
+            if (isset($conf[$key])) {
+                $conf[$key]['selected'] = true;
             }
         }
+    }
 
-        echo $output.'
-                </body>
-            </html>
-        ';
-
-    // Otherwise we're outputting data to the message block in the WordPress admin area
-    } else {
-
-        // Start with div class to output in standard admin notice block
-        $output .= '<div class="updated"><p>';
-
-        // Get the notice texts
-        $notices = get_option('glmMembersAdminNotices');
-
-        if (is_array($notices) && count($notices) > 0) {
-
-            // For each notice retrieved
-            $br = '';
-            foreach($notices as $n) {
-
-                // Add the notice to the output
-                $output .= $br.$n;
-                $br = '<br>';
-            }
+    return $conf;
 
-        }
+}
 
-        echo $output.'</p></div>';
 
+/**
+ * Function to display admin notices. - Depreciated
+ *
+ * This function is only called using the add_action('admin_notices','...') function
+ * in the code below this function.
+ *
+ * @return void
+ * @access public
+ */
+function glmMembersAdminNotices($windowed = true)
+{
 
-    }
+    // Depreciating original debug system
+    return;
 
-    delete_option('glmMembersAdminNoticeAlerts');
-    delete_option('glmMembersAdminNotices');
-    delete_option('glmMembersAdminNoticeProcess');
-    delete_option('glmMembersAdminNoticeDataBlocks');
-*/
 }
 
 /**
index 4e21f2f..205a6a6 100644 (file)
@@ -254,6 +254,11 @@ class glmMembersAdmin extends GlmPluginSupport
     public function  glmMembersAdminAjax()
     {
 
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+            trigger_error(glmAssociateMemoryUsage()." - Start AJAX Controller",E_USER_NOTICE);
+            trigger_error(glmAssociateTimeTracker()." - Start AJAX Controller",E_USER_NOTICE);
+        }
+
         $defaultTimeZone = date_default_timezone_get();
         date_default_timezone_set($this->config['settings']['time_zone']);
 
@@ -358,6 +363,11 @@ class glmMembersAdmin extends GlmPluginSupport
 
         }
 
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+            trigger_error("AJAX Controller, Model = $modelName",E_USER_NOTICE);
+            trigger_error("AJAX Controller, View = $viewPath/$viewFile",E_USER_NOTICE);
+        }
+
         /*
          * Merge data returned from the model with the selected view
          */
@@ -390,6 +400,11 @@ class glmMembersAdmin extends GlmPluginSupport
         // Restore timezone that was set before our code was called
         date_default_timezone_set($defaultTimeZone);
 
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+            trigger_error(glmAssociateMemoryUsage()." - End AJAX Controller",E_USER_NOTICE);
+            trigger_error(glmAssociateTimeTracker()." - End AJAX Controller",E_USER_NOTICE);
+        }
+
         exit;   // Need to test if this is here for a reason!
         wp_die();
 
index 8e99123..d02c39a 100644 (file)
@@ -182,6 +182,8 @@ class GlmMembersAdmin_member_memberEdit extends GlmDataMembers
 
         }
 
+        $memberStatusBefore = $this->getDisplayStatus($this->memberID);
+
         /*
          * Perform requested action
          */
@@ -228,6 +230,17 @@ class GlmMembersAdmin_member_memberEdit extends GlmDataMembers
 
                 glmClearShortcodeCache();
 
+                // Get member display status again and if status goes from true to false, remove it from the search index
+/*
+                $memberStatusAfter = $this->getDisplayStatus($this->memberID);
+                $url = ''; // ************************* NEED TO PUT URL HERE *************************
+                if ($memberStatusBefore && !$memberStatusAfter) {
+                    $result = apply_filters( 'glm_member_db_common_search_removeurl', $url );
+                }
+                if (!$memberStatusBefore && $memberStatusAfter) {
+                    $result = apply_filters( 'glm_member_db_common_search_indexurl', $url );
+                }
+*/
                 break;
 
                 // Add the new member