<dtml-comment>
title:
connection_id:MySQL
max_rows:1000
max_cache:100
cache_time:0
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params>correspondance_id=""
forme_id_list=""
mesure_vetement_list=""
taille_list=""

description=""
etat=""
id_list=""</params>
SELECT DISTINCT vetement.id, vetement.relative_url, vetement.path, vetement.Description, vetement.forme_state
FROM catalog AS vetement

<dtml-if expr="_.len(correspondance_id)>0">
  <dtml-if expr="not (_.len(correspondance_id)==1 and correspondance_id[0]=='')">
    , catalog AS catal1 JOIN category AS cat1 ON catal1.uid=cat1.category_uid
  </dtml-if>
</dtml-if>

<dtml-if expr="_.len(forme_id_list)>0">
  <dtml-if expr="not (_.len(forme_id_list)==1 and forme_id_list[0]=='')">
    , catalog AS catal2 JOIN category AS cat2 ON catal2.uid=cat2.category_uid
  </dtml-if>
</dtml-if>

<dtml-if expr="_.len(mesure_vetement_list)>0">
  <dtml-if expr="not (_.len(mesure_vetement_list)==1 and mesure_vetement_list[0]=='')">
    , category AS cat3
  </dtml-if>
</dtml-if>

<dtml-if expr="_.len(taille_list)>0">
  <dtml-if expr="not (_.len(taille_list)==1 and taille_list[0]=='')">
    , category AS cat4
  </dtml-if>
</dtml-if>


WHERE vetement.portal_type = "Vetement"

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

<dtml-if expr="_.len(correspondance_id)>0">
  <dtml-if expr="not (_.len(correspondance_id)==1 and correspondance_id[0]=='')">
    AND cat1.uid=vetement.uid
    AND cat1.base_category_uid=<dtml-var "portal_categories.specialise.uid">
    AND catal1.portal_type = "Correspondance mesures"
    AND ( (catal1.id LIKE   "<dtml-var expr="correspondance_id[0]">")
      <dtml-in prefix="loop" expr="_.range(_.len(correspondance_id)-1)">
        OR (catal1.id LIKE "<dtml-var expr="correspondance_id[loop_item+1]">")
      </dtml-in>
    )
  </dtml-if>
</dtml-if>

<dtml-if expr="_.len(forme_id_list)>0">
  <dtml-if expr="not (_.len(forme_id_list)==1 and forme_id_list[0]=='')">
    AND cat2.uid=vetement.uid
    AND cat2.base_category_uid=<dtml-var "portal_categories.specialise.uid">
    AND catal2.portal_type = "Forme"
    AND ( (catal2.id LIKE   "<dtml-var expr="forme_id_list[0]">")
      <dtml-in prefix="loop" expr="_.range(_.len(forme_id_list)-1)">
        OR (catal2.id LIKE "<dtml-var expr="forme_id_list[loop_item+1]">")
      </dtml-in>
    )
  </dtml-if>
</dtml-if>

<dtml-if expr="_.len(mesure_vetement_list)>0">
  <dtml-if expr="not (_.len(mesure_vetement_list)==1 and mesure_vetement_list[0]=='')">
    AND cat3.uid=vetement.uid
    AND ( cat3.category_uid=<dtml-var expr="identify_category(base_category='mesure_vetement',category=mesure_vetement_list[0])">
      <dtml-in prefix="loop" expr="_.range(_.len(mesure_vetement_list)-1)">
        OR cat3.category_uid=<dtml-var expr="identify_category(base_category='mesure_vetement',category=mesure_vetement_list[loop_item+1])">
      </dtml-in>
    )
    AND cat3.base_category_uid=<dtml-var "portal_categories.mesure_vetement.uid">
  </dtml-if>
</dtml-if>

<dtml-if expr="_.len(taille_list)>0">
  <dtml-if expr="not (_.len(taille_list)==1 and taille_list[0]=='')">
    AND cat4.uid=vetement.uid
    AND ( cat4.category_uid=<dtml-var expr="identify_category(base_category='taille',category=taille_list[0])">
      <dtml-in prefix="loop" expr="_.range(_.len(taille_list)-1)">
        OR cat4.category_uid=<dtml-var expr="identify_category(base_category='taille',category=taille_list[loop_item+1])">
      </dtml-in>
    )
    AND cat4.base_category_uid=<dtml-var "portal_categories.taille.uid">
  </dtml-if>
</dtml-if>


<dtml-if expr="not(etat=='')">
  AND vetement.vetement_state LIKE "<dtml-var expr="etat">"
</dtml-if>

<dtml-if expr="not(description=='')">
  AND vetement.Description LIKE "<dtml-var expr="description">"
</dtml-if>

