f8e992e9f796bb0580ae1c6e6de22809e1e59566
[shipsimu.git] / application / ship-simu / main / structures / extended / class_BaseCabinStructure.php
1 <?php
2 /**
3  * General cabin structure class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class BaseCabinStructure extends BaseStructure {
25         // --- Besondere Eigenschaften dazufuegen: ---
26         // Anzahl der Kabinen im Schiff
27         private $numCabin = 0;
28
29         // Anzahl Raeume pro Kabine (kann auch nur 1 sein)
30         private $numRooms = 0;
31
32         // Anzahl Betten, verallgemeinert
33         private $numBeds = 0;
34
35         // Konstruktor
36         protected function __construct ($className) {
37                 // Call parent constructor
38                 parent::__construct($className);
39         }
40
41         // Kabine hinzufuegen
42         public function addShipPartToShip (ConstructableShip $shipInstance, ConstructableShipPart $cabinInstance) {
43                 // Eltern-Methode aufrufen
44                 parent::addShipPartToShip ($shipInstance, $cabinInstance);
45
46                 // Restlichen Daten ebenfalls
47                 $this->setNumCabin($cabinInstance->numCabin);
48                 $this->setNumRooms($cabinInstance->numRooms);
49                 $this->setNumBeds($cabinInstance->numBeds);
50
51                 // Unnoetige Attribute entfernen
52                 $cabinInstance->removeNumCabin();
53                 $cabinInstance->removeNumRooms();
54                 $cabinInstance->removeNumBeds();
55
56                 // Instanz setzen
57                 $this->setDeckInstance($cabinInstance);
58         }
59
60         // Wrapper fuer setDeckInstance->setPartInstance
61         public final function setDeckInstance ($deck) {
62                 parent::setPartInstance($deck);
63         }
64
65         // Getter-Methode fuer Anzahl Betten
66         public final function getNumBeds () {
67                 return $this->numBeds;
68         }
69
70         // Getter-Methode fuer Anzahl Kabinen
71         public final function getNumCabin () {
72                 return $this->numCabin;
73         }
74
75         // Setter-Methode fuer Anzahl Betten
76         public final function setNumBeds ($numBeds) {
77                 $this->numBeds = $numBeds;
78         }
79
80         // Setter-Methode fuer Anzahl Raeume
81         public final function setNumRooms ($numRooms) {
82                 $this->numRooms = $numRooms;
83         }
84
85         // Setter-Methode fuer Anzahl Kabinen
86         public final function setNumCabin ($numCabin) {
87                 $this->numCabin = $numCabin;
88         }
89
90         // Loesch-Methode fuer Anzahl Betten
91         public final function removeNumBeds() {
92                 unset($this->numBeds);
93         }
94
95         // Loesch-Methode fuer Anzahl Kabinen
96         public final function removeNumCabin() {
97                 unset($this->numCabin);
98         }
99
100         // Loesch-Methode fuer Anzahl Raeume
101         public final function removeNumRooms() {
102                 unset($this->numRooms);
103         }
104
105         // Bettenanzahl pro Kabine berechnen
106         public function calcTotalBedsByCabin () {
107                 // Dann Bettenanzahl holen und aufaddieren
108                 $beds = $this->getNumBeds();
109                 $num  = $this->getNumCabin();
110                 $cabinBeds = $beds * $num;
111                 if ((defined('DEBUG_STRUCTURE')) || (defined('DEBUG_ALL'))) {
112                         // Get new instance
113                         $cabType = "Kabine ohne Namen";
114                         $cab = $this->getPartInstance();
115                         if (!is_null($cab)) {
116                                 // Kabinenbeschreibung holen
117                                 $cabType = $cab->__toString();
118                         }
119
120                         // Debug-Meldung ausgeben
121                         $this->debugOutput(sprintf("[%s:%d] Es exisitieren <strong>%d</strong> Kabinen vom Typ <strong>%s</strong> zu je <strong>%d</strong> Betten. Das sind <strong>%d</strong> Betten.",
122                                 __CLASS__,
123                                 __LINE__,
124                                 $num,
125                                 $cabType,
126                                 $beds,
127                                 $cabinBeds
128                         ));
129                 }
130                 return $cabinBeds;
131         }
132 }
133
134 // [EOF]
135 ?>