Jump to content
fruid

pagination is never easy

Recommended Posts

I'm having and always have a hard time building PaginatedArrays, I never know where to put the "limit=24" selector so please enlighten me.

Here's what I'm doing…

$categories = $page->protable('start=0, limit=999999'); // this I need in order to retrieve the pages's "categories" and I don't know how to make use of $rows instead for that purpose because of this confusing limit-API 

$rows = $page->protable; // put ("limit=20") here?
$custom = buildSelector($input, $rows); // this function returns an array of selectors depending on the user input

$items = new PaginatedArray; // or here?
// or here? $items->find("limit=20")
// or like this? $items("limit=20")
// or like this? $items = $items("limit=20")
// or like this? $items = $items->find("limit=20")

foreach ($rows as $r) :
    if ($custom->get('selector')->matches($r)) :
        $items->add($r);
    endif;
endforeach;

// or at this point?

and then

if ($items) { // or maybe somewhere here?
    echo '<span class="grey">'.$items->getPaginationString(array(
       'label' => 'entries',
       'zeroLabel' => '0 entries', // 3.0.127+ only
       'usePageNum' => false,
       'count' => count($items),
       'start' => $items->getStart(),
       'limit' => count($items),
       'total' => $items->getTotal()
    ));

and then of course…

$pager = $modules->get("MarkupPagerNav");
echo '<div class="uk-flex uk-flex-center">'.$pager->render($items, $options).'</div>';

I'm out of ideas and confused cause it doesn't make sense to me either way.

____

The buildSelector function above returns and array…

$selected = new Selectors("$letter, $searchterm, $category");
$custom = new Wirearray;
$custom->set('selector', $selected);
$built->set('sort', $sort);
return $custom;

and each of the new selectors are basically strings ("category=whatever")

Also, you cannot put the "sort=title" or whatever as a selector for the Selectors function (see above). Why, I know not.

I don't know if that is the proper way but selecting kind of works now as opposed to many other ways I tried. Selectors always require a lot of trial and error, it seems to have a very sensitive API, always depends on double quotes, single quotes and how you concatenate.

Thanks for help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By fruid
      textformatters=TextformatterEntities in my field settings cause problems when moving data around (exporting, importing). I can't get rid of the entities in my code and so I have troubles filtering and selecting the content (I tried $sanitizer->unentities, actually need to apply that twice for it to look good but still does not filter/select properly). I figured It must be possible to change the format in the field directly and once and for all.
      What other options does "textformatters" allow? Because deleting it altogether doesn't work at all.
      thanks
       
    • By fruid
      I have a profield table and one of its fields is called category.
      I want to use the values of this field and created a unique array which I use for the options-filter.
      $rows = $pages->get('path/to/parent/page')->protable; $categories = new WireArray; foreach ($rows as $r) :     if ($r->category != '') :         $categories->add($r->category);     endif; endforeach; $categories = $categories->unique(); So I loop through the $categories array and output an option field for each.
      This kinda works but not with the pagination. On the second page it would only show the "options" (categories) of those entries that the unfiltered array would show on a second page.
      Where's the problem?
    • By picarica
      Hello si have this gallery, pretty good website, but yesterday client uploaded over 3000 images oto the site, and it cannot handle filtering them out and showing them at the same time , i wanted some simple pagination maybe infinite scrool or onclikc load whatever, but i cannot seem to implement infinite ajax scrool and any other JS methods, nut sure why i still got stuck at the next method, like there is not next page.
      so i wanted to implement PW method of paginating i wanted to use MarkupPagerNav
      so far i have  this code for outputting images
      $pa = $pages->find("template=basic-page|art_gallery, images.tags!=''"); /* $pa = $pages->find("has_parent!=2,id!=2|7,status<".Page::statusTrash.",include=all"); */ echo "<div class='js-filter' id='gal' >"; /* row gtr-50 gtr-uniform */ $frame = $pages->get('/settings/')->watermark; foreach ($pa as $p) { foreach($p->images as $image) { if(!$image->hasTag("act")) { $options = array('quality' => 80, 'upscaling' => true, 'cropping' => 'north', 'sharpening'=>'medium'); $large = $image->size(1200, 0, $options); $wmImage = $large->pim2Load('wm1', ['quality'=>80, 'upscaling' => true, 'sharpening'=>'medium', 'defaultGamma'=>-1])->watermarkLogo($frame, $position='se',$padding=1.5)->pimSave(); /* zmazanie variacii, treba odpoznakovat ked sa menia nastavenie vyssie */ /* $image->pim2Load('wm1')->removePimVariations(); */ $thumb = $image->size(400, 300, $options); echo "<div class='$image->tags grid-item' style=''>"; echo "<span style='overflow:hidden;'class='image fit'>"; echo "<a class='hvr-reveal' href='$wmImage->url'>"; echo "<img uk-scrollspy='cls: uk-animation-fade; repeat: false' src='$thumb->url' alt='$image->tags'>"; echo "</a>"; echo "</span>"; echo "</div>"; } else { $options = array('quality' => 80, 'upscaling' => true, 'cropping' => 'north', 'sharpening'=>'medium'); $large = $image->size(1200, 0, $options); $wmImage = $large->pim2Load('wm2', ['quality'=>80, 'upscaling' => true, 'sharpening'=>'medium', 'defaultGamma'=>-1])->pixelate(25)->smooth(255)->watermarkLogo($frame, $position='se',$padding=1.5)->pimSave(); /* zmazanie variacii, treba odpoznakovat ked sa menia nastavenie vyssie */ /* $image->pim2Load('wm2')->removePimVariations(); */ $thumb = $image->size(400, 300, $options); echo "<div class='$image->tags blur grid-item' style=''>"; echo "<span style='overflow:hidden;'class='image fit'>"; echo "<a class='hvr-reveal' href='$wmImage->url'>"; echo "<img uk-scrollspy='cls: uk-animation-fade; repeat: false' src='$thumb->url' alt='$image->tags'><span>18+</span>"; /* <span>BY OPENING THIS IMAGE YOU CONSET THAT YOU'RE 18 YEARS OR OLDER</span> text copyraightova,y dat vedla obrazky potom */ echo "</a>"; echo "</span>"; echo "</div>"; } } }; to put it  simply, it first searches for sites, and then outputs all images from those sites, pretty simple, it also uses watermarking and uikit filtering
      i have filtering done like this
      $num = 1; echo "<ul class='uk-subnav uk-subnav-pill'>"; foreach(array_unique($alltags) as $key => $tag) { echo"<li uk-filter-control='filter: .$tag;group: $num' class='butt$num' uk-toggle='target: .butt$num ; animation: uk-animation-fade; queued: true'><a href='#'>$tag</a></li>"; echo"<li uk-filter-control='group: $num' class='butt$num active' aria-hidden='true' hidden='' uk-toggle='target: .butt$num; animation: uk-animation-fade'><a href='#'>remove - $tag</a></li>"; $num++; } echo "</ul>"; simple, but i have NO idea how to implement pagination, just because it seems to work that it like find all images, and stores with limit, and then just paginates them, but i cannot apply this method in my code.
      any idea how to make any JS inifite scroll work ? or just how to make this work ? with my setup, or with some modifications, it just have to work as is now
    • By fruid
      so I have a Profields Table on a sibling's page, trying to access it from its sibling's page (DUH!) which is $page now, cause that's where I am right now.
      I do
          $toc = $page->siblings("template=tableofcontents")->tableofcontents_table;     $toc->render(); or
          $toc = $page->siblings("template=tableofcontents");     $toc = $toc->tableofcontents_table;     $toc->render(); but it just won't work because Call to a member function render() on null
      The table clearly is there and clearly is a sibling and its template is as stated and the table also.
      Please help me quick, about to throw the computer out the window, thank you.
    • By SwimToWin
      I want to add a dependent SELECT field on my template page that lists pages from a parent "sub-page" in the current parent node.
      On /product1/page I have the field "photo" which is a SELECT field.
      I want the SELECT to list pages from /ROOTPARENT/photos.
      The idea is that I can reuse the same photo in many places - but only need to keep it update it once under /product1/photos.
      My page structure looks like so:
      /product1/page /product1/photos/photo3 (template=photos) /product2/photos/photo9 I have tried adding these Selector Strings on the Field (Setup -> Fields -> PHOTO -> Input tab -> Selectable Pages field group -> Selector String):
      parent=/product1/page, template=photos, sort=name WORKS (but only on children of current product). parent=page.rootParent ... parent=$page.rootParent ... parent=$page.rootParent parent=$parent ... parent=$parent1 When using a SELECT Input Field Type, the editing pages gives the fatal error "Unrecognized operator: $". parent=parent ... parent=. Returns an empty list How might I find child pages from the current "/product1/photos/ page"?
      Your inputs are appreciated. Thanks.
×
×
  • Create New...