<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>id_list=""
source_title=""
categorie_tissu=""
motif=""
description=""
collection_list=""
composition_list=""
eip_list=""
code_entretien_list=""
composant_state=""</params>
SELECT DISTINCT tissu.id, tissu.relative_url, tissu.path, tissu.Description, tissu.composant_state
FROM catalog AS tissu

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

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

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

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

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

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

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


WHERE tissu.portal_type = "Tissu"


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


<dtml-if expr="_.len(source_title)>0">
  <dtml-if expr="not (_.len(source_title)==1 and source_title[0]=='')">
    AND cat7.uid=tissu.uid
    AND cat7.base_category_uid=<dtml-var "portal_categories.source.uid">
    AND ( (catalog.title LIKE   "<dtml-var expr="source_title[0]">")
      <dtml-in prefix="loop" expr="_.range(_.len(source_title)-1)">
        OR (catalog.title LIKE "<dtml-var expr="source_title[loop_item+1]">")
      </dtml-in>
    )
  </dtml-if>
</dtml-if>


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


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


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


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


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


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

<dtml-if expr="not(composant_state=='')">
  AND tissu.composant_state LIKE "<dtml-var expr="composant_state">"
</dtml-if>

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

