Page 1 of 1

serendipity_fetchPrintEntries: prevent duplicate entries?

Posted: Sun Mar 23, 2008 2:40 am
by Don Chambers
Does any combination of caching, prevent_reset, filter_sql, etc of serendipity_fetchPrintEntries eliminate the possibility of duplicate entries in successive serendipity_fetchPrintEntries for different categories?

To better explain, lets say I have a page where I want to fetch the 5 most recent entries for category 1, then the 5 most recent for category 2, then the 5 most recent for category 3..... So, in smarty, I have

Code: Select all

{serendipity_fetchPrintEntries limit="0,5" category="1"}
{serendipity_fetchPrintEntries limit="0,5" category="2"}
{serendipity_fetchPrintEntries limit="0,5" category="3"}
It is possible that entries could be associated with 1, 2 or all 3 categories.

Is there any way to not include an entry if it has already been fetched or to otherwise assign some kind of priority? IE, if I fetch category 1 first, then get to category 2, and an entry has already been fetched because it is in cat 1, I do not want to list it a second time.....

Priority of some kind would be even better, because lets say an entry is assigned to categories 2 & 3... I'm fetching category 2 at that stage, but really want the entry to appear in category 3's list......

I've tried to simplify the matter using just 3 categories, but the solution (if any) needs to work with a lot more than just 3 categories (or as little as 2).

Posted: Mon Mar 24, 2008 2:22 am
by judebert
filter_sql can do the job. Unfortunately, it's not going to be easy unless you know SQL. If you set 'prevent_reset' to true, the entries you fetched will stay in the {$entries} array. You could then build an SQL filter excluding their IDs by looping through them:

Code: Select all

{assign var=filter value=""}
{foreach from=$entries.dategroup item="dategroup"}
  {foreach from=$dategroup.entries item="entry"}
    {if $filter}
      {assign var=filter value="e.id != $entry.id"}
    {else}
      {assign var=filter value="$filter AND e.id != $entry.id}
    {/if}
  {/foreach}
{/foreach}
The {if} prevents the AND from being added on the front; it doesn't belong there, as fetchPrintEntries will add one itself.

Then add a filter_sql variable equivalent to the new filter to your next fetchPrintEntries call. That'll keep the entries from being duplicated.

Complex, but it should work. Otherwise we'd have to add some kind of memory to serendipity_fetchEntries(), and it's already pretty darn complex.

The only way to prioritize is to call the functions in the correct order. There might be something to be done with Smarty blocks, but I don't know how those work. (I'm still figuring out this Smarty stuff.) You could allow prioritization without printing by using {capture} on the highest-priority stuff first, I suppose. You could always print it out later.

Posted: Mon Mar 24, 2008 2:43 am
by Don Chambers
No Jude - i do not know SQL - you sure about this? Did you try something like this with your newsbox plugin to prevent duplicates?

Where exactly does this get executed? I am fetching from index.tpl using entries_custom.tpl.

Posted: Mon Mar 24, 2008 3:15 pm
by judebert
Well, I believe the Smarty code I supplied will do the job, unmodified. So maybe you don't really need the SQL knowledge, since it's built into the code.

I did do something like this with my newbox template, but I did it all in PHP. And then I decided it wasn't worth it. (If the user puts an entry into two different newsbox categories, it's important enough to show up in each.)

The Smarty should get executed in the Smarty template, probably your index.tpl, right after each {serendipity_fetchPrintEntries}.