00001 <?php
00024 class WorksContract extends BaseFrameworkSystem implements SignableContract {
00025
00026 private $shipName = "";
00027
00028
00029 private $shipInstance = null;
00030
00031
00032 private $contractPartner = null;
00033
00034
00035 private $contractParty = null;
00036
00037
00038 private $signed = false;
00039
00040
00041 private $merchantInstance = null;
00042
00043
00044 protected function __construct () {
00045
00046 parent::__construct(__CLASS__);
00047
00048
00049 $this->removeSystemArray();
00050 $this->removeNumberFormaters();
00051 }
00052
00053
00054 public final static function createWorksContract ($shipType, $shipName, ContractPartner $partnerInstance) {
00055
00056 $shipType = (string) $shipType;
00057 $shipName = (string) $shipName;
00058
00059
00060 $contractInstance = new WorksContract();
00061
00062
00063 $contractInstance->setShipName($shipName);
00064
00065
00066 if (!class_exists($shipType)) {
00067
00068 throw new ClassNotFoundException ($shipType, self::EXCEPTION_CLASS_NOT_FOUND);
00069 }
00070
00071
00072 $shipInstance = ObjectFactory::createObjectByName($shipType, array($shipName));
00073 $contractInstance->setShipInstance($shipInstance);
00074
00075
00076 unset($shipInstance);
00077
00078
00079 $contractInstance->setContractPartner($partnerInstance);
00080
00081
00082 return $contractInstance;
00083 }
00084
00085
00086 private final function setShipInstance (ConstructableShip $shipInstance) {
00087 $this->shipInstance = $shipInstance;
00088 }
00089
00090
00091 private final function setShipName ($shipName) {
00092 $this->shipName = (string) $shipName;
00093 }
00094
00095
00096 public final function getShipName () {
00097 return $this->shipName;
00098 }
00099
00100
00101 public final function getShipInstance () {
00102 return $this->shipInstance;
00103 }
00104
00105
00106 public function addContractDetails ($shipPart, $parentPart, array $dataArray) {
00107
00108 $shipPart = (string) $shipPart;
00109 $parentPart = (string) $parentPart;
00110
00111
00112 if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiffsteil <strong>%s</strong> wird zusammen mit dem Konstruktionsteil <strong>%s</strong> in den Bauvertrag aufgenommen.",
00113 __CLASS__,
00114 __LINE__,
00115 $shipPart,
00116 $parentPart
00117 ));
00118
00119
00120 $partInstance = null;
00121
00122
00123 try {
00124 $partInstance = ObjectFactory::createObjectByName($shipPart, $dataArray);
00125 } catch (DimNotFoundInArrayException $e) {
00126 $this->debugOutput(sprintf("[main:] Die <strong>%s</strong> konnte nicht vervollständigt werden. Grund: <strong>%s</strong><br />",
00127 $this->getShipInstance()->getShipName(),
00128 $e->getMessage()
00129 ));
00130
00131
00132 if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Versuche ein Schiffsteil in den Bauvertrag aufzunehmen.",
00133 __CLASS__,
00134 __LINE__
00135 ));
00136
00137
00138 if (!$partInstance instanceof ConstructableShipPart) {
00139
00140 throw new ShipPartNotConstructableException(array($shipPart), self::EXCEPTION_NOT_CONSTRUCTABLE);
00141 } elseif ($this->getShipInstance()->createShipPart($partInstance, $parentPart) === false) {
00142
00143 throw new ShipNotConstructedException(sprintf("Das Schiff <strong>%s</strong> konnte wegen eines Fehlers nicht gebaut werden. Siehe obere Meldungen.",
00144 $this->getShipInstance()->getShipName()
00145 ));
00146 }
00147 } catch (ClassNotFoundException $e) {
00148
00149 throw new ClassNotFoundException($e->getMessage(), $e->getCode());
00150 }
00151
00152
00153 $price = $this->getMerchantInstance()->getPriceFromList($partInstance);
00154
00155
00156 $partInstance->setPrice($price);
00157 }
00158
00159
00160 public final function setContractPartner (ContractPartner $partnerInstance) {
00161 $this->contractPartner = $partnerInstance;
00162 }
00163
00164
00165 public final function getContractPartner () {
00166 return $this->contractPartner;
00167 }
00168
00169
00170 public final function setContractParty (ContractPartner $partyInstance) {
00171 $this->contractParty = $partyInstance;
00172 }
00173
00174
00175 public final function getContractParty () {
00176 return $this->contractParty;
00177 }
00178
00179
00180 public final function setSigned ($signed) {
00181 $this->signed = (boolean) $signed;
00182 }
00183
00184
00185 public function isSigned () {
00186 return $this->signed;
00187 }
00188
00189
00190 public function signContract (ContractPartner $partnerInstance, ContractPartner $partyInstance) {
00191
00192 if ($this->isSigned()) {
00193
00194 throw new ContractAllreadySignedException(array($this, $this->getContractPartner(), $this->getContractParty()), self::EXCEPTION_CONTRACT_ALREADY_SIGNED);
00195 }
00196
00197
00198 if ($partnerInstance->equals($this->getContractPartner())) {
00199
00200 $this->setContractParty($partyInstance);
00201
00202
00203 $this->setSigned(true);
00204 } else {
00205
00206 throw new ContractPartnerMismatchException(array($this, $this->getContractPartner(), $partyInstance), self::EXCEPTION_CONTRACT_PARTNER_MISMATCH);
00207 }
00208
00209
00210 if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) {
00211 if ($partnerInstance->equals($partyInstance)) {
00212
00213 $this->debugOutput(sprintf("[%s:%d] Die <strong>%s</strong> <em><strong>%s</strong></em> stimmt einem Bauvertrag über das <strong>%s</strong> <em><strong>%s</strong></em> zu.",
00214 __CLASS__,
00215 __LINE__,
00216 $partnerInstance->getObjectDescription(),
00217 $partnerInstance->getCompanyName(),
00218 $this->getShipInstance()->getObjectDescription(),
00219 $this->getShipInstance()->getShipName()
00220 ));
00221 } else {
00222
00223 $this->debugOutput(sprintf("[%s:%d] Die <strong>%s</strong> <em><strong>%s</strong></em> geht mit der <strong>%s</strong> <em><strong>%s</strong></em> einen Bauvertrag über das <strong>%s</strong> <em><strong>%s</strong></em> ein.",
00224 __CLASS__,
00225 __LINE__,
00226 $partnerInstance->getObjectDescription(),
00227 $partnerInstance->getCompanyName(),
00228 $partyInstance->getObjectDescription(),
00229 $partyInstance->getCompanyName(),
00230 $this->getShipInstance()->getObjectDescription(),
00231 $this->getShipInstance()->getShipName()
00232 ));
00233 }
00234 }
00235 }
00236
00237
00238 public final function setMerchantInstance (Merchant $merchantInstance) {
00239 $this->merchantInstance = $merchantInstance;
00240 }
00241
00242
00243 public final function getMerchantInstance () {
00244 return $this->merchantInstance;
00245 }
00246
00247
00248 public final function getTotalPrice () {
00249
00250 $shipInstance = $this->getShipInstance();
00251
00252
00253 if (is_null($shipInstance)) {
00254
00255 throw new NullPointerException($shipInstance, self::EXCEPTION_IS_NULL_POINTER);
00256 } elseif (!is_object($shipInstance)) {
00257
00258 throw new NoObjectException($shipInstance, self::EXCEPTION_IS_NO_OBJECT);
00259 } elseif (!$shipInstance instanceof ConstructableShip) {
00260
00261 throw new ShipIsInvalidException(array($shipInstance), self::EXCEPTION_INVALID_SHIP_INSTANCE);
00262 }
00263
00264
00265 $struct = $shipInstance->getStructuresArray();
00266
00267
00268 if (is_null($struct)) {
00269
00270 throw new EmptyStructuresListException($this, self::EXCEPTION_EMPTY_STRUCTURES_ARRAY);
00271 }
00272
00273
00274 $totalPrice = 0;
00275
00276
00277 for ($iter = $struct->getIterator(); $iter->valid(); $iter->next()) {
00278
00279 $item = $iter->current();
00280
00281
00282 if (is_null($item)) {
00283
00284 throw new NullPointerException($item, self::EXCEPTION_IS_NULL_POINTER);
00285 } elseif (!is_object($item)) {
00286
00287 throw new NoObjectException($item, self::EXCEPTION_IS_NO_OBJECT);
00288 } elseif (!$item instanceof BaseSimulator) {
00289
00290 throw new MissingMethodException(array($item, 'getPartInstance'), self::EXCEPTION_MISSING_METHOD);
00291 }
00292
00293
00294 $part = $item->getPartInstance();
00295
00296
00297 if (is_null($part)) {
00298
00299 throw new NullPointerException($part, self::EXCEPTION_IS_NULL_POINTER);
00300 } elseif (!is_object($part)) {
00301
00302 throw new NoObjectException($part, self::EXCEPTION_IS_NO_OBJECT);
00303 } elseif (!method_exists($part, 'getPrice')) {
00304
00305 throw new MissingMethodException(array($part, 'getPrice'), self::EXCEPTION_MISSING_METHOD);
00306 }
00307
00308
00309 $price = $part->getPrice();
00310
00311
00312 if (method_exists($item, 'getNumCabin')) {
00313
00314 $price = $price * $item->getNumCabin();
00315 }
00316
00317
00318 $totalPrice += $price;
00319 }
00320
00321
00322 if ($totalPrice === 0) {
00323
00324 throw new TotalPriceNotCalculatedException($this, self::EXCEPTION_TOTAL_PRICE_NOT_CALCULATED);
00325 }
00326
00327
00328 return $totalPrice;
00329 }
00330 }
00331
00332
00333 ?>