Added option to include Clicks and Views when esporting a members list.
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 29 Aug 2017 19:28:49 +0000 (15:28 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 29 Aug 2017 19:29:45 +0000 (15:29 -0400)
models/admin/ajax/membersListExport.php
models/admin/members/list.php
views/admin/ajax/membersListExport.html
views/admin/ajax/membersListExportCsv.html
views/admin/members/list.html

index 6453a2f..84ee033 100644 (file)
@@ -122,7 +122,9 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
             'exportPriContactName'  => $this->checkFlag('exportPriContactName'),
             'exportPriContactEmail' => $this->checkFlag('exportPriContactEmail'),
             'exportUrl'             => $this->checkFlag('exportUrl'),
-            'exportCategories'      => $this->checkFlag('exportCategories')
+            'exportCategories'      => $this->checkFlag('exportCategories'),
+            'exportClicks'          => $this->checkFlag('exportClicks'),
+            'exportViews'           => $this->checkFlag('exportViews')
         );
 
         // Only return information records that are active
@@ -235,7 +237,46 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
             // If we have any entries
             $memberCount = count($list);
             if ($memberCount > 0) {
+
                 $haveMembers = true;
+
+                // If URL Clicks and/or Views are selected
+                if ($select['exportClicks'] || $select['exportViews']) {
+                    
+                    foreach($list as $k=>$v) {
+
+                        $thisMonth = date('Y-m-d', strtotime($_REQUEST['monthYear']));
+                        
+                        if ($select['exportClicks']) {
+                            $clicks = $this->wpdb->get_row("
+                                SELECT COALESCE ((
+                                    SELECT clicks
+                                      FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."clickthrough_stats
+                                     WHERE member = ".$v['id']."
+                                       AND stat_type = 3
+                                       AND stat_date = '$thisMonth'
+                               ), 0) AS month
+                            ", ARRAY_A);
+                            $list[$k]['clicks'] = $clicks['month'];
+                            
+                        }
+                            
+                        if ($select['exportViews']) {
+                            $views = $this->wpdb->get_row("
+                                SELECT COALESCE ((
+                                    SELECT clicks
+                                      FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_detail_stats
+                                     WHERE member = ".$v['id']."
+                                       AND stat_type = 3
+                                       AND stat_date = '$thisMonth'
+                               ), 0) AS month
+                            ", ARRAY_A);
+                        
+                            $list[$k]['views'] = $views['month'];
+
+                        }
+                    }
+                }
             }
         }
 
index 32c00aa..f8a8a7e 100644 (file)
@@ -333,8 +333,12 @@ class GlmMembersAdmin_members_list extends GlmDataMembers
             }
         }
 
+        // Create current month/date string to pre-populate the Month/Year field for 
+        $monthYear = date('F Y');
+        
         // Compile template data
         $templateData = array(
+            'monthYear'      => $monthYear,
             'enable_members' => $enable_members,
             'haveMembers'    => $haveMembers,
             'members'        => $list,
index bcb2e4b..7df1761 100644 (file)
@@ -15,6 +15,8 @@
                     {if $select.exportOldId}<th align="left">Old ID</th>{/if}
                     {if $select.exportMember}<th align="left">{$terms.term_member_cap} Name</th>{/if}
                     {if $select.exportReferenceName}<th align="left">Active Profile</th>{/if}
+                    {if $select.exportClicks}<th align="left">Clicks</th>{/if}
+                    {if $select.exportViews}<th align="left">Views</th>{/if}
                     {if $select.exportAddr1}<th align="left">Address</th>{/if}
                     {if $select.exportAddr2}<th align="left">Addr Line #2</th>{/if}
                     {if $select.exportCity}<th align="left">City</th>{/if}
@@ -50,6 +52,8 @@
                     {if $select.exportOldId}<td>{$m.old_id}</td>{/if}
                     {if $select.exportMember}<td>{$m.member}</td>{/if}
                     {if $select.exportReferenceName}<td>{$m.reference_name}</td>{/if}
+                    {if $select.exportClicks}<td>{$m.clicks}</td>{/if}
+                    {if $select.exportViews}<td>{$m.views}</td>{/if}
                     {if $select.exportAddr1}<td>{$m.addr1}</td>{/if}
                     {if $select.exportAddr2}<td>{$m.addr2}</td>{/if}
                     {if $select.exportCity}<td>{$m.city}</td>{/if}
index 1175533..a32ff70 100644 (file)
@@ -4,6 +4,8 @@
 {if $select.exportOldId}"Old ID",{/if}
 {if $select.exportMember}"{$terms.term_member_cap} Name",{/if}
 {if $select.exportReferenceName}"Current Profile",{/if}
+{if $select.exportClicks}"Clicks",{/if}
+{if $select.exportViews}"Views",{/if}
 {if $select.exportAddr1}"Address",{/if}
 {if $select.exportAddr2}"Addr Line #2",{/if}
 {if $select.exportCity}"City",{/if}
@@ -29,6 +31,8 @@
 {if $select.exportOldId}"{$m.old_id}",{/if}
 {if $select.exportMember}"{$m.member}",{/if}
 {if $select.exportReferenceName}"{$m.reference_name}",{/if}
+{if $select.exportClicks}"{$m.clicks}",{/if}
+{if $select.exportViews}"{$m.views}",{/if}
 {if $select.exportAddr1}"{$m.addr1}",{/if}
 {if $select.exportAddr2}"{$m.addr2}",{/if}
 {if $select.exportCity}"{$m.city}",{/if}
index e723f50..6f84ffd 100644 (file)
                         </table>
                     </td>
                 </tr>
+                <tr>
+                    <th>Include&nbsp;Clicks&nbsp;&&nbsp;Views</th>
+                    <td>
+                        <table padding="3">
+                            <tr>
+                                <td>
+                                    Month: <input type="text" class="monthPicker" name="monthYear" value="{$monthYear}">
+                                </td> 
+                            </tr>
+                            <tr>
+                                <td>
+                                    <input type="checkbox" name="exportClicks"> URL Click Counts<br>
+                                    <input type="checkbox" name="exportViews"> Detail Page View Counts
+                                </td>
+                            </tr>
+                        </table>
+                    </td>
+                </tr>
                 <tr>
                     <th>Export to: </th>
                     <td>
     <script type="text/javascript">
         jQuery(document).ready(function($) {
 
-
-            $("#exportMembersDialog").dialog({
+               $('.monthPicker').datepicker( {
+                   changeMonth: true,
+                   changeYear: true,
+                   showButtonPanel: true,
+                   dateFormat: 'MM yy',
+                   onClose: function(dateText, inst) { 
+                       var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
+                       var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
+                       $(this).datepicker('setDate', new Date(year, month, 1));
+                   },
+                   beforeShow: function (input, inst) {
+                       var $this = $(this),
+                           // For the simplicity we suppose the dateFormat will be always without the day part, so we
+                           // manually add it since the $.datepicker.parseDate will throw if the date string doesn't contain the day part
+                           dateFormat = 'd ' + $this.datepicker('option', 'dateFormat'),
+                           date;
+
+                       try {
+                           date = $.datepicker.parseDate(dateFormat, '1 ' + $this.val());
+                       } catch (ex) {
+                           return;
+                       }
+
+                       $this.datepicker('option', 'defaultDate', date);
+                       $this.datepicker('setDate', date);
+
+                       inst.dpDiv.addClass('datepicker-month-year');
+                   }
+               });
+               
+               $("#exportMembersDialog").dialog({
                 autoOpen: false,
-                minWidth: 600,
+                minWidth: 700,
                 dialogClass: "glm-dialog-no-close"
             });
             $('#exportMembersButton').click( function() {