From: Chuck Scott Date: Mon, 24 Sep 2018 17:58:15 +0000 (-0400) Subject: Added "Random" option to getList() in data abstract X-Git-Tag: v2.10.45^2~19 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=bf7a69f91c26aa5c65367c10b100afe25ecbd700;p=WP-Plugins%2Fglm-member-db.git Added "Random" option to getList() in data abstract Cleaned up description for glmCron.php Fixed Undefined index in front-end members list. --- diff --git a/config/plugin.ini b/config/plugin.ini old mode 100644 new mode 100755 index 5c29c624..cbecf5c0 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -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 diff --git a/lib/GlmDataAbstract/DataAbstract.php b/lib/GlmDataAbstract/DataAbstract.php old mode 100644 new mode 100755 index 1b126ebe..31fda89c --- a/lib/GlmDataAbstract/DataAbstract.php +++ b/lib/GlmDataAbstract/DataAbstract.php @@ -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. diff --git a/lib/GlmDataAbstract/documentation.odt b/lib/GlmDataAbstract/documentation.odt old mode 100644 new mode 100755 index dabb4fab..6c85b79b Binary files a/lib/GlmDataAbstract/documentation.odt and b/lib/GlmDataAbstract/documentation.odt differ diff --git a/models/admin/ajax/glmCron.php b/models/admin/ajax/glmCron.php old mode 100644 new mode 100755 index d370fb4f..4e8b5f6a --- a/models/admin/ajax/glmCron.php +++ b/models/admin/ajax/glmCron.php @@ -16,8 +16,19 @@ 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 { diff --git a/models/admin/members/list.php b/models/admin/members/list.php old mode 100644 new mode 100755 diff --git a/models/front/members/list.php b/models/front/members/list.php old mode 100644 new mode 100755 index 91bf6255..a4894929 --- a/models/front/members/list.php +++ b/models/front/members/list.php @@ -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']: diff --git a/views/front/members/list.html b/views/front/members/list.html index 8025541f..f73b75d7 100755 --- a/views/front/members/list.html +++ b/views/front/members/list.html @@ -42,18 +42,6 @@ {if $settings.list_show_search_category}
By Category: -