You are here

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

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

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

Parameters

string $id: Machine name of the recipe book to look for.

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

Return value

BotchaRecipebookAbstract

6 calls to Botcha::getRecipebook()
Botcha::getAdminForm in controller/botcha.controller.inc
Botcha::getRecipebooks in controller/botcha.controller.inc
Get a list of all BOTCHA recipe book objects.
BotchaBaseWebTestCase::assertFormSubmission in ./botcha.test
Check whether our suspections are real.
BotchaFormAbstract::getRecipebook in controller/botcha_form.controller.inc
@todo BotchaForm getRecipebook Description.
botcha_recipebook_id_validate in ./botcha.admin.inc

... See full list

File

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

Class

Botcha
Singleton realization of botcha application.

Code

public static function getRecipebook($id = 'default', $create = TRUE) {
  $recipebook_session =& $_SESSION[self::BOTCHA_SESSION_RECIPEBOOKS][$id];
  if (empty($recipebook_session) || $create) {
    $recipebook = BotchaRecipebook::getRecipebook($id, $create);
    if (!$recipebook instanceof BotchaRecipebookNone) {

      // Set relationships for this concrete recipe book.
      $fs = array_keys(BotchaModel::getRecipebooksForms(array(
        'mode' => 'form',
        'recipebooks' => $id,
      )));
      foreach ($fs as $form_id) {
        $recipebook = $recipebook
          ->setForm($form_id);
      }

      // Get recipe book - recipe relationships.
      $rs = array_keys(BotchaModel::getRecipebooksRecipes(array(
        'mode' => 'recipe',
        'recipebooks' => $id,
      )));
      foreach ($rs as $recipe_id) {
        $recipebook = $recipebook
          ->setRecipe($recipe_id);
      }
    }
    Botcha::setRecipebook($recipebook);
  }
  $recipebook = unserialize($recipebook_session);
  return $recipebook;
}