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