Fórum

Controlling Asset Publisher Pagination

abdul hakim muzani, modificado 7 Anos atrás.

Controlling Asset Publisher Pagination

New Member Postagens: 9 Data de Entrada: 01/02/17 Postagens Recentes
Hey all,

So i have an asset publisher, that loads a list of web contents with certain template. I also have a requirement to only list items if the item's userId equals to the logged in userId.

What i did so far is to check those user ids inside the asset entry loop, in application display template (freemarker)

<#list entries as entry >
    ..... 
    <#if userId == articleUserId>
         ......
    <!--#if-->
<!--#list-->


This however, does not bode well with pagination. When the asset publisher loads the designated web contents, it also set the total items variable. So my pagination becomes incorrect.

For example :
Let's say i have 30 items loaded by asset publisher, and i set pagination to 10 per page. But the contents that satisfy the userId == articleUserId criteria, is only 3. This will make the asset publisher only show 3 items, but the pagination buttons are there. So when i clicked next, it only shows empty list.

So how do i control the pagination? Is there a better way to filter listed items?
If i need to hook it, is there a way that my hook will only work to this particular asset publisher?

Thanks in Advance,

Abdul Hakim Muzani
abdul hakim muzani, modificado 7 Anos atrás.

RE: Controlling Asset Publisher Pagination

New Member Postagens: 9 Data de Entrada: 01/02/17 Postagens Recentes
In hook, in view_dynamic_list.jspf, i found this line :

Hits hits = AssetUtil.search(request, assetEntryQuery, start, end);
total = hits.getLength();
searchContainer.setTotal(total);
results = AssetUtil.getAssetEntries(hits);


The code above, controls which and how many shown for each pagination page. So doing the userId check on result, and the total value still don't give whats desired.

To complicate things, i also have requirement to check a custom field value in each article.

So what i need now is to control the assetEntryQuery. How can i use assetEntryQuery to look for certain userId and get custom field from each asset entry?

Please help.
thumbnail
Kailash Yadav, modificado 7 Anos atrás.

RE: Controlling Asset Publisher Pagination

Regular Member Postagens: 211 Data de Entrada: 18/10/11 Postagens Recentes
You can remove view permission from web contents for guest/user roles. Only visible for owner.
Also you can try following code in hook, not sure it will work or not..

SearchContext searchContext = SearchContextFactory.getInstance(request);
searchContext.setUserId(userId);
Hits hits = AssetUtil.search(searchContext , assetEntryQuery, start, end);
abdul hakim muzani, modificado 7 Anos atrás.

RE: Controlling Asset Publisher Pagination

New Member Postagens: 9 Data de Entrada: 01/02/17 Postagens Recentes
Thank you for your response Kailash Yadav. But i decided to go in different way
Nikita Laitinen, modificado 4 Anos atrás.

RE: Controlling Asset Publisher Pagination

Junior Member Postagens: 44 Data de Entrada: 18/12/19 Postagens Recentes
Hi! Could you tell me which way you've decided to use?