Adding table for streamsend cache develop
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 17 Feb 2017 20:37:28 +0000 (15:37 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 17 Feb 2017 20:37:28 +0000 (15:37 -0500)
Add table for the streamsend cache.

defines.php
models/admin/communicator/index.php
models/admin/management/communicator.php
setup/adminHooks.php
setup/databaseScripts/create_database_V0.0.1.sql
setup/databaseScripts/dbVersions.php
views/admin/management/communicator.html

index af5ea62..ecd1717 100644 (file)
@@ -13,7 +13,7 @@ define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_SLUG', 'glm-member-db-communicator');
 
 // Database table prefixes - change if using add-on tables
 global $wpdb;
-define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_DB_PREFIX', $wpdb->prefix.'glmMembersCommunicator');
+define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_DB_PREFIX', $wpdb->prefix.'glm_membersCommunicator_');
 define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_ACTIVE_DB_OPTION', 'glmMembersCommunicatorDbVersion');
 
 // Determine which system we're running on - If not provided, assume PRODUCTION
index 4393156..3ece396 100644 (file)
@@ -29,7 +29,7 @@
   */
 //define('STREAMSEND_DEFAULT_DELIVER_WELCOME', 'false');
 
-class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator
+class GlmMembersAdmin_communicator_index
 {
 
     /**
@@ -74,21 +74,11 @@ class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator
      */
     public function __construct ($wpdb, $config)
     {
-
         // Save WordPress Database object
         $this->wpdb = $wpdb;
 
         // Save plugin configuration object
         $this->config = $config;
-
-        /*
-         * Run constructor for the Communicator data class
-         *
-         * Note, the third parameter is a flag that indicates to the Contacts
-         * data class that it should flag a group of fields as 'view_only'.
-         */
-        //parent::__construct(false, false, true);
-
     }
 
     public function modelAction($actionData = false)
@@ -116,7 +106,7 @@ class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator
                     if ( isset( $memberInfo['categories'] ) ) {
                         $cats = array();
                         foreach ( $memberInfo['categories'] as $cat ) {
-                            $cats[] = $cat['name'];
+                            $cats[] = $cat['parent_name'] . '/' . $cat['name'];
                         }
                         $categories = implode( '|', $cats );
                     }
@@ -133,12 +123,18 @@ class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator
                         'member-type'     => 'Member',
                     );
                     //echo '<pre>$contactData: ' . print_r( $contactData, true ) . '</pre>';
+                    //break;
                     if ( $ret->contact ) {
-                        echo '<pre>$ret->contact: ' . print_r( $ret->contact, true ) . '</pre>';
+                        //echo '<pre>$ret->contact: ' . print_r( $ret->contact, true ) . '</pre>';
                         if ( $memberInfo['status']['value'] == 10 ) {
                             // Update Contact if member is active
+                            $streamsend->contactUpdate(
+                                $ret->contact->id,
+                                $contactData
+                            );
                         } else {
                             // Delete Contact if member is inactive
+                            $streamsend->contactDelete( $memberInfo['email'] );
                         }
                     } else {
                         // Add Contact if member is active
@@ -155,18 +151,60 @@ class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator
 
                 break;
             case 'memberContact':
+                $memberContact = $actionData['memberContact']['fieldData'];
+                //echo '<pre>$memberContact: ' . print_r( $memberContact, true ) . '</pre>';
+                if ( isset( $memberContact['email'] ) && $memberContact['email'] ) {
+                    $ret = $streamsend->contactSearch( $memberContact['email'] );
+                    $contactData = array(
+                        'email-address'   => $memberContact['email'],
+                        'company'         => $memberContact['ref_dest_name'],
+                        'address1'        => $memberContact['addr1'],
+                        'address2'        => $memberContact['addr2'],
+                        'city'            => $memberContact['city']['name'],
+                        'stateprovince'   => $memberContact['state']['name'],
+                        'postal-code'     => $memberContact['zip'],
+                        'phone-number'    => $memberContact['office_phone'],
+                        'member-type'     => 'Member Contact',
+                    );
+                    if ( $ret->contact ) {
+                        echo '<pre>$ret->contact: ' . print_r( $ret->contact, true ) . '</pre>';
+                        if ( $memberContact['active']['value'] == 1 ) {
+                            // Update Contact if member is active
+                            $streamsend->contactUpdate(
+                                $ret->contact->id,
+                                $contactData
+                            );
+                        } else {
+                            // Delete Contact if member is inactive
+                            $streamsend->contactDelete( $memberContact['email'] );
+                        }
+                    } else {
+                        // Add Contact if member is active
+                        if ( $memberContact['active']['value'] == 1 ) {
+                            $contacts = $streamsend->contactCreate(
+                                $contactData,
+                                STREAMSEND_DEFAULT_ACTIVATE,
+                                STREAMSEND_DEFAULT_DELIVER_ACTIVATION,
+                                STREAMSEND_DEFAULT_DELIVER_WELCOME
+                            );
+                        }
+                    }
+                }
+                break;
+            case 'deleteMemberInfo':
+                $memberInfo = $actionData['memberInfo']['fieldData'];
+                $streamsend->contactDelete( $memberInfo['email'] );
+                break;
+            case 'deleteMemberContact':
+                $memberContact = $actionData['memberContact']['fieldData'];
+                $streamsend->contactDelete( $memberContact['email'] );
                 break;
             }
         }
-        //echo '<pre>$config: ' . print_r( $config, true ) . '</pre>';
-
 
         return array(
             'status'        => true,
             'modelRedirect' => false,
         );
-
     }
-
-
 }
index 486e904..ae2c43f 100644 (file)
@@ -122,67 +122,83 @@ class GlmMembersAdmin_management_communicator extends GlmDataCommunicatorManagem
 
         switch ($option) {
 
-            case 'settings':
+        case 'sync':
+            echo '<p>Please stand by whilst we sync you!</p>';
+
+            // Determine if current user can edit configurations
+            if (!current_user_can('glm_members_management')) {
+                return array(
+                    'status'           => false,
+                    'menuItemRedirect' => 'error',
+                    'modelRedirect'    => 'index',
+                    'view'             => 'admin/error/index.html',
+                    'data'             => array(
+                        'reason' => 'User does not have rights to make configuration changes.'
+                    )
+                );
+            }
+            break;
+
+        case 'settings':
+
+        default:
+
+            // Make sure option is set if default
+            $option = 'settings';
+
+            // Determine if current user can edit configurations
+            if (!current_user_can('glm_members_management')) {
+                return array(
+                    'status'           => false,
+                    'menuItemRedirect' => 'error',
+                    'modelRedirect'    => 'index',
+                    'view'             => 'admin/error/index.html',
+                    'data'             => array(
+                        'reason' => 'User does not have rights to make configuration changes.'
+                    )
+                );
+            }
+
+            // Check for submission option
+            $option2 = '';
+            if (isset($_REQUEST['option2'])) {
+                $option2 = $_REQUEST['option2'];
+            }
+
+            switch($option2) {
+
+                // Update the settings and redisplay the form
+                case 'submit':
+
+                    // Update the event management settings
+                    $communicator_settings = $this->updateEntry(1);
+                    if ($communicator_settings['status']) {
+                        $settings_updated = true;
+                    } else {
+                        $settings_update_error = true;
+                    }
+
+                    break;
+
+                // Default is to get the current settings and display the form
+                default:
+
+
+                    break;
+
+            }
+
+            break;
 
-            default:
-
-                // Make sure option is set if default
-                $option = 'settings';
-
-                // Determine if current user can edit configurations
-                if (!current_user_can('glm_members_management')) {
-                    return array(
-                        'status'           => false,
-                        'menuItemRedirect' => 'error',
-                        'modelRedirect'    => 'index',
-                        'view'             => 'admin/error/index.html',
-                        'data'             => array(
-                            'reason' => 'User does not have rights to make configuration changes.'
-                        )
-                    );
-                }
-
-                // Check for submission option
-                $option2 = '';
-                if (isset($_REQUEST['option2'])) {
-                    $option2 = $_REQUEST['option2'];
-                }
-
-                switch($option2) {
-
-                    // Update the settings and redisplay the form
-                    case 'submit':
-
-                        // Update the event management settings
-                        $communicator_settings = $this->updateEntry(1);
-                        if ($communicator_settings['status']) {
-                            $settings_updated = true;
-                        } else {
-                            $settings_update_error = true;
-                        }
-
-                        break;
-
-                    // Default is to get the current settings and display the form
-                    default:
-
-                        // Try to get the first (should be only) entry for general settings.
-                        $communicator_settings = $this->editEntry(1);
-                        //echo '<pre>$communicator_settings: ' . print_r( $communicator_settings, true ) . '</pre>';
-
-                        if ($communicator_settings === false) {
-
-                            if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
-                                glmMembersAdmin::addNotice("<b>&nbsp;&nbsp;/models/admin/management/communicator.php: Unable to load communicator management settings.", 'Alert');
-                            }
-
-                        }
-
-                        break;
+        }
 
-                }
+        // Try to get the first (should be only) entry for general settings.
+        $communicator_settings = $this->editEntry(1);
 
-                break;
+        if ($communicator_settings === false) {
+            if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+                glmMembersAdmin::addNotice("<b>&nbsp;&nbsp;/models/admin/management/communicator.php: Unable to load communicator management settings.", 'Alert');
+            }
 
         }
 
@@ -191,10 +207,10 @@ class GlmMembersAdmin_management_communicator extends GlmDataCommunicatorManagem
 
         // Compile template data
         $template_data = array(
-            'option'              => $option,
-            'settingsUpdated'     => $settings_updated,
-            'settingsUpdateError' => $settings_update_error,
-            'communicatorSettings'  => $communicator_settings,
+            'option'               => $option,
+            'settingsUpdated'      => $settings_updated,
+            'settingsUpdateError'  => $settings_update_error,
+            'communicatorSettings' => $communicator_settings,
         );
 
         // Return status, suggested view, and data to controller
index 6ac8206..4855588 100644 (file)
   */
 // Adding Action for when the memberInfo record is saved (new or update)
 add_action('glm-member-db-memberinfosave', function($member){
-    $memberData = array(
+    $this->controller( 'communicator', 'index', array(
         'type'       => 'memberInfo',
         'memberInfo' => $member
-    );
-    $this->controller( 'communicator', 'index', $memberData );
-}, 10, 2);
+    ) );
+}, 10, 1);
 
 // Adding Action for when the Member Contact record is saved (new or update)
 add_action('glm-member-db-membercontactsave', function($contact){
-    // Code here for hook
-    echo '<p>Contact action hook</p>';
-    echo '<pre>$contact: ' . print_r( $contact, true ) . '</pre>';
+    $this->controller( 'communicator', 'index', array(
+        'type'          => 'memberContact',
+        'memberContact' => $contact
+    ) );
 }, 10, 1);
index 76f87d9..292a4d1 100644 (file)
@@ -22,7 +22,7 @@ CREATE TABLE {prefix}management (
     enable_constant_contact BOOLEAN NULL,       -- Constant Contact On Off Flag
     constant_contact_password TINYTEXT NULL,    -- Constant Contact Password
     constant_contact_api_key TINYTEXT NULL,     -- Constant Contact API Key
-    constant_contact_login TINYTEXT NULL,      -- Constant Contact Login
+    constant_contact_login TINYTEXT NULL,       -- Constant Contact Login
     constant_contact_api_path TINYTEXT NULL,    -- Constant Contact API Path
     constant_contact_list TINYTEXT NULL,        -- Constant Contact List ID
     enable_mailchimp BOOLEAN NULL,              -- MailChimp On Off
@@ -39,3 +39,16 @@ INSERT INTO {prefix}management
    VALUES
     ( 1, false, false, false )
 ;
+
+----
+
+-- StreamSend Cache Table
+CREATE TABLE {prefix}streamsend_cache (
+    id INT NOT NULL AUTO_INCREMENT,
+    field_id INT NOT NULL,                      -- Field id for Member Category
+    field_name TINYTEXT NOT NULL,               -- Field Name from StreamSend
+    option_id INT NOT NULL,                     -- StreamSend field id
+    option_name TINYTEXT NOT NULL,              -- StreamSend option name
+    category_id INT NOT NULL,                   -- Member Category id
+    PRIMARY KEY (id)
+);
index 03a3548..0537496 100644 (file)
@@ -14,6 +14,6 @@
  */
 
 $glmMembersCommunicatorDbVersions = array(
-    '0.0.1' => array('version' => '0.0.1', 'tables' => 1),
+    '0.0.1' => array('version' => '0.0.1', 'tables' => 2),
 );
 
index 95b932b..00e9762 100644 (file)
@@ -7,6 +7,20 @@
     <!-- Management Settings -->
 
     <table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option!='settings'} glm-hidden{/if}">
+        <tr>
+            <td>
+                <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                    <input type="hidden" name="glm_action" value="communicator">
+                    <input type="hidden" name="option" value="sync">
+                    <table class="glm-admin-table">
+                        <tr>
+                            <td colspan="2"><h3>Sync StreamSend</h3></td>
+                        </tr>
+                    </table>
+                    <input type="submit" value="Sync" class="button-primary">
+                </form>
+            </td>
+        </tr>
         <tr>
             <td colspan="2">
                 {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}