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