<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>collection_list=""
description=""
eip_list=""
etat=""
forme_id_list=""
id_list=""
option_forme_list=""
present_au_catalogue=""
referentiel_forme_list=""</params>
SELECT DISTINCT forme.id, forme.relative_url, forme.path, forme.Description, forme.forme_state
FROM catalog AS forme

<dtml-if expr="_.len(collection_list)>0">
  <dtml-if expr="not (_.len(collection_list)==1 and collection_list[0]=='')">
    , category AS cat1
  </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 cat2
  </dtml-if>
</dtml-if>

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

<dtml-if expr="_.len(referentiel_forme_list)>0">
  <dtml-if expr="not (_.len(referentiel_forme_list)==1 and referentiel_forme_list[0]=='')">
    , category AS cat4
  </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]=='')">
    , category AS cat5
    JOIN catalog ON catalog.uid=cat5.category_uid
  </dtml-if>
</dtml-if>


WHERE forme.portal_type = "Forme"

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

<dtml-if expr="_.len(collection_list)>0">
  <dtml-if expr="not (_.len(collection_list)==1 and collection_list[0]=='')">
    AND cat1.uid=forme.uid
    AND ( cat1.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 cat1.category_uid=<dtml-var expr="identify_category(base_category='collection',category=collection_list[loop_item+1])">
    </dtml-in>
    )
    AND cat1.base_category_uid=<dtml-var "portal_categories.collection.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 cat2.uid=forme.uid
    AND ( cat2.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 cat2.category_uid=<dtml-var expr="identify_category(base_category='eip',category=eip_list[loop_item+1])">
      </dtml-in>
    )
    AND cat2.base_category_uid=<dtml-var "portal_categories.eip.uid">
  </dtml-if>
</dtml-if>

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

<dtml-if expr="_.len(referentiel_forme_list)>0">
  <dtml-if expr="not (_.len(referentiel_forme_list)==1 and referentiel_forme_list[0]=='')">
    AND cat4.uid=forme.uid
    AND ( cat4.category_uid=<dtml-var expr="identify_category(base_category='referentiel_forme',category=referentiel_forme_list[0])">
      <dtml-in prefix="loop" expr="_.range(_.len(referentiel_forme_list)-1)">
        OR cat4.category_uid=<dtml-var expr="identify_category(base_category='referentiel_forme',category=referentiel_forme_list[loop_item+1])">
      </dtml-in>
    )
    AND cat4.base_category_uid=<dtml-var "portal_categories.referentiel_forme.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]=='')">
    AND cat5.uid=forme.uid
    AND cat5.base_category_uid=<dtml-var "portal_categories.specialise.uid">
    
    AND ( (catalog.id LIKE   "<dtml-var expr="forme_id_list[0]">")
      <dtml-in prefix="loop" expr="_.range(_.len(forme_id_list)-1)">
        OR (catalog.id LIKE "<dtml-var expr="forme_id_list[loop_item+1]">")
      </dtml-in>
    )

  </dtml-if>
</dtml-if>



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

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

