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