You are here

function _votingapi_query_builder in Voting API 6.2

Same name and namespace in other branches
  1. 6 votingapi.module \_votingapi_query_builder()

Internal helper function constructs individual elements of WHERE clauses. Don't use unless you're me.

1 call to _votingapi_query_builder()
_votingapi_query in ./votingapi.module
Internal helper function constructs WHERE clauses. Don't use unless you're me.

File

./votingapi.module, line 642
A generalized voting API for Drupal.

Code

function _votingapi_query_builder($name, $value, &$query, &$args, $col_is_string = FALSE) {
  if (!isset($value)) {

    // Do nothing
  }
  elseif ($name === 'timestamp') {
    $query .= " AND timestamp >= %d";
    $args[] = $value;
  }
  elseif ($name === 'v.timestamp') {
    $query .= " AND v.timestamp >= %d";
    $args[] = $value;
  }
  else {
    if (is_array($value)) {
      if ($col_is_string) {
        $query .= " AND {$name} IN (" . db_placeholders($value, 'varchar') . ")";
        $args = array_merge($args, $value);
      }
      else {
        $query .= " AND {$name} IN (" . db_placeholders($value, 'int') . ")";
        $args = array_merge($args, $value);
      }
    }
    else {
      if ($col_is_string) {
        $query .= " AND {$name} = '%s'";
        $args[] = $value;
      }
      else {
        $query .= " AND {$name} = %d";
        $args[] = $value;
      }
    }
  }
}