Add restore and archive message links. develop
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 4 Sep 2019 13:32:54 +0000 (09:32 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 4 Sep 2019 13:32:54 +0000 (09:32 -0400)
Ability to restore and archive the email messages.

classes/data/dataEmailMessages.php
models/admin/messages/index.php
views/admin/messages/editHtmlEmail.html
views/admin/messages/listMessagesTable.html

index eab54a3..f28e64f 100644 (file)
@@ -254,4 +254,40 @@ class GlmDataEmailMessages extends GlmDataAbstract
     }
 
 
+    /**
+     * Archive this message.
+     *
+     * @param int id Message id to archive
+     *
+     * @return void
+     */
+    public function archive( $id )
+    {
+        $this->wpdb->update(
+            $this->table,
+            array( 'archived' => true ),
+            array( 'id' => $id ),
+            array( '%d' ),
+            array( '%d' )
+        );
+    }
+
+    /**
+     * Restore this message.
+     *
+     * @param int id Message id to restore
+     *
+     * @return void
+     */
+    public function restore( $id )
+    {
+        $this->wpdb->update(
+            $this->table,
+            array( 'archived' => false ),
+            array( 'id' => $id ),
+            array( '%d' ),
+            array( '%d' )
+        );
+    }
+
 }
index e6164a2..35a2ac0 100644 (file)
@@ -257,6 +257,7 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages
                 'paging'   => $paging,
             ];
             break;
+
         case 'search':
             $view          = 'search';
             $searchResults = array();
@@ -445,73 +446,6 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages
             );
             break;
 
-        case 'editTemplate':
-            $error = false;
-            $view      = 'editTemplate';
-            $newEntry  = false;
-            $Templates = new GlmDataEmailTemplates( $this->wpdb, $this->config );
-            if ( isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
-                $template = $Templates->editEntry( $id );
-            } else {
-                $template = $Templates->newEntry();
-                $newEntry = true;
-            }
-            $tData = array(
-                'template' => $template,
-                'newEntry' => $newEntry,
-                'error'    => $error,
-            );
-            break;
-
-        case 'updateTemplate':
-            $error   = false;
-            $success = false;
-            $templateData['thisOption'] = 'listTemplates';
-            $Templates = new GlmDataEmailTemplates( $this->wpdb, $this->config );
-            if ( isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
-                $newEntry = false;
-                $template = $Templates->updateEntry( $id );
-            } else {
-                $newEntry = true;
-                $template = $Templates->insertEntry();
-            }
-            if ( $template['status'] != 1 ) {
-                $error = true;
-                $view  = 'editTemplate';
-                $tData = array(
-                    'template' => $template,
-                    'newEntry' => $newEntry,
-                    'error'    => $error,
-                    'success'  => $success,
-                );
-            } else {
-                $success  = true;
-                $view     = 'editTemplate';
-                $tData    = array(
-                    'template' => $template,
-                    'newEntry' => $newEntry,
-                    'error'    => $error,
-                    'success'  => $success,
-                );
-            }
-            break;
-
-        case 'deleteTemplate':
-            $view = 'list';
-            $Templates = new GlmDataEmailTemplates( $this->wpdb, $this->config );
-            if ( $option == 'deleteTemplate' && isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
-                $Templates->deleteEntry( $id, true );
-            }
-
-        case 'listTemplates':
-            $view = 'listTemplates';
-            $Templates = new GlmDataEmailTemplates( $this->wpdb, $this->config );
-            $templates = $Templates->getList();
-            $tData = array(
-                'templates' => $templates,
-            );
-            break;
-
         case 'editHtmlEmail':
             $view     = 'editHtmlEmail';
             $newEntry = false;
@@ -569,6 +503,18 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages
                 $this->deleteEntry( $id, true );
             }
 
+        case 'archive':
+            $view = 'list';
+            if ( $option == 'archive' && isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
+                $this->archive( $id );
+            }
+
+        case 'restore':
+            $view = 'list';
+            if ( $option == 'restore' && isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
+                $this->restore( $id );
+            }
+
         case 'list':
             $view = 'list';
 
index 259b44f..f123705 100644 (file)
 
         {* UI for Delete Dialog *}
         {if !$newEntry}
-            {assign var="itemName" value="Message"}
-            {assign var="deleteUrl" value="{$thisUrl}?page={$thisPage}&option=deleteMessage&id={$message.fieldData.id}"}
+            {$itemName="Message"}
+            {$deleteUrl="{$thisUrl}?page={$thisPage}&option=deleteMessage&id={$message.fieldData.id}"}
             {include file='admin/ui/deleteDialog.html'}
         {/if}
 
index 50027f2..0448cfd 100644 (file)
@@ -6,6 +6,7 @@
             <th align="left">Last Updated</th>
             <th align="left">Last Sent</th>
             <th align="left">Queued</th>
+            <th align="left">Archive</th>
             <th align="left" width="50">Preview</th>
         </tr>
     </thead>
                     <td> {$message.last_updated.timestamp|date_format:"%D %r"} </td>
                     <td> {$message.sent|date_format:"%D %r"} </td>
                     <td> {$message.stats|date_format:"%D %r"} </td>
+                    <td>
+                        {if $message.archived.value}
+                        <a href="{$thisUrl}?page={$thisPage}&option=restore&id={$message.id}&filterArchived=1">Restore</a>
+                        {else}
+                        <a href="{$thisUrl}?page={$thisPage}&option=archive&id={$message.id}">Archive</a>
+                        {/if}
+                    </td>
                     <td>
                         <a href="{$thisUrl}?page={$thisPage}&option=preview&id={$message.template_id.value}&message_id={$message.id}" class="preview" data-id="{$message.template_id.value}" data-message="{$message.id}" >Preview</a>
                     </td>