Advertisement
algore87

bestellung.php

Jan 10th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.98 KB | None | 0 0
  1. <?php   // UTF-8 marker äöüÄÖÜ߀
  2. /**
  3.  * Class PageTemplate for the exercises of the EWA lecture
  4.  * Demonstrates use of PHP including class and OO.
  5.  * Implements Zend coding standards.
  6.  * Generate documentation with Doxygen or phpdoc
  7.  *
  8.  * PHP Version 5
  9.  *
  10.  * @category File
  11.  * @package  Pizzaservice
  12.  * @author   Bernhard Kreling, <b.kreling@fbi.h-da.de>
  13.  * @author   Ralf Hahn, <ralf.hahn@h-da.de>
  14.  * @license  http://www.h-da.de  none
  15.  * @Release  1.2
  16.  * @link     http://www.fbi.h-da.de
  17.  */
  18.  
  19. // to do: change name 'PageTemplate' throughout this file
  20. require_once 'Page.php';
  21.  
  22. /**
  23.  * This is a template for top level classes, which represent
  24.  * a complete web page and which are called directly by the user.
  25.  * Usually there will only be a single instance of such a class.
  26.  * The name of the template is supposed
  27.  * to be replaced by the name of the specific HTML page e.g. baker.
  28.  * The order of methods might correspond to the order of thinking
  29.  * during implementation.
  30.  
  31.  * @author   Bernhard Kreling, <b.kreling@fbi.h-da.de>
  32.  * @author   Ralf Hahn, <ralf.hahn@h-da.de>
  33.  */
  34. class Bestellung extends Page
  35. {
  36.     // to do: declare reference variables for members
  37.     // representing substructures/blocks
  38.     /**
  39.      * TODO: Login Rechte? Wie?
  40.      */
  41.     protected $auswahl_warenkorb = null;
  42.    
  43.     /**
  44.      * Instantiates members (to be defined above).  
  45.      * Calls the constructor of the parent i.e. page class.
  46.      * So the database connection is established.
  47.      *
  48.      * @return none
  49.      */
  50.     protected function __construct()
  51.     {
  52.         parent::__construct();
  53.         // to do: instantiate members representing substructures/blocks
  54.         require_once './divs/auswahl_warenkorb.php';
  55.         $this->auswahl_warenkorb = new Auswahl_Warenkorb($this->database);
  56.     }
  57.    
  58.     /**
  59.      * Cleans up what ever is needed.  
  60.      * Calls the destructor of the parent i.e. page class.
  61.      * So the database connection is closed.
  62.      *
  63.      * @return none
  64.      */
  65.     protected function __destruct()
  66.     {
  67.         parent::__destruct();
  68.     }
  69.  
  70.     /**
  71.      * Fetch all data that is necessary for later output.
  72.      * Data is stored in an easily accessible way e.g. as associative array.
  73.      *
  74.      * @return none
  75.      */
  76.     protected function getViewData()
  77.     {
  78.         // to do: fetch data for this view from the database
  79.     }
  80.    
  81.     /**
  82.      * First the necessary data is fetched and then the HTML is
  83.      * assembled for output. i.e. the header is generated, the content
  84.      * of the page ("view") is inserted and -if avaialable- the content of
  85.      * all views contained is generated.
  86.      * Finally the footer is added.
  87.      *
  88.      * @return none
  89.      */
  90.     protected function generateView()
  91.     {
  92.         $this->getViewData();
  93.         $this->generatePageHeader("Bestellung");
  94.         echo <<< EOT
  95. <div id="site_body">
  96.     <form id="bestellen" action="kunde.php" method="post">
  97.         <fieldset><legend>Bestellung</legend>
  98. EOT;
  99.  
  100.         /* INHALT */
  101.         $this->auswahl_warenkorb->generateView("div_auswahl_warenkorb");
  102.         echo <<< EOT
  103.         </fieldset>
  104.     </form>
  105. EOT;
  106.  
  107.         $this->generatePageFooter();
  108.     }
  109.    
  110.     /**
  111.      * Processes the data that comes via GET or POST i.e. CGI.
  112.      * If this page is supposed to do something with submitted
  113.      * data do it here.
  114.      * If the page contains blocks, delegate processing of the
  115.      * respective subsets of data to them.
  116.      *
  117.      * @return none
  118.      */
  119.     protected function processReceivedData()
  120.     {
  121.         parent::processReceivedData();
  122.         // to do: call processReceivedData() for all members
  123.  
  124.  
  125.     }
  126.  
  127.     /**
  128.      * This main-function has the only purpose to create an instance
  129.      * of the class and to get all the things going.
  130.      * I.e. the operations of the class are called to produce
  131.      * the output of the HTML-file.
  132.      * The name "main" is no keyword for php. It is just used to
  133.      * indicate that function as the central starting point.
  134.      * To make it simpler this is a static function. That is you can simply
  135.      * call it without first creating an instance of the class.
  136.      *
  137.      * @return none
  138.      */    
  139.     public static function main()
  140.     {
  141.         try {
  142.             $page = new Bestellung();
  143.             $page->processReceivedData();
  144.             $page->generateView();
  145.         }
  146.         catch (Exception $e) {
  147.             header("Content-type: text/plain; charset=UTF-8");
  148.             echo $e->getMessage();
  149.         }
  150.     }
  151. }
  152.  
  153. // This call is starting the creation of the page.
  154. // That is input is processed and output is created.
  155. Bestellung::main();
  156.  
  157. // Zend standard does not like closing php-tag!
  158. // PHP doesn't require the closing tag (it is assumed when the file ends).
  159. // Not specifying the closing ? >  helps to prevent accidents
  160. // like additional whitespace which will cause session
  161. // initialization to fail ("headers already sent").
  162. //? >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement