-
-
Save a-am/0123f70b4ae7ee679dc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set bread = craft.entries({ section: 'bread' }).limit(null) %} | |
{# | |
# Users with bread on 3 days | |
#} | |
{% set users3Days = craft.users({ | |
group: 'customers', | |
relatedTo: [ | |
'and', | |
{ targetElement: bread, field: 'breadForMonday' }, | |
{ targetElement: bread, field: 'breadForWednesday' }, | |
{ targetElement: bread, field: 'breadForFriday' } | |
] | |
}) %} | |
{# | |
# Users with bread per weekday | |
#} | |
{% set usersMonday = craft.users({ | |
group: 'customers', | |
relatedTo: { targetElement: bread, field: 'breadForMonday' } | |
}) %} | |
{% set usersWednesday = craft.users({ | |
group: 'customers', | |
relatedTo: { targetElement: bread, field: 'breadForWednesday' } | |
}) %} | |
{% set usersFriday = craft.users({ | |
group: 'customers', | |
relatedTo: { targetElement: bread, field: 'breadForFriday' } | |
}) %} | |
{# | |
# Users with bread on 1 day (grouped per weekday) | |
#} | |
{% set usersIdsMonday = usersMonday.ids() %} | |
{% set usersIdsWednesday = usersWednesday.ids() %} | |
{% set usersIdsFriday = usersFriday.ids() %} | |
{% set usersOnlyMonday = craft.users({ | |
id: usersIdsMonday|without(usersIdsWednesday)|without(usersIdsFriday) | |
}) %} | |
{% set usersOnlyWednesday = craft.users({ | |
id: usersIdsWednesday|without(usersIdsMonday)|without(usersIdsFriday) | |
}) %} | |
{% set usersOnlyFriday = craft.users({ | |
id: usersIdsFriday|without(usersIdsMonday)|without(usersIdsWednesday) | |
}) %} | |
{# | |
# Users with bread on 1 day | |
#} | |
{% set users1Days = craft.users({ | |
id: usersOnlyMonday.ids()|merge(usersOnlyWednesday.ids())|merge(usersOnlyFriday.ids()) | |
}) %} | |
{# | |
# Users with bread on 1, 2 or 3 days | |
#} | |
{% set usersAnyDay = craft.users({ | |
group: 'customers', | |
relatedTo: { targetElement: bread } | |
}) %} | |
{# | |
# Users with bread on no day at all | |
#} | |
{% set users0Days = craft.users({ | |
id: 'and, not ' ~ usersIdsAnyDay.ids()|join(', not ') | |
}) %} | |
{# | |
# Users with bread on 2 days | |
#} | |
{% set users2Days = craft.users({ | |
id: usersAnyDay.ids()|without(users0Days.ids())|without(users1Days.ids())|without(users3Days.ids()) | |
}) %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment