A lot debug messages removed, mailer with stubs added, resend link basicly finished...
[shipsimu.git] / application / ship-simu / main / ships / passenger / class_PassengerShip.php
1 <?php
2 /**
3  * A passenger ship with one or more decks, cabins, bridge (replacement for the
4  * captain) and many more
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0.0
8  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.ship-simu.org
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 class PassengerShip extends BaseShip implements ConstructableShip {
26         // Konstruktor
27         protected function __construct () {
28                 // Eltern-Kontruktor aufrufen
29                 parent::__construct(__CLASS__);
30
31                 // Set description
32                 $this->setObjectDescription("Passagier-Schiff");
33
34                 // Generate unique ID number
35                 $this->generateUniqueId();
36
37                 // Clean up a little
38                 $this->removeSystemArray();
39         }
40
41         // Passagier-Schiff erstellen
42         public final static function createPassengerShip ($shipName) {
43                 // Get new instance
44                 $passInstance = new PassengerShip();
45
46                 // Debug message
47                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) {
48                         $passInstance->getDebugInstance()->output(sprintf("[%s:%d] Ein Passagier-Schiff wird erstellt.",
49                                 __CLASS__,
50                                 __LINE__
51                         ));
52                 } // END - if
53
54                 // Set ship's name
55                 $passInstance->setShipName($shipName);
56
57                 // Instanz zurueckgeben
58                 return $passInstance;
59         }
60
61         // Anzahl Betten ermitteln
62         final function calcTotalBeds () {
63                 // Struktur-Array holen
64                 $struct = $this->getStructuresArray();
65
66                 if (is_null($struct)) {
67                         // Empty structures list!
68                         throw new EmptyStructuresListException($this, self::EXCEPTION_EMPTY_STRUCTURES_ARRAY);
69                 } // END - if
70
71                 // Anzahl Betten auf 0 setzen
72                 $numBeds = 0;
73
74                 // Alle Strukturen nach Kabinen durchsuchen
75                 for ($idx = $struct->getIterator(); $idx->valid(); $idx->next()) {
76                         // Element holen
77                         $el = $idx->current();
78
79                         // Ist es eine Kabine?
80                         if ($el->isCabin()) {
81                                 // Anzahl Betten ermitteln
82                                 $total = $el->calcTotalBedsByCabin();
83                                 $numBeds += $total;
84
85                                 // Debug-Meldung ausgeben?
86                                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) {
87                                         // Get new instance
88                                         $cabType = "Kabine ohne Namen";
89                                         $cab = $el->getPartInstance();
90                                         if (!is_null($cab)) {
91                                                 // Kabinenbeschreibung holen
92                                                 $cabType = $cab->getObjectDescription();
93                                         }
94
95                                         // Debug-Meldung ausgeben
96                                         $this->getDebugInstance()->output(sprintf("[%s:%d] Es stehen <strong>%d</strong> Betten vom Kabinen-Typ <strong>%s</strong> bereit.",
97                                                 __CLASS__,
98                                                 __LINE__,
99                                                 $total,
100                                                 $cabType
101                                         ));
102                                 }
103                         } else {
104                                 // Keine Kabine!
105                                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%s</strong> ist keine Kabine.",
106                                         __CLASS__,
107                                         __LINE__,
108                                         $el->getObjectDescription()
109                                 ));
110                         }
111                 } // END - for
112
113                 if ((defined('DEBUG_SHIP')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das <strong>%s</strong> mit dem Namen <strong>%s</strong> hat <strong>%d</strong> Betten.",
114                         __CLASS__,
115                         __LINE__,
116                         $this->getObjectDescription(),
117                         $this->getShipName(),
118                         $numBeds
119                 ));
120
121                 // Anzahl zurueckliefern
122                 return $numBeds;
123         }
124 }
125
126 // [EOF]
127 ?>