<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>resource_id_list=""
variante_id_list=""
sort_on
portal_type</params>
SELECT DISTINCT catalog.id, catalog.uid, catalog.relative_url, catalog.path, catalog.Description, catalog.simulation_state, catalog.default_destination_title
FROM catalog, catalog AS line
<dtml-if expr="_.len(resource_id_list)>0">
, catalog AS resource
, category AS cat1
</dtml-if>
<dtml-if expr="_.len(variante_id_list)>0">
, catalog as variante
, category AS cat2
</dtml-if>

WHERE line.parent_uid = catalog.uid

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

<dtml-if expr="_.len(resource_id_list)>0">
AND ( resource.id LIKE "<dtml-var expr="resource_id_list[0]">"
<dtml-in prefix="loop" expr="_.range(_.len(resource_id_list)-1)">
OR resource.id LIKE "<dtml-var expr="resource_id_list[loop_item+1]">"
</dtml-in>
)
AND cat1.uid=line.uid
AND cat1.category_uid=resource.uid
AND cat1.base_category_uid=<dtml-var "portal_categories.resource.uid">
</dtml-if>

<dtml-if expr="_.len(variante_id_list)>0">
AND ( variante.id LIKE "<dtml-var expr="variante_id_list[0]">"
<dtml-in prefix="loop" expr="_.range(_.len(variante_id_list)-1)">
OR variante.id LIKE "<dtml-var expr="variante_id_list[loop_item+1]">"
</dtml-in>
)
AND (
( cat2.uid=line.uid
AND cat2.category_uid=variante.uid
AND cat2.base_category_uid=<dtml-var "portal_categories.coloris.uid">)
OR
( cat2.uid=line.uid
AND cat2.category_uid=variante.uid
AND cat2.base_category_uid=<dtml-var "portal_categories.variante.uid">)
)
</dtml-if>

<dtml-if sort_on>
ORDER BY <dtml-var sort_on>
</dtml-if>