rolling back database changes, changing the model action names
authorAnthony Talarico <talarico@gaslightmedia.com>
Thu, 19 Oct 2017 19:18:20 +0000 (15:18 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Thu, 19 Oct 2017 19:18:20 +0000 (15:18 -0400)
changing the fields action to entity, adjusting database table column names and
datatypes

classes/data/dataCustomFields.php
models/admin/entity/fields.php [new file with mode: 0644]
models/admin/fields/fields.php [deleted file]
setup/adminHooks.php
setup/databaseScripts/create_database_V0.0.4.sql
setup/databaseScripts/update_database_V0.0.4.sql
setup/validActions.php
views/admin/entity/fields.html [new file with mode: 0644]
views/admin/fields/fields.html [deleted file]

index d6cc38b..f70c2b8 100644 (file)
@@ -139,7 +139,7 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
             // group id
             'uid' => array (
                 'field'     => 'uid',
-                'type'      => 'integer',
+                'type'      => 'text',
                 'view_only' => false,
                 'use'       => 'a'
             ),
diff --git a/models/admin/entity/fields.php b/models/admin/entity/fields.php
new file mode 100644 (file)
index 0000000..545f19a
--- /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_entity_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;
+            print_r($actionData);
+        }  
+
+        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 = customFieldsGetFields( $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/entity/fields.html',
+            'data'             => $template_data
+        );
+
+
+    }
+
+}
diff --git a/models/admin/fields/fields.php b/models/admin/fields/fields.php
deleted file mode 100644 (file)
index df98639..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_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 = customFieldsGetFields( $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
-        );
-
-
-    }
-
-}
index 2cd50b8..dda3f48 100644 (file)
@@ -42,9 +42,10 @@ add_filter( 'glm-members-customfields-edit', function( $content, $uid ){
 /**
  * Filter returns the html for the form segment
  */
-add_filter( 'glm-members-customfields-form', function( $content, $uid, $id ){
+add_filter( 'glm-members-custom-fields-form', function( $content, $uid, $id ){
     unset( $_REQUEST['glm_action'] );
-    $content = $this->controller( 'fields', 'fields', array( 'uid' => $uid, 'memberId' => $id ), true );
+    // $content = $this->controller( 'entity', 'fields', array( 'uid' => false, 'memberId' => false ), true );
+    $content = $this->controller( 'entity', 'fields', array('uid'=>$uid, "memberId"=>$id), true );
     return $content;
 }, 10, 3 );
 /**
index 75a0f58..c98235f 100644 (file)
@@ -20,8 +20,8 @@ CREATE TABLE {prefix}custom_fields (
   field_order SMALLINT NOT NULL DEFAULT 0,      -- Order for Field
   admin_search BOOLEAN NOT NULL DEFAULT '0',    -- If the field is added to member list filters.
   required BOOLEAN NOT NULL DEFAULT '0',        -- If the field is required.
-  uid INT NOT NULL,                             -- id for the series of custom fields associated with an entity
-  entity_id INT NOT NULL DEFAULT '0',           -- id for the specific field associated with an entity
+  uid TINYTEXT NOT NULL,                             -- id for the series of custom fields associated with an entity
+  entity_id INT NOT NULL DEFAULT 0,           -- id for the specific field associated with an entity
   PRIMARY KEY (id),
   INDEX(field_name(20))
 );
@@ -34,7 +34,7 @@ CREATE TABLE {prefix}custom_field_data (
   field_id INT NOT NULL DEFAULT 0,              -- Field Id
   ref_dest INT NOT NULL DEFAULT 0,              -- Member Info Id
   field_data TEXT NOT NULL DEFAULT '',          -- Data for the field
-  entity_id INT NOT NULL,                       -- id for the specific field associated with an entity
+  entity_id INT NOT NULL DEFAULT 0,             -- id for the specific field associated with an entity
   PRIMARY KEY (id),
   INDEX(field_id),
   INDEX(ref_dest)
index 122845d..d32183d 100644 (file)
@@ -10,7 +10,7 @@ ALTER TABLE {prefix}custom_fields ADD COLUMN required BOOLEAN DEFAULT '0';
 
 ----
 
-ALTER TABLE {prefix}custom_fields ADD COLUMN uid INT NOT NULL;
+ALTER TABLE {prefix}custom_fields ADD COLUMN uid TINYTEXT NOT NULL DEFAULT '';
 
 ----
 
@@ -18,4 +18,4 @@ ALTER TABLE {prefix}custom_field_data ADD COLUMN entity_id INT NOT NULL;
 
 ----
 
-ALTER TABLE {prefix}custom_fields ADD COLUMN entity_id INT NOT NULL DEFAULT '0';
+ALTER TABLE {prefix}custom_fields ADD COLUMN entity_id INT NOT NULL DEFAULT 0;
index ee086cf..db6208d 100644 (file)
@@ -62,7 +62,7 @@ $glmMembersFieldsAddOnValidActions = array(
         'ajax' => array(
           'filterSearch' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG,
         ),
-        'fields' => array(
+        'entity' => array(
             'fields' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG,
         ),
         'management' => array(
diff --git a/views/admin/entity/fields.html b/views/admin/entity/fields.html
new file mode 100644 (file)
index 0000000..72fb72d
--- /dev/null
@@ -0,0 +1,26 @@
+<table id="glm-table-custom-fields" class="glm-admin-table glm-hidden glm-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/fields/fields.html b/views/admin/fields/fields.html
deleted file mode 100644 (file)
index 72fb72d..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<table id="glm-table-custom-fields" class="glm-admin-table glm-hidden glm-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>