From: Steve Sutton Date: Tue, 27 Sep 2016 17:27:18 +0000 (-0400) Subject: Adding dashboard for the member contact plugin X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=c49475b62148569158dd5dd86dee7a20e8f695e8;p=WP-Plugins%2Fglm-member-db-contacts.git Adding dashboard for the member contact plugin Shows list of 5 contacts. --- diff --git a/models/admin/contacts/index.php b/models/admin/contacts/index.php index f9bf4ab..11a4881 100644 --- a/models/admin/contacts/index.php +++ b/models/admin/contacts/index.php @@ -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 index 0000000..b7298d7 --- /dev/null +++ b/models/admin/dashboard/contacts.php @@ -0,0 +1,143 @@ + + * @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 '
$contactsList: ' . print_r( $contactsList, true ) . '
'; + 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 + ); + + } + +} diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 7fcc24a..ff39838 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -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 +); + +?> diff --git a/setup/validActions.php b/setup/validActions.php index 458862c..c4f8488 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -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 index 0000000..9cd13f8 --- /dev/null +++ b/views/admin/dashboard/contacts.html @@ -0,0 +1,32 @@ +
+
+

Contacts

+ + Add New {$terms.term_member_cap} Contact + +
+ + + + + + + + + {if $haveContacts} + {foreach $contactsList as $c} + + + + + + {/foreach} + {else} + + {/if} +
NameActivePrimary
+ {$c.lname}, {$c.fname} + {$c.active.name}{if $c.primary_contact.value}Yes{/if}
(no contacts listed)
+
+
+