changing the member info actions to a generic fields action
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 18 Oct 2017 18:55:52 +0000 (14:55 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 18 Oct 2017 18:55:52 +0000 (14:55 -0400)
using fields for actions instead of member_info and changing the model view structure

models/admin/fields/fields.php [new file with mode: 0644]
models/admin/memberinfo/fields.php [deleted file]
setup/adminHooks.php
setup/validActions.php
views/admin/fields/fields.html [new file with mode: 0644]
views/admin/memberinfo/fields.html [deleted file]

diff --git a/models/admin/fields/fields.php b/models/admin/fields/fields.php
new file mode 100644 (file)
index 0000000..b815863
--- /dev/null
@@ -0,0 +1,179 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Fields Add-on - Management Fields Tab
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author     Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  fields.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Management Fields data abstract
+require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
+
+/**
+ * GlmMembersAdmin_management_fields
+ *
+ * PHP version 5
+ *
+ * @category Model
+ * @package GLM Member DB
+ * @author    Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ *            @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
+ *            Exp $
+ */
+class GlmMembersAdmin_fields_fields extends GlmDataFieldsCustomFields
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * dbh Postgres database connection
+     *
+     * @var mixed
+     * @access public
+     */
+    public $dbh;
+    /**
+     * settings used for the schema and tablenames
+     *
+     * @var mixed
+     * @access public
+     */
+    public $settings = array();
+    /**
+     * categories
+     *
+     * @var bool
+     * @access public
+     */
+    public $categories = array();
+    public $oldCatMap = array();
+    /**
+     * fields
+     *
+     * @var bool
+     * @access public
+     */
+    public $fields = array();
+    public $image_owner;
+
+    /**
+     * Constructor
+     *
+     * This contructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'view'
+     *
+     * A suggested view name that the contoller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     * @wpdb object WordPress database object
+     *
+     * @return array Array containing status, suggested view, and any data
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for members data class
+        parent::__construct(false, false);
+
+    }
+
+    /**
+     * modelAction
+     *
+     * @param bool $actionData
+     * @access public
+     * @return void
+     */
+    public function modelAction($actionData = false)
+    {
+        $option           = false;
+        $customFields     = false;
+        $haveCustomFields = false;
+        $customFieldData  = false;
+
+        if (isset($_REQUEST['option'])) {
+            $option = $_REQUEST['option'];
+        }
+
+        // Check if a field ID is supplied
+        $id = 0;
+        if (isset($_REQUEST['id'])) {
+            $id = $_REQUEST['id']-0;
+        }
+        $memberId = 0;
+        if (isset($actionData)) {
+            $memberId = $actionData-0;
+        }
+
+        switch ($option) {
+
+            default:
+                // Make sure option is set if default
+                $option = 'list';
+
+                break;
+
+        }
+
+        // Get list of Custom Fields
+        $customFields = $this->getList( null, 'field_order,id' );
+        if ( isset($customFields) && $customFields && count( $customFields ) > 0 ) {
+            $haveCustomFields = true;
+        }
+
+        require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
+        $customFieldsData = customFieldsGetMemberInfoFields( $memberId );
+
+        // Compile template data
+        $template_data = array(
+            'prefix'           => 'glm_custom_field',
+            'customFields'     => $customFields,
+            'customFieldsData' => $customFieldsData,
+            'fieldTypes'       => $this->config['custom_field_types'],
+            'haveCustomFields' => $haveCustomFields,
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => true,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/fields/fields.html',
+            'data'             => $template_data
+        );
+
+
+    }
+
+}
diff --git a/models/admin/memberinfo/fields.php b/models/admin/memberinfo/fields.php
deleted file mode 100644 (file)
index 372cc4b..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-<?php
-/**
- * Gaslight Media Members Database
- * GLM Members DB - Fields Add-on - Management Fields Tab
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package  glmMembersDatabase
- * @author     Chuck Scott <cscott@gaslightmedia.com>
- * @license  http://www.gaslightmedia.com Gaslightmedia
- * @release  fields.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
- * @link     http://dev.gaslightmedia.com/
- */
-
-// Load Management Fields data abstract
-require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
-
-/**
- * GlmMembersAdmin_management_fields
- *
- * PHP version 5
- *
- * @category Model
- * @package GLM Member DB
- * @author    Chuck Scott <cscott@gaslightmedia.com>
- * @license http://www.gaslightmedia.com Gaslightmedia
- *            @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
- *            Exp $
- */
-class GlmMembersAdmin_memberinfo_fields extends GlmDataFieldsCustomFields
-{
-
-    /**
-     * WordPress Database Object
-     *
-     * @var $wpdb
-     * @access public
-     */
-    public $wpdb;
-    /**
-     * dbh Postgres database connection
-     *
-     * @var mixed
-     * @access public
-     */
-    public $dbh;
-    /**
-     * settings used for the schema and tablenames
-     *
-     * @var mixed
-     * @access public
-     */
-    public $settings = array();
-    /**
-     * categories
-     *
-     * @var bool
-     * @access public
-     */
-    public $categories = array();
-    public $oldCatMap = array();
-    /**
-     * fields
-     *
-     * @var bool
-     * @access public
-     */
-    public $fields = array();
-    public $image_owner;
-
-    /**
-     * Constructor
-     *
-     * This contructor performs the work for this model. This model returns
-     * an array containing the following.
-     *
-     * 'status'
-     *
-     * True if successfull and false if there was a fatal failure.
-     *
-     * 'view'
-     *
-     * A suggested view name that the contoller should use instead of the
-     * default view for this model or false to indicate that the default view
-     * should be used.
-     *
-     * 'data'
-     *
-     * Data that the model is returning for use in merging with the view to
-     * produce output.
-     *
-     * @wpdb object WordPress database object
-     *
-     * @return array Array containing status, suggested view, and any data
-     */
-    public function __construct ($wpdb, $config)
-    {
-
-        // Save WordPress Database object
-        $this->wpdb = $wpdb;
-
-        // Save plugin configuration object
-        $this->config = $config;
-
-        // Run constructor for members data class
-        parent::__construct(false, false);
-
-    }
-
-    /**
-     * modelAction
-     *
-     * @param bool $actionData
-     * @access public
-     * @return void
-     */
-    public function modelAction($actionData = false)
-    {
-        $option           = false;
-        $customFields     = false;
-        $haveCustomFields = false;
-        $customFieldData  = false;
-
-        if (isset($_REQUEST['option'])) {
-            $option = $_REQUEST['option'];
-        }
-
-        // Check if a field ID is supplied
-        $id = 0;
-        if (isset($_REQUEST['id'])) {
-            $id = $_REQUEST['id']-0;
-        }
-        $memberId = 0;
-        if (isset($actionData)) {
-            $memberId = $actionData-0;
-        }
-
-        switch ($option) {
-
-            default:
-                // Make sure option is set if default
-                $option = 'list';
-
-                break;
-
-        }
-
-        // Get list of Custom Fields
-        $customFields = $this->getList( null, 'field_order,id' );
-        if ( isset($customFields) && $customFields && count( $customFields ) > 0 ) {
-            $haveCustomFields = true;
-        }
-
-        require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
-        $customFieldsData = customFieldsGetMemberInfoFields( $memberId );
-
-        // Compile template data
-        $template_data = array(
-            'prefix'           => 'glm_custom_field',
-            'customFields'     => $customFields,
-            'customFieldsData' => $customFieldsData,
-            'fieldTypes'       => $this->config['custom_field_types'],
-            'haveCustomFields' => $haveCustomFields,
-        );
-
-        // Return status, suggested view, and data to controller
-        return array(
-            'status'           => true,
-            'menuItemRedirect' => false,
-            'modelRedirect'    => false,
-            'view'             => 'admin/memberinfo/fields.html',
-            'data'             => $template_data
-        );
-
-
-    }
-
-}
index 1b83e06..7423add 100644 (file)
@@ -44,7 +44,7 @@ add_filter( 'glm-members-customfields-edit', function( $content, $uid ){
  */
 add_filter( 'glm-members-customfields-form', function( $content, $uid, $id ){
     unset( $_REQUEST['glm_action'] );
-    $content = $this->controller( 'memberinfo', 'fields', array( 'uid' => $uid, 'memberId' => $id ), true );
+    $content = $this->controller( 'fields', 'fields', array( 'uid' => $uid, 'memberId' => $id ), true );
     return $content;
 }, 10, 3 );
 /**
@@ -68,7 +68,7 @@ add_filter( 'glm-member-db-member-info-custom-nav', function( $content ){
 
 add_filter( 'glm-member-db-member-info-custom-tab', function( $content, $memberId = '' ){
     unset( $_REQUEST['glm_action'] );
-    $content = $this->controller( 'memberinfo', 'fields', $memberId );
+    $content = $this->controller( 'fields', 'fields', $memberId );
     return $content;
 },1,2);
 add_filter( 'glm-member-db-custom-filter-search', function ( $content ) {
index 3c2be84..ee086cf 100644 (file)
@@ -59,9 +59,6 @@
 
 $glmMembersFieldsAddOnValidActions = array(
     'adminActions' => array(
-        'memberinfo' => array(
-            'fields' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG,
-        ),
         'ajax' => array(
           'filterSearch' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG,
         ),
diff --git a/views/admin/fields/fields.html b/views/admin/fields/fields.html
new file mode 100644 (file)
index 0000000..11e2cc9
--- /dev/null
@@ -0,0 +1,26 @@
+<table id="glm-table-custom-fields" class="glm-admin-table glm-hidden glm-member-info-table">
+    {foreach $customFields as $field}
+        <tr >
+            <th>{$field.field_name}</th>
+            <td>
+                {if $field.field_type.name == 'text'}
+                <input type="text" name="{$prefix}[{$field.id}]" value="{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape}{/if}">
+                {elseif $field.field_type.name == 'textarea'}
+                    {php}
+                    wp_editor('{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape:quotes}{/if}', 'custom-field-{$field.id}', array(
+                        'media_buttons' => false,
+                        // 'quicktags' => false,
+                        // 'wpautop' => false,  NOTE: Dont's use. Problem when numerous spaces before text.
+                        'textarea_name' => '{$prefix}[{$field.id}]',
+                        'editor_height' => 200,     // Height in px, overrides editor_rows
+                        // 'textarea_rows' => 8
+                    ));
+                    {/php}
+                {elseif $field.field_type.name == 'checkbox'}
+                <input type="hidden" name="{$prefix}[{$field.id}]" value="No" {if !isset($customFieldsData[$field.id]) || $customFieldsData[$field.id] == 'No'}checked{/if}>
+                <input type="checkbox" name="{$prefix}[{$field.id}]" value="Yes" {if isset($customFieldsData[$field.id]) && $customFieldsData[$field.id] == 'Yes'}checked{/if}>
+                {/if}
+            </td>
+        </tr>
+    {/foreach}
+</table>
diff --git a/views/admin/memberinfo/fields.html b/views/admin/memberinfo/fields.html
deleted file mode 100644 (file)
index 11e2cc9..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<table id="glm-table-custom-fields" class="glm-admin-table glm-hidden glm-member-info-table">
-    {foreach $customFields as $field}
-        <tr >
-            <th>{$field.field_name}</th>
-            <td>
-                {if $field.field_type.name == 'text'}
-                <input type="text" name="{$prefix}[{$field.id}]" value="{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape}{/if}">
-                {elseif $field.field_type.name == 'textarea'}
-                    {php}
-                    wp_editor('{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape:quotes}{/if}', 'custom-field-{$field.id}', array(
-                        'media_buttons' => false,
-                        // 'quicktags' => false,
-                        // 'wpautop' => false,  NOTE: Dont's use. Problem when numerous spaces before text.
-                        'textarea_name' => '{$prefix}[{$field.id}]',
-                        'editor_height' => 200,     // Height in px, overrides editor_rows
-                        // 'textarea_rows' => 8
-                    ));
-                    {/php}
-                {elseif $field.field_type.name == 'checkbox'}
-                <input type="hidden" name="{$prefix}[{$field.id}]" value="No" {if !isset($customFieldsData[$field.id]) || $customFieldsData[$field.id] == 'No'}checked{/if}>
-                <input type="checkbox" name="{$prefix}[{$field.id}]" value="Yes" {if isset($customFieldsData[$field.id]) && $customFieldsData[$field.id] == 'Yes'}checked{/if}>
-                {/if}
-            </td>
-        </tr>
-    {/foreach}
-</table>