You are here

class BotchaFormModel in BOTCHA Spam Prevention 6.2

Same name and namespace in other branches
  1. 6.3 model/form/botcha.form.model.inc \BotchaFormModel
  2. 7.2 model/botcha_form.model.inc \BotchaFormModel
  3. 7.3 model/form/botcha.form.model.inc \BotchaFormModel

@file Contains BotchaFormModel class.

Model layer of the BotchaForm objects.

Hierarchy

Expanded class hierarchy of BotchaFormModel

File

model/botcha_form.model.inc, line 10
Contains BotchaFormModel class.

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

}

Members

Namesort descending Modifiers Type Description Overrides
BotchaFormModel::delete public static function
BotchaFormModel::getForm public static function
BotchaFormModel::getForms public static function
BotchaFormModel::save public static function Save form to the database.