I am using the CGUserDirectory for a website I'm constructing and had a question. I added the UDT multi-array function I found in the forum and it works great. Only problem I'm finding is with the pagelimit option. When I set the limit for whatever 25, 50, 100.. The sorting only affects the current page shown, it does not sort the complete directory of users.
Any Ideas?
Source I used..
http://forum.cmsmadesimple.org/index.ph ... #msg176045
Link to the directory in question
http://www.dickinsonisdalumni.com/index.php?directory
You will need to login to view it.
Username: AbshierRobert1969
password: temp123
CGUserDirectory pagelimit multi-array sort issue
Re: CGUserDirectory pagelimit multi-array sort issue
Here.. First you can make arrays in smarty.. This is how..
{foreach ','|explode:"foo,sue,tool" key=$key item=$item}
...
{/foreach}
from there you can sort
so you should be able to do this...
{foreach ','|explode:"foo,sue,tool"|sort:SORT_STRING key=$key item=$item}
(http://php.net/manual/en/function.sort.php)
also smarty has some of this...
{foreach from=$users|@sortby:lastName item=user}...
Hope this help give you some ideas on how to approach you need. Cheers -Jeremy
{foreach ','|explode:"foo,sue,tool" key=$key item=$item}
...
{/foreach}
from there you can sort
so you should be able to do this...
{foreach ','|explode:"foo,sue,tool"|sort:SORT_STRING key=$key item=$item}
(http://php.net/manual/en/function.sort.php)
also smarty has some of this...
{foreach from=$users|@sortby:lastName item=user}...
Hope this help give you some ideas on how to approach you need. Cheers -Jeremy
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: CGUserDirectory pagelimit multi-array sort issue
CGUserDirectories 'limit' parameter limits the amount of data that is queried from the database and allows for pagination, and sorting on a limited amount of stuff.
The other UDT is capable of taking that 'already limited' data and sorting it differently.
They're two different types of sorting... and unfortunately you can't mix them very well. i.e: if you have 5000 users, and want them sorted in page sizes of 30 you can do that. You can then take those 30 records that are displayed and sort them differently using the UDT that Jeremy created. But you can't mix the two. CGUserDirectory doesn't support arbitrary user property sorting at this time.
The other UDT is capable of taking that 'already limited' data and sorting it differently.
They're two different types of sorting... and unfortunately you can't mix them very well. i.e: if you have 5000 users, and want them sorted in page sizes of 30 you can do that. You can then take those 30 records that are displayed and sort them differently using the UDT that Jeremy created. But you can't mix the two. CGUserDirectory doesn't support arbitrary user property sorting at this time.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: CGUserDirectory pagelimit multi-array sort issue
Calguy knows based here
... is this based of a udt I posted? I didn't look at the post...
but side note hgmd2005 you don't want have you passwords up..


but side note hgmd2005 you don't want have you passwords up..
Re: CGUserDirectory pagelimit multi-array sort issue
That was a temp password, to let you guys in to see what the issue was.
I have already changed it.
I have already changed it.
Re: CGUserDirectory pagelimit multi-array sort issue
To All here is my current Template I'm using for the Summary Results and I included the UDT's I'm using for the sorting.
CGUserDirectory
Summary Tempate
Member-List
User Diffined Tag Multi_Array by planegoofy on 08 Sep 2009, 21:28
UDT
Name: array_flatten
UDT
Name: array_multisort
CGUserDirectory
Summary Tempate
Member-List
Code: Select all
{* CGUserDirectory summary template *}
{* {CGUserDirectory action="directory"} *}
{foreach from=$users item=foo name=oneuser}
{if $smarty.foreach.oneuser.last}
{array_flatten var="members" prop="properties" array="$users"}
{array_multisort var="members" array="$members" sortby="lastname,SORT_ASC"}
<strong> There are {$smarty.foreach.oneuser.total} members per page.</strong>
{/if}
{/foreach}
<div align="center"><span class="directory_arrows">
{if isset($firstpage_url)}
<a href="{$firstpage_url}" title="{$mod->Lang('lbl_first_page')}">«</a>
{/if}
{if isset($prevpage_url)}
<a href="{$prevpage_url}" title="{$mod->Lang('libl_prev_page')}">‹</a>
{/if}
<span class="directory_nav">
{$mod->Lang('page')} <span class="directory_page">{$curpage}</span> {$mod->Lang('of')} <span class="directory_page">{$numpages} </span>
</span>
{if isset($nextpage_url)}
<a href="{$nextpage_url}" title="{$mod->Lang('lbl_next_page')}">›</a>
{/if}
{if isset($lastpage_url)}
<a href="{$lastpage_url}" title="{$mod->Lang('lbl_last_page')}">»</a>
{/if}
</span></div>
<br>
<table style="width: 100%;" border="0" cellspacing="0" cellpadding="8">
<tr>
<th align="left">Member Name</th>
<th align="left">Class of</th>
<th align="left">Email Address</th>
<th align="left">Address</th>
</tr>
{foreach from=$members item=oneuser}
{* Members Name *}
<tr>
<td><span class="moderator">{if $oneuser.title ne ""}{$oneuser.title} {/if}{if $oneuser.firstname ne ""}{$oneuser.firstname } {/if}
{if $oneuser.nickname ne ""}<span class="nickname">"{$oneuser.nickname}" </span>{/if}
{if $oneuser.middlename ne ""}{$oneuser.middlename} {/if}
{if $oneuser.lastname ne ""}{$oneuser.lastname} {/if}
{if $oneuser.suffix ne ""}{$oneuser.suffix} {/if}</span>
{if $oneuser.maidenname ne ""}<span class="maidenname"> ({$oneuser.maidenname})</span>{/if}<br>
{if $oneuser.type == "Student"}<img src="images/disdalumni/layout2/gradcap.jpg" width="39" height="23" />{/if}
{if $oneuser.type == "Coach"}<img src="images/disdalumni/layout2/coach.jpg" width="34" height="25" />{/if}
{if $oneuser.type == "Teacher"}<img src="images/disdalumni/layout2/teacher.jpg" width="39" height="23" />{/if}
</td>
<td>
{if $oneuser.classof ne ""}<strong>{$oneuser.classof}</strong>{/if}<br>
{if $oneuser.classof2 ne ""}<span class="maidenname">{$oneuser.classof2}</span>{/if}
</td>
<td>
{foreach from=$oneuser.emailaddress item='onepropvalue' key='propname'}
{if $oneuser.emailaddress != ''}
<a href="mailto:{$onepropvalue}">{$onepropvalue}</a>
{/if}
{/foreach}
</td>
<td>
{if $oneuser.address1 != ''}{$oneuser.address1}{/if}<br>
{if $oneuser.city != ''}{$oneuser.city}{/if}, {if $oneuser.stateprovince != ''}{$oneuser.stateprovince}{/if} {if $oneuser.zip != ''}{$oneuser.zip}{/if}
</td>
</tr>
<tr>
<td colspan="4"><img src="images/disdalumni/layout2/hrblue.jpg" width="100%" height="1" /></td>
</tr>
{/foreach}
</tr>
</table>
<br>
<div align="center"><span class="directory_arrows">
{if isset($firstpage_url)}
<a href="{$firstpage_url}" title="{$mod->Lang('lbl_first_page')}">«</a>
{/if}
{if isset($prevpage_url)}
<a href="{$prevpage_url}" title="{$mod->Lang('libl_prev_page')}">‹</a>
{/if}
<span class="directory_nav">
{$mod->Lang('page')} <span class="directory_page">{$curpage}</span> {$mod->Lang('of')} <span class="directory_page">{$numpages} </span>
</span>
{if isset($nextpage_url)}
<a href="{$nextpage_url}" title="{$mod->Lang('lbl_next_page')}">›</a>
{/if}
{if isset($lastpage_url)}
<a href="{$lastpage_url}" title="{$mod->Lang('lbl_last_page')}">»</a>
{/if}
</span></div>
{* userdirectory_summary *}
User Diffined Tag Multi_Array by planegoofy on 08 Sep 2009, 21:28
UDT
Name: array_flatten
Code: Select all
// UDT to 'flatten' an array in smarty for use in your templates
// Created by Jeff Blank
// v0.1, August 30, 2009
// To use, add the following tag to your template:
// {array_flatten var="new_array" prop="field_to_remove" array="$original_array"}
global $gCms;
$smarty= &$gCms->GetSmarty();
// Get parameter values
$var_name= $params['var'];
$prop = $params['prop'];
$assoc_array= $params['array'];
$array_new=array();
foreach($assoc_array as $key => $value) {
foreach($value as $key2 => $value2) {
if ($key2 == $prop) {
foreach($value2 as $key3 => $value3) {
$array_new[$key][$key3]=$value3;
}
} else {
$array_new[$key][$key2]=$value2;
}
}
}
// Assign variables to smarty variable
$smarty->assign($var_name, $array_new);
Name: array_multisort
Code: Select all
// UDT to sort a multidimensional array in smarty for use in your templates
// Created by Jeff Blank
// v0.1, September 8, 2009
// usage : {array_multisort var="SortedArray" array="$ArrayToSort sortby=("field_name1,
// SORT_ASC/SORT_DESC,(SORT_REGULAR/SORT_STRING/SORT_NUMERIC),field_name2,...)}
// SORT_ASC - Sort field_name ascending
// SORT_DESC - Sort field_name descending.
// see array_multisort documentation for usage of optional SORT_REGULAR/SORT_STRING/SORT_NUMERIC
global $gCms;
$smarty= &$gCms->GetSmarty();
// Get parameter values
$var_name= $params['var'];
$array= $params['array'];
$sortby = explode(",", $params['sortby']);
// Assign all variables
$i= 0;
$sortdir=array("SORT_ASC"=>SORT_ASC, "SORT_DESC"=>SORT_DESC);
$sortmodes=array("SORT_REGULAR"=>SORT_REGULAR,"SORT_NUMERIC"=>SORT_NUMERIC,"SORT_STRING"=>SORT_STRING);
$arraylength= count($sortby)-1;
$params=array();
while ($i<$arraylength) {
$key=$sortby[$i];
$sortorder=$sortdir[$sortby[$i+1]];
foreach ($array as $k => $row) {
$colarray[$key][$k] = strtolower($row[$key]);
} // end foreach
if (in_array($sortorder, $sortdir)) {
if (in_array($sortby[$i+2], $sortmodes)) {
$sorttmode=$sortmodes[$sortby[$i+2]];
$params=array_merge ($params, array($colarray[$key], (int)$sortorder, (int)$sorttmode));
$i=$i+3;
} else {
$params=array_merge ($params, array($colarray[$key], (int)$sortorder));
$i=$i+2;
} // end if
} else {
echo "$sortby not a valid sort direction!!!";
} // end if
} // End while
$params=array_merge ($params, array(&$array));
call_user_func_array('array_multisort', $params);
// Assign variables to smarty variable
$smarty->assign($var_name, $array);
Re: CGUserDirectory pagelimit multi-array sort issue
Hi all,
It's good to see someone is getting use out of these UDTs. I wrote them to sort the results from CGuserdirectory and as Calguy said, you are limited to either all of the items in the selected FEU category or only to the number of items selected per page. One of my goals was to further this and work with both pagination and adding alphabetical anchors (for A, B, C etc...) but unfortunately I do this for an organization i belong to and family and work take higher precedence. Please let me know if you figure out a solution.
Maybe you could sort the list and crop it to the number you wanted and utilize extra parameters in the page address to tell whare to start, for example sort the list and either create a new list with only the first 50 (30, 100 or whatever) and use this list to display on the page. The pagination links could then add a variable to the end to indicate where in the list to start the next group in the list based on the page number. I know this may not be the most efficient but maybe it will work. If I get the time, I'll try it but not anytime soon as I am in the middle of a number of other issues and upgrades. Thanks.
Jeff
It's good to see someone is getting use out of these UDTs. I wrote them to sort the results from CGuserdirectory and as Calguy said, you are limited to either all of the items in the selected FEU category or only to the number of items selected per page. One of my goals was to further this and work with both pagination and adding alphabetical anchors (for A, B, C etc...) but unfortunately I do this for an organization i belong to and family and work take higher precedence. Please let me know if you figure out a solution.
Maybe you could sort the list and crop it to the number you wanted and utilize extra parameters in the page address to tell whare to start, for example sort the list and either create a new list with only the first 50 (30, 100 or whatever) and use this list to display on the page. The pagination links could then add a variable to the end to indicate where in the list to start the next group in the list based on the page number. I know this may not be the most efficient but maybe it will work. If I get the time, I'll try it but not anytime soon as I am in the middle of a number of other issues and upgrades. Thanks.
Jeff
Re: CGUserDirectory pagelimit multi-array sort issue (Solved)
I changed something and now it works.