You are here

class BotchaRecipeModel in BOTCHA Spam Prevention 6.2

Same name and namespace in other branches
  1. 6.3 model/recipe/botcha.recipe.model.inc \BotchaRecipeModel
  2. 7.2 model/botcha_recipe.model.inc \BotchaRecipeModel
  3. 7.3 model/recipe/botcha.recipe.model.inc \BotchaRecipeModel

@file Contains BotchaRecipeModel class.

Model layer of the BotchaRecipe objects.

Hierarchy

Expanded class hierarchy of BotchaRecipeModel

File

model/botcha_recipe.model.inc, line 10
Contains BotchaRecipeModel class.

View source
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,
      ));
    }
  }

}

Members