You are here

class BotchaFormController in BOTCHA Spam Prevention 7.3

Same name and namespace in other branches
  1. 6.3 controller/form/botcha.form.controller.inc \BotchaFormController

Special class to abstract operations with form_id. It looks like additional layer of abstraction after DatabaseAbstractionLayer. It helps us to get necessary data - while we don't have to repeat ourselves in many places, writing queries to the database. All logic is hidden under this simple interface: getForm, getRecipebook, getRecipe, etc.

Hierarchy

Expanded class hierarchy of BotchaFormController

File

controller/form/botcha.form.controller.inc, line 22
Controller layer of the BotchaForm objects.

View source
class BotchaFormController extends Controller implements IBotchaFormController {
  protected $app_name = 'Botcha';
  protected $controller_type = Botcha::CONTROLLER_TYPE_FORM;

  /**
   * Just for IDE autocomplete feature.
   * @return BotchaFormModel
   */
  protected function getModel() {
    return parent::getModel();
  }

  /**
   * 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.
   * @param string $form_id
   * @param boolean $create
   *   Determines should we construct new form or return NULL if it does not exist.
   * @return BotchaForm
   */
  public function getForm($form_id, $create = TRUE) {
    $none = TRUE;

    // Respect form exceptions (done by forbidden_forms recipe book).

    //if (!in_array($form_id, array('user_login', 'user_login_block', 'update_script_selection_form'))) {
    $form = $this
      ->getModel()
      ->getForm($form_id);
    if ($form || $create) {
      $none = FALSE;
    }

    //}
    if ($none) {
      $botcha_form = new BotchaFormNone($form_id);
    }
    else {
      $botcha_form = new BotchaForm($form_id);
      $botcha_form
        ->getRecipebook();
    }
    return $botcha_form;
  }

  /**
   * Get a list of available BOTCHA form objects.
   * @todo Respect reset (?via Cacher?)
   * @param boolean $reset
   * @return BotchaForm
   */
  public function getForms($reset = FALSE) {
    $forms = array();
    foreach ($this
      ->getModel()
      ->getForms() as $form) {
      $forms[$form->id] = $this
        ->getForm($form->id, FALSE);
    }
    return $forms;
  }

  // @todo ?Should we separate BotchaForm and BotchaFormAbstract?
  public function save($form) {

    // Save form to DB.
    $this
      ->getModel()
      ->save($form);

    // Return updated object to check results if necessary.
    return $this
      ->getForm($form->id, FALSE);
  }
  public function delete($form) {

    // Save form to DB.
    $this
      ->getModel()
      ->delete($form);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BotchaFormController::$app_name protected property
BotchaFormController::$controller_type protected property
BotchaFormController::delete public function Overrides IBotchaFormController::delete
BotchaFormController::getForm public function 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. Overrides IBotchaFormController::getForm
BotchaFormController::getForms public function Get a list of available BOTCHA form objects. @todo Respect reset (?via Cacher?) Overrides IBotchaFormController::getForms
BotchaFormController::getModel protected function Just for IDE autocomplete feature.
BotchaFormController::save public function Overrides IBotchaFormController::save