From: Steve Sutton Date: Thu, 8 Sep 2016 20:31:32 +0000 (-0400) Subject: Setting up the dashboard content for the leads. X-Git-Tag: v1.1.0^2~1^2~8 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=3ca073a3667ee7d2f812d87e408f2516e5af47e5;p=WP-Plugins%2Fglm-member-db-leads.git Setting up the dashboard content for the leads. Link to search form. Link to the last search download. --- diff --git a/models/admin/dashboard/leads.php b/models/admin/dashboard/leads.php new file mode 100644 index 0000000..184c9a5 --- /dev/null +++ b/models/admin/dashboard/leads.php @@ -0,0 +1,153 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataEvents.php'; + +/** + * Dashboard Class Model + * + * Each Add-On can have one or more dashboards. + */ + +class GlmMembersAdmin_dashboard_leads // extends GlmDataEvents +{ + /** + * 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; + $hasLastDownload = false; + $lastSearchDate = ''; + + // Get list of member events. + if ( isset( $this->config['loggedInUser']['contactUser']['ref_dest'] ) + && $memberID = filter_var( $this->config['loggedInUser']['contactUser']['ref_dest'], FILTER_VALIDATE_INT) + ) { + // See if this member has a saved search. + // If the do not then give message about it. + $user_id = $this->config['loggedInUser']['contactUser']['ID']; + if ( $user_id ) { + $last_search = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "searches + WHERE user_id = %d", + $user_id + ), + ARRAY_A + ); + if ( $last_search ) { + $hasLastDownload = true; + $lastSearchDate = $last_search['date_created']; + //echo '
$last_search: ' . print_r( $last_search, true ) . '
'; + $last_search_params = $last_search['search']; + //echo '
$last_search_params: ' . print_r( $last_search_params, true ) . '
'; + $search_params = unserialize( $last_search_params ); + //echo '
$search_params: ' . print_r( $search_params, true ) . '
'; + } + } + + } + + // Compile template data. + $templateData = array( + 'lastSearchDate' => $lastSearchDate, + 'hasLastDownload' => $hasLastDownload, + 'memberID' => $memberID, + ); + + // Return status, suggested view, and data to controller. + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/dashboard/leads.html', + 'data' => $templateData + ); + + } + +} diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 191d4d6..c74faaa 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -25,14 +25,24 @@ * * Also note that parameters will be in the context of the main admin controller constructor. */ +if ( current_user_can( 'glm_members_members' ) ) { + function ts_dashboard_1( $post, $callback_args ) { + echo 'Hello Test Test!!'; + } -function ts_dashboard_1( $post, $callback_args ) { - echo 'Hello Test Test!!'; -} + function add_ts_dashboard() { + wp_add_dashboard_widget( 'dashboard_widget', 'Example Dashboard Widget', 'ts_dashboard_1' ); + } -function add_ts_dashboard() { - wp_add_dashboard_widget( 'dashboard_widget', 'Example Dashboard Widget', 'ts_dashboard_1' ); + add_action( 'wp_dashboard_setup', 'add_ts_dashboard' ); } -add_action( 'wp_dashboard_setup', 'add_ts_dashboard' ); - +add_filter( + 'glm-member-db-dashboard-member-widgets', + function ( $member = null ) { + $content .= $this->controller( 'dashboard', 'leads', $member ); + return $content; + }, + 11, + 1 +); diff --git a/setup/validActions.php b/setup/validActions.php index 8d96b85..a2116e2 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -36,6 +36,9 @@ $glmMembersLeadsAddOnValidActions = array( 'csvExport' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, 'statCollector' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, ), + 'dashboard' => array( + 'leads' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, + ), 'leads' => array( 'index' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, 'edit' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, diff --git a/views/admin/dashboard/leads.html b/views/admin/dashboard/leads.html new file mode 100644 index 0000000..ec9ea0d --- /dev/null +++ b/views/admin/dashboard/leads.html @@ -0,0 +1,17 @@ +
+
+

+ Leads +

+
+ {if $hasLastDownload} +

Last Download Available

+ {$lastSearchDate|date_format:"%m/%d/%Y"} + Search Again + Download + {else} +

Search for leads

+ {/if} +
+
+