* @access public
* @return void
*/
- public function sendEmailNotification( $notification_id, $account )
+ public function sendEmailNotification( $notification_id, $account_id )
{
// Support Class
$BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
// get the Account
- $account = $BillingSupport->getAccountById( $account );
+ $account = $BillingSupport->getAccountById( $account_id );
if ( !$account ) {
// If there's no account then return false.
return false;
// remove the filter to avoid conflicts
remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
+
+ // Send notification to recordNotification
+ $notice_data = array(
+ 'notification_type' => $notification_id,
+ 'account' => $account_id,
+ 'from_replyto' => $from_header,
+ 'subject' => $subject,
+ 'message' => $message,
+ 'email_sent' => $to_email,
+ );
+ $this->recordNotification( $notice_data );
+ }
+
+ /**
+ * 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;
+ }
+
+ public function getNotificationByType( $type )
+ {
+ echo '<pre>$this->config: ' . print_r( $this->config['send_action_numb'], true ) . '</pre>';
+ 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
+ );
}
/**
* 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>';
- require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php';
- $Notifications = new GlmNotifications( $this->wpdb, $this->config );
+ // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ // require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php';
+ // $Notifications = new GlmNotifications( $this->wpdb, $this->config );
+ // // Test
+ // $notices = $Notifications->getNotificationByType( '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 ) {
echo '<pre>$notification_id: ' . print_r( $notification_id, true ) . '</pre>';
$account = 1; // TODO: remove this. It's for testing only
$noticeReturned = $Notifications->sendEmailNotification( $notification_id, $account );
- var_dump( $noticeReturned );
+ // var_dump( $noticeReturned );
}
wp_die('Testing here');
break;
/**
* add:
*
- * This calls the dataabstract newEntry method and sets up the
+ * This calls the dataAbstract newEntry method and sets up the
* edit for for creating a new notification_type.
*/
$notification = $this->newEntry();
*
* 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
+);
+