View source
<?php
module_load_include('inc', 'botcha', 'model/botcha_form.model');
module_load_include('inc', 'botcha', 'model/botcha_recipe.model');
module_load_include('inc', 'botcha', 'model/botcha_recipebook.model');
class BotchaModel {
public static function getFormsRecipebooks($parameters = array()) {
$parameters['mode'] = !empty($parameters['mode']) ? $parameters['mode'] : 'recipebook';
return self::getRecipebooksForms($parameters);
}
public static function getRecipebooksForms($parameters = array()) {
$fields = array();
switch ($parameters['mode']) {
case 'form':
$fields[] = 'form_id';
break;
case 'recipebook':
default:
$fields[] = 'rbid';
break;
}
$rbf = db_select('botcha_recipebook_form', 'brf')
->fields('brf', $fields);
if (!empty($parameters['recipebooks'])) {
$rbf
->condition('rbid', (array) $parameters['recipebooks'], 'IN');
}
if (!empty($parameters['forms'])) {
$rbf
->condition('form_id', (array) $parameters['forms'], 'IN');
}
try {
$result = $rbf
->execute()
->fetchCol();
} catch (Exception $e) {
if ($e instanceof PDOException) {
watchdog_exception('BOTCHA', $e, 'Please perform an update via update.php or reinstall the BOTCHA module to fix the reason of this warning! %type: !message in %function (line %line of %file).', array(), WATCHDOG_WARNING);
$result = array();
}
}
return $result;
}
public static function getRecipesRecipebooks($parameters = NULL) {
return self::getRecipebooksRecipes($parameters);
}
public static function getRecipebooksRecipes($parameters = NULL) {
$fields = array();
switch ($parameters['mode']) {
case 'recipe':
$fields[] = 'recipe_id';
break;
case 'recipebook':
default:
$fields[] = 'rbid';
break;
}
$rbr = db_select('botcha_recipebook_recipe', 'brr')
->fields('brr', $fields);
if (!empty($parameters['recipebooks'])) {
$rbr
->condition('rbid', (array) $parameters['recipebooks'], 'IN');
}
if (!empty($parameters['recipes'])) {
$rbr
->condition('recipe_id', (array) $parameters['recipes'], 'IN');
}
try {
$result = $rbr
->execute()
->fetchCol();
} catch (Exception $e) {
if ($e instanceof PDOException) {
watchdog_exception('BOTCHA', $e, 'Please perform an update via update.php or reinstall the BOTCHA module to fix the reason of this warning! %type: !message in %function (line %line of %file).', array(), WATCHDOG_WARNING);
$result = array();
}
}
return $result;
}
}