From: Steve Sutton Date: Wed, 17 Jan 2018 21:54:08 +0000 (-0500) Subject: Setup crons for notifications and paging and search on invoices. X-Git-Tag: v1.0.0^2~176 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=8207131b4e3e720478d77473e666ecdd18cb48f1;p=WP-Plugins%2Fglm-member-db-billing.git Setup crons for notifications and paging and search on invoices. 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. --- diff --git a/classes/data/dataNotifications.php b/classes/data/dataNotifications.php new file mode 100644 index 0000000..c24fea0 --- /dev/null +++ b/classes/data/dataNotifications.php @@ -0,0 +1,206 @@ + + * @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 + * @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; + } + + +} diff --git a/classes/notifications.php b/classes/notifications.php index 90b8f83..fc821d0 100644 --- a/classes/notifications.php +++ b/classes/notifications.php @@ -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 ); } diff --git a/models/admin/ajax/runQueue.php b/models/admin/ajax/runQueue.php index 2e4c5d4..d6c2a5c 100644 --- a/models/admin/ajax/runQueue.php +++ b/models/admin/ajax/runQueue.php @@ -16,11 +16,12 @@ 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 diff --git a/models/admin/ajax/setupQueue.php b/models/admin/ajax/setupQueue.php index 5e495ea..be12d8b 100644 --- a/models/admin/ajax/setupQueue.php +++ b/models/admin/ajax/setupQueue.php @@ -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 diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index ae10eee..c2cef43 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -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 index 0000000..425ce34 --- /dev/null +++ b/models/admin/billing/logs.php @@ -0,0 +1,218 @@ + + * @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 '
$logsResult: ' . print_r( $logsResult, true ) . '
'; + + // 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 '
$logs: ' . print_r( $logs, true ) . '
'; + + 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 + ); + + } + +} diff --git a/setup/validActions.php b/setup/validActions.php index c63fd14..ad30ded 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -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, diff --git a/views/admin/billing/header.html b/views/admin/billing/header.html index 31289e7..9cdc580 100644 --- a/views/admin/billing/header.html +++ b/views/admin/billing/header.html @@ -2,8 +2,12 @@

Billing

diff --git a/views/admin/billing/invoices.html b/views/admin/billing/invoices.html index d08d59e..50574e8 100644 --- a/views/admin/billing/invoices.html +++ b/views/admin/billing/invoices.html @@ -5,6 +5,45 @@

Invoices

+
+ + + + + + + + +
+

+ + From Date: + To Date: + + + Member Account:  + + + + Text Search: + + +

+

+
+ + {if $paging} + + + {/if} +
+ @@ -39,9 +78,19 @@
+ {if $paging} + + + {/if} + +
+ diff --git a/views/admin/billing/logs.html b/views/admin/billing/logs.html new file mode 100644 index 0000000..482d07f --- /dev/null +++ b/views/admin/billing/logs.html @@ -0,0 +1,44 @@ +{include file='admin/billing/header.html'} + + +

Notification Logs

+ + + + + + + + + + + + + {if $haveLogs} + {assign var="i" value="0"} + {foreach $logs as $t} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + + + + {/foreach} + {else} + + {/if} + +
IDDate SentSubjectMember NameEmail
{$t.id} {$t.date_sent.date} {$t.subject} {$t.member_name} {$t.email_sent}
(no Invoice Types listed)
+ + + +{include file='admin/footer.html'}