Updates for different uid
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 24 Jul 2018 20:59:34 +0000 (16:59 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 24 Jul 2018 20:59:34 +0000 (16:59 -0400)
fix for both member and contacts
update filters for the searching in admin side.

models/admin/entity/fields.php
models/admin/management/fields.php
setup/adminHooks.php

index 80c7d4c..ea4f9f4 100644 (file)
@@ -122,6 +122,7 @@ class GlmMembersAdmin_entity_fields extends GlmDataFieldsCustomFields
         $customFieldData  = false;
         $where            = 'true';
         $uid              = '';
+        $haveGroups       = false;
 
         if (isset($_REQUEST['option'])) {
             $option = $_REQUEST['option'];
index 1268950..93c7862 100644 (file)
@@ -206,7 +206,7 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
                     $this->wpdb->update(
                         GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_groups',
                         array(
-                            'uid'         => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
+                            'uid'         => $uid,
                             'group_name'  => filter_var( $_REQUEST['group_name'] ),
                             'publish'     => filter_var( $_REQUEST['publish'], FILTER_VALIDATE_BOOLEAN ),
                         ),
@@ -228,7 +228,7 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
                 $max_group_order = $this->wpdb->get_var(
                     "SELECT max(group_order)
                        FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_groups
-                      WHERE uid = '" . GLM_MEMBERS_CONTACTS_PLUGIN_SLUG . "'"
+                      WHERE uid = '$uid'"
                 );
                 if ( $max_group_order ) {
                     // Set the new group to last place
@@ -237,7 +237,7 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
                 $this->wpdb->insert(
                     GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_groups',
                     array(
-                        'uid'         => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
+                        'uid'         => $uid,
                         'group_name'  => filter_var( $_REQUEST['group_name'] ),
                         'group_order' => $group_order,
                         'publish'     => filter_var( $_REQUEST['publish'], FILTER_VALIDATE_BOOLEAN ),
@@ -280,7 +280,7 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
                     $field_order = $this->wpdb->get_var(
                         "SELECT max(field_order)
                            FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
-                          WHERE uid = '" . GLM_MEMBERS_CONTACTS_PLUGIN_SLUG . "'
+                          WHERE uid = '$uid'
                             AND gid = $gid"
                     );
                     $field_order++;
@@ -356,7 +356,7 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
         $groups = $this->wpdb->get_results(
             "SELECT *
                FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_groups
-              WHERE uid = '" . GLM_MEMBERS_CONTACTS_PLUGIN_SLUG . "'
+              WHERE uid = '$uid'
             ORDER BY group_order",
             ARRAY_A
         );
index 299aa36..31015d9 100644 (file)
@@ -90,7 +90,7 @@ add_filter( 'glm-members-customfields-data', function( $content, $uid, $id ){
  */
 add_filter( 'glm-member-db-custom-fields-nav', function( $content, $tableName ){
     $tabLabel = ( $tableName == 'contact-info' ) ? 'Directory Info' : 'Custom Fields';
-    $out .= '<a id="glm-custom-fields" data-show-table="glm-table-custom-fields" class="glm-' . $tableName . '-tab nav-tab">' . $tabLabel . '</a>';
+    $out = '<a id="glm-custom-fields" data-show-table="glm-table-custom-fields" class="glm-' . $tableName . '-tab nav-tab">' . $tabLabel . '</a>';
     return $out;
 },10,2);
 
@@ -106,12 +106,13 @@ add_filter( 'glm-member-db-custom-fields-tab', function( $content, $entityID = '
 /**
  * Admin member list filter for displaying filters for the custom fields
  */
-add_filter( 'glm-member-db-custom-filter-search', function ( $content ) {
+add_filter( 'glm-member-db-custom-filter-search', function ( $content, $uid ) {
 $parts = array();
     $customFields = $this->wpdb->get_results(
         "SELECT *
            FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX .  "custom_fields
-          WHERE admin_search = 1",
+          WHERE admin_search = 1
+            AND uid = '$uid'",
         ARRAY_A
     );
     if ( isset( $customFields ) && count( $customFields ) > 0 ) {
@@ -137,23 +138,52 @@ $parts = array();
                     $parts[$field['id']] .= ' checked';
                 }
                 $parts[$field['id']] .= '></b>';
+                break;
+            case 'picklist':
+                // Get the options for this field
+                $options = $this->wpdb->get_results(
+                    $this->wpdb->prepare(
+                        "SELECT *
+                           FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_options
+                          WHERE field_id = %d
+                        ORDER BY option_text",
+                        $field['id']
+                    ),
+                    ARRAY_A
+                );
+                if ( $options ) {
+                    $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
+                    $parts[$field['id']] = '<b>' . $field['field_name'] . ':</b>';
+                    $parts[$field['id']] .= '<select name="' . $field_name . '">';
+                    $parts[$field['id']] .= '<option value=""></option>';
+                    foreach ( $options as $option ) {
+                        $parts[$field['id']] .= '<option value="' . $option['option_text'] . '"';
+                        if ( isset( $_REQUEST[$field_name] ) && $option['option_text'] == $_REQUEST[$field_name] ) {
+                            $parts[$field['id']] .= ' selected';
+                        }
+                        $parts[$field['id']] .= '>' . $option['option_text'] . '</option>';
+                    }
+                    $parts[$field['id']] .= '</select>';
+                }
+
                 break;
             }
         }
     }
     return implode( ' ', $parts );
-});
+},1,2);
 
 /**
  * Admin Query Hook for searching member by custom fields
  */
-add_filter('glm-member-db-admin-search-query', function() {
+add_filter('glm-member-db-admin-search-query', function( $content, $uid ) {
     $queryParts = array();
     // Get all custom fields
     $customFields = $this->wpdb->get_results(
         "SELECT *
            FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX .  "custom_fields
-          WHERE admin_search = 1",
+          WHERE admin_search = 1
+            AND uid = '$uid'",
         ARRAY_A
     );
     if ( isset( $customFields ) && count( $customFields ) > 0 ) {
@@ -194,7 +224,7 @@ add_filter('glm-member-db-admin-search-query', function() {
         }
     }
     return $queryParts;
-});
+}, 1, 2);
 
 /**
  * Filter for returning the memberDb custom fields.