Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/recipe-fiddle.git
<?php
namespace com\whitemagicsoftware;

require "constants.php";
require "class.BaseController.php";

/**
 * Superclass for all Ajax request handlers.
 */
abstract class Ajax extends BaseController {
  function __construct() {
    parent::__construct();
  }

  /**
   * The parameter passed into the Ajax routines must be recipe-id.
   */
  protected function getParameterIdName() {
    return "recipe-id";
  }

  /**
   * All Ajax subclasses are GET requests for information and therefore
   * do not need to be authorized. This reduces stress on the database.
   *
   * @return false Do not authorize the account.
   */
  protected function authorize() {
    return false;
  }

  /**
   * Unused.
   */
  protected function exists( $id ) {
    return true;
  }

  /**
   * Unused.
   */
  protected function getAuthorizationFunctionName() {
    return "";
  }

  /**
   * Unused.
   */
  protected function getXhtml() {
    return "";
  }

  /**
   * Subclasses must implement this method to return data based on some
   * input parameters.
   *
   * @return Content to encode using the json_encode function.
   */
  protected abstract function handleAjaxRequest();

  protected function handleRequest() {
    global $CONTENT_ENCODING_AJAX;
    $this->sendHttpHeaders( $CONTENT_ENCODING_AJAX );

    echo $this->handleAjaxRequest();
  }
}