Setup categories in member export.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 26 Jan 2017 17:02:50 +0000 (12:02 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 26 Jan 2017 17:02:50 +0000 (12:02 -0500)
Giving one column per member category.
Both in html and csv output.

models/admin/ajax/membersListExport.php
views/admin/ajax/membersListExport.html
views/admin/ajax/membersListExportCsv.html

index c5e7bfc..c4b49a5 100644 (file)
@@ -17,7 +17,8 @@
 // Load Member Info data abstract
 require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php';
 
-/*
+/**
+ *
  * This class exports the currently selected members list
  * to a printable HTML file, to a CSV file, or otherwise.
  */
@@ -39,10 +40,10 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
      */
     public $config;
 
-    /*
+    /**
      * Constructor
      *
-     * This contructor sets up this model. At this time that only includes
+     * This constructor sets up this model. At this time that only includes
      * storing away the WordPress data object.
      *
      * @return object Class object
@@ -61,7 +62,8 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
 
     }
 
-    /*
+    public function checkFlag($t) {return isset($_REQUEST[$t]) && $_REQUEST[$t] == 'on';}
+    /**
      * Perform Model Action
      *
      * This modelAction takes an AJAX image upload and stores the image in the
@@ -73,29 +75,28 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
      *
      * Echos JSON string as response and does not return
      */
-    public function checkFlag($t) {return isset($_REQUEST[$t]) && $_REQUEST[$t] == 'on';}
     public function modelAction ($actionData = false)
     {
 
         // When processing member info records, also get primary contact data
         $this->postProcessPrimaryContact = true;
 
-        $where = ' true ';
-        $categories = false;
-        $haveMembers = false;
-        $list = false;
-        $success = false;
-        $filterPending = false;
+        $where          = ' true ';
+        $categories     = false;
+        $haveMembers    = false;
+        $list           = false;
+        $success        = false;
+        $filterPending  = false;
         $filterArchived = false;
-        $haveFilter = false;
-        $numbDisplayed = false;
-        $lastDisplayed = false;
-        $paging = true;
-        $prevStart = false;
-        $nextStart = false;
-        $start = 1;
-        $limit = 20;        // Set to the number of listings per page
-        $namesList = false;
+        $haveFilter     = false;
+        $numbDisplayed  = false;
+        $lastDisplayed  = false;
+        $paging         = true;
+        $prevStart      = false;
+        $nextStart      = false;
+        $start          = 1;
+        $limit          = 20;        // Set to the number of listings per page
+        $namesList      = false;
 
         // Check selected fields
         $select = array(
@@ -150,7 +151,7 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
         // Check if there is a category filter (multi-select)
         if (isset($_REQUEST['filterCategories']) && count($_REQUEST['filterCategories']) > 0) {
 
-            $cats = '';
+            $cats    = '';
             $catsSep = '';
 
             // For each selected category
@@ -161,15 +162,15 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
             }
 
             $where .= " AND T.id in (
-                    SELECT DISTINCT(I.member)
-                      FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info I,
-                           ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info M,
-                           ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories C
-                     WHERE I.id = M.member_info
-                       AND (
-                           M.category in ($cats)
-                           OR (C.parent in ($cats) AND M.category = C.id)
-                           )
+                SELECT DISTINCT(I.member)
+                  FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info I,
+                       ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info M,
+                       ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories C
+                 WHERE I.id = M.member_info
+                   AND (
+                       M.category in ($cats)
+                       OR (C.parent in ($cats) AND M.category = C.id)
+                       )
             )";
         }
 
@@ -185,7 +186,7 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
             )";
 
             $filterPending = true;
-            $haveFilter = true;
+            $haveFilter    = true;
         }
 
         // Check for "Featured Only
@@ -200,14 +201,27 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
             )";
 
             $filterFeatured = true;
-            $haveFilter = true;
+            $haveFilter     = true;
         }
 
+        // Get a list of member categories
+        $sql = "
+        SELECT C.id,C.name,C.parent,
+            COALESCE ((SELECT name
+                   FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX. "categories
+                  WHERE id = C.parent), '') AS parent_name
+          FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "categories C
+        ORDER BY C.parent,C.name";
+        $category_data = $this->wpdb->get_results( $sql, ARRAY_A );
+        //echo '<pre>$category_data: ' . print_r( $category_data, true ) . '</pre>';
+
         // Get a current list of members without paging
         $list = $this->getList($where, "member_name");
+        //echo '<pre>$list: ' . print_r( $list, true ) . '</pre>';
+        //exit;
 
         // If we have list entries - even if it's an empty list
-        $success = true;
+        $success     = true;
         $haveMembers = false;
         if ($list !== false) {
 
@@ -226,23 +240,24 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
 
         // Compile template data
         $templateData = array(
-            'select' => $select,
-            'haveMembers' => $haveMembers,
-            'members' => $list,
-            'memberCount' => $memberCount,
-            'categories' => $categories,
-            'haveFilter' => $haveFilter,
+            'category_data'  => $category_data,
+            'select'         => $select,
+            'haveMembers'    => $haveMembers,
+            'members'        => $list,
+            'memberCount'    => $memberCount,
+            'categories'     => $categories,
+            'haveFilter'     => $haveFilter,
             'filterArchived' => $filterArchived,
             'filterFeatured' => $filterFeatured,
-            'filterPending' => $filterPending,
-            'numbDisplayed' => $numbDisplayed,
-            'lastDisplayed' => $lastDisplayed,
-            'paging' => $paging,
-            'prevStart' => $prevStart,
-            'nextStart' => $nextStart,
-            'start' => $start,
-            'limit' => $limit,
-            'namesList' => $namesList
+            'filterPending'  => $filterPending,
+            'numbDisplayed'  => $numbDisplayed,
+            'lastDisplayed'  => $lastDisplayed,
+            'paging'         => $paging,
+            'prevStart'      => $prevStart,
+            'nextStart'      => $nextStart,
+            'start'          => $start,
+            'limit'          => $limit,
+            'namesList'      => $namesList
         );
 
         $view = 'admin/ajax/membersListExport.html';
@@ -262,11 +277,11 @@ class GlmMembersAdmin_ajax_membersListExport extends GlmDataMemberInfo
 
         // Return status, suggested view, and data to controller
         return array(
-            'status' => $success,
+            'status'           => $success,
             'menuItemRedirect' => false,
-            'modelRedirect' => false,
-            'view' => $view,
-            'data' => $templateData
+            'modelRedirect'    => false,
+            'view'             => $view,
+            'data'             => $templateData
         );
 
     }
index 46eb8da..d9c54c9 100644 (file)
                     {if $select.exportPriContactName}<th align="left">Primary Contact</th>{/if}
                     {if $select.exportPriContactEmail}<th align="left">Primary Contact E-Mail</th>{/if}
                     {if $select.exportUrl}<th align="left">Web Address</th>{/if}
-                    {if $select.exportCategories}<th align="left">Categories</th>{/if}
+                    {if $select.exportCategories}
+                        {if $category_data}
+                            {foreach $category_data as $cat}
+                            <th align="left">{if $cat.parent_name}{$cat.parent_name}:{/if}{$cat.name}</th>
+                            {/foreach}
+                        {/if}
+                    {/if}
                 </tr>
             </thead>
             <tbody>
                     {if $select.exportPriContactName}<td>{if $m.primary_contact}{$m.primary_contact.fname} {$m.primary_contact.lname}{/if}</td>{/if}
                     {if $select.exportPriContactEmail}<td>{if $m.primary_contact}{$m.primary_contact.email}{/if}</td>{/if}
                     {if $select.exportUrl}<td>{$m.url}</td>{/if}
-                    {if $select.exportCategories}<td>
-               {foreach $m.categories as $t}
-                        {$t.name},
-               {/foreach}
-                    </td>{/if}
+                    {if $select.exportCategories}
+                        {if $category_data}
+                            {foreach $category_data as $cat}
+                                <td>
+                                {$cat_exists=''}
+                                {foreach $m.categories as $t}
+                                {if $t.id == $cat.id}{$cat_exists='Yes'}{/if}
+                                {/foreach}
+                                {$cat_exists}
+                                </td>
+                            {/foreach}
+                        {/if}
+                    {/if}
 
                 </tr>
         {/foreach}
index abc1707..4a08d51 100644 (file)
@@ -20,7 +20,7 @@
 {if $select.exportPriContactName}"Pri Contact",{/if}
 {if $select.exportPriContactEmail}"Pri Contact E-Mail",{/if}
 {if $select.exportUrl}"Web Address",{/if}
-{if $select.exportCategories}"Categories"{/if}
+{if $select.exportCategories} {if $category_data} {foreach $category_data as $cat} "{if $cat.parent_name}{$cat.parent_name}:{/if}{$cat.name}" {if !$cat@last},{/if} {/foreach} {/if} {/if}
 
 {foreach $members as $m}
 {if $select.exportId}"{$m.id}",{/if}
@@ -43,7 +43,7 @@
 {if $select.exportPriContactName}"{if $m.primary_contact}{$m.primary_contact.fname} {$m.primary_contact.lname}{/if}",{/if}
 {if $select.exportPriContactEmail}"{if $m.primary_contact}{$m.primary_contact.email}{/if}",{/if}
 {if $select.exportUrl}"{$m.url}",{/if}
-{if $select.exportCategories}"{foreach $m.categories as $t}{$t.name},{/foreach}"{/if}
+{if $select.exportCategories} {if $category_data} {foreach $category_data as $cat} {$cat_exists='""'} {foreach $m.categories as $t} {if $t.id == $cat.id}{$cat_exists='"Yes"'}{/if} {/foreach} {$cat_exists} {if !$cat@last},{/if} {/foreach} {/if} {/if}
 
 {/foreach}
 {else}No {$terms.term_member_plur_cap} Selected{/if}