X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=application%2Fship-simu%2Fmain%2Fclass_WorksContract.php;h=7f61096fc5a532879b97652195be0a38d939b722;hp=d1cf574b85bc5af4df68b03623365c3da0d89a89;hb=abb8bf6be9f5238f8a4552707bcb190f0dbf0b7a;hpb=b44e5e7347f9a1dbd49b5b47d506a4f6526caf2f diff --git a/application/ship-simu/main/class_WorksContract.php b/application/ship-simu/main/class_WorksContract.php index d1cf574..7f61096 100644 --- a/application/ship-simu/main/class_WorksContract.php +++ b/application/ship-simu/main/class_WorksContract.php @@ -4,9 +4,9 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,14 +45,9 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { // Call parent constructor parent::__construct(__CLASS__); - // Set description - $this->setObjectDescription("Bauvertrag"); - - // Unique-ID generieren - $this->generateUniqueId(); - // Clean up a little $this->removeSystemArray(); + $this->removeNumberFormaters(); } // Neuen Bauvertrag generieren @@ -61,30 +56,9 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { $shipType = (string) $shipType; $shipName = (string) $shipName; - // Is the other one a contract partner? - if (is_null($partnerInstance)) { - // Opps! Empty partner instance? - throw new NullPointerException($partnerInstance, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_object($partnerInstance)) { - // Not an object! ;-( - throw new NoObjectException($partnerInstance, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($partnerInstance, 'isContractPartner')) { - // Does not have the required feature (method) - throw new MissingMethodException(array($partnerInstance, 'isContractPartner'), self::EXCEPTION_MISSING_METHOD); - } - // Get new instance $contractInstance = new WorksContract(); - // Debug-Meldung ausgeben - if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $contractInstance->getDebugInstance()->output(sprintf("[%s:%d] Neuer Bauvertrag wird für das Schiff %s mit der %s %s erstellt.
\n", - __CLASS__, - __LINE__, - $shipName, - $partnerInstance->getObjectDescription(), - $partnerInstance->getCompanyName() - )); - // Schiffsnamen setzen $contractInstance->setShipName($shipName); @@ -95,21 +69,11 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { } // Schiff-Instanz temporaer erzeugen und in den Bauvertrag einfuegen - $eval = sprintf("\$contractInstance->setShipInstance(%s::create%s(\"%s\"));", - $shipType, - $shipType, - $shipName - ); + $shipInstance = ObjectFactory::createObjectByName($shipType, array($shipName)); + $contractInstance->setShipInstance($shipInstance); - // Debug message - if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $contractInstance->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung:
%s

\n", - __CLASS__, - __LINE__, - htmlentities($eval) - )); - - // Execute constructed command - @eval($eval); + // Remove the ship instance + unset($shipInstance); // Set itself as contract partner $contractInstance->setContractPartner($partnerInstance); @@ -120,40 +84,21 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { // Setter for ship instance private final function setShipInstance (ConstructableShip $shipInstance) { - if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiff %s wird in den Bauvertrag aufgenommen.
\n", - __CLASS__, - __LINE__, - $shipInstance->getShipName() - )); $this->shipInstance = $shipInstance; } // Setter for ship name private final function setShipName ($shipName) { - if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das neue Schiff wird %s heissen.
\n", - __CLASS__, - __LINE__, - $shipName - )); $this->shipName = (string) $shipName; } // Getter for ship name public final function getShipName () { - if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Schiffsname %s angefordert.
\n", - __CLASS__, - __LINE__, - $this->shipName - )); return $this->shipName; } // Getter for ship instance public final function getShipInstance () { - if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Schiff-Instanz angefordert.
\n", - __CLASS__, - __LINE__ - )); return $this->shipInstance; } @@ -164,7 +109,7 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { $parentPart = (string) $parentPart; // Debug message - if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Das Schiffsteil %s wird zusammen mit dem Konstruktionsteil %s in den Bauvertrag aufgenommen.
\n", + if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Das Schiffsteil %s wird zusammen mit dem Konstruktionsteil %s in den Bauvertrag aufgenommen.", __CLASS__, __LINE__, $shipPart, @@ -172,71 +117,28 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { )); // Initialize the instance (shall not be done within dynamic part) - $instance = null; - - // Prepare the big command for everthing - $eval = "try { - \$instance = ".$shipPart."::create".$shipPart."("; - foreach ($dataArray as $pIdx => $parts) { - if (is_string($parts)) { - // String einbauen - $eval .= "\"".$parts."\", "; - } elseif (is_array($parts)) { - // Ist ein weiteres Array! - $eval .= "array("; - foreach ($parts as $idx2 => $sub) { - $eval .= "'".$idx2."' => "; - if (is_string($sub)) { - // Ist erneut ein String - $eval .= "\"".$sub."\""; - } elseif (is_array($sub)) { - // Wird nicht mehr unterstuetzt! - ApplicationEntryPoint::app_die("No more arrays!"); - } else { - // Direkt anhaengen - $eval .= $sub; - } - $eval .= ", "; - } - - // Letztes Komma entfernen - $eval = substr($eval, 0, -2); - $eval .= "), "; - } else { - // Etwas anderes direkt! - $eval .= $parts.", "; - } - } - - // Letztes Komma abhaengen - $eval = substr($eval, 0, -2); - $eval .= "); -} catch (DimNotFoundInArrayException \$e) { - \$this->getDebugInstance()->output(sprintf(\"[main:] Die %s konnte nicht vervollständigt werden. Grund: %s
\\n\", - \$this->getShipInstance()->getShipName(), - \$e->getMessage() - )); - \$instance = null; -}"; - - // Debug message - if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[Ship:] Konstruierte PHP-Anweisung:
%s

\n", - htmlentities($eval) - )); - - // Code ausfuhren - @eval($eval); + $partInstance = null; - // Try to add the ship part to the contract + // Try to get an instance for this ship part try { - if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Versuche ein Schiffsteil in den Bauvertrag aufzunehmen.
\n", + $partInstance = ObjectFactory::createObjectByName($shipPart, $dataArray); + } catch (DimNotFoundInArrayException $e) { + $this->debugOutput(sprintf("[main:] Die %s konnte nicht vervollständigt werden. Grund: %s
", + $this->getShipInstance()->getShipName(), + $e->getMessage() + )); + + // Debug message + if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Versuche ein Schiffsteil in den Bauvertrag aufzunehmen.", __CLASS__, __LINE__ )); - if (!$instance instanceof ConstructableShipPart) { + + // Is this ship part constructable? + if (!$partInstance instanceof ConstructableShipPart) { // Ship part not constructable! throw new ShipPartNotConstructableException(array($shipPart), self::EXCEPTION_NOT_CONSTRUCTABLE); - } elseif (!$this->getShipInstance()->createShipPart($instance, $parentPart)) { + } elseif (!$this->getShipInstance()->createShipPart($partInstance, $parentPart)) { // Schiff konnte nicht gebaut werden! throw new ShipNotConstructedException(sprintf("Das Schiff %s konnte wegen eines Fehlers nicht gebaut werden. Siehe obere Meldungen.", $this->getShipInstance()->getShipName() @@ -248,25 +150,10 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { } // Get price for this item - $price = $this->getMerchantInstance()->getPriceFromList($instance); - - // Final debug message - if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] %s kostet %s.
\n", - __CLASS__, - __LINE__, - $instance->getObjectDescription(), - $this->getMerchantInstance()->formatCurrency($price) - )); + $price = $this->getMerchantInstance()->getPriceFromList($partInstance); // Add price - $instance->setPrice($price); - - // Final debug message - if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] %s wurde in den Bauvertrag aufgenommen.
\n", - __CLASS__, - __LINE__, - $instance->getObjectDescription() - )); + $partInstance->setPrice($price); } // Setter for contract partner @@ -323,7 +210,7 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) { if ($partnerInstance->equals($partyInstance)) { // With itself - $this->getDebugInstance()->output(sprintf("[%s:%d] Die %s %s stimmt einem Bauvertrag über das %s %s zu.
\n", + $this->debugOutput(sprintf("[%s:%d] Die %s %s stimmt einem Bauvertrag über das %s %s zu.", __CLASS__, __LINE__, $partnerInstance->getObjectDescription(), @@ -333,7 +220,7 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { )); } else { // Other contract party - $this->getDebugInstance()->output(sprintf("[%s:%d] Die %s %s geht mit der %s %s einen Bauvertrag über das %s %s ein.
\n", + $this->debugOutput(sprintf("[%s:%d] Die %s %s geht mit der %s %s einen Bauvertrag über das %s %s ein.", __CLASS__, __LINE__, $partnerInstance->getObjectDescription(), @@ -398,7 +285,7 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { } elseif (!is_object($item)) { // Not an object! ;-( throw new NoObjectException($item, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($item, 'getPartInstance')) { + } elseif (!$item instanceof BaseSimulator) { // Does not have the required feature (method) throw new MissingMethodException(array($item, 'getPartInstance'), self::EXCEPTION_MISSING_METHOD); }