Dave Jarvis' Repositories

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

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

/**
 * Allows the user to either organize or add themselves to a potluck.
 */
class Potluck extends BaseController {
  function __construct() {
    parent::__construct();
  }

  /**
   * Checks to see if the given account ID exists.
   *
   * @param id The identifier for an existing account.
   * @return true
   */
  protected function exists( $id ) {
    return true;
    /*
    return $this->isTrue( $this->call( "is_existing_potluck", "exists", $id ) );
    */
  }

  /**
   * Returns the name of the parameter used to obtain the identifier for
   * the object to edit.
   *
   * @return "potluck-id"
   */
  protected function getParameterIdName() {
    return "potluck-id";
  }

  /**
   * Returns the name of the database function to call to verify that this
   * authentication token is allowed to modify a given potluck. Note that
   * the authentication token (ID) is associated with the browser cookie.
   *
   * @return true iff the potluck ID can be modified by the authentication ID.
   */
  protected function getAuthorizationFunctionName() {
    return "is_authorized_potluck";
  }

  /**
   * Returns the default potluck ID to use.
   *
   * @return 0
   */
  protected function getPotluckId() {
    return 0;
  }

  /** 
   * Overrides the default behaviour (return 0) to return the account ID.
   * This should only get called when all other means to determine the ID
   * for this request have failed.
   *
   * @return $this->getPotluckId()
   */
  protected function getLastResortId() {
    return $this->getPotluckId();
  }

  /**
   * Returns the name of the stylesheet to use for transforming the
   * recipe from XML to XHTML.
   *
   * @return "xsl/potluck.xsl"
   */
  protected function getStylesheetName() {
    return "xsl/potluck.xsl";
  }

  /**
   * Returns the list of recipes for an account in XML format.
   */
  private function getXml() {
    $result = $this->call( "generate_potluck_xml", "x", $this->getId() );

    return isset( $result ) ?
      $result[0]["x"] : $this->getErrorXml( "potluck" );
  }

  /**
   * Returns account information in XHTML format.
   */
  protected function getXhtml() {
    $xslt = $this->getXsltEngine();
    $xslt->setXml( $this->getXml() );
    $xslt->setStylesheet( $this->getStylesheetName() );

    $xslt->setParameter( $this->getParameterIdName(), $this->getId() );
    $xslt->setParameter( "editable", $this->isEditable() );
    $xslt->setParameter( "cookie", $this->getCookieToken() );

    return $xslt->transform();
  }

  /**
   * Executes database transactions depending on the supplied commands.
   */
  protected function handleRequest() {
    $command = $this->getCommand();
    $subcommand = $this->getSubCommand();

    $this->render();
  }
}