* @link http://dev.gaslightmedia.com/
*/
+// Load required class for support
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH . '/regCartSupport.php';
+
class GlmRegNotifications
{
/**
}
/**
- * sendEmailNotification
+ * getAttendeesForEventWithEmails
*
- * Send out the email notification based on reg_notification and the regEventID.
+ * Grab the attendees for the Event.
+ * Must have the email.
*
- * @param mixed $reg_notification Id for reg_notifgication.
- * @param mixed $reg_event_id Id for the reg Event.
+ * @param mixed $reg_event Id for the reg_event
*
* @access public
* @return void
*/
- public function sendEmailNotification( $reg_notification, $reg_event_id )
+ public function getAttendeesForEventWithEmails( $reg_event )
{
- $to_email = $account['email'];
- // echo '<pre>$to_email: ' . print_r( $to_email, true ) . '</pre>';
- if ( !$to_email ) {
- // If there's no email then return false.
- return false;
- }
-
- // get the Notification type
- var_dump( $reg_notification );
- $notification = $this->getRegNotificationById( $reg_notification );
- echo '<pre>$notification: ' . print_r( $notification, true ) . '</pre>';
- if ( !$notification ) {
- // If there's no notification type then return false.
- return false;
- }
- $subject = $notification['subject'];
- if ( !$subject ) {
- // If there's no subject then return false.
- return false;
- }
- $from_header = $notification['from_header'];
- $replyto = $notification['replyto'];
-
- // Setup the Smarty Engine
- $smarty = new smartyTemplateSupport();
- $viewPath = GLM_MEMBERS_BILLING_PLUGIN_PATH . '/views';
- $smarty->template->setTemplateDir( $viewPath );
-
- // Add standard parameters
- require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
- $viewFile = 'admin/notifications/notification.html';
-
- $account_data = array(
- 'account' => array(
- 'name' => $account['ref_name'],
- 'email' => $account['email'],
- 'addr1' => $account['billing_addr1'],
- 'addr2' => $account['billing_addr2'],
- 'city' => $account['billing_city'],
- 'state' => $account['billing_state'],
- 'zip' => $account['billing_zip'],
- 'phone' => $account['billing_phone'],
- )
+ $query = $this->wpdb->prepare(
+ "SELECT RRR.*,A.email,RE.event_name,RRC.class_name
+ FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request_registrant RRR
+ LEFT OUTER JOIN " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "account A ON (A.id = RRR.account)
+ LEFT OUTER JOIN " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_event RE ON (RE.id = RRR.reg_event)
+ LEFT OUTER JOIN " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request_class RRC ON (RRC.id = RRR.reg_request_class)
+ WHERE RRR.reg_event = %d
+ AND RRR.not_attending <> 1
+ AND A.email != ''
+ AND A.email IS NOT NULL
+ GROUP BY RRR.account",
+ $reg_event
);
- echo '<pre>$notification[message]: ' . print_r( $notification['message'], true ) . '</pre>';
- $notification_message = $this->parseSmartyTemplateString(
- $account_data,
- wpautop( $notification['message'] )
- );
- echo '<pre>$account_data: ' . print_r( $account_data, true ) . '</pre>';
- echo '<pre>$notification_message: ' . print_r( $notification_message, true ) . '</pre>';
- // exit;
-
- $smarty->templateAssign( 'title', $notification['subject'] );
- $smarty->templateAssign( 'html_content', $notification_message );
-
- // Generate output from model data and view
- $htmlMessage = $smarty->template->fetch( $viewFile );
-
-
- // change the default wordpress from name when sending mail
- add_filter(
- 'wp_mail_from_name',
- function ( $name ) {
- $siteName = get_bloginfo( 'name' );
- return $siteName;
- }
- );
- // Send confirmation email, set the content type to allow html by using this filter
- add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
-
- $message = $htmlMessage;
- $header[] = 'From:' . $from_header;
- $header[] = 'Reply-To:' . $replyto;
-
- wp_mail( $to_email, $subject, $message, $header );
-
- // remove the filter to avoid conflicts
- remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
+ return $this->wpdb->get_results( $query, ARRAY_A );
+ }
- // Send notification to recordNotification
- $notice_data = array(
- 'reg_notification' => $reg_notification,
- 'account' => $account_id,
- 'from_replyto' => $from_header,
- 'subject' => $subject,
- 'message' => $message,
- 'email_sent' => $to_email,
- );
- $this->recordNotification( $notice_data );
+ /**
+ * getRegNotificationsByDate
+ *
+ * Grab all reg notifications. Include the first_datetime from the related event.
+ *
+ * @access public
+ * @return void
+ */
+ public function getRegNotificationsByDate()
+ {
+ $query =
+ "SELECT RN.*, date_format( RE.first_datetime, '%Y-%m-%d' ) as first_datetime
+ FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_notification RN
+ LEFT OUTER JOIN " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_event RE
+ ON (RE.id = RN.reg_event)";
+ return $this->wpdb->get_results( $query, ARRAY_A );
}
/**
return $smarty->template->fetch( 'eval:' . $template_string );
}
- /**
- * recordNotification
- *
- * Record the notification.
- *
- * @param mixed $notification Array of data for the notification
- i
- * @access public
- * @return void
- */
- public function recordNotification( $notification )
- {
- if ( !$notification['notification_type'] || !$notification['account']
- || !$notification['from_replyto'] || !$notification['subject']
- || !$notification['message'] || !$notification['email_sent']
- ) {
- return false;
- }
- $this->wpdb->insert(
- GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'notifications',
- array(
- 'notification_type' => $notification['notification_type'],
- 'account' => $notification['account'],
- 'from_replyto' => $notification['from_replyto'],
- 'subject' => $notification['subject'],
- 'message' => $notification['message'],
- 'date_sent' => date('Y-m-d H:i;s'),
- 'email_sent' => $notification['email_sent'],
- ),
- array(
- '%d', // notification_type
- '%d', // account
- '%s', // from_replyto
- '%s', // subject
- '%s', // message
- '%s', // date_sent
- '%s', // email_sent
- )
- );
- return true;
- }
-
- /**
- * Set content type of the email.
- *
- * Used as filter for the wp_mail_content_type
- */
- function set_content_type()
- {
- return "text/html";
- }
-
/**
* queueNotice
*
- * Queue the noticifation.
+ * Queue the notification.
*
- * @param mixed $notification_type Id for the notification type
- * @param mixed $account Id for the account
+ * @param mixed $reg_notification Id for the notification type
+ * @param mixed $account Id for the account
*
* @access public
* @return void
*/
- public function queueNotice( $notification_type, $account )
+ public function queueNotice( $reg_notification, $account )
{
// First check to see if there's already one in the queue.
$queue_id = $this->wpdb->get_var(
$this->wpdb->prepare(
"SELECT id
- FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_queue
- WHERE notification_type = %d
+ FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "notification_queue
+ WHERE reg_notification = %d
AND account = %d",
- $notification_type,
+ $reg_notification,
$account
)
);
if ( !$queue_id ) {
$this->wpdb->insert(
- GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'notification_queue',
+ GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'notification_queue',
array(
- 'notification_type' => $notification_type,
- 'account' => $account
+ 'reg_notification' => $reg_notification,
+ 'account' => $account
),
array(
'%d',
* @access public
* @return array
*/
- public function getQueuedNotifications( $limit )
+ public function getQueuedNotifications( $limit = 10 )
{
$query =
"SELECT *
- FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_queue";
+ FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "notification_queue
+ WHERE processed_time IS NULL";
if ( $numb = filter_var( $limit, FILTER_VALIDATE_INT ) ) {
$query .= " LIMIT $limit OFFSET 0";
}
);
}
- /**
- * deleteQueue
- *
- * Remove notice from the queue.
- *
- * @param mixed $queue_id Queue id to delete.
- *
- * @access public
- * @return void
- */
- public function deleteQueue( $queue_id )
- {
- $this->wpdb->delete(
- GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'notification_queue',
- array( 'id' => $queue_id ),
- array( '%d' )
- );
- }
}
--- /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
+ */
+
+// Load Support class for notifications
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH . '/regCartSupport.php';
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH . '/regNotifications.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_runEventRegQueue //extends GlmDataRegistrationsAccount
+{
+
+ /**
+ * WordPress 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 data class
+ // parent::__construct(false, false);
+
+ }
+
+ /*
+ * Perform Model Action
+ *
+ * This model checks to see if the creditials passed in are correct.
+ *
+ * This model action does not return, it simply does it's work then calls die();
+ *
+ * @param $actionData
+ *
+ * Echos JSON string as response and does not return
+ */
+ public function modelAction( $actionData = false )
+ {
+ $return = false;
+
+ echo '<p>From the admin ajax runEventRegQueue in Event Registrations.</p>';
+
+ // Support class for sending emails.
+ $GlmRegCartSupport = new GlmRegCartSupport( $this->wpdb, $this->config );
+
+ // Grab list of reg_notifications that are due today.
+ $Notifications = new GlmRegNotifications( $this->wpdb, $this->config );
+ $notifications = $Notifications->getQueuedNotifications( 10 );
+ // echo '<pre>$notifications: ' . print_r( $notifications, true ) . '</pre>';
+
+ if ( isset( $notifications ) && is_array( $notifications ) && !empty( $notifications ) ) {
+ foreach ( $notifications as $notice ) {
+ // Send out the notice.
+ echo '<pre>$notice: ' . print_r( $notice, true ) . '</pre>';
+ $GlmRegCartSupport->sendHtmlEmail(
+ $notice['to_email'],
+ $notice['subject'],
+ wpautop( $notice['html_message'] )
+ );
+ // Mark it as processed.
+ $this->wpdb->update(
+ GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'notification_queue',
+ array( 'processed_time' => date( 'Y-m-d' ) ),
+ array( 'id' => $notice['id'] ),
+ array( '%s' ),
+ array( '%d' )
+ );
+ }
+ }
+
+
+ exit();
+ }
+}
* @version 0.1
*/
-// Load Members data abstract
-// require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH . '/data/dataAccount.php';
+// Load Support class for notifications
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH . '/regNotifications.php';
/**
* This class performs the work of handling images passed to it via
echo '<p>From the admin ajax setupEventRegQueue in Event Registrations.</p>';
+ // Grab list of reg_notifications that are due today.
+ $Notifications = new GlmRegNotifications( $this->wpdb, $this->config );
+ $notifications = $Notifications->getRegNotificationsByDate();
+ echo '<pre>$notifications: ' . print_r( $notifications, true ) . '</pre>';
+
+ foreach ( $notifications as $notice ) {
+ // have to check to see when this notice will go out.
+ $notice_date = new DateTime( $notice['first_datetime'] );
+ $notice_date->add( DateInterval::createFromDateString( $notice['notification_days'] . ' day' ) );
+ $current_date = new DateTime( date( 'Y-m-d' ) );
+ $interval = $current_date->diff($notice_date);
+ $daysAway = (int)$interval->format( '%d' );
+
+ // We're only going to queue notifications if they are 0 days away.
+ if ( $daysAway === 0 ) {
+ // get list of attendees for adding notices to queue.
+ $attendees = $Notifications->getAttendeesForEventWithEmails( $notice['reg_event'] );
+ echo '<pre>$attendees: ' . print_r( $attendees, true ) . '</pre>';
+
+ foreach ( $attendees as $attendee ) {
+ // Check to see if the attendee is already in the queue
+ $notice_id = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "notification_queue
+ WHERE reg_notification = %d
+ AND account = %d",
+ $notice['id'],
+ $attendee['id']
+ )
+ );
+ if ( !$notice_id ) {
+ // Create the html_message to be sent
+ $template_data = array(
+ 'event' => array(
+ 'name' => $attendee['event_name'],
+ 'date' => date( 'n/j/Y', strtotime( $attendee['event_datetime'] ) ),
+ 'time' => date( 'h:i A', strtotime( $attendee['event_datetime'] ) ),
+ ),
+ 'registration' => array(
+ 'level' => $attendee['class_name'],
+ ),
+ 'last' => array(
+ 'name' => $attendee['lname']
+ ),
+ 'first' => array(
+ 'name' => $attendee['fname']
+ ),
+ );
+ echo '<pre>$template_data: ' . print_r( $template_data, true ) . '</pre>';
+ $RegCartSupport = new GlmRegCartSupport( $this->wpdb, $this->config );
+ $html_message = $RegCartSupport->generateHTML($template_data, $notice['message'], true);
+
+
+ // Setup the queue_date
+ $queue_data = array(
+ 'reg_notification' => $notice['id'],
+ 'account' => $attendee['id'],
+ 'queued_time' => date( 'Y-m-d' ),
+ 'to_email' => $attendee['email'],
+ 'from_email' => $this->config['settings']['reg_org_from_email'],
+ 'subject' => $notice['name'],
+ 'html_message' => $html_message,
+ );
+ echo '<pre>$queue_data: ' . print_r( $queue_data, true ) . '</pre>';
+ // Now add them to the queue
+ $this->wpdb->insert(
+ GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'notification_queue',
+ $queue_data,
+ array(
+ '%d',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ )
+ );
+ }
+ }
+ }
+ }
+
+
exit();
}
}