class BotchaRecipebookModel in BOTCHA Spam Prevention 6.2
Same name and namespace in other branches
- 6.3 model/recipebook/botcha.recipebook.model.inc \BotchaRecipebookModel
- 7.2 model/botcha_recipebook.model.inc \BotchaRecipebookModel
- 7.3 model/recipebook/botcha.recipebook.model.inc \BotchaRecipebookModel
@file Contains BotchaRecipebookModel class.
Model layer of the BotchaRecipebook objects.
Hierarchy
- class \BotchaRecipebookModel
Expanded class hierarchy of BotchaRecipebookModel
File
- model/
botcha_recipebook.model.inc, line 10 - Contains BotchaRecipebookModel class.
View source
class BotchaRecipebookModel {
protected static $recipebooks;
public static function getRecipebooks($parameters = NULL) {
// Parameters to pass to the build query mechanism.
$pars = array();
$pars['fields'] = array();
if (!empty($parameters['recipebooks'])) {
$pars['conditions'][BOTCHA_MODEL_OP_IN]['id'] = (array) $parameters['recipebooks'];
}
// Execute query and fetch the result.
$query = BotchaModel::buildQuery(BOTCHA_MODEL_TYPE_SELECT, 'botcha_recipebook', $pars);
$result_query = BotchaModel::getQueryResult($query['query'], $query['query_subs']);
$result = BotchaModel::fetchQueryResult($result_query);
return $result;
}
public static function getRecipebook($id) {
$recipebooks = BotchaRecipebookModel::getRecipebooks();
return !empty($recipebooks[$id]) ? $recipebooks[$id] : NULL;
}
/**
* Save recipe book to the database.
* @param BotchaRecipebook $recipebook
*/
public static function save($recipebook) {
db_query("DELETE FROM {botcha_recipebook_recipe} WHERE rbid = '%s'", array(
$recipebook->id,
));
db_query("DELETE FROM {botcha_recipebook_form} WHERE rbid = '%s'", array(
$recipebook->id,
));
if (!$recipebook instanceof BotchaRecipebookNone) {
if (db_result(db_query("SELECT COUNT(*) FROM {botcha_recipebook} brb WHERE brb.id = '%s'", array(
$recipebook->id,
)))) {
db_query("UPDATE {botcha_recipebook} SET title = '%s', description = '%s' WHERE id = '%s'", array(
$recipebook->title,
$recipebook->description,
$recipebook->id,
));
}
else {
db_query("INSERT INTO {botcha_recipebook} (id, title, description) VALUES('%s', '%s', '%s')", array(
$recipebook->id,
$recipebook->title,
$recipebook->description,
));
}
// Save relationships between recipe book and recipes to DB.
$recipes = $recipebook
->getRecipes();
$query = "INSERT INTO {botcha_recipebook_recipe} (rbid, recipe_id) VALUES('%s', '%s')";
foreach ($recipes as $recipe) {
db_query($query, array(
$recipebook->id,
$recipe->id,
));
}
// Save relationships between recipe book and forms to DB.
$forms = $recipebook
->getForms();
foreach ($forms as $form) {
if (db_result(db_query("SELECT COUNT(*) FROM {botcha_recipebook_form} brf WHERE brf.form_id = '%s'", array(
$form->id,
)))) {
db_query("UPDATE {botcha_recipebook_form} SET rbid = '%s' WHERE form_id = '%s'", array(
$recipebook->id,
$form->id,
));
}
else {
db_query("INSERT INTO {botcha_recipebook_form} (rbid, form_id) VALUES('%s', '%s')", array(
$recipebook->id,
$form->id,
));
}
}
}
}
/**
* Delete recipe book from the database.
* @param BotchaRecipebook $recipebook
*/
public static function delete($recipebook) {
db_query("DELETE FROM {botcha_recipebook_recipe} WHERE rbid = '%s'", array(
$recipebook->id,
));
db_query("DELETE FROM {botcha_recipebook_form} WHERE rbid = '%s'", array(
$recipebook->id,
));
db_query("DELETE FROM {botcha_recipebook} WHERE rbid = '%s'", array(
$recipebook->id,
));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BotchaRecipebookModel:: |
protected static | property | ||
BotchaRecipebookModel:: |
public static | function | Delete recipe book from the database. | |
BotchaRecipebookModel:: |
public static | function | ||
BotchaRecipebookModel:: |
public static | function | ||
BotchaRecipebookModel:: |
public static | function | Save recipe book to the database. |