Advertisement
algore87

auswahl.php

Jan 10th, 2016
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.06 KB | None | 0 0
  1. <?php   // UTF-8 marker äöüÄÖÜ߀
  2. /**
  3.  * Class BlockTemplate 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. /**
  20.  * This is a template for classes, which represent div-blocks
  21.  * within a web page. Instances of these classes are used as members
  22.  * of top level classes.
  23.  * The order of methods might correspond to the order of thinking
  24.  * during implementation.
  25.  
  26.  * @author   Bernhard Kreling, <b.kreling@fbi.h-da.de>
  27.  * @author   Ralf Hahn, <ralf.hahn@h-da.de>
  28. */
  29.  
  30. class Auswahl        // to do: change name of class
  31. {
  32.     // --- ATTRIBUTES ---
  33.  
  34.     /**
  35.      * Reference to the MySQLi-Database that is
  36.      * accessed by all operations of the class.
  37.      */
  38.     protected $_database = null;
  39.     protected $table = null;
  40.     protected $menuArray = [];
  41.    
  42.     // to do: declare reference variables for members
  43.     // representing substructures/blocks
  44.    
  45.     // --- OPERATIONS ---
  46.    
  47.     /**
  48.      * Gets the reference to the DB from the calling page template.
  49.      * Stores the connection in member $_database.
  50.      *
  51.      * @param $database $database is the reference to the DB to be used    
  52.      *
  53.      * @return none
  54.      */
  55.     public function __construct($database)
  56.     {
  57.         $this->_database = $database;
  58.         // to do: instantiate members representing substructures/blocks
  59.     }
  60.  
  61.     /**
  62.      * Fetch all data that is necessary for later output.
  63.      * Data is stored in an easily accessible way e.g. as associative array.
  64.      *
  65.      * @return none
  66.      */
  67.     protected function getViewData()
  68.     {
  69.         /* Auswahlliste */
  70.         $this->table = $this->_database->query("SELECT * FROM `Angebot` ORDER BY `PizzaName`");
  71.         while (($row = $this->table->fetch_assoc()) != null)
  72.             $this->menuArray[] = $row;
  73.         $this->table->free();
  74.     }
  75.    
  76.     /**
  77.      * Generates an HTML block embraced by a div-tag with the submitted id.
  78.      * If the block contains other blocks, delegate the generation of their
  79.      * parts of the view to them.
  80.      *
  81.      * @param $id $id is the unique (!!) id to be used as id in the div-tag    
  82.      *
  83.      * @return none
  84.      */
  85.     public function generateView($id = "")
  86.     {
  87.         $this->getViewData();
  88.         if ($id) {
  89.             $id = "id=\"$id\"";
  90.         }
  91.         echo "<div $id>\n";
  92.         // ToDo: Evtl. als Liste mit fester Größe (Scrollbar)
  93.  
  94.         echo <<< EOT
  95. <h3>Auswahl</h3>
  96.     <table cellpadding="5" title="Ziehe Pizza von hier in den Warenkorb">
  97. EOT;
  98.         foreach($this->menuArray as $row) {
  99.             echo <<< PIZZA
  100.         <tr>
  101.             <td><img id="{$row["PizzaName"]}" src="img/{$row["Bilddatei"]}" alt="pizza_bild" width="75" height="75" draggable="true" data-preis="{$row["Preis"]}" ondragstart="drag(event);"/></td>
  102.             <td>{$row["PizzaName"]}</td>
  103.             <td>{$row["Preis"]} &euro;</td>
  104.         </tr>
  105. PIZZA;
  106.  
  107.         }
  108.         echo"</table>";
  109.         echo "</div>\n";
  110.     }
  111.    
  112.     /**
  113.      * Processes the data that comes via GET or POST i.e. CGI.
  114.      * If this block is supposed to do something with submitted
  115.      * data do it here.
  116.      * If the block contains other blocks, delegate processing of the
  117.      * respective subsets of data to them.
  118.      *
  119.      * @return none
  120.      */
  121.     public function processReceivedData()
  122.     {
  123.         // to do: call processData() for all members
  124.     }
  125. }
  126. // Zend standard does not like closing php-tag!
  127. // PHP doesn't require the closing tag (it is assumed when the file ends).
  128. // Not specifying the closing ? >  helps to prevent accidents
  129. // like additional whitespace which will cause session
  130. // initialization to fail ("headers already sent").
  131. //? >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement