Setting up the dashboard content for the leads.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 8 Sep 2016 20:31:32 +0000 (16:31 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 8 Sep 2016 20:31:32 +0000 (16:31 -0400)
Link to search form.
Link to the last search download.

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

diff --git a/models/admin/dashboard/leads.php b/models/admin/dashboard/leads.php
new file mode 100644 (file)
index 0000000..184c9a5
--- /dev/null
@@ -0,0 +1,153 @@
+<?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_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 '<pre>$last_search: ' . print_r( $last_search, true ) . '</pre>';
+                    $last_search_params = $last_search['search'];
+                    //echo '<pre>$last_search_params: ' . print_r( $last_search_params, true ) . '</pre>';
+                    $search_params = unserialize( $last_search_params );
+                    //echo '<pre>$search_params: ' . print_r( $search_params, true ) . '</pre>';
+                }
+            }
+
+        }
+
+        // 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
+        );
+
+    }
+
+}
index 191d4d6..c74faaa 100644 (file)
  *
  *  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
+);
index 8d96b85..a2116e2 100644 (file)
@@ -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 (file)
index 0000000..ec9ea0d
--- /dev/null
@@ -0,0 +1,17 @@
+<div class="glm-widget-container">
+    <div class="glm-widget">
+        <h2>
+            <span>Leads</span>
+        </h2>
+        <div class="glm-widget-content">
+            {if $hasLastDownload}
+            <h3>Last Download Available</h3>
+            {$lastSearchDate|date_format:"%m/%d/%Y"}
+            <a href="{$thisUrl}?page=glm-members-admin-menu-leads-index">Search Again</a>
+            <a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=csvExport">Download</a>
+            {else}
+            <h3>Search for leads</h3>
+            {/if}
+        </div>
+    </div>
+</div>