You are here

function _xmlsitemap_build_conditions in XML sitemap 6.2

Condition builder for queries.

5 calls to _xmlsitemap_build_conditions()
xmlsitemap_link_delete_multiple in ./xmlsitemap.module
Delete multiple sitemap links from the database.
xmlsitemap_link_load_multiple in ./xmlsitemap.module
Load sitemap links from the database.
xmlsitemap_link_update_multiple in ./xmlsitemap.module
Perform a mass update of sitemap data.
xmlsitemap_sitemap_load_multiple in ./xmlsitemap.module
Load multiple XML sitemaps from the database.
_xmlsitemap_check_changed_links in ./xmlsitemap.module
Check if there is a visible sitemap link given a certain set of conditions.

File

./xmlsitemap.inc, line 13
Miscellaneous functions for the xmlsitemap module.

Code

function _xmlsitemap_build_conditions(array &$conditions, array $args = array(), array $options = array()) {
  $options += array(
    'table' => 'xmlsitemap',
    'operator' => '=',
    'update' => FALSE,
  );
  $operators = array(
    'null' => array(
      '=' => 'IS',
      '<>' => 'IS NOT',
    ),
    'in' => array(
      '=' => 'IN',
      '<>' => 'NOT IN',
    ),
  );
  foreach ($conditions as $field => $value) {
    if (is_int($field)) {
      continue;
    }
    elseif ($value === NULL) {
      if ($options['update']) {
        $conditions[$field] = "{$field} = NULL";
      }
      else {
        $operator = $operators['null'][$options['operator']];
        $conditions[$field] = "{$field} {$operator} NULL";
      }
    }
    elseif (is_array($value)) {
      if ($options['update']) {
        trigger_error(strtr('Update not supported for field %field in @function.', array(
          '%field' => theme('placeholder', $field),
          '@function' => __FUNCTION__,
        )));
        unset($conditions[$field]);
      }
      else {
        $operator = $operators['in'][$options['operator']];
        $type = _xmlsitemap_get_field_type($options['table'], $field);
        $conditions[$field] = "{$field} {$operator} (" . db_placeholders($value, $type) . ")";
        $args = array_merge($args, $value);
      }
    }
    else {
      $operator = $options['operator'];
      $placeholder = db_type_placeholder(_xmlsitemap_get_field_type($options['table'], $field));
      $conditions[$field] = "{$field} {$operator} {$placeholder}";
      $args[] = $value;
    }
  }
  return $args;
}