You are here

botcha_recipe.model.inc in BOTCHA Spam Prevention 6.2

Same filename and directory in other branches
  1. 7.2 model/botcha_recipe.model.inc

Contains BotchaRecipeModel class.

Model layer of the BotchaRecipe objects.

File

model/botcha_recipe.model.inc
View source
<?php

/**
 * @file
 * Contains BotchaRecipeModel class.
 *
 * Model layer of the BotchaRecipe objects.
 */
class BotchaRecipeModel {
  protected static $recipes;
  public static function getRecipes($parameters = array()) {

    // Parameters to pass to the build query mechanism.
    $pars = array();
    $pars['fields'] = array();
    if (!empty($parameters['recipes'])) {
      $pars['conditions'][BOTCHA_MODEL_OP_IN]['id'] = (array) $parameters['recipes'];
    }

    // Execute query and fetch the result.
    $query = BotchaModel::buildQuery(BOTCHA_MODEL_TYPE_SELECT, 'botcha_recipe', $pars);
    $result_query = BotchaModel::getQueryResult($query['query'], $query['query_subs']);
    $result = BotchaModel::fetchQueryResult($result_query);
    return $result;
  }
  public static function getRecipe($id) {
    $recipes = self::getRecipes();
    return !empty($recipes[$id]) ? $recipes[$id] : NULL;
  }
  function save($recipe) {

    // Save recipe to DB.
    if (db_result(db_query("SELECT COUNT(*) FROM {botcha_recipe} br WHERE br.id = '%s'", array(
      $recipe->id,
    )))) {
      db_query("UPDATE {botcha_recipe} SET classname = '%s', title = '%s', description = '%s' WHERE id = '%s'", array(
        $recipe->classname,
        $recipe->title,
        $recipe->description,
        $recipe->id,
      ));
    }
    else {
      db_query("INSERT INTO {botcha_recipe} (id, classname, title, description) VALUES('%s', '%s', '%s', '%s')", array(
        $recipe->id,
        $recipe->classname,
        $recipe->title,
        $recipe->description,
      ));
    }
  }

}

Classes

Namesort descending Description
BotchaRecipeModel @file Contains BotchaRecipeModel class.