1

The company whose website I'm building host events, and for each of these events, it is only possible to purchase tickets on certain days, but for each event, there can be more than 1 such day.

They want a view which shows:

Event A

  • Ticket sale days: day 1, day 2

Event B

  • Ticket sale days: day 1

Event C

  • Ticket sale days: day 2

And another view which shows:

Ticket sale day 1

  • Event A
  • Event B

Ticket sale day 2

  • Event A
  • Event C

I'm currently using a single-column table field for the ticket sale days which allows me to add as many dates as I wish. With this, I can implement the first view above really easily by looping over the rows in the table.

However, the second view has me stumped since I am unable to group the entries by the rows in the table field. Note that I want to keep this data within a single 'events' section.

1

You could loop through all your events, and create a date-keyed hash with the ids of the entries - assuming your (e.g

    {% set saleDays = {} %}
    {% for entry in events %}
       {% for row in table %}
          {% if attribute(saleDays, row.date|date(mdY)) is defined %}
               {% set saleDays = saleDays|merge({ 
                  (row.date|date(mdY)): attribute(saleDays, row.date|date(mdY)) | merge([entry.id]) 
               }) %}
          {% else %}
               {% set saleDays = saleDays|merge({ (row.date|date(mdY)): [entry.id]})
          {% endif %}
     {% endfor %}

This would result in a hash, whose keys were dates of ticket sales, and whose values were arrays of entry id's (which could then be queried), or you could set the values inside the array to the entry models themselves.

You would then need to sort this hash to get the dates in order (think you'd need to write a custom extension), and then you could loop through it.

But to be honest, by that point you'd be better off just writing a module and doing the whole thing in php where it'd be easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.