(no commit message)
[shipsimu.git] / application / ship-simu / main / companies / class_ShippingCompany.php
1 <?php
2
3 // Die Reederei-Klasse
4 class ShippingCompany extends BaseSimulator implements Customer, ContractPartner {
5         // Firmenname
6         private $companyName     = "Namenlose Reederei";
7
8         // Firmenkuerzel
9         private $shortName       = "";
10
11         // Reederei-Gruender
12         private $founderInstance = null;
13
14         // Angestellten-Liste
15         private $employeeList    = null;
16
17         // Zugewiesener Hafen
18         private $hqInstance      = null;
19
20         // Werftenliste
21         private $shipyardList   = null;
22
23         // Der Reederei gehoerenden Schiffe
24         private $ownedShips      = null;
25
26         // Bauauftraege als Kunde
27         private $contractList    = null;
28
29         // Konstruktor
30         private function __construct () {
31                 // Eltern-Konstruktor aufrufen
32                 parent::constructor(__CLASS__);
33
34                 // Debug message
35                 if (((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
36                         $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
37                                 __CLASS__,
38                                 __LINE__
39                         ));
40                 }
41
42                 // Beschreibung setzen
43                 $this->setPartDescr("Reederei");
44
45                 // Unique-ID erzeugen
46                 $this->createUniqueID();
47
48                 // Clean up a little
49                 $this->removeSystemArray();
50         }
51
52         // Reederei gruenden (create wegen Namenskonvention)
53         public static function createShippingCompany ($companyName, Harbor $hqInstance) {
54                 // Instanz holen
55                 $companyInstance = new ShippingCompany();               
56
57                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $companyInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> wird gegr&uuml;ndet.<br />\n",
58                         __CLASS__,
59                         __LINE__,
60                         $companyName
61                 ));
62
63                 // Firmennamen setzen
64                 $companyInstance->setCompanyName($companyName);
65
66                 // Kuerzel setzen
67                 $companyInstance->createShortName();
68
69                 // Sitz festlegen
70                 $companyInstance->setHQInstance($hqInstance);
71
72                 // Werftenliste erstellen
73                 $companyInstance->createshipyardList();
74
75                 // Angestellten-Liste erstellen
76                 $companyInstance->createEmployeeList();
77
78                 // Auftragsliste erstellen
79                 $companyInstance->createContractList();
80
81                 // Etwas aufraeumen
82                 $companyInstance->removeWidth();
83                 $companyInstance->removeHeight();
84                 $companyInstance->removeLength();
85                 $companyInstance->removeDraught();
86                 $companyInstance->removePartInstance();
87
88                 // Instanz zurueckgeben
89                 return $companyInstance;
90         }
91
92         // Angestellten-Liste erstellen
93         private function createEmployeeList () {
94                 if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erh&auml;lt eine Angestelltenliste.<br />\n",
95                         __CLASS__,
96                         __LINE__,
97                         $this->getCompanyName()
98                 ));
99                 $this->employeeList = new FrameworkArrayObject();
100         }
101
102         // Werftenliste erstellen
103         public function createShipyardList () {
104                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erh&auml;lt eine Werftsliste.<br />\n",
105                         __CLASS__,
106                         __LINE__,
107                         $this->getCompanyName()
108                 ));
109                 $this->shipyardList = new FrameworkArrayObject();
110         }
111
112         // Auftragsliste erstellen
113         public function createContractList () {
114                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erh&auml;lt eine Auftragsliste.<br />\n",
115                         __CLASS__,
116                         __LINE__,
117                         $this->getCompanyName()
118                 ));
119                 $this->contractList = new FrameworkArrayObject();
120         }
121
122         // Setter-Methode fuer Firmennamen
123         public function setCompanyName ($companyName) {
124                 $this->companyName = (string) $companyName;
125         }
126
127         // Getter-Methode fuer Firmennamen
128         public function getCompanyName () {
129                 return $this->companyName;
130         }
131
132         // Setter-Methode fuer Firmensitz
133         public function setHQInstance (Harbor $hqInstance) {
134                 $this->hqInstance = $hqInstance;
135         }
136
137         // Kuerzel setzen
138         private function createShortName () {
139                 // Mindestens eine Leerstelle?
140                 $dummy = explode(" ", $this->getCompanyName());
141                 foreach ($dummy as $part) {
142                         $this->shortName .= substr($part, 0, 1);
143                 }
144         }
145
146         // Reedereien Werften bauen lassen
147         public function createShipyardInHarbor($shipyardName, Harbor $harborInstance) {
148                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> baut im <strong>%s</strong> eine Werft <strong>%s</strong>.<br />\n",
149                         __CLASS__,
150                         __LINE__,
151                         $this->getCompanyName(),
152                         $harborInstance->getHarborName(),
153                         $shipyardName
154                 ));
155
156                 // Wird im HQ gebaut?
157                 if ($this->hqInstance->equals($harborInstance)) {
158                         // Die neue Werft wird im HQ gebaut!
159                         $this->hqInstance->addNewShipyardNotify($shipyardName, $this);
160                         // Die Werft drueber in Kenntnis setzen, welcher Reederei sie angehoert
161                 } else {
162                         // Ausserhalb des Heimathafens soll eine Werft gebaut werden
163                         $harborInstance->addNewShipyardNotify($shipyardName, $this);
164                 }
165         }
166
167         // Setter fuer Reederei-Gruender
168         public function setCompanyFounder(CompanyEmployee $founderInstance) {
169                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> ist von <strong>%s %s</strong> gegr&uuml;ndet worden.<br />\n",
170                         __CLASS__,
171                         __LINE__,
172                         $this->getCompanyName(),
173                         $founderInstance->getSurname(),
174                         $founderInstance->getFamily()
175                 ));
176                 $this->founderInstance = $founderInstance;
177         }
178
179         // Getter for founder instance
180         public function getFounderInstance () {
181                 return $this->founderInstance;
182         }
183
184         // Neue(n) Angestellte(n) in Angestellten-Liste aufnehmen
185         public function addNewEmployee (SimulatorPersonell $employeeInstance) {
186                 if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%s %s</strong> tritt der Reederei <strong>%s</strong> als <strong>%s</strong> bei und erh&auml;lt ein Gehalt von <strong>%s</strong>.<br />\n",
187                         __CLASS__,
188                         __LINE__,
189                         $employeeInstance->getSurname(),
190                         $employeeInstance->getFamily(),
191                         $this->getCompanyName(),
192                         $employeeInstance->getPartDescr(),
193                         $this->formatCurrency($employeeInstance->getSalary())
194                 ));
195                 $this->employeeList->append($employeeInstance);
196         }
197
198         // Neue Werft in Liste aufnehmen
199         public function addNewShipyard (Shipyard $shipyardInstance) {
200                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erh&auml;lt die Werft <strong>%s</strong> hinzugef&uuml;gt.<br />\n",
201                         __CLASS__,
202                         __LINE__,
203                         $this->getCompanyName(),
204                         $shipyardInstance->getShipyardName()
205                 ));
206                 $this->shipyardList->append($shipyardInstance);
207         }
208
209         // Neue Mitarbeiter per Zufall einstellen/rekrutieren
210         public function recruitRandomEmployees($amount, SimulatorPersonell $personellInstance) {
211                 // Anzahl Mitarbeiter absichern
212                 $amount = (int) $amount;
213
214                 // Debug-Meldung ausgeben
215                 if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> stellt per Zufall <strong>%d</strong> neue Mitarbeiter ein.<br />\n",
216                         __CLASS__,
217                         __LINE__,
218                         $this->getCompanyName(),
219                         $amount
220                 ));
221
222                 // Gesamtanzahl verfuegbarer Erwerbsloser holen
223                 $totalUnemployed = $personellInstance->getAllUnemployed();
224
225                 // Existiert die gewuenschte Anzahl freier Arbeiter? (doppelt geht derzeit nicht)
226                 if ($totalUnemployed < $amount) {
227                         // Reichte nicht aus!
228                         throw new ToMuchEmployeesException(array($amount, $personellInstance->getAllUnemployed()), self::EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES);
229                 }
230
231                 // Get list for all unemployed people
232                 $list = $personellInstance->getSpecialPersonellList(false); // Should be cached
233
234                 // Get iterator of the list
235                 $iterator = $list->getIterator();
236
237                 // Get the requested amount of personell
238                 for ($idx = 0; $idx < $amount; $idx++) {
239                         $employee = null;
240                         // Is this personl unemployed?
241                         while (is_null($employee) || $employee->isEmployed()) {
242                                 // Generate random number
243                                 $pos = mt_rand(0, ($totalUnemployed - 1)); // Don't remove the -1 here:
244                                 // E.g. 100 entries means latest position is 99...
245
246                                 // Seek for the position
247                                 $iterator->seek($pos);
248
249                                 // Is the current position valid?
250                                 if ($iterator->valid()) {
251                                         // Element holen
252                                         $employee = $iterator->current();
253                                 } else {
254                                         // Should normally not happen... :(
255                                         throw new StructuresOutOfBoundsException($idx, self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
256                                 }
257                         }
258
259                         // A dummy just for the description and real class
260                         $dummy = CompanyEmployee::createCompanyEmployee("", "", "M", 1970, 1, 1, $employee->isMarried(), 0);
261
262                         // Make this person employed and give him some money to work
263                         $employee->setEmployed(true);
264                         $employee->setPartDescr($dummy->getPartDescr());
265                         $employee->setRealClass($dummy->__toString());
266                         $employee->increaseSalary((mt_rand(7, 14) * 100)); // Are 700 to 1400 EUR for the begin okay?
267
268                         // Debug message
269                         if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> stellt den/die Angestellte(n) <strong>%s %s</strong> ein.<br />\n",
270                                 __CLASS__,
271                                 __LINE__,
272                                 $this->getCompanyName(),
273                                 $employee->getSurname(),
274                                 $employee->getFamily()
275                         ));
276
277                         // Add this employee
278                         $this->addNewEmployee($employee);
279                 } // End - for
280
281                 // Cache resetten
282                 $personellInstance->resetCache();
283
284                 // Debug-Meldung ausgeben
285                 if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> hat per Zufall <strong>%d</strong> neue Mitarbeiter eingestellt.<br />\n",
286                         __CLASS__,
287                         __LINE__,
288                         $this->getCompanyName(),
289                         $amount
290                 ));
291         } // End - method
292
293         // Distribute all personells on all shipyards
294         public function distributeAllPersonellOnShipyards () {
295                 if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> verteilt alle ihre <strong>%d</strong> Mitarbeiter auf alle <strong>%d</strong> Werft(en).<br />\n",
296                         __CLASS__,
297                         __LINE__,
298                         $this->getCompanyName(),
299                         $this->getTotalEmployee(),
300                         $this->getTotalShipyards()
301                 ));
302
303                 // Do we have some shipyards?
304                 if (is_null($this->shipyardList)) {
305                         // No shipyards created
306                         throw new NoShipyardsConstructedException($this, self::EXCEPTION_HARBOR_HAS_NO_SHIPYARDS);
307                 }
308
309                 // Get iterator for shipyards
310                 $shipyardIter = $this->shipyardList->getIterator();
311
312                 // Iterate through all employees
313                 for ($idx = $this->employeeList->getIterator(); $idx->valid(); $idx->next()) {
314                         // Is the shipyard iterator still okay?
315                         if (!$shipyardIter->valid()) {
316                                 // Rewind to first position
317                                 $shipyardIter->seek(0);
318                         }
319
320                         // Get Shipyard object
321                         $shipyard = $shipyardIter->current();
322
323                         // Is this a Shipyard object?
324                         if (is_null($shipyard)) {
325                                 // No class returned
326                                 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
327                         } elseif (!is_object($shipyard)) {
328                                 // Not an object! ;-(
329                                 throw new NoObjectException($shipyard, self::EXCEPTION_IS_NO_OBJECT);
330                         } elseif (!$shipyard->isClass("Shipyard")) {
331                                 // Nope, so throw exception
332                                 throw new ClassMismatchException(array($shipyard->__toString(), "Shipyard"), self::EXCEPTION_CLASSES_NOT_MATCHING);
333                         }
334
335                         // Add employee to the shipyard
336                         $shipyard->addNewPersonell($idx->current());
337
338                         // Continue to next shipyard
339                         $shipyardIter->next();
340                 }
341         }
342
343         // Getter for total employees
344         public function getTotalEmployee () {
345                 // Count all...
346                 $total = $this->employeeList->count();
347
348                 // Debug message
349                 if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> hat <strong>%d</strong> Mitarbeiter.<br />\n",
350                         __CLASS__,
351                         __LINE__,
352                         $this->getCompanyName(),
353                         $total
354                 ));
355
356                 // Return amount
357                 return $total;
358         }
359
360         // Getter for total shipyards
361         public function getTotalShipyards () {
362                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] F&uuml;r die Reederei <strong>%s</strong> werden die Anzahl der Werften in allen H&auml;fen ermittelt.<br />\n",
363                         __CLASS__,
364                         __LINE__,
365                         $this->getCompanyName()
366                 ));
367
368                 // Do we have some shipyards?
369                 if (is_null($this->shipyardList)) {
370                         // No shipyards created
371                         throw new NoShipyardsConstructedException($this, self::EXCEPTION_HARBOR_HAS_NO_SHIPYARDS);
372                 }
373
374                 // Get iterator
375                 $total = $this->shipyardList->count();
376
377                 // Debug message
378                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> hat <strong>%d</strong> Werft(en).<br />\n",
379                         __CLASS__,
380                         __LINE__,
381                         $this->getCompanyName(),
382                         $total
383                 ));
384
385                 // Return amount
386                 return $total;
387         }
388
389         // Add a ship type (class) to all shipyards
390         public function addShipTypeToAllShipyards ($shipType) {
391                 // Secure strings
392                 $shipType = (string) $shipType;
393
394                 // Is the class there?
395                 if (!class_exists($shipType)) {
396                         // Throw exception
397                         throw new ClassNotFoundException($shipType, 0);
398                 }
399
400                 // Create dummy ship
401                 eval(sprintf("\$shipInstance = %s::create%s(\"M/S Dummy\");",
402                         $shipType,
403                         $shipType
404                 ));
405
406                 // Debug message
407                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> baut in allen Werften bald Schiffe vom Typ <strong>%s</strong>.<br />\n",
408                         __CLASS__,
409                         __LINE__,
410                         $this->getCompanyName(),
411                         $shipInstance->getPartDescr()
412                 ));
413
414                 // Iterate shipyard list
415                 for ($idx = $this->shipyardList->getIterator(); $idx->valid(); $idx->next()) {
416                         // Get current element
417                         $shipyard = $idx->current();
418
419                         // Is this a shipyard?
420                         if (is_null($shipyard)) {
421                                 // Opps! Empty list?
422                                 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
423                         } elseif (!is_object($shipyard)) {
424                                 // Not an object! ;-(
425                                 throw new NoObjectException($shipyard, self::EXCEPTION_IS_NO_OBJECT);
426                         } elseif (!$shipyard->isClass("Shipyard")) {
427                                 // Class is not a shipyard
428                                 throw new ClassMismatchException(array($shipyard->__toString(), "Shipyard"), self::EXCEPTION_CLASSES_NOT_MATCHING);
429                         }
430
431                         // Add the new ship type to the shipyard
432                         $shipyard->addNewConstructableShipType($shipType);
433                 }
434         }
435
436         // Validate the requested ship type with the company if they can construct it
437         public function validateWorksContractShipType (WorksContract $contractInstance) {
438                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> pr&uuml;ft den Bauauftrag der <strong>%s</strong>.<br />\n",
439                         __CLASS__,
440                         __LINE__,
441                         $this->getCompanyName(),
442                         $contractInstance->getShipName()
443                 ));
444
445                 // First get the ship type
446                 $shipInstance = $contractInstance->getShipInstance();
447
448                 // Ist there a ship instance?
449                 if (is_null($shipInstance)) {
450                         // Opps! Empty entry?
451                         throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
452                 } elseif (!is_object($shipInstance)) {
453                         // Not an object! ;-(
454                         throw new NoObjectException($shipInstance, self::EXCEPTION_IS_NO_OBJECT);
455                 }
456
457                 // Get it's real class name
458                 $shipType = $shipInstance->__toString();
459
460                 // Debug message
461                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> pr&uuml;ft, ob die <strong>%s</strong> (Typ:<strong>%s</strong>) gebaut werden kann.<br />\n",
462                         __CLASS__,
463                         __LINE__,
464                         $this->getCompanyName(),
465                         $contractInstance->getShipName(),
466                         $shipInstance->getPartDescr()
467                 ));
468
469                 // Now check if the ship type is in any list and return the result
470                 return ($this->isShipTypeConstructable($shipType));
471         }
472
473         // Is the ship type constructable?
474         public function isShipTypeConstructable ($shipType) {
475                 // The type must be a string!
476                 $shipType = (string) $shipType;
477
478                 // Debug message
479                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> fragt alle Werften ab, ob diese Schiffe vom Typ <strong>%s</strong> bauen k&ouml;nnen.<br />\n",
480                         __CLASS__,
481                         __LINE__,
482                         $this->getCompanyName(),
483                         $shipType
484                 ));
485
486                 // First everthing is failed...
487                 $result = false;
488
489                 // Iterate through all shipyards
490                 for ($idx = $this->shipyardList->getIterator(); $idx->valid(); $idx->next()) {
491                         // Get current Shipyard instance
492                         $shipyard = $idx->current();
493
494                         // Is this a shipyard?
495                         if (is_null($shipyard)) {
496                                 // Opps! Empty list?
497                                 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
498                         } elseif (!is_object($shipyard)) {
499                                 // Not an object! ;-(
500                                 throw new NoObjectException($shipyard, self::EXCEPTION_IS_NO_OBJECT);
501                         } elseif (!$shipyard->isClass("Shipyard")) {
502                                 // Class is not a shipyard
503                                 throw new ClassMismatchException(array($shipyard->__toString(), "Shipyard"), self::EXCEPTION_CLASSES_NOT_MATCHING);
504                         }
505
506                         // Validate if the first found shipyard can construct the requested type
507                         $result = $shipyard->isShipTypeConstructable($shipType);
508
509                         // Does this shipyard construct the requested ship type?
510                         if ($result) break; // Then abort the search!
511                 }
512
513                 // Debug message
514                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> hat die Suche nach einer Werft beendet, die Schiffe vom Typ <strong>%s</strong> bauen kann.<br />\n",
515                         __CLASS__,
516                         __LINE__,
517                         $this->getCompanyName(),
518                         $shipType
519                 ));
520
521                 // Return result
522                 return $result;
523         }
524
525         // As a customer the shipping company can add new contracts
526         public function addNewWorksContract (WorksContract $contractInstance) {
527                 if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erstellt einen Bauauftrag f&uuml;r ein <strong>%s</strong> mit dem Namen <strong>%s</strong>.<br />\n",
528                         __CLASS__,
529                         __LINE__,
530                         $this->getCompanyName(),
531                         $contractInstance->getShipInstance()->getPartDescr(),
532                         $contractInstance->getShipInstance()->getShipName()
533                 ));
534                 $this->contractList->append($contractInstance);
535         }
536
537         // As a customer the shippng company can withdraw from a contract
538         public function withdrawFromContract (WorksContract $contractInstance) {
539                 ApplicationEntryPoint::app_die("WITHDRAW:<pre>".print_r($contractInstance, true)."</pre>");
540         }
541
542         // Get latest added contract instance
543         public function getLastContractInstance () {
544                 // Get iterator
545                 $iter = $this->contractList->getIterator();
546
547                 // Get latest entry (total - 1)
548                 $iter->seek($iter->count() - 1);
549
550                 // Return entry
551                 return $iter->current();
552         }
553
554         // Sign a contract with an other party which must also implement Customer
555         public function signContract (WorksContract $contractInstance, ContractPartner $partnerInstance) {
556                 if (!$partnerInstance->isContractPartner($contractInstance)) {
557                         // Invalid contract partner!
558                         throw new InvalidContractPartnerException($partnerInstance, self::EXCEPTION_CONTRACT_PARTNER_INVALID);
559                 }
560                 
561                 // Determine if company "signs" own contract (must be done) or with an other party
562                 if ($this->equals($partnerInstance)) {
563                         // With itself
564                         if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erteilt an sich selbst einen Bauauftrag f&uuml;r das <strong>%s</strong> &quot;<strong>%s</strong>&quot;.<br />\n",
565                                 __CLASS__,
566                                 __LINE__,
567                                 $this->getCompanyName(),
568                                 $contractInstance->getShipInstance()->getPartDescr(),
569                                 $contractInstance->getShipInstance()->getShipName()
570                         ));
571                 } else {
572                         // Other external company
573                         if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> unterzeichnet einen Bauauftrag f&uuml;r das <strong>%s</strong> &quot;<strong>%s</strong>&quot; mit der <strong>%s</strong>.<br />\n",
574                                 __CLASS__,
575                                 __LINE__,
576                                 $this->getCompanyName(),
577                                 $contractInstance->getShipInstance()->getPartDescr(),
578                                 $contractInstance->getShipInstance()->getShipName(),
579                                 $partnerInstance->getCompanyName()
580                         ));
581                 }
582
583                 // Sign the contract
584                 $contractInstance->signContract($this, $partnerInstance);
585
586                 /**
587                  * @todo        Maybe do something more here...
588                  */
589         }
590
591         // Is this the right contract partner?
592         public function isContractPartner (WorksContract $contractInstance) {
593                 // Get contract partner instance and compare it with $this contract partner
594                 return ($this->equals($contractInstance->getContractPartner()));
595         }
596
597         // Setter for merchant instance
598         public function setMerchantInstance (Merchant $merchantInstance) {
599                 // Get contract
600                 $contractInstance = $this->getLastContractInstance();
601
602                 if (is_null($contractInstance)) {
603                         // Opps! Empty contract instance?
604                         throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
605                 } elseif (!is_object($contractInstance)) {
606                         // Not an object! ;-(
607                         throw new NoObjectException($contractInstance, self::EXCEPTION_IS_NO_OBJECT);
608                 } elseif (!$contractInstance->isClass('WorksContract')) {
609                         // Is not a merchant
610                         throw new ClassMismatchException(array($contractInstance->__toString(), "WorksContract"), self::EXCEPTION_CLASSES_NOT_MATCHING);
611                 }
612
613                 // Set the merchant in the contract (for getting prices)
614                 $contractInstance->setMerchantInstance($merchantInstance);
615         }
616
617         /**
618          * Stub!
619          */
620         public function saveObjectToDatabase () {
621                 $this->getDebugInstance()->output(sprintf("[%s:] Stub <strong>%s</strong> erreicht.",
622                         $this->__toString(),
623                         __FUNCTION__
624                 ));
625         }
626
627         /**
628          * Limits this object with an ObjectLimits instance
629          */
630         public function limitObject (ObjectLimits $limitInstance) {
631                 ApplicationEntryPoint::app_die("".__METHOD__." reached! Stub!");
632         }
633 }
634
635 // [EOF]
636 ?>