You are here

public static function Botcha::getForm in BOTCHA Spam Prevention 6.2

Same name and namespace in other branches
  1. 7.2 controller/botcha.controller.inc \Botcha::getForm()

Gets a form from cache. If it does not exists in cache - gets from database. If it does not exists there also - returns new form or BotchaFormNone depending on input parameter.

Parameters

string $form_id:

boolean $create: Determines whether we should initialize new recipe book or not.

Return value

BotchaForm

8 calls to Botcha::getForm()
Botcha::getForms in controller/botcha.controller.inc
Get a list of available BOTCHA form objects.
BotchaAdminTestCase::testBotchaAdminLinks in ./botcha.test
Testing of the BOTCHA administration links.
BotchaBaseWebTestCase::assertFormSubmission in ./botcha.test
Check whether our suspections are real.
BotchaBaseWebTestCase::getForm in ./botcha.test
Get one of predefined forms. Used to unify the process of testing.
BotchaRecipebookAbstract::getForms in controller/botcha_recipebook.controller.inc
@todo BotchaRecipebook getForms Description.

... See full list

File

controller/botcha.controller.inc, line 292
Contains Botcha class.

Class

Botcha
Singleton realization of botcha application.

Code

public static function getForm($form_id, $create = TRUE) {

  // We are using $_SESSION to store the state of the spam checking, because
  // HTTP is stateless by design.
  $form_session =& $_SESSION[self::BOTCHA_SESSION_FORMS][$form_id];
  if (empty($form_session) || $create) {
    $form = BotchaForm::getForm($form_id, $create);
    if (!$form instanceof BotchaFormNone) {

      // Set relationships for this concrete form.
      $rbs = array_keys(BotchaModel::getFormsRecipebooks(array(
        'mode' => 'recipebook',
        'forms' => $form_id,
      )));
      foreach ($rbs as $rbid) {
        $form = $form
          ->setRecipebook($rbid);
      }
    }
    Botcha::setForm($form);
  }
  $form = unserialize($form_session);
  return $form;
}