You are here

botcha_form.model.inc in BOTCHA Spam Prevention 6.2

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

Contains BotchaFormModel class.

Model layer of the BotchaForm objects.

File

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

/**
 * @file
 * Contains BotchaFormModel class.
 *
 * Model layer of the BotchaForm objects.
 */
class BotchaFormModel {

  //protected static $forms;
  public static function getForms($parameters = array()) {

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

    // Execute query and fetch the result.
    $query = BotchaModel::buildQuery(BOTCHA_MODEL_TYPE_SELECT, 'botcha_form', $pars);
    $result_query = BotchaModel::getQueryResult($query['query'], $query['query_subs']);
    $result = BotchaModel::fetchQueryResult($result_query);
    return $result;
  }
  public static function getForm($id) {
    $forms = self::getForms();
    return !empty($forms[$id]) ? $forms[$id] : NULL;
  }

  /**
   * Save form to the database.
   * @param BotchaForm $form
   */
  public static function save($form) {

    // Save form.
    if (!db_result(db_query("SELECT COUNT(*) FROM {botcha_form} bf WHERE bf.id = '%s'", array(
      $form->id,
    )))) {
      db_query("INSERT INTO {botcha_form} (id) VALUES('%s')", array(
        $form->id,
      ));
    }
    $recipebook = $form
      ->getRecipebook();

    // Save form-recipe book relationship.
    if ($recipebook instanceof BotchaRecipebookNone) {
      db_query("DELETE FROM {botcha_recipebook_form} WHERE form_id = '%s'", array(
        $form->id,
      ));
    }
    else {
      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} (form_id, rbid) VALUES('%s', '%s')", array(
          $form->id,
          $recipebook->id,
        ));
      }
    }
  }
  public static function delete($form) {

    // Delete all data related to this form.
    db_query("DELETE FROM {botcha_recipebook_form} WHERE form_id = '%s'", array(
      $form->id,
    ));
    db_query("DELETE FROM {botcha_form} WHERE id = '%s'", array(
      $form->id,
    ));
  }

}

Classes

Namesort descending Description
BotchaFormModel @file Contains BotchaFormModel class.