You are here

public static function BotchaModel::buildQuery in BOTCHA Spam Prevention 6.2

5 calls to BotchaModel::buildQuery()
BotchaFormModel::getForms in model/botcha_form.model.inc
BotchaModel::getRecipebooksForms in model/botcha.model.inc
BotchaModel::getRecipebooksRecipes in model/botcha.model.inc
BotchaRecipebookModel::getRecipebooks in model/botcha_recipebook.model.inc
BotchaRecipeModel::getRecipes in model/botcha_recipe.model.inc

File

model/botcha.model.inc, line 91

Class

BotchaModel

Code

public static function buildQuery($type, $table, $parameters) {
  $query = '';
  $query_subs = array();
  switch ($type) {
    case BOTCHA_MODEL_TYPE_SELECT:
    default:
      $query = 'SELECT ';

      // Fields.
      $query .= !empty($parameters['fields']) ? implode(', ', (array) $parameters['fields']) . ' ' : '* ';

      // From.
      $query .= "FROM {{$table}}";

      // Conditions.
      if (!empty($parameters['conditions'])) {
        foreach ((array) $parameters['conditions'] as $op => $conditions) {
          switch ($op) {
            case BOTCHA_MODEL_OP_IN:
            default:
              $where = '';
              foreach ($conditions as $field => $value) {
                $query .= empty($where) ? $where = " WHERE " : " AND ";
                $query .= "{$field} {$op} ('" . implode("', '", array_fill(0, count((array) $value), '%s')) . "')";
                $query_subs = array_merge($query_subs, (array) $value);
              }
              break;
          }
        }
      }
      break;
  }
  return array(
    'query' => $query,
    'query_subs' => $query_subs,
  );
}