Still working on it.
* @param mixed $account Id of the account.
*
* @access public
- * @return void
+ * @return array
*/
public function getUnPaidInvoicesByAccount( $account )
{
);
}
+ /**
+ * getUnPaidInvoices
+ *
+ * Get All Un Paid Invoices
+ *
+ * @access public
+ * @return array
+ */
+ public function getUnPaidInvoices()
+ {
+ return $this->wpdb->get_results(
+ "SELECT *
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
+ WHERE paid <> true
+ ORDER BY transaction_time ASC",
+ ARRAY_A
+ );
+ }
+
/**
* getPaymentById
*
/**
* getNotificationsByType
*
- * @param mixed $type Type of send_action (10: Create Invoice, 20: Received Payment)
+ * @param mixed $type Type of send_action ('Create Invoice', 'Received Payment')
*
* @access public
* @return void
*/
public function getNotificationsByType( $type )
{
- echo '<pre>$this->config: ' . print_r( $this->config['send_action_numb'], true ) . '</pre>';
return $this->wpdb->get_results(
$this->wpdb->prepare(
"SELECT id
);
}
+ /**
+ * getNotificationsWithSendByAction
+ *
+ * Return array of notifications with send_by_action as $type
+ *
+ * @param mixed $type Type of send_by_action ('Create Invoice', 'Payment Received')
+ *
+ * @access public
+ * @return array
+ */
+ public function getNotificationsWithSendByAction( $type )
+ {
+ return $this->wpdb->get_results(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_types
+ WHERE send_by_action
+ AND send_action = %d",
+ $this->config['send_action_numb'][$type]
+ ),
+ ARRAY_A
+ );
+ }
+
+ /**
+ * getNotificationsWithSendByDate
+ *
+ * Return array of notifications with send_by_date
+ *
+ * @access public
+ * @return void
+ */
+ public function getNotificationsWithSendByDate()
+ {
+ return $this->wpdb->get_results(
+ "SELECT *
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_types
+ WHERE send_by_date",
+ ARRAY_A
+ );
+ }
+
/**
* getNotificationTypeById
*
; Send Date When
send_date_when[10] = "Before"
send_date_when[20] = "After"
+
+send_date_when_numb['Before'] = 10
+send_date_when_numb['After'] = 20
}
define('GLM_MEMBERS_BILLING_PLUGIN_HOST', $host);
+// Cron defines
+define( 'GLM_MEMBERS_BILLING_PLUGIN_CRON_HOOK', 'glm_members_billing_notifications' );
+define( 'GLM_MEMBERS_BILLING_PLUGIN_CRON_RECURRANCE', 'twicedaily' );
+
// Determine current http/https protocol
$pageProtocol = 'http';
if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') {
}
/*
-* Some initial setup and tests
-*/
+ * Some initial setup and tests
+ */
$startupNotices = '';
function glmMembersBillingPluginRequired() {
echo '
<div class="error">
- <p>The '.GLM_MEMBERS_BILLING_PLUGIN_NAME.' add-on requires the base GLM Member DB plugin to be installed and active!</p>
- <p>The '.GLM_MEMBERS_BILLING_PLUGIN_NAME.' plugin has been de-activated.</p>
+ <p>The '.GLM_MEMBERS_BILLING_PLUGIN_NAME.' add-on requires the base GLM Member DB plugin to be installed and active!</p>
+ <p>The '.GLM_MEMBERS_BILLING_PLUGIN_NAME.' plugin has been de-activated.</p>
</div>
- ';
+ ';
}
$plugin_name = 'glm-member-db/index.php';
$is_active = is_plugin_active($plugin_name);
function glmMembersBillingMinVerRequired() {
echo '
<div class="error">
- <p>The '.GLM_MEMBERS_BILLING_PLUGIN_NAME.' requires that the main GLM Member DB plugin version be no older than '
- .GLM_MEMBERS_BILLING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION.'!<br>
- '.GLM_MEMBERS_BILLING_MIN_VERSION_NOTE.'</p>
- <p>The '.GLM_MEMBERS_BILLING_PLUGIN_NAME.' plugin has been de-activated.</p>
+ <p>The '.GLM_MEMBERS_BILLING_PLUGIN_NAME.' requires that the main GLM Member DB plugin version be no older than '
+ .GLM_MEMBERS_BILLING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION.'!<br>
+ '.GLM_MEMBERS_BILLING_MIN_VERSION_NOTE.'</p>
+ <p>The '.GLM_MEMBERS_BILLING_PLUGIN_NAME.' plugin has been de-activated.</p>
</div>
- ';
+ ';
}
$glmMembersDatabasePluginVersion = get_option('glmMembersDatabasePluginVersion');
if (version_compare($glmMembersDatabasePluginVersion, GLM_MEMBERS_BILLING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION) < 0) {
// Load Add-On Management Settings data
/* None - Need to figure out a smooth way to do this.
-*/
+ */
$glmMembersBillingSettings = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX."settings WHERE id = 1", ARRAY_A );
unset($glmMembersBillingSettings['id']);
${GLM_MEMBERS_BILLING_PLUGIN_PREFIX."updateChecker"}->declareCredentials(array(
'license_key' => __('License Key:')
));
-*/
+ */
/*
- *
- * Activate and Deactivate hooks
- *
+ *
+ * Activate and Deactivate hooks
+ *
*/
- // Activate
- function glmMembersBillingPluginActivate ()
- {
- global $wpdb, $config;
- require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/activate.php';
- new glmMembersBillingPluginActivate($wpdb, $config);
- }
- register_activation_hook(__FILE__, 'glmMembersBillingPluginActivate');
-
- // Deactivate
- function glmMembersBillingPluginDeactivate ()
- {
- global $wpdb, $config;
- require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/deactivate.php';
- $x = new glmMembersBillingPluginDeactivate($wpdb, $config);
- return false;
- }
- register_deactivation_hook(__FILE__, 'glmMembersBillingPluginDeactivate');
+// Activate
+function glmMembersBillingPluginActivate ()
+{
+ global $wpdb, $config;
+ require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/activate.php';
+ new glmMembersBillingPluginActivate($wpdb, $config);
+}
+register_activation_hook(__FILE__, 'glmMembersBillingPluginActivate');
+
+// Deactivate
+function glmMembersBillingPluginDeactivate ()
+{
+ global $wpdb, $config;
+ require_once GLM_MEMBERS_BILLING_PLUGIN_PATH . '/deactivate.php';
+ $x = new glmMembersBillingPluginDeactivate($wpdb, $config);
+ return false;
+}
+register_deactivation_hook(__FILE__, 'glmMembersBillingPluginDeactivate');
/*
* Hooks for testing capabilities provided by this add-on
*/
require_once GLM_MEMBERS_BILLING_PLUGIN_SETUP_PATH.'/permissions.php';
+/**
+ * Action for the cron tasks.
+ * This cannot be inside the controllers.
+ */
+add_action(
+ GLM_MEMBERS_BILLING_PLUGIN_CRON_HOOK,
+ function(){
+ trigger_error( print_r( $_REQUEST, true ) );
+ },
+ 10,
+ 1
+ );
--- /dev/null
+We discussed how to implement the notifications. We talked about the wordpress
+wp_cron stuff and haven't settled on if we'll use it. We may have to setup
+some cron task outside of wordpress. However if we do that then the plugin
+won't be very friendly to other developers who may purchase it.
+
+Two steps for setting up email notifications.
+1. Generate a list of notifications and store them into a db-table queue.
+2. Have a cron task (wp or otherwise) run every 5 or 10 minutes to go through
+the queue and send out a number of them each time.
+
+
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * PDF Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php';
+/**
+ * Steve Note...
+ *
+ * You can get to this using the following URL.
+ *
+ * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=pdfOutput&mystuff=THIS
+ *
+ * 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
+ * modelAction() function below.
+ *
+ * To add another model under models/admin/ajax all you need to do is create it and add it to the
+ * setup/validActions.php file.
+ *
+ */
+
+// Load Members data abstract
+// require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php';
+
+/**
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_runCron
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ public function __construct ($wpdb, $config)
+ {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ }
+
+ public function modelAction( $actionData = false ) {
+ // Get all notifications that are done by date.
+ $Notifications = new GlmNotifications( $this->wpdb, $this->config );
+ $notifications = $Notifications->getNotificationsWithSendByDate();
+ echo '<pre>$notifications: ' . print_r( $notifications, true ) . '</pre>';
+
+ // Get all invoices that are unpaid.
+ $billingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+ $unpaid_invoices = $billingSupport->getUnPaidInvoices();
+ echo '<pre>$unpaid_invoices: ' . print_r( $unpaid_invoices, true ) . '</pre>';
+
+ // Loop through the invoices and for each one see if any notices are to be sent out.
+ foreach ( $unpaid_invoices as $invoice ) {
+ $due_date = $invoice['due_date'];
+ $dueDate = new DateTime( $due_date );
+ echo '<pre>$dueDate 1: ' . print_r( $dueDate, true ) . '</pre>';
+
+ // Loop through the notifications and see if this unpaid one is due.
+ foreach ( $notifications as $notice ) {
+ // Is this before or after
+ switch ( $notice['send_date_when'] ) {
+ case $this->config['send_date_when_numb']['Before']:
+ echo '<p>Before</p>';
+ $dueDate->modify(
+ '-' . $notice['send_date_number'] . ' '.
+ $this->config['send_date_period'][$notice['send_date_period']] .
+ (($notice['send_date_number'] > 1) ? 's': '')
+
+ );
+ echo '<pre>$dueDate 2: ' . print_r( $dueDate, true ) . '</pre>';
+ break;
+ case $this->config['send_date_when_numb']['After']:
+ echo '<p>After</p>';
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ wp_die();
+ }
+}
* Currently this is just using a hard coded account id of 1.
* After the test it will call wp_die
*/
- // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
- // // Test
- // $notices = $Notifications->getNotificationsByType( 'Create Invoice' );
- // echo '<pre>$notices: ' . print_r( $notices, true ) . '</pre>';
- // if ( $notices ) {
- // foreach ( $notices as $notice ) {
- // $Notifications->sendEmailNotification( $notice['id'], 1 );
- // }
- // }
- // wp_die('here');
-
-
$notification_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT );
if ( $notification_id ) {
* Also note that parameters will be in the context of the main admin controller constructor.
*/
-add_action(
- 'glm-member-db-billing-create-invoice',
- function( $account ){
- // Need to get notification id's for all notifications that are done when invoice is created.
- $notices = $this->wpdb->get_results(
- $this->wpdb->prepare(
- "SELECT id
- FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_types
- WHERE send_action = %d",
- $this->config['send_action_numb']['Create Invoice']
- ),
- ARRAY_A
- );
- },
- 10,
- 1
-);
-
--- /dev/null
+<?php
+/**
+ * GLM Members Billing
+ * GLM Members Misc Admin Hooks and Filters
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release adminHooks.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+/*
+ * Place Misc Hooks and Filters here. If this file exists, it will be included
+ * by the add-on main plugin script.
+ *
+ * Note that filter and hook callback functions must be included in-line as shown below...
+ *
+ * add_filter( 'filter_title', function( $parameter ) {
+ * // Function code
+ * });
+ *
+ * Also note that parameters will be in the context of the main admin controller constructor.
+ */
+
$glmMembersBillingAddOnValidActions = array(
'adminActions' => array(
+ 'ajax' => array(
+ 'runCron' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ ),
'management' => array(
'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
),