<dtml-comment>
title:
connection_id:erp5_sql_connection
max_rows:1000
max_cache:100
cache_time:0
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params>organisation_id_list
group_list</params>
SELECT DISTINCT organisation.id, organisation.relative_url, organisation.path, organisation.title
FROM catalog AS organisation
<dtml-if group_list>
, category AS cat1
</dtml-if>

WHERE organisation.portal_type = "Organisation"

<dtml-if organisation_id_list>
AND ( organisation.id = "<dtml-var expr="organisation_id_list[0]">"
<dtml-in prefix="loop" expr="_.range(_.len(organisation_id_list)-1)">
OR organisation.id = "<dtml-var expr="organisation_id_list[loop_item+1]">"
</dtml-in>
)
</dtml-if>

<dtml-if group_list>
AND cat1.uid=organisation.uid
AND ( cat1.category_uid=<dtml-var expr="identify_category(base_category='group',category=group_list[0])">
<dtml-in prefix="loop" expr="_.range(_.len(group_list)-1)">
OR cat1.category_uid=<dtml-var expr="identify_category(base_category='cgroup',category=group_list[loop_item+1])">
</dtml-in>
)
AND cat1.base_category_uid=<dtml-var "portal_categories.group.uid">
</dtml-if>