Added "Random" option to getList() in data abstract
authorChuck Scott <cscott@gaslightmedia.com>
Mon, 24 Sep 2018 17:58:15 +0000 (13:58 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Mon, 24 Sep 2018 17:58:15 +0000 (13:58 -0400)
Cleaned up description for glmCron.php
Fixed Undefined index in front-end members list.

config/plugin.ini [changed mode: 0644->0755]
lib/GlmDataAbstract/DataAbstract.php [changed mode: 0644->0755]
lib/GlmDataAbstract/documentation.odt [changed mode: 0644->0755]
models/admin/ajax/glmCron.php [changed mode: 0644->0755]
models/admin/members/list.php [changed mode: 0644->0755]
models/front/members/list.php [changed mode: 0644->0755]
views/front/members/list.html

old mode 100644 (file)
new mode 100755 (executable)
index 5c29c62..cbecf5c
@@ -44,9 +44,11 @@ image_sizes['grid'] = 'Grid'
 ;
 sort_order[10] = 'Alpha-Numeric'
 sort_order[20] = 'Pseudo-Random'
+sort_order[30] = 'Random'
 
 sort_order_numb['Alpha-Numeric'] = 10
 sort_order_numb['Pseudo-Random'] = 20
+sort_order_numb['Random'] = 30
 
 ;
 ; Entry Status Types
old mode 100644 (file)
new mode 100755 (executable)
index 1b126eb..31fda89
@@ -144,6 +144,12 @@ abstract class GlmDataAbstract
      * @access private
      */
     public $pseudoRand = false;
+    /**
+     * Random Order flag (uses new seed each time)
+     *
+     * @access private
+     */
+    public $rand = false;
 
 
     /*
@@ -3204,9 +3210,13 @@ $forEdit = true;
      *
      * @param string $where Optional WHERE clause for selection of entries. Defaults to all.
      * @param string $order Optional ORDER BY clause for sorting of results.
-     *                      Set to "pseudo-random" for Pseudo-Random sorting that uses a browser cookie
+     *
+     *                      Set to "pseudo-random" for Pseudo-Random sorting that uses a session parameter
      *                      to store a custom seed value so all results are in the same randomized order
      *                      for some period of time. See genPseudoRandIdArray() and pseudoRandDataSort().
+     *
+     *                      Set to "random" to do a simple random sort where that order is not repeated.
+     *
      * @param boolean $fieldVals Optional flag requesting fields contain array of all possible values.
      * @param string $idField Optional name of ID field (primary index) to use for result array keys.
      * @param integer $start Optional start of list index
@@ -3221,6 +3231,8 @@ $forEdit = true;
     public function getList($where = '', $order = '', $fieldVals = true, $idField = 'id', $start = false, $limit = false, $prohibitListOptions = false)
     {
 
+        $seed = false;
+
         // NOTE: $fieldVals not yet implemented
 
         // Check if we're asked to block all list field options. Only enable this, the parameter does not permit turning it off
@@ -3241,9 +3253,24 @@ $forEdit = true;
 
         }
 
-        // If doing pseudo-random ordering, generate array of IDs in pseudo-random order
+        // If random order is requested
+        $this->rand = false;
+        if ($order == 'random') {
+
+            // Set rand and pseudoRand flags and clear the order string
+            // Note that random uses pseudo-random code but overrides the seed each time
+            $this->rand = true;
+            $this->pseudoRand = true;
+            $order = '';
+
+            // Generate a new seed each time - this causes full random ordering and overrides "pseudo-random"
+            $seed = intval(time()*1000000+microtime()*1000000);
+
+        }
+
+        // If doing pseudo-random or random ordering, generate array of IDs in pseudo-random order
         $idString = '';
-        if ($this->pseudoRand) {
+        if ($this->pseudoRand || $this->rand) {
 
             $prSql = "SELECT $idField
                     FROM $this->table T
@@ -3254,7 +3281,7 @@ $forEdit = true;
             }
 
             $idList = $this->wpdb->get_results($prSql, ARRAY_A);
-            $prList = $this->genPseudoRandIdArray($idList, $start, $limit);
+            $prList = $this->genPseudoRandIdArray($idList, $start, $limit, 'id', 'GLM_PR_SEED', $seed);
             $idString = $prList['idString'];
 
         }
@@ -3961,9 +3988,9 @@ $forEdit = true;
      * Generate a list of ID's sorted in pseudo-random order from
      * a supplied array of record IDs.
      *
-     * This function checks for a browser cookie that is used to save
+     * This function checks for a session parameter ('GLM_PR_SEED') that is used to save
      * the seed. If that seed exists and has not timed out, it is used.
-     * Otherwise a new seed is generated and stored into a browser cookie.
+     * Otherwise a new seed is generated and stored into the session.
      *
      * This function is passed an array of all possible record IDs that have been
      * retrieved by a query against some table. That query should use a specific
@@ -3985,9 +4012,8 @@ $forEdit = true;
      * @param int $length         Optional length of page value for paging
      *                              (required if there is a $start value)
      * @param string $idName      Optional id field name to override default 'id'
-     * @param string $cookieName  Optional name for seed cookie
-     * @param int $cookieTime     Optional # of seconds for cookie timeout
-     * @param int $seed Optional seed value to use instead of using value from cookie
+     * @param string $sessionName  Optional name for seed session variable
+     * @param int $seed Optional seed value to use instead of using value from session
      *
      * @return array Array inluding the following...
      *      'idString'      A comma separated string to use for an "in" clause in
@@ -3995,10 +4021,10 @@ $forEdit = true;
      *      'idArray'       An array of IDs in the generated pseudo-random order
      *
      */
-    private function genPseudoRandIdArray ($ids, $start = false, $length = false, $idName = 'id', $cookieName = 'GLM_PR_SEED', $cookieTime = 86400, $seed = false)
+    private function genPseudoRandIdArray ($ids, $start = false, $length = false, $idName = 'id', $seedSessionName = 'GLM_PR_SEED', $seed = false)
     {
 
-        $transientSeed = false;     // Indicates if the function was passed a specific seed. These are not stored back into a browser cookie.
+        $transientSeed = false;     // Indicates if the function was passed a specific seed. These are not stored back into session
 
         // Change $ids array to simple array of ids
         foreach ($ids as $k => $v) {
@@ -4013,15 +4039,15 @@ $forEdit = true;
         // If a seed is supplied
         if ($seed && is_int($seed)) {
 
-            // Set flag so cookie is not updated with this seed.
+            // Set flag so session is not updated with this seed.
             $transientSeed = true;
 
-        //Otherwise, use a browser cookie seed if available or generate a new one
+        //Otherwise, use the session seed if available or generate a new one
         } else {
 
-            // Get browser cookie if it exists
-            if (isset($_COOKIE[$cookieName])) {
-                $seed = ($_COOKIE[$cookieName]);
+            // Get see from session if it exists
+            if (isset($_SESSION[$seedSessionName])) {
+                $seed = ($_SESSION[$seedSessionName]);
             } else {
 
                 // Generate a new seed
@@ -4038,9 +4064,9 @@ $forEdit = true;
             return false;
         }
 
-        // If this is not a transient seed, store or updated it into the browser cookie.
+        // If this is not a transient seed, store or updated it into the session
         if (!$transientSeed) {
-            setcookie($cookieName, $seed, time() + $cookieTime);
+            $_SESSION[$seedSessionName] = $seed;
         }
 
         // Use the seed to order the ID list - Note that shuffle() will produce the same results if strand() has the same seed.
old mode 100644 (file)
new mode 100755 (executable)
index dabb4fa..6c85b79
Binary files a/lib/GlmDataAbstract/documentation.odt and b/lib/GlmDataAbstract/documentation.odt differ
old mode 100644 (file)
new mode 100755 (executable)
index d370fb4..4e8b5f6
 require_once GLM_MEMBERS_PLUGIN_PATH . '/controllers/admin.php';
 
 /*
- * This class exports the currently selected members list
- * to a printable HTML file, to a CSV file, or otherwise.
+ * This class is the main cron for all GLM Associate plugins and add-ons.
+ *
+ * The index.php file for this plugin schedules an hourly call to modelAction()
+ * in this class using sp_schedule_event().
+ *
+ * All GLM Associate plugins and add-ons that need cron services sets an add_filter()
+ * for "glm_associate_cron_request".
+ *
+ * When an hourly call is made to modelAction(), those filters are called and each
+ * add-on that wants a cron action returns an entry for the $cronActions array.
+ *
+ * If any of those actions are to occur at the current time, the admin controller
+ * is called to run the action specified.
  */
 class GlmMembersAdmin_ajax_glmCron extends glmMembersAdmin
 {
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 91bf625..a489492
@@ -810,6 +810,11 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
                     ${$resultParam} = $this->getList($where.$alphaWhere, 'pseudo-random', true, 'id', $start, $limit);
                     break;
 
+                    // Random list order
+                case $this->config['sort_order_numb']['Random']:
+                    ${$resultParam} = $this->getList($where.$alphaWhere, 'random', true, 'id', $start, $limit);
+                    break;
+
                 // Default is alpha-numeric list order
                 default:
                 case $this->config['sort_order_numb']['Alpha-Numeric']:
index 8025541..f73b75d 100755 (executable)
                             {if $settings.list_show_search_category}
                                 <div>
                                     By Category:
-    <!-- To enable multi-select, use this code for the category search instead of the code below
-                                    <select name="categorySearchMultiple[]" id="categorySelect" multiple>
-                                    {if !$singleCategory}
-                                        <option value="">(all)</option>
-                                    {/if}
-                                    {foreach from=$categories item=v}
-                                        <option value="{$v.id}"{if $v.default} selected="selected"{/if}>
-                                            {if $v.parent}&nbsp;&nbsp;&nbsp;&nbsp;{/if}{$v.name}
-                                        </option>
-                                    {/foreach}
-                                    </select>
-    -->
                                     <select name="categorySearch" id="categorySelect">
                                     {if !$singleCategory}
                                         <option value="">(all)</option>
                         {if $m.region && $settings.list_map_show_region}<b>Region:</b> {$m.region}<br>{/if}
                         {if $m.url && $settings.list_map_show_url}<a href="{$m.url}"{if $settings.list_map_show_url_newtarget} target="_blank"{/if}>Website</a><br>{/if}
                     </p>
-                    {if $m.descr && $settings.list_map_show_descr}{$m.descr|nl2br}<br>{/if}
+                    {if isset($m.descr) && $settings.list_map_show_descr}{$m.descr|nl2br}<br>{/if}
                     {if $m.short_descr && $settings.list_map_show_short_descr}{$m.short_descr|truncate:200}<br>{/if}
                     {if $settings.list_map_show_detaillink && !$m.has_no_profile}
                         <a href="{$siteBaseUrl}{$settings.canonical_member_page}/{$m.member_slug}/{if $settings.enable_multiple_profiles}{$m.id}/{/if}">More Info</a>
                     {/if}
-                    {if $m.categories && $settings.list_map_show_categories}
+                    {if isset($m.categories) && $settings.list_map_show_categories}
                         <div class="glm-member-list-items">
                             <b>{$terms.term_member_cap} Categories</b>
                             <ul>