Setup crons for notifications and paging and search on invoices.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 17 Jan 2018 21:54:08 +0000 (16:54 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 17 Jan 2018 21:54:08 +0000 (16:54 -0500)
Starting setup of paging and search on invoices.
setup two cron task (admin ajax).
one for setupQueue
one for runQueue
Have to be unique names.

classes/data/dataNotifications.php [new file with mode: 0644]
classes/notifications.php
models/admin/ajax/runQueue.php
models/admin/ajax/setupQueue.php
models/admin/billing/invoices.php
models/admin/billing/logs.php [new file with mode: 0644]
setup/validActions.php
views/admin/billing/header.html
views/admin/billing/invoices.html
views/admin/billing/logs.html [new file with mode: 0644]

diff --git a/classes/data/dataNotifications.php b/classes/data/dataNotifications.php
new file mode 100644 (file)
index 0000000..c24fea0
--- /dev/null
@@ -0,0 +1,206 @@
+<?php
+/**
+ * GLM Member-DB WordPress Add-On Plugin
+ * Data Class Management
+ *
+ * PHP version 5.3
+ *
+ * @category Data
+ * @package  GLM Member-DB
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  SVN: $Id: dataEvents.php,v 1.0 2011/01/25 19:31:47 cscott Exp $
+ */
+
+/**
+ * GlmDataBillingManagement class
+ *
+ * PHP version 5
+ *
+ * @category Data
+ * @package GLM Member DB
+ * @author  Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ *          @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott
+ *          Exp $
+ */
+class GlmDataNotifications extends GlmDataAbstract
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Data Table Name
+     *
+     * @var $table
+     * @access public
+     */
+    public $table;
+    /**
+     * Field definitions
+     *
+     * 'type' is type of field as defined by the application
+     * text Regular text field
+     * pointer Pointer to an entry in another table
+     * 'filters' is the filter name for a particular filter ID in PHP filter
+     * functions
+     * See PHP filter_id()
+     *
+     * 'use' is when to use the field
+     * l = List
+     * g = Get
+     * n = New
+     * i = Insert
+     * e = Edit
+     * u = Update
+     * d = Delete
+     * a = All
+     *
+     * @var $ini
+     * @access public
+     */
+    public $fields = false;
+
+    /**
+     * Constructor
+     *
+     * @param object $d database connection
+     * @param array $config Configuration array
+     * @param bool $limitedEdit Flag to say indicate limited edit requested
+     *
+     * @return void
+     * @access public
+     */
+    public function __construct($wpdb, $config, $limitedEdit = false)
+    {
+
+        // If this class is not being extended along with existing $wpdb and $config
+        if (!$this->wpdb) {
+
+            // Save WordPress Database object
+            $this->wpdb = $wpdb;
+
+            // Save plugin configuration object
+            $this->config = $config;
+
+        }
+
+        /*
+         * Table Name
+         */
+        $this->table = GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'notifications';
+
+        /*
+         * Table Data Fields
+         */
+
+        $this->fields = array (
+
+            'id' => array (
+                'field'     => 'id',
+                'type'      => 'integer',
+                'view_only' => true,
+                'use'       => 'a',
+            ),
+
+            'notification_type' => array(
+                'field'     => 'notification_type',
+                'type'       => 'pointer',
+                'p_table'    => GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX .  'notification_types',
+                'p_field'    => 'id',
+                'p_orderby'  => 'name',
+                'p_blank'    => true,
+                'force_list' => true,
+                'required'   => false,
+                'use'        => 'a'
+            ),
+
+            // Account ref to accounts table
+            'account' => array(
+                'field'      => 'account',
+                'type'       => 'pointer',
+                'p_table'    => GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX .  'accounts',
+                'p_field'    => 'ref_dest',
+                'p_orderby'  => 'ref_name',
+                'p_blank'    => true,
+                'force_list' => true,
+                'required'   => false,
+                'use'        => 'a'
+            ),
+
+            // Amount Total
+            'subject' => array(
+                'field' => 'subject',
+                'type'  => 'text',
+                'use'   => 'a',
+            ),
+
+            // Payment Method
+            'message' => array(
+                'field'   => 'message',
+                'type'    => 'text',
+                'use'     => 'a',
+            ),
+
+            // Date Sent
+            'date_sent' => array(
+                'field' => 'date_sent',
+                'type'  => 'date',
+                'use'   => 'a',
+            ),
+
+
+            // Payment Data
+            'email_sent' => array(
+                'field'   => 'email_sent',
+                'type'    => 'text',
+                'use'     => 'a',
+            ),
+
+         );
+
+
+    }
+
+    /*
+     * Entry Post Processing Call-Back Method
+     *
+     * Perform post-processing for all result entries.
+     *
+     * In this case we're using it to append an array of category
+     * data to each member result and also sort by member name.
+     *
+     * @param array $r Array of field result data for a single entry
+     * @param string $a Action being performed (l, i, g, ...)
+     *
+     * @return object Class object
+     *
+     */
+    public function entryPostProcessing($r, $a)
+    {
+        $r['member_name'] = $this->wpdb->get_var(
+            $this->wpdb->prepare(
+                "SELECT A.ref_name
+                   FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notifications N
+                   LEFT OUTER JOIN " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts A ON ( N.account = A.id )
+                  WHERE N.id = %d",
+                $r['id']
+            )
+        );
+        return $r;
+    }
+
+
+}
index 90b8f83..fc821d0 100644 (file)
@@ -383,16 +383,24 @@ class GlmNotifications
     /**
      * getQueuedNotifications
      *
-     * Grab all queued notifications.
+     * Grab queued notifications. Number is based on input.
+     * If nothing given then defaults to all queued notifications.
+     *
+     * @param int $limit Number of queued items to fetch.
      *
      * @access public
      * @return array
      */
-    public function getQueuedNotifications()
+    public function getQueuedNotifications( $limit )
     {
+        $query =
+        "SELECT *
+           FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_queue";
+        if ( $numb = filter_var( $limit, FILTER_VALIDATE_INT ) ) {
+            $query .= " LIMIT $limit OFFSET 0";
+        }
         return $this->wpdb->get_results(
-            "SELECT *
-               FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_queue",
+            $query,
             ARRAY_A
         );
     }
index 2e4c5d4..d6c2a5c 100644 (file)
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php';
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php';
 /**
- * Steve Note...
+ * Steve Note
  *
  * You can get to this using the following URL.
  *
- * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=runCron
+ *
+ {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=runQueue
  *
  * You should be able to do this as POST or GET and should be able to add and read additional parameters.
  * I added a "mystuff" parameter to the URL above and it does output from the code in the
index 5e495ea..be12d8b 100644 (file)
@@ -20,7 +20,7 @@ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php';
  *
  * You can get to this using the following URL.
  *
- * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=runCron
+ * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=setupQueue
  *
  * You should be able to do this as POST or GET and should be able to add and read additional parameters.
  * I added a "mystuff" parameter to the URL above and it does output from the code in the
index ae10eee..c2cef43 100644 (file)
@@ -119,6 +119,8 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
         $invoiceTypeJSON     = '';
         $accounts            = false;
         $invoiceHtml         = '';
+        $fromDate            = '';
+        $toDate              = '';
 
         // Get any provided option
         if (isset($_REQUEST['option'])) {
@@ -363,7 +365,6 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             'invoiceAdded'        => $invoiceAdded,
             'invoiceAddError'     => $invoiceAddError,
             'invoiceInsertError'  => $invoiceInsertError,
-            // 'numbTransactions' => $numbTransactions,
             'invoiceDeleted'      => $invoiceDeleted,
             'invoiceDeleteError'  => $invoiceDeleteError,
             'invoiceInvoiceError' => $invoiceDeleteError,
@@ -378,6 +379,8 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             'invoiceTypes'        => $invoiceTypes,
             'accounts'            => $accounts,
             'invoiceHtml'         => $invoiceHtml,
+            'fromDate'            => $fromDate,
+            'toDate'              => $toDate,
         );
 
         // Return status, any suggested view, and any data to controller
diff --git a/models/admin/billing/logs.php b/models/admin/billing/logs.php
new file mode 100644 (file)
index 0000000..425ce34
--- /dev/null
@@ -0,0 +1,218 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Transactions List
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Contacts data class
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataNotifications.php';
+
+class GlmMembersAdmin_billing_logs extends GlmDataNotifications
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /**
+     * Constructor
+     *
+     * This constructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successful and false if there was a fatal failure.
+     *
+     * '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.
+     *
+     * @wpdb object WordPress database object
+     *
+     * @return array Array containing status, suggested view, and any data
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        /*
+         * Run constructor for the Contacts 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)
+    {
+
+        $option        = 'list';
+        $haveLogs      = false;
+        $view          = 'logs';
+        $fromDate      = false;
+        $toDate        = false;
+        $numbDisplayed = false;
+        $lastDisplayed = false;
+        $paging        = true;
+        $prevStart     = false;
+        $nextStart     = false;
+        $start         = 1;
+        $limit         = 20;        // Set to the number of listings per page
+        $invTypes      = array();
+        $accounts      = false;
+
+        // Get any provided option
+        if (isset($_REQUEST['option'])) {
+            $option = $_REQUEST['option'];
+        }
+
+        // Do selected option
+        switch ($option) {
+
+        case 'list':
+        default:
+
+            $where = 'true';
+
+            // Check for paging
+            if ( isset( $_REQUEST['pageSelect'] ) ) {
+                $_SESSION['search']['pageSelect'] = $_REQUEST['pageSelect'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['pageSelect'] ) ) {
+                unset( $_SESSION['search']['pageSelect'] );
+            }
+            if ( isset( $_REQUEST['nextStart'] ) ) {
+                $_SESSION['search']['nextStart'] = $_REQUEST['nextStart'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['nextStart'] ) ) {
+                unset( $_SESSION['search']['nextStart'] );
+            }
+            if ( isset( $_REQUEST['prevStart'] ) ) {
+                $_SESSION['search']['prevStart'] = $_REQUEST['prevStart'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['prevStart'] ) ) {
+                unset( $_SESSION['search']['prevStart'] );
+            }
+
+            // Check if we're doing paging
+            if (isset($_REQUEST['pageSelect'])) {
+                // If request is for Next
+                if ($_REQUEST['pageSelect'][0] == 'N') {
+                    $newStart = $_REQUEST['nextStart'] - 0;
+
+                // Otherwise it must be Previous
+                } else {
+                    $newStart = $_REQUEST['prevStart'] - 0;
+                }
+
+                if ($newStart > 0) {
+                    $start = $newStart;
+                }
+            }
+
+            if( isset($_SESSION['search']['pageSelect']) ){
+                 // If request is for Next
+                if ($_SESSION['search']['pageSelect'][0] == 'N') {
+                    $newStart = $_SESSION['search']['nextStart'] - 0;
+
+                // Otherwise it must be Previous
+                } else {
+                    $newStart = $_SESSION['search']['prevStart'] - 0;
+                }
+                if ($newStart > 0) {
+                    $start = $newStart;
+                }
+            }
+
+            // Get the list of logs and determine number of logs in list
+            $orderBy = 'date_sent asc';
+            $logsResult = $this->getList($where, $orderBy, true, 'id', $start, $limit);
+            // echo '<pre>$logsResult: ' . print_r( $logsResult, true ) . '</pre>';
+
+            // Get paging results
+            $numbDisplayed = $logsResult['returned'];
+            $lastDisplayed = $logsResult['last'];
+            if ($start == 1) {
+                $prevStart = false;
+            } else {
+                $prevStart = $start - $limit;
+                if ($start < 1) {
+                    $start = 1;
+                }
+            }
+            if ($logsResult['returned'] == $limit) {
+                $nextStart = $start + $limit;
+            }
+
+            // since we're doing paging, we have to break out just the logs data
+            $logs = $logsResult['list'];
+            if (count($logs)>0) {
+                $haveLogs = true;
+            }
+            unset($logsResult);
+
+            // echo '<pre>$logs: ' . print_r( $logs, true ) . '</pre>';
+
+            break;
+
+        }
+
+
+        $templateData = array(
+            'option'        => $option,
+            'logs'          => $logs,
+            'haveLogs'      => $haveLogs,
+            'numbDisplayed' => $numbDisplayed,
+            'lastDisplayed' => $lastDisplayed,
+            'paging'        => $paging,
+            'prevStart'     => $prevStart,
+            'nextStart'     => $nextStart,
+            'start'         => $start = 1,
+            'limit'         => $limit,
+            'accounts'      => $accounts,
+        );
+
+        // Return status, any suggested view, and any data to controller
+        return array(
+            'status'        => true,
+            'modelRedirect' => false,
+            'view'          => "admin/billing/$view.html",
+            'data'          => $templateData
+        );
+
+    }
+
+}
index c63fd14..ad30ded 100644 (file)
@@ -76,6 +76,7 @@ $glmMembersBillingAddOnValidActions = array(
             'list'     => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'invoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'payments' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+            'logs'     => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
         ),
         'member' => array(
             'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
index 31289e7..9cdc580 100644 (file)
@@ -2,8 +2,12 @@
     <h2>Billing</h2>
     <h2 class="nav-tab-wrapper">
         <a href="{$thisUrl}?page=glm-members-admin-menu-billing" class="nav-tab{if $thisAction==index} nav-tab-active{/if}">Dashboard</a>
-        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices" class="nav-tab{if $thisAction==invoices} nav-tab-active{/if}">Invoices</a>
-        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=payments" class="nav-tab{if $thisAction==payments} nav-tab-active{/if}">Payments</a>
+        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices"
+            class="nav-tab{if $thisAction==invoices} nav-tab-active{/if}">Invoices</a>
+        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=payments"
+            class="nav-tab{if $thisAction==payments} nav-tab-active{/if}">Payments</a>
+        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=logs"
+            class="nav-tab{if $thisAction==logs} nav-tab-active{/if}">Logs</a>
     </h2>
     <div id="glm-admin-content-container">
 
index d08d59e..50574e8 100644 (file)
@@ -5,6 +5,45 @@
 
 <h2>Invoices</h2>
 
+<form action="{$thisUrl}?page={$thisPage}" method="post" id="searchForm">
+    <input type="hidden" name="glm_action" value="invoices">
+    <input type="hidden" name="option" value="list">
+
+    <input type="hidden" name="searched" value="1">
+    <input type="hidden" name="prevStart" value="{$prevStart}">
+    <input type="hidden" name="nextStart" value="{$nextStart}">
+    <input type="hidden" name="limit" value="{$limit}">
+
+        <div class="">
+            <p>
+                <span class="glm-nowrap">
+                    <b>From Date: </b><input type="text" name="fromDate" value="{$fromDate}" class="glm-form-text-input-short glm-date-input">
+                    <b>To Date: </b><input type="text" name="toDate" value="{$toDate}" class="glm-form-text-input-short glm-date-input">
+                </span>
+                <span class="glm-nowrap">
+                    <b>Member Account:&nbsp;</b>
+                    <select id="filterAccounts" name="filterAccounts">
+                        {foreach from=$accounts item=account}
+                            <option value="{$account.id}"{if $account.selected} selected{/if}>
+                                {$account.name}
+                            </option>
+                        {/foreach}
+                    </select>
+                </span>
+                <span class="glm-nowrap">
+                    <b>Text Search: </b><input  id="glmEventsSearch" name="textSearch" type="text" id="autoTest">
+                    <input type="submit" value="Submit">
+                </span>
+            <p>
+        </div>
+        <br clear="all">
+
+    {if $paging}
+        <input type="Submit" name="pageSelect" value="Previous {$limit} Events" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Next {$limit} Events" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+    {/if}
+        <br clear="all">
+
 <table class="wp-list-table widefat fixed posts glm-admin-table">
     <thead>
         <tr>
     </tbody>
 </table>
 
+    {if $paging}
+        <input type="Submit" name="pageSelect" value="Previous {$limit} Events" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Next {$limit} Events" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+    {/if}
+
+    </form>
+
 <script type="text/javascript">
     jQuery(document).ready(function($) {
 
+            // Date Input
+            $('.glm-date-input').datepicker();
+
     });
 </script>
 
diff --git a/views/admin/billing/logs.html b/views/admin/billing/logs.html
new file mode 100644 (file)
index 0000000..482d07f
--- /dev/null
@@ -0,0 +1,44 @@
+{include file='admin/billing/header.html'}
+
+
+<h2>Notification Logs</h2>
+
+<table class="wp-list-table widefat fixed posts glm-admin-table">
+    <thead>
+        <tr>
+            <th>ID</th>
+            <th>Date Sent</th>
+            <th>Subject</th>
+            <th>Member Name</th>
+            <th>Email</th>
+        </tr>
+    </thead>
+    <tbody>
+        {if $haveLogs}
+            {assign var="i" value="0"}
+            {foreach $logs as $t}
+                {if $i++ is odd by 1}
+                    <tr>
+                {else}
+                    <tr class="alternate">
+                {/if}
+                    <td> {$t.id} </td>
+                    <td> {$t.date_sent.date} </td>
+                    <td> {$t.subject} </td>
+                    <td> {$t.member_name} </td>
+                    <td> {$t.email_sent} </td>
+                </tr>
+            {/foreach}
+        {else}
+            <tr class="alternate"><td colspan="2">(no Invoice Types listed)</td></tr>
+        {/if}
+    </tbody>
+</table>
+
+<script type="text/javascript">
+    jQuery(document).ready(function($) {
+
+    });
+</script>
+
+{include file='admin/footer.html'}