You are here

class BotchaModel in BOTCHA Spam Prevention 7.2

Same name and namespace in other branches
  1. 6.2 model/botcha.model.inc \BotchaModel
  2. 6.3 model/application/botcha.application.model.inc \BotchaModel
  3. 7.3 model/application/botcha.application.model.inc \BotchaModel

Hierarchy

Expanded class hierarchy of BotchaModel

File

model/botcha.model.inc, line 14

View source
class BotchaModel {

  //protected static $recipebooks_forms;

  //protected static $recipebooks_recipes;

  /**
   * Just an alias for getRecipebooksForms.
   * @param array $parameters
   * @return array
   */
  public static function getFormsRecipebooks($parameters = array()) {
    $parameters['mode'] = !empty($parameters['mode']) ? $parameters['mode'] : 'recipebook';
    return self::getRecipebooksForms($parameters);
  }
  public static function getRecipebooksForms($parameters = array()) {

    // Get the value from the cache.

    //self::$recipebooks_forms = &drupal_static('botcha_recipebooks_forms');

    //if (empty(self::$recipebooks_forms) || $parameters['reset']) {
    $fields = array();
    switch ($parameters['mode']) {
      case 'form':

        //return self::$recipebooks_forms->fetchAllAssoc('form_id');
        $fields[] = 'form_id';
        break;
      case 'recipebook':
      default:

        //return self::$recipebooks_forms->fetchAllAssoc('rbid');
        $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');
    }

    //self::$recipebooks_forms = $rbf;

    //}

    // Catching of PDOException helps to avoid WSOD during update use case. The
    // reason is in that form_alter is called before performing an update.
    // @see http://drupal.org/node/1828710
    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) {

    // Get the value from the cache.

    //self::$recipebooks_recipes = &drupal_static('botcha_recipebooks_recipes');

    //if (empty(self::$recipebooks_recipes) || $parameters['reset']) {
    $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');
    }

    // Catching of PDOException helps to avoid WSOD during update use case. The
    // reason is in that form_alter is called before performing an update.
    // @see http://drupal.org/node/1828710
    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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BotchaModel::getFormsRecipebooks public static function Just an alias for getRecipebooksForms.
BotchaModel::getRecipebooksForms public static function
BotchaModel::getRecipebooksRecipes public static function
BotchaModel::getRecipesRecipebooks public static function