Forums / General / Fetching objects with conditions belonging to children

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

Fetching objects with conditions belonging to children

Author Message

Thomas Nunninger

Friday 03 February 2006 3:23:30 pm

Hi,

I have a class event calendar. The children of this class are events. And each event can have an article and a gallery as children. It looks something like that:

event calendar
  event 1
    article
    gallery
  event 2
    article
  event 3
  event 4
    gallery
  event 5
    article
    gallery

Now I want to list all events having an article or a gallery (e.g. event 3 isn't listed). This can look like this:

  event 1
   -> article  -> gallery
  event 2
   -> article
  event 4
   -> gallery
  event 5
   -> article -> gallery

In order to be efficient and to use the offset/limit functionality (e.g. 10 events per page) I don't like this algortihm:

fetch all events sort by event_date
foreach event {
  fetch childen
  if has(article child) or has(gallery child) {
    echo event name
    fetch children
    foreach child {
      echo child.name
    }
  }
}

Another idea was:

fetch all articles and galleries sort by path
event_ids = array()
foreach object {
  fetch parent_event
  if not in_array(parent_event_id, event_ids) {
    echo event.name
    event_ids[] = parent_event_id
  }

  echo object.name  
}

But also here I'm not able to do offset/limit things. And I can't sort by event_date.

I think, I need an extended_attribute_filter with in my content-list-fetch (fetching all events which have children) and fetching the arcticle and gallery children of the retrieved events (cf the first algorithm). Any other ideas?

Thomas