You are here

public static function BotchaFormModel::save in BOTCHA Spam Prevention 6.2

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

Save form to the database.

Parameters

BotchaForm $form:

2 calls to BotchaFormModel::save()
BotchaFormAbstract::save in controller/botcha_form.controller.inc
BotchaFormNone::save in controller/botcha_form.controller.inc

File

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

Class

BotchaFormModel
@file Contains BotchaFormModel class.

Code

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