Userlist pagination problem

Permalink
Hi Folks

I hope I am posting in the right place if not just let me know. Basically I have managed to print out a list of all users to a page. And I have managed to display a total number of users listed. I can also filter all users via a form. The only problem is that it doesn't split the users into separate pages with the pagination.

It recognises there are 10 users listed, it recognises that they should be in sets of 5 and so shows two pages as an option, it just doesn't split the users in to 5 on each page...

I am using this:

<?php
   $pagination = $list->getPagination();
   $pagination->setMaxPerPage(5)->setCurrentPage(1);
   $results = $pagination->getCurrentPageResults();
   $pagination->hasNextPage();
   $pagination->hasPreviousPage();
?>


and this at the bottom

<?php if ($pagination->getTotalPages() > 1) {
echo $pagination->renderDefaultView(); 
}?>


Just give me a shout to see what else you need, the dev site is here:http://hostga.aurora-studio-dev.co.uk/index.php/all-guides...

AuroraTim
 
shahroq replied on at Permalink Reply
shahroq
I am not sure why sometimes pagination not only in user list but also in the collection and file list generates a wrong result and I haven't investigated the reason. But adding this line before 'getCurrentPageResults();' should fix it in your case:
$pagination->setCurrentPage($_GET['ccm_paging_p'] ? $_GET['ccm_paging_p'] : 1);
//OR If you are on PHP 7:
$pagination->setCurrentPage($_GET['ccm_paging_p'] ?? 1);

https://github.com/shahroq/whale_c5_cheat_sheet#get-list-of-users-wi...
AuroraTim replied on at Permalink Reply
AuroraTim
Hi Shahroq

Thankn you very much for the reply, it sstill doesnt seem to want to split the results up, I am wondering if I just dont have it in the right order?

Here is the entire code for the page

[code]

<?php
$list = new \Concrete\Core\User\UserList();
$group = \Group::getByName('Administrators');
$submit_form = $_REQUEST['submit'];
$language = $_REQUEST['language'];
$startingPoints = $_REQUEST['starting_points'];
$tourInterests = $_REQUEST['tour_interests'];
$tourType = $_REQUEST['tour_type'];
$list->filterByGroup($group, false);
$users = $list->getResults();
?>



<!DOCTYPE html>
<?=$view->inc('elements/head.php');?>

<body class="inner">
<div class="<?= $c->getPageWrapperClass() ?>">
<?=$view->inc('elements/header.php');?>
<?=$view->inc('elements/innerslider.php');?>
<section class ="guide-widget">
<div class="guide-widget-wrapper">
<?php
$a = new Area('Guide Widget Content');
$a->display($c);
?>

<form class="selections" method="get" id="submit_form">
<fieldset>
<label for="language">Language</label>
<select class="select-css" id = "language" name="language" onchange="this.form.submit()">
<option value="all">All</option>
<option value="english">English</option>
<option value="danish">Danish</option>
<option value="french">French</option>
<option value="german">German</option>
<option value="italian">Italian</option>
<option value="norwegian">Norwegian</option>
<option value="russian">Russian</option>
<option value="spanish">Spanish</option>
<option value="swedish">Swedish</option>
<option value="mandarin">Mandarin</option>
</select>
</fieldset>


<fieldset class = "starting-point-fields">
<label for="starting_points">Starting Points</label>
<select class="select-css" id = "starting_points" name="starting_points" onchange="this.form.submit()" >
<option value="all">All</option>
<option value="aberdeen">Aberdeen</option>
<option value="edinburgh">Edinburgh</option>
<option value="fort_william">Fort William</option>
<option value="glasgow">Glasgow</option>
<option value="invergordon">Invergordon</option>
<option value="inverness">Inverness</option>
<option value="kirkwall">Kirkwall</option>
<option value="moray">Moray</option>
<option value="oban">Oban</option>
<option value="peterhead">Peterhead</option>
<option value="portree">Portree</option>
<option value="scottish_borders">Scottish Borders</option>
<option value="scrabster">Scrabster</option>
<option value="ullapool">Ullapool</option>
</select>
</fieldset>

<fieldset>
<label for="tour_interests">Tour Interests</label>
<select class="select-css" id = "tour_interests" name="tour_interests" onchange="this.form.submit()">
<option value="all">All</option>
<option value="architecture_industry">Architecture & Industry</option>
<option value="archaeology_prehistory">Archaeology & Prehistory</option>
<option value="castles_clans">Castles/Clans</option>
<option value="distilleries_whisky">Distilleries & Whisky</option>
<option value="gardens_landscapes">Gardens & Landscaping</option>
<option value="geology_geomorphology">Geology & Geomorphology</option>
<option value="hill_walking_hiking">Hill Walking & Hiking</option>
<option value="landscapes_scenery">Landscapes & Scenery</option>
<option value="outlander">Outlander</option>
<option value="scottish_history">Scottish History</option>
<option value="wildlife_fauna_flora">Wildlife Fauna & Flora</option>
</select>
</fieldset>

<fieldset>
<label for="tour_type">Tour Type</label>
<select class="select-css" id = "tour_type" name="tour_type" onchange="this.form.submit()">
<option value="all">All</option>
<option value="shore_excursions">Shore Excurions</option>
<option value="day_coach_tours">Day Coach Tours</option>
<option value="extended_coach_tours">Extended Coach Tours</option>
<option value="driving_day_tour">Driving Day Tour</option>
<option value="special_needs">Special Needs</option>
<option value="walking_hiking">Walking & Hiking</option>
</select>
</fieldset>

<a type="reset" href="http://hostga.aurora-studio-dev.co.uk/index.php/all-guides">Refresh</a>
</form>



</div>
</section>

<section id="inner-content">
<div class="inner-content-wrapper">



<?php

if ($_SERVER['REQUEST_METHOD'] == 'GET'){

switch ($language) {
case "all":
echo('<script>$("#language").val("all");</script>');
break;
case "english":
$list->filterByEnglish(1);
echo('<script>$("#language").val("english");</script>');
break;
case "danish":
$list->filterByDanish(1);
echo('<script>$("#language").val("danish");</script>');
break;
case "french":
$list->filterByFrench(1);
echo('<script>$("#language").val("french");</script>');
break;
case "german":
$list->filterByGerman(1);
echo('<script>$("#language").val("german");</script>');
break;
case "italian":
$list->filterByItalian(1);
echo('<script>$("#language").val("italian");</script>');
break;
case "norwegian":
$list->filterByNorwegian(1);
echo('<script>$("#language").val("norwegian");</script>');
break;
case "russian":
$list->filterByRussian(1);
echo('<script>$("#language").val("russian");</script>');
break;
case "spanish":
$list->filterBySpanish(1);
echo('<script>$("#language").val("spanish");</script>');
break;
case "swedish":
$list->filterBySwedish(1);
echo('<script>$("#language").val("swedish");</script>');
break;
case "mandarin":
$list->filterByMandarin(1);
echo('<script>$("#language").val("mandarin");</script>');
break;

default:
echo('<script>$("#language").val("all");</script>');
};


switch ($startingPoints) {
case "all":
echo('<script>$("#starting_points").val("all");</script>');
break;
case "aberdeen":
$list->filterByAberdeen(1);
echo('<script>$("#starting_points").val("aberdeen");</script>');
break;
case "edinburgh":
$list->filterByEdinburgh(1);
echo('<script>$("#starting_points").val("edinburgh");</script>');
break;
case "fort_willliam":
$list->filterByFortWilliam(1);
echo('<script>$("#starting_points").val("fort_william");</script>');
break;
case "glasgow":
$list->filterByGlasgow(1);
echo('<script>$("#starting_points").val("glasgow");</script>');
break;
case "invergordon":
$list->filterByInvergordon(1);
echo('<script>$("#starting_points").val("invergordon");</script>');
break;
case "inverness":
$list->filterByInverness(1);
echo('<script>$("#starting_points").val("inverness");</script>');
break;
case "kirkwall":
$list->filterByKirkwall(1);
echo('<script>$("#starting_points").val("kirkwall");</script>');
break;
case "moray":
$list->filterByMoray(1);
echo('<script>$("#starting_points").val("moray");</script>');
break;
case "oban":
$list->filterByOban(1);
echo('<script>$("#starting_points").val("oban");</script>');
break;
case "peterhead":
$list->filterByPeterhead(1);
echo('<script>$("#starting_points").val("peterhead");</script>');
break;
case "portree":
$list->filterByPortree(1);
echo('<script>$("#starting_points").val("portree");</script>');
break;
case "scottish_borders":
$list->filterByScottishBorders(1);
echo('<script>$("#starting_points").val("scottish_borders");</script>');
break;
case "scrabster":
$list->filterByScrabster(1);
echo('<script>$("#starting_points").val("scrabster");</script>');
break;
case "ullapool":
$list->filterByUllapool(1);
echo('<script>$("#starting_points").val("ullapool");</script>');
break;

default:
echo('<script>$("#starting_points").val("all");</script>');
};

switch ($tourInterests) {
case "all":
echo('<script>$("#tour_interests").val("all");</script>');
break;
case "architecture_industry":
$list->filterByArchitectureIndustry(1);
echo('<script>$("#tour_interests").val("architecture_industry");</script>');
break;
case "archaeology_prehistory":
$list->filterByArchaeologyPrehistory(1);
echo('<script>$("#tour_interests").val("archaeology_prehistory");</script>');
break;
case "castles_clans":
$list->filterByCastlesClans(1);
echo('<script>$("#tour_interests").val("castles_clans");</script>');
break;
case "distilleries_whisky":
$list->filterByDistilleriesWhisky(1);
echo('<script>$("#tour_interests").val("distilleries_whisky");</script>');
break;
case "gardens_landscapes":
$list->filterByGardensLandscapes(1);
echo('<script>$("#tour_interests").val("gardens_landscapes");</script>');
break;
case "geology_geomorphology":
$list->filterByGeologyGeomorphology(1);
echo('<script>$("#tour_interests").val("geology_geomorphology");</script>');
break;
case "hill_walking_hiking":
$list->filterByHillWalkingHiking(1);
echo('<script>$("#tour_interests").val("hill_walking_hiking");</script>');
break;
case "landscapes_scenery":
$list->filterByLandscapesScenery(1);
echo('<script>$("#tour_interests").val("landscapes_scenery");</script>');
break;
case "outlander":
$list->filterByOutlander(1);
echo('<script>$("#tour_interests").val("outlander");</script>');
break;
case "scottish_history":
$list->filterByScottishHistory(1);
echo('<script>$("#tour_interests").val("scottish_history");</script>');
break;
case "wildlife_fauna_flora":
$list->filterByWildlifeFaunaFlora(1);
echo('<script>$("#tour_interests").val("wildlife_fauna_flora");</script>');
break;

default:
echo('<script>$("#tour_interests").val("all");</script>');

};

switch ($tourType) {
case "all":
echo('<script>$("#tour_type").val("all");</script>');
break;
case "shore_excursions":
echo('<script>$("#tour_type").val("shore_excursions");</script>');
break;
case "day_coach_tours":
echo('<script>$("#tour_type").val("day_coach_tours");</script>');
break;
case "extended_coach_tours":
echo('<script>$("#tour_type").val("extended_coach_tours");</script>');
break;
case "driving_day_tour":
echo('<script>$("#tour_type").val("driving_day_tour");</script>');
break;
case "special_needs":
echo('<script>$("#tour_type").val("special_needs");</script>');
break;
case "walking_hiking":
echo('<script>$("#tour_type").val("walking_hiking");</script>');
break;

default:
echo('<script>$("#tour_type").val("all");</script>');

};


}
?>

<?php
$pagination = $list->getPagination();
$pagination->setMaxPerPage(5)->setCurrentPage(1);
$pagination->setCurrentPage($_GET['ccm_paging_p'] ?? 1);
$results = $pagination->getCurrentPageResults();
$pagination->hasNextPage();
$pagination->hasPreviousPage();
?>

<div class="results">
<h3>There are
<?php
echo $pagination->getTotalResults();
?>
guides matching your search
</h3>
</div>

<ul class="guide-list">



<?php
$loggedIn = false;
$loggedInUserName = '';
$u = new User();
if ($u -> isLoggedIn()) {
$loggedIn = true;
$loggedInUserName = $u->getUsername();
}
?>

<?php
function trunc($longUserBio, $max_words) {
$userBio_array = explode(' ',$longUserBio);
if(count($userBio_array) > $max_words && $max_words > 0){
$userBio = implode(' ',array_slice($userBio_array, 0, $max_words)).'...';
return $userBio;
};
};

$users = $list->getResults();
foreach ($users as $user){
$avatar = $user->getUserAvatar();
$userName = $user->getUserName();
$userGuideName = $user->getUserGuideName();
$userGuideEmail = $user->getUserGuideEmail();
$userGuideWebsite = $user->getUserGuideWebsite();
$userGuideLandline = $user->getUserGuideLandline();
$userGuideMobile = $user->getUserGuideMobile();
$userLinks = $user->getUserAccountProfileLinks();
$userBio = strip_tags($user->getUserGuideBio());
$userBio = trunc($userBio, 40);
$userCpd = $user->getUserCpd();
$userHostga = $user->getUserHostga();
$userStgaBlue = $user->getUserStgaBlue();
$userStgaGreen = $user->getUserStgaGreen();
$userHalfDay = $user->getUserHalfDay();
$userFullDay = $user->getUserFullDay();
$userAllYearRound = $user->getUserAllYearRound();
//Guide Starting Points
$userAberdeen = $user->getUserAberdeen();
$userEdinburgh = $user->getUserEdinburgh();
$userFortWilliam = $user->getUserFortWilliam();
$userGlasgow = $user->getUserGlasgow();
$userInvergordon = $user->getUserInvergordon();
$userInverness = $user->getUserInverness();
$userMoray = $user->getUserMoray();
$userKirkwall = $user->getUserKirkwall();
$userOban = $user->getUserOban();
$userPeterhead = $user->getUserPeterhead();
$userPortree = $user->getUserPortree();
$userScrabster = $user->getUserScrabster();
$userScottishBorders = $user->getUserScottishBorders();
$userUllapool = $user->getUserUllapool();
//Tour Types
$userShoreExcursions = $user->getUserShoreExcursions();
$userDayCoachTours = $user->getUserDayCoachTours();
$userExtendedCoach = $user->getUserExtendedCoach();
$userDrivingDayTour = $user->getUserDrivingDayTour();
$userDrivingExtended = $user->getUserDrivingExtended();
$userSpecialNeeds = $user->getUserSpecialNeeds();
$userWalkingHiking = $user->getUserWalkingHiking();
//Tour Interest
$userArchitectureIndustry = $user->getUserArchitectureIndustry();
$userArchaeologyPrehistory = $user->getUserArchaeologyPrehistory();
$userCastlesClans = $user->getUserCastlesClans();
$userDistilleriesWhisky = $user->getUserDistilleriesWhisky();
$userFolkloreMusic = $user->getUserFolkloreMusic();
$userGardensLandscaping = $user->getUserGardensLandscaping();
$userGeologyGeomorphology = $user->getUserGeologyGeomorphology();
$userHillWalkingHiking = $user->getUserHillWalkingHiking();
$userLandscapeScenery = $user->getUserLandscapeScenery();
$userOutlander = $user->getUserOutlander();
$userScottishHistory = $user->getUserScottishHistory();
$userWildlifeFaunaFlora = $user->getUserWildlifeFaunaFlora();
//Languages

$userPrimaryLanguage = $user->getUserPrimaryLanguage();

//Secondary Languages
$userEnglish = $user->getUserEnglish();
$userEnglishConv = $user->getUserEnglishConv();
$userDanish = $user->getUserDanish();
$userDanishConv = $user->getUserDanishConv();
$userFrench = $user->getUserFrench();
$userFrenchConv = $user->getUserFrenchConv();
$userGerman = $user->getUserGerman();
$userGermanConv = $user->getUserGermanConv();
$userItalian = $user->getUserItalian();
$userItalianConv = $user->getUserItalianConv();
$userNorwegian = $user->getUserNorwegian();
$userNorwegianConv = $user->getUserNorwegianConv();
$userRussian = $user->getUserRussian();
$userRussianConv = $user->getUserRussianConv();
$userSpanish = $user->getUserSpanish();
$userSpanishConv = $user->getUserSpanishConv();
$userSwedish = $user->getUserSwedish();
$userSwedishConv = $user->getUserSwedishConv();
$userMandarin = $user->getUserMandarin();
$userMandarinConv = $user->getUserMandarinConv();
?>





<li>
<div class="left-column">
<div class="guide">
<?php
if ($user->hasAvatar()) {
$img = $avatar->getPath();
echo('<img src = "'.$img.'">');
} else {
echo('<img src = "/application/files/avatars/member-default.jpg">');
}
?>

</div>
<div class="guide-contacts">

<a class="guide-email" href="mailto:<?php echo $userGuideEmail; ?>">Email Guide</a>

<?php if ($userGuideWebsite != null){
echo ('<a class="guide-website" target="_blank" href="'.$userGuideWebsite = $user->getUserGuideWebsite().'">Website</a>');
}
?>


<div class="guide-socials">

<?php

if (is_object($userLinks)){

foreach ($userLinks->getSelectedLinks() as $link) {
$serviceObject = \Concrete\Core\Sharing\SocialNetwork\Service::getByHandle($link->getService());
if (is_object($serviceObject)) {
$iconHtml = $serviceObject->getServiceIconHTML();
}
echo('<a target="_blank" class="" href = "'.$link->getServiceInfo().'">'.$iconHtml.'</a>');
}
}

?>

</div>
</div>
</div><!-- end left column -->

<div class="right-column">
<h3 class="guide-name"><?php echo $userGuideName; ?></h3>

<ul class="guide-qualifications">
<?php if ($user->getUserCpd()){
echo ('<li class="cpd"></li>');
};

if ($user->getUserHostga()){
echo ('<li class="hostga"></li>');
};

if ($user->getUserStgaBlue()){
echo ('<li class="stga-blue"></li>');
};

if ($user->getUserStgaGreen()){
echo ('<li class="stga-green"></li>');
};

?>
</ul>

<p><?php echo $userBio; ?>...<br><a class="readmore" href="<?php echo $this->url('/members/profile','view', $user->getUserID())?>">Read more</a>
</p>

<hr class="inner-rule">


<ul class="guide-phone">
<h3>Contact Numbers</h3>
<li class="landline"><?php echo $userGuideLandline; ?></li>
<li class="mobile"><?php echo $userGuideMobile; ?></li>
</ul>
<hr class="inner-rule">
<ul class="days">
<h3>Availability</h3>
<?php if ($userHalfDay){
echo ('<li>Half Day</li>');
};

if ($userFullDay){
echo ('<li>Full Day</li>');
};

if ($userAllYearRound){
echo ('<li>All Year Round</li>');
};
?>
</ul>

<hr class="inner-rule">

<div class="guide-services-list">
<div class="guide-services">
<h3>Tour Types</h3>
<ul>
<?php if ($userShoreExcursions){
echo ('<li>Shore Excursions</li>');
};

if ($userDayCoachTours){
echo ('<li>Day Coach Tours</li>');
};

if ($userExtendedCoach){
echo ('<li>Extended Coach</li>');
};

if ($userDrivingDayTour){
echo ('<li>Driving Day Tour</li>');
};

if ($userDrivingExtended){
echo ('<li>Driving Extended</li>');
};

if ($userSpecialNeeds){
echo ('<li>Special Needs</li>');
};

if ($userWalkingHiking){
echo ('<li>Walking & Hiking</li>');
};
?>
</ul>
</div>

<div class="guide-services">
<h3>Starting Points</h3>
<ul>
<?php if ($userAberdeen){
echo ('<li>Aberdeen</li>');
};

if ($userEdinburgh){
echo ('<li>Edinburgh</li>');
};

if ($userFortWilliam){
echo ('<li>Fort William</li>');
};

if ($userGlasgow){
echo ('<li>Glasgow</li>');
};

if ($userInvergordon){
echo ('<li>Invergordon</li>');
};

if ($userInverness){
echo ('<li>Inverness</li>');
};

if ($userMoray){
echo ('<li>Moray</li>');
};

if ($userKirkwall){
echo ('<li>Kirkwall</li>');
};

if ($userOban){
echo ('<li>Oban</li>');
};

if ($userPeterhead){
echo ('<li>Peterhead</li>');
};

if ($userPortree){
echo ('<li>Portree</li>');
};

if ($userScrabster){
echo ('<li>Scrabster</li>');
};

if ($userScottishBorders){
echo ('<li>Scottish Borders</li>');
};

if ($userUllapool){
echo ('<li>Ullapool</li>');
};


?>
</ul>
</div>

<div class="guide-services">
<h3>Tour Interests</h3>
<ul>
<?php if ($userArchitectureIndustry){
echo ('<li>Architecture & Industry</li>');
};

if ($userArchaeologyPrehistory){
echo ('<li>Archaeology & Pre-History</li>');
};

if ($userCastlesClans){
echo ('<li>Castles & Clans</li>');
};

if ($userDistilleriesWhisky){
echo ('<li>Distilleries & Whisky</li>');
};

if ($userFolkloreMusic){
echo ('<li>Folklore & Music</li>');
};

if ($userGardensLandscaping){
echo ('<li>Gardening & Landscaping</li>');
};

if ($userGeologyGeomorphology){
echo ('<li>Geology & Geomorphology</li>');
};

if ($userHillWalkingHiking){
echo ('<li>Hill Walking & Hiking</li>');
};

if ($userLandscapeScenery){
echo ('<li>Landscapes & Scenery</li>');
};

if ($userOutlander){
echo ('<li>Outlander</li>');
};

if ($userScottishHistory){
echo ('<li>Scottish History</li>');
};

if ($userWildlifeFaunaFlora){
echo ('<li>Wildlife Fauna & Flora</li>');
};

?>
</ul>
</div>

<div class="guide-services">
<h3>Languages</h3>

<ul>
<li><strong><?php echo $userPrimaryLanguage; ?></strong></li>
<?php if ($userEnglish || $userEnglishConv){
if ($userEnglishConv){
echo ('<li>English (Conv)</li>');
} else {
echo ('<li>English</li>');
}
};

if ($userDanish || $userDanishConv){
if ($userDanishConv){
echo ('<li>Danish (Conv)</li>');
} else {
echo ('<li>Danish</li>');
}
};

if ($userFrench || $userFrenchConv){
if ($userFrenchConv){
echo ('<li>French (Conv)</li>');
} else {
echo ('<li>French</li>');
}
};

if ($userGerman || $userGermanConv){
if ($userGermanConv){
echo ('<li>German (Conv)</li>');
} else {
echo ('<li>German</li>');
}
};

if ($userItalian || $userItalianConv){
if ($userItalianConv){
echo ('<li>Italian (Conv)</li>');
} else {
echo ('<li>Italian</li>');
}
};

if ($userNorwegian || $userNorwegianConv){
if ($userNorwegianConv){
echo ('<li>Norwegian (Conv)</li>');
} else {
echo ('<li>Norwegian</li>');
}
};

if ($userRussian || $userRussianConv){
if ($userRussianConv){
echo ('<li>Russian (Conv)</li>');
} else {
echo ('<li>Russian</li>');
}
};

if ($userSpanish || $userSpanishConv){
if ($userSpanishConv){
echo ('<li>Spanish (Conv)</li>');
} else {
echo ('<li>Spanish</li>');
}
};

if ($userSwedish || $userSwedishConv){
if ($userSwedishConv){
echo ('<li>Swedish (Conv)</li>');
} else {
echo ('<li>Swedish</li>');
}
};

if ($userMandarin || $userMandarinConv){
if ($userMandarinConv){
echo ('<li>Mandarin (Conv)</li>');
} else {
echo ('<li>Mandarin</li>');
}
};


?>
</ul>
</div>
</div>

</div><!-- end right column -->
</li><!-- end guide -->





<?php } ?>








</ul>


<?php
if ($pagination->getTotalPages() > 1) {
echo $pagination->renderDefaultView(); //Outputs HTML for Bootstrap 3.

}?>
</section>






</div><!-- end inner content wrapper -->
</section>
<?=$view->inc('elements/footer.php');?>
</div>
<?php Loader::element('footer_required') ?>
</body>
</html>

[/code]
shahroq replied on at Permalink Reply
shahroq
I don't see any problem in your code except you have 2 'setCurrentPage'. Yet it shouldn't affect the result as the second one is correct. Have you tried your page with all cache setting off?
AuroraTim replied on at Permalink Reply
AuroraTim
Yip all block caching was off but I also dumped the cache files from the application folder too just in case.

I tried it in a different browser too just to be sure.
AuroraTim replied on at Permalink Reply
AuroraTim
Got this sorted, I literally had one extra "for each" and it was screwing my pages... typical.

cheers for the help