Finish up the bulk edit
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 21 Aug 2019 13:54:03 +0000 (09:54 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 21 Aug 2019 13:54:33 +0000 (09:54 -0400)
Bulk Approve
Bulk Decline

classes/data/dataEvents.php
classes/helper/notification.php
models/admin/dashboard/events.php
models/admin/events/list.php
views/admin/dashboard/events.html
views/admin/events/memberEmail.html

index 21fc142..8cc4c7f 100644 (file)
@@ -726,6 +726,17 @@ class GlmDataEvents extends GlmDataAbstract
 
     }
 
+    public function updateStatus( $id, $newStatus )
+    {
+        $this->wpdb->update(
+            $this->table,
+            array( 'status' => $newStatus ),
+            array( 'id' => $id ),
+            array( '%d' ),
+            array( '%d' )
+        );
+    }
+
     /**
      * Delete an event and all data associated with it.
      *
@@ -985,5 +996,3 @@ class GlmDataEvents extends GlmDataAbstract
 
 
 }
-
-?>
index 7cec4fc..ec638c9 100644 (file)
@@ -83,7 +83,7 @@ class GlmMembersAdmin_event_notification extends GlmDataMembers
      * If not found use the member info record email.
      * If nothing in either one then return.
      */
-    public function sendMemberNotice( $memberId, $event )
+    public function sendMemberNotice( $memberId, $event, $status )
     {
         $member = $this->getEntry( $memberId );
         // find notify_to
@@ -112,7 +112,20 @@ class GlmMembersAdmin_event_notification extends GlmDataMembers
         require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
         $viewFile   = 'admin/events/memberEmail.html';
 
+        $subject  = 'Event Approved';
         $eventList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-events-list&glm_action=list";
+        switch ( $status ) {
+        case $this->config['event_status_numb']['Active']:
+            $smarty->templateAssign( 'status', 'Approval' );
+            $smarty->templateAssign( 'status_message', $this->config['settings']['approved_message'] );
+            $subject  = 'Event Approved';
+            break;
+        case $this->config['event_status_numb']['Declined']:
+            $smarty->templateAssign( 'status', 'Declined' );
+            $smarty->templateAssign( 'status_message', $this->config['settings']['declined_message'] );
+            $subject  = 'Event Declined';
+            break;
+        }
         $smarty->templateAssign( 'location', 'Member Events' );
         $smarty->templateAssign( 'name', $event['fieldData']['name'] );
         $smarty->templateAssign( 'pendingEvents', $eventList );
@@ -132,7 +145,6 @@ class GlmMembersAdmin_event_notification extends GlmDataMembers
         // 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' ) );
 
-        $subject  = 'Event Approved';
         $message  = $htmlMessage;
         $header[] = 'From:' . $notify_from;
         $header[] = 'Reply-To:' . $notify_from;
index 0677916..31c24e3 100644 (file)
@@ -101,33 +101,34 @@ class GlmMembersAdmin_dashboard_events extends GlmDataEvents
         $success  = true;
         $memberID = false;
 
-        // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
         if ( isset( $_REQUEST['bulkAction'] ) && isset( $_REQUEST['bulkEdit'] ) && !empty( $_REQUEST['bulkEdit'] ) ) {
+            // Load Notifications from the helper classes
+            include_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/helper/notification.php';
+            $notification = new GlmMembersAdmin_event_notification( $this->wpdb, $this->config );
             $members = array();
             // Process the bulk edit events.
             $bulkAction = filter_var( $_REQUEST['bulkAction'], FILTER_SANITIZE_STRING );
             $bulkEdit   = filter_var( $_REQUEST['bulkEdit'], FILTER_VALIDATE_INT, [ 'flags' => FILTER_FORCE_ARRAY ] );
-            // echo '<pre>$bulkEdit: ' . print_r( $bulkEdit, true ) . '</pre>';
             foreach ( $bulkEdit as $eventId ) {
-                $mId = $this->wpdb->get_var(
-                    $this->wpdb->prepare(
-                        "SELECT ref_dest
-                           FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
-                          WHERE id = %d",
-                        $eventId
-                    )
-                );
-                $members[] = $mId;
-            }
-            switch ( $bulkAction ) {
-            case 'Approve':
-                // Foreach members send Approval notification
-                break;
-            case 'Decline':
-                // Foreach members send Decline notification
-                break;
-            default:
-                break;
+                $event     = $this->editEntry( $eventId );
+                $member_id = $event['fieldData']['ref_dest_id'];
+                switch ( $bulkAction ) {
+                case 'Approve':
+                    $this->updateTimestamp( 'approved', $eventId );
+                    $this->updateStatus( $eventId, $this->config['event_status_numb']['Active'] );
+                    if ( $member_id ) {
+                        $notification->sendMemberNotice( $member_id, $event, $this->config['event_status_numb']['Active'] );
+                    }
+                    break;
+                case 'Decline':
+                    $this->updateStatus( $eventId, $this->config['event_status_numb']['Declined'] );
+                    if ( $member_id ) {
+                        $notification->sendMemberNotice( $member_id, $event, $this->config['event_status_numb']['Declined'] );
+                    }
+                    break;
+                default:
+                    break;
+                }
             }
         }
 
index d1102f1..8e7545e 100644 (file)
@@ -457,7 +457,11 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
                         // Update approved timestamp.
                         $this->updateTimestamp('approved', $this->eventID);
                         if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest'] ) ) {
-                            $notification->sendMemberNotice( $member_id, $event );
+                            $notification->sendMemberNotice( $member_id, $event, $new_status );
+                        }
+                    } else if ( $old_event_status == 20 && $new_status == 40 ) {
+                        if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest'] ) ) {
+                            $notification->sendMemberNotice( $member_id, $event, $new_status );
                         }
                     } else if ( $isModerated && $old_event_status == 10 && $new_status == 20 ) {
                         if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest'] ) ) {
@@ -962,13 +966,15 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
                 if( $old_event_status === '20' && $current_status === '10' ) {
                     $subject  = 'Event Approved';
                     $message  .= $email_notifications['approved_message'];
-                    wp_mail( $to_email, $subject, $message, $header );
+                    // This is done using helper class notifications
+                    // wp_mail( $to_email, $subject, $message, $header );
 
                 } else if( $old_event_status === '20' && $current_status === '40' ){
                     $declined = $email_notifications['declined_message'];
                     $subject  = 'Event Declined';
                     $message  .= "Your event has been declined for the following reason(s):<br> $declined";
-                    wp_mail( $to_email, $subject, $message, $header );
+                    // This is done using helper class notifications
+                    // wp_mail( $to_email, $subject, $message, $header );
                 }
             }
             remove_filter( 'wp_mail_content_type', 'set_content_type' );
index b4ef200..77be6ac 100644 (file)
                 <a class="button glm-button glm-right" href="{$thisUrl}?page=glm-members-admin-menu-events-list&glm_action=list&option=add">Add Event</a>
             </h2>
             <div class="glm-widget-content">
-                <div>
-                    <select name="bulkAction">
-                        <option value="">Bulk Actions</option>
-                        <option value="Approve">Approve</option>
-                        <option value="Decline">Decline</option>
-                    </select>
-                    <input type="submit" value="Apply" class="button">
-                </div>
                 {if $events}
+                    {if !$memberID}
+                        <div>
+                            <select name="bulkAction">
+                                <option value="">Bulk Actions</option>
+                                <option value="Approve">Approve</option>
+                                <option value="Decline">Decline</option>
+                            </select>
+                            <input type="submit" value="Apply" class="button">
+                        </div>
+                    {/if}
                     <table style="width: 100%">
                         <thead>
                             <tr>
index 159db8f..5a0022b 100644 (file)
@@ -4,10 +4,10 @@
         <meta http-equiv="content-type" content="text/html;charset=utf-8">
     </head>
     <body>
-        <h1 id="title"> Event Approval Notification</h1>
+        <h1 id="title"> Event {$status} Notification</h1>
 
         <div style="width: 500px">
-            <p> Your event has been approved! </p>
+            <p> {$status_message} </p>
         </div>
 
         <table cellspacing="0" cellpadding="0" width="500" style="background: lightgrey;border:1px solid #ccc;border-collapse:collapse;">
@@ -18,7 +18,7 @@
         </table>
 
         <div id="emailFooter">
-            <p style="margin-bottom: 0px;">A Event has been approved.</p>
+            <p style="margin-bottom: 0px;">Event Status has been updated.</p>
             <p style="margin-top: 0px;">To view it, please go to the <a style="color: rgb(5, 104, 179);" href="{$pendingEvents}"> events </a> page in your admin.</p>
         </div>
     </body>