* @access private
*/
public $pseudoRand = false;
+ /**
+ * Random Order flag (uses new seed each time)
+ *
+ * @access private
+ */
+ public $rand = false;
/*
*
* @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
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
}
- // 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
}
$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'];
}
* 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
* @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
* '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) {
// 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
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.
{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} {/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>