Adding dashboard for the member contact plugin
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 27 Sep 2016 17:27:18 +0000 (13:27 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 27 Sep 2016 17:27:18 +0000 (13:27 -0400)
Shows list of 5 contacts.

models/admin/contacts/index.php
models/admin/dashboard/contacts.php [new file with mode: 0644]
setup/adminHooks.php
setup/validActions.php
views/admin/dashboard/contacts.html [new file with mode: 0644]

index f9bf4ab..11a4881 100644 (file)
@@ -660,7 +660,6 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts
             'haveFilter' => $haveFilter,
             'userDeleted' => $userDeleted,
             'wpUserDeleted' => $wpUserDeleted,
-
             'numbDisplayed' => $numbDisplayed,
             'lastDisplayed' => $lastDisplayed,
             'paging' => $paging,
@@ -674,10 +673,10 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts
 
         // Return status, any suggested view, and any data to controller
         return array(
-                'status' => true,
-                'modelRedirect' => false,
-                'view' => 'admin/contacts/'.$view,
-                'data' => $templateData
+            'status' => true,
+            'modelRedirect' => false,
+            'view' => 'admin/contacts/'.$view,
+            'data' => $templateData
         );
 
     }
@@ -720,4 +719,4 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts
     }
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/models/admin/dashboard/contacts.php b/models/admin/dashboard/contacts.php
new file mode 100644 (file)
index 0000000..b7298d7
--- /dev/null
@@ -0,0 +1,143 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin Members Dashboard
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Steve Sutton <steve@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataContacts.php';
+
+/**
+ * Dashboard Class Model
+ *
+ * Each Add-On can have one or more dashboards.
+ */
+
+class GlmMembersAdmin_dashboard_contacts extends GlmDataContacts
+{
+    /**
+     * Word Press Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /**
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    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 );
+
+    }
+
+    /**
+     * Perform Model Action
+     *
+     * This method does the work for this model and returns any resulting data
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successful and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * 'view'
+     *
+     * A suggested view name that the controller 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.
+     *
+     */
+    public function modelAction( $actionData = false )
+    {
+
+        $success      = true;
+        $haveContacts = false;
+        $contactsList = false;
+        $memberID     = false;
+        $where        = '';
+
+        // Get list of member contacts.
+        if ( isset( $this->config['loggedInUser']['contactUser']['ref_dest'] )
+            && $memberID = filter_var( $this->config['loggedInUser']['contactUser']['ref_dest'], FILTER_VALIDATE_INT )
+        ) {
+            $where = "ref_type = " . $this->config['ref_type_numb']['Member'] . ' AND ref_dest = ' . $memberID;
+            // Get list of contacts
+            $contactsList = $this->getSimplified( $where, false, 'lname, fname', true, 'id', 1, 5 );
+            //echo '<pre>$contactsList: ' . print_r( $contactsList, true ) . '</pre>';
+            if ( $contactsList != false ) {
+
+                // Get paging results
+                if ( count($contactsList ) > 0) {
+                    $haveContacts = true;
+                }
+
+            }
+        }
+
+        // Compile template data.
+        $templateData = array(
+            'memberID'     => $memberID,
+            'haveContacts' => $haveContacts,
+            'contactsList' => $contactsList['list'],
+        );
+
+        // Return status, suggested view, and data to controller.
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/dashboard/contacts.html',
+            'data'             => $templateData
+        );
+
+    }
+
+}
index 7fcc24a..ff39838 100644 (file)
@@ -44,4 +44,14 @@ add_filter('glm-member-db-admin-management-hooksHelp', function($content) {
     2
 );
 
-?>
\ No newline at end of file
+add_filter(
+    'glm-member-db-dashboard-member-widgets',
+    function( $member = null ) {
+        $content = $this->controller( 'dashboard', 'contacts', $member );
+        return $content;
+    },
+    11,
+    1
+);
+
+?>
index 458862c..c4f8488 100644 (file)
@@ -46,11 +46,14 @@ $glmMembersContactsAddOnValidActions = array(
         ),
         'management' => array(
             'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
-        )
+        ),
+        'dashboard' => array(
+            'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
+        ),
     ),
     'frontActions' => array(
     )
 );
 
 
-?>
\ No newline at end of file
+?>
diff --git a/views/admin/dashboard/contacts.html b/views/admin/dashboard/contacts.html
new file mode 100644 (file)
index 0000000..9cd13f8
--- /dev/null
@@ -0,0 +1,32 @@
+<div class="glm-widget-container">
+    <div class="glm-widget">
+        <h2><span>Contacts</span></h2>
+        <span class="glm-right">
+        <a href="{$thisUrl}?page={$thisPage}&glm_action=contacts&member={$memberID}&option=create" class="button button-primary glm-button glm-right">Add New {$terms.term_member_cap} Contact</a>
+        </span>
+        <div class="glm-widget-content">
+            <table class="striped glm-admin-table">
+                <thead>
+                    <tr>
+                        <th>Name</th>
+                        <th>Active</th>
+                        <th>Primary</th>
+                    </tr>
+                </thead>
+            {if $haveContacts}
+                {foreach $contactsList as $c}
+                <tr>
+                    <td class="glm-shrink">
+                        <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=contacts&option=edit&member={$c.ref_dest}&contact={$c.id}">{$c.lname}, {$c.fname}</a>
+                    </td>
+                    <td class="glm-shrink">{$c.active.name}</td>
+                    <td class="glm-shrink">{if $c.primary_contact.value}Yes{/if}</td>
+                </tr>
+                {/foreach}
+            {else}
+                <tr class="alternate"><td colspan="7">(no contacts listed)</td></tr>
+            {/if}
+            </table>
+        </div>
+    </div>
+</div>