<?xml version="1.0" encoding="iso-8859-1" ?>

<table>
  <base>CRM/Contact</base>
  <class>SavedSearch</class>
  <name>civicrm_saved_search</name>
  <comment>Users can save their complex SQL queries and use them later.</comment>
  <icon>fa-search-plus</icon>
  <labelField>label</labelField>
  <add>1.1</add>
  <field>
    <name>id</name>
    <type>int unsigned</type>
    <title>Saved Search ID</title>
    <required>true</required>
    <comment>Saved Search ID</comment>
    <html>
      <label>ID</label>
      <type>Number</type>
    </html>
    <add>1.1</add>
  </field>
  <primaryKey>
    <name>id</name>
    <autoincrement>true</autoincrement>
  </primaryKey>

  <field>
    <name>name</name>
    <title>Saved Search Name</title>
    <type>varchar</type>
    <length>255</length>
    <default>NULL</default>
    <comment>Unique name of saved search</comment>
    <html>
      <label>Name</label>
      <type>Text</type>
    </html>
    <add>1.0</add>
  </field>
  <index>
    <name>UI_name</name>
    <fieldName>name</fieldName>
    <unique>true</unique>
    <add>5.32</add>
  </index>

  <field>
    <name>label</name>
    <title>Saved Search Label</title>
    <type>varchar</type>
    <length>255</length>
    <default>NULL</default>
    <comment>Administrative label for search</comment>
    <html>
      <label>Label</label>
      <type>Text</type>
    </html>
    <add>5.32</add>
  </field>

  <field>
    <name>form_values</name>
    <title>Submitted Form Values</title>
    <type>text</type>
    <import>true</import>
    <comment>Submitted form values for this search</comment>
    <serialize>PHP</serialize>
    <add>1.1</add>
  </field>

  <field>
    <name>mapping_id</name>
    <type>int unsigned</type>
    <title>Mapping ID</title>
    <comment>Foreign key to civicrm_mapping used for saved search-builder searches.</comment>
    <html>
      <label>Mapping</label>
    </html>
    <add>1.5</add>
  </field>
  <foreignKey>
    <name>mapping_id</name>
    <table>civicrm_mapping</table>
    <key>id</key>
    <onDelete>SET NULL</onDelete>
    <add>1.5</add>
  </foreignKey>

  <field>
    <name>search_custom_id</name>
    <type>int unsigned</type>
    <title>Option Value ID</title>
    <comment>Foreign key to civicrm_option value table used for saved custom searches.</comment>
    <add>2.0</add>
  </field>

  <field>
    <name>where_clause</name>
    <type>text</type>
    <title>Where Clause</title>
    <comment>the sql where clause if a saved search acl</comment>
    <add>1.6</add>
    <drop>5.24</drop>
  </field>

  <field>
    <name>select_tables</name>
    <type>text</type>
    <title>Select Tables</title>
    <comment>the tables to be included in a select data</comment>
    <serialize>PHP</serialize>
    <add>1.6</add>
    <drop>5.24</drop>
  </field>

  <field>
    <name>where_tables</name>
    <type>text</type>
    <title>Where Tables</title>
    <comment>the tables to be included in the count statement</comment>
    <serialize>PHP</serialize>
    <add>1.6</add>
    <drop>5.24</drop>
  </field>

  <field>
    <name>api_entity</name>
    <type>varchar</type>
    <title>Entity Name</title>
    <length>255</length>
    <comment>Entity name for API based search</comment>
    <add>5.24</add>
    <html>
      <label>For</label>
      <type>Select</type>
    </html>
    <pseudoconstant>
      <callback>CRM_Contact_BAO_SavedSearch::getApiEntityOptions</callback>
    </pseudoconstant>
  </field>

  <field>
    <name>api_params</name>
    <type>text</type>
    <title>API Parameters</title>
    <comment>Parameters for API based search</comment>
    <serialize>JSON</serialize>
    <add>5.24</add>
  </field>
  <field>
    <name>created_id</name>
    <type>int unsigned</type>
    <title>Created By Contact ID</title>
    <comment>FK to contact table.</comment>
    <html>
      <label>Created By</label>
    </html>
    <readonly>true</readonly>
    <add>5.36</add>
  </field>
  <foreignKey>
    <name>created_id</name>
    <table>civicrm_contact</table>
    <key>id</key>
    <add>5.36</add>
    <onDelete>SET NULL</onDelete>
  </foreignKey>
  <field>
    <name>modified_id</name>
    <type>int unsigned</type>
    <title>Modified By Contact ID</title>
    <comment>FK to contact table.</comment>
    <html>
      <label>Modified By</label>
    </html>
    <readonly>true</readonly>
    <add>5.36</add>
  </field>
  <foreignKey>
    <name>modified_id</name>
    <table>civicrm_contact</table>
    <key>id</key>
    <add>5.36</add>
    <onDelete>SET NULL</onDelete>
  </foreignKey>
  <field>
    <name>expires_date</name>
    <type>timestamp</type>
    <title>Search Expiry Date</title>
    <required>false</required>
    <comment>Optional date after which the search is not needed</comment>
    <add>5.36</add>
  </field>
  <field>
    <name>created_date</name>
    <type>timestamp</type>
    <comment>When the search was created.</comment>
    <required>true</required>
    <default>CURRENT_TIMESTAMP</default>
    <readonly>true</readonly>
    <add>5.36</add>
  </field>
  <field>
    <name>modified_date</name>
    <type>timestamp</type>
    <comment>When the search was last modified.</comment>
    <required>true</required>
    <default>CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP</default>
    <add>5.36</add>
    <readonly>true</readonly>
  </field>
  <field>
    <name>description</name>
    <type>text</type>
    <title>Saved Search Description</title>
    <html>
      <label>Description</label>
      <type>TextArea</type>
      <rows>2</rows>
      <cols>60</cols>
    </html>
    <add>5.36</add>
  </field>
</table>
