]> git.mxchange.org Git - shipsimu.git/commitdiff
Following things are changed: (in order of class names)
authorRoland Häder <roland@mxchange.org>
Fri, 27 Jun 2008 22:58:07 +0000 (22:58 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 27 Jun 2008 22:58:07 +0000 (22:58 +0000)
- Exception "NoShippingCompanyOwnedException" added which will be thrown when
  the current user does not own or participate in any shipping company.
- Factory method for ShippingCompany class rewritten to check above exception
  conditions. The class has some stubs and a lot old methods which needs be
  updated/rewritten/obsoleted.
- Cast removed from older exception and re-added as type-hint
- Wrapper class added for "company" table.
- Minor improvements to some classes
- Block for personal data added (the login area will now have another stub
  message) which is being generated by a generic WebBlockHelper class
- The DataSetCriteria class now returns the primary key (column name) or if
  not set the unique key (column name again).
- All wrappers are now initialized (cache instance) by BaseDatabaseWrapper ...
- ... and must set the table name in factory method.
- The method doSelectByCriteria() is now generic written and resists in class
  BaseDatabaseWrapper
- New helper class "WebLinkHelper" added
- Helper classes rewritten so we have more generic methods (code reduced)
- New helper class "WebBlockHelper" added
- User and Guest class are now extending BaseUser class
- Method doFilterFormatTimestamp() now resists in BaseFrameworkSystem class

31 files changed:
.gitattributes
application/ship-simu/config.php
application/ship-simu/exceptions/class_NoShippingCompanyOwnedException.php [new file with mode: 0644]
application/ship-simu/exceptions/class_ToMuchEmployeesException.php
application/ship-simu/main/companies/class_ShippingCompany.php
application/ship-simu/main/personell/class_SimulatorPersonell.php
application/ship-simu/main/wrapper/.htaccess [new file with mode: 0644]
application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php [new file with mode: 0644]
application/ship-simu/templates/de/code/block_persona_data.ctp [new file with mode: 0644]
application/ship-simu/templates/de/code/login_main.ctp
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/criteria/class_DataSetCriteria.php
inc/classes/main/database/class_BaseDatabaseWrapper.php
inc/classes/main/database/databases/class_LocalFileDatabase.php
inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php
inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php
inc/classes/main/extended/.htaccess [deleted file]
inc/classes/main/extended/class_ObjectLimits.php [deleted file]
inc/classes/main/extended/class_SerializationContainer.php [deleted file]
inc/classes/main/helper/captcha/images/class_ImageHelper.php
inc/classes/main/helper/class_
inc/classes/main/helper/class_BaseHelper.php
inc/classes/main/helper/web/blocks/class_WebBlockHelper.php
inc/classes/main/helper/web/class_ [new file with mode: 0644]
inc/classes/main/helper/web/forms/class_WebFormHelper.php
inc/classes/main/helper/web/links/.htaccess [new file with mode: 0644]
inc/classes/main/helper/web/links/class_WebLinkHelper.php [new file with mode: 0644]
inc/classes/main/user/class_BaseUser.php
inc/classes/middleware/database/class_DatabaseConnection.php
inc/config.php
index.php

index beb522662461f7dc60d28e7f2e1fef89e19eb5e6..9598bc117ed3b0424e796dc35c49686d58894d55 100644 (file)
@@ -32,6 +32,7 @@ application/ship-simu/exceptions/class_ItemNotInPriceListException.php -text
 application/ship-simu/exceptions/class_ItemNotTradeableException.php -text
 application/ship-simu/exceptions/class_MissingSimulatorIdException.php -text
 application/ship-simu/exceptions/class_MotorShipMismatchException.php -text
+application/ship-simu/exceptions/class_NoShippingCompanyOwnedException.php -text
 application/ship-simu/exceptions/class_NoShipyardsConstructedException.php -text
 application/ship-simu/exceptions/class_PersonellListAlreadyCreatedException.php -text
 application/ship-simu/exceptions/class_RoomShipMismatchException.php -text
@@ -130,9 +131,12 @@ application/ship-simu/main/structures/extended/decks/class_BaseDeck.php -text
 application/ship-simu/main/structures/extended/lower/.htaccess -text
 application/ship-simu/main/structures/extended/upper/.htaccess -text
 application/ship-simu/main/structures/extended/upper/class_Bridge.php -text
+application/ship-simu/main/wrapper/.htaccess -text
+application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php -text
 application/ship-simu/starter.php -text
 application/ship-simu/templates/.htaccess -text
 application/ship-simu/templates/de/.htaccess -text
+application/ship-simu/templates/de/code/block_persona_data.ctp -text
 application/ship-simu/templates/de/code/captch_graphic_code.ctp -text
 application/ship-simu/templates/de/code/footer.ctp -text
 application/ship-simu/templates/de/code/header.ctp -text
@@ -434,9 +438,6 @@ inc/classes/main/debug/.htaccess -text
 inc/classes/main/debug/class_DebugConsoleOutput.php -text
 inc/classes/main/debug/class_DebugErrorLogOutput.php -text
 inc/classes/main/debug/class_DebugWebOutput.php -text
-inc/classes/main/extended/.htaccess -text
-inc/classes/main/extended/class_ObjectLimits.php -text
-inc/classes/main/extended/class_SerializationContainer.php -text
 inc/classes/main/factories/.htaccess -text
 inc/classes/main/factories/cache/.htaccess -text
 inc/classes/main/factories/cache/class_CacheFactory.php -text
@@ -498,9 +499,12 @@ inc/classes/main/helper/login/class_BaseLoginHelper.php -text
 inc/classes/main/helper/web/.htaccess -text
 inc/classes/main/helper/web/blocks/.htaccess -text
 inc/classes/main/helper/web/blocks/class_WebBlockHelper.php -text
+inc/classes/main/helper/web/class_ -text
 inc/classes/main/helper/web/class_BaseWebHelper.php -text
 inc/classes/main/helper/web/forms/.htaccess -text
 inc/classes/main/helper/web/forms/class_WebFormHelper.php -text
+inc/classes/main/helper/web/links/.htaccess -text
+inc/classes/main/helper/web/links/class_WebLinkHelper.php -text
 inc/classes/main/images/.htaccess -text
 inc/classes/main/images/class_ -text
 inc/classes/main/images/class_BaseImage.php -text
index dceca29aec6447fb7f0f9c0e5fec61061d51dbb1..1a71aea51e7c6a882b916188f1eb3d8a7c6c51b2 100644 (file)
@@ -211,5 +211,11 @@ $cfg->setConfigEntry('shipsimu_guest_login_captcha_secured', "Y");
 // CFG: BLOCK-SHOWS-REGISTRATION
 $cfg->setConfigEntry('block_shows_registration', "Y");
 
+// CFG: COMPANY-CLASS
+$cfg->setConfigEntry('company_class', "ShippingCompany");
+
+// CFG: COMPANY-DB-WRAPPER-CLASS
+$cfg->setConfigEntry('company_db_wrapper_class', "CompanyDatabaseWrapper");
+
 // [EOF]
 ?>
diff --git a/application/ship-simu/exceptions/class_NoShippingCompanyOwnedException.php b/application/ship-simu/exceptions/class_NoShippingCompanyOwnedException.php
new file mode 100644 (file)
index 0000000..8611b6e
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * An exception thrown when a user owns no shipping companies
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @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
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class NoShippingCompanyOwnedException extends FrameworkException {
+       /**
+        * Constructor of this exception
+        *
+        * @param       $msgArray       Message array with exception data
+        * @param       $code           Exception code
+        * @return      void
+        */
+       public function __construct (array $msgArray, $code) {
+               // Add a message around the missing class
+               $message = sprintf("[%s:%d] Current user (class <u>%s</u>) does not own any shipping companies.",
+                       $msgArray[0]->__toString(),
+                       $this->getLine(),
+                       $msgArray[1]->__toString()
+               );
+
+               // Call parent constructor
+               parent::__construct($message, $code);
+       }
+}
+
+// [EOF]
+?>
index 69e76c836b59d4c23260fb58a300c05d42f133ad..ca07ecf051bac7378ae4a14128517ebef9cecfa2 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class ToMuchEmployeesException extends FrameworkException {
-       public function __construct ($amountArray, $code) {
-               // Cast the array
-               $amountArray = (array) $amountArray;
-
+       public function __construct (array $amountArray, $code) {
                // Add a message around the missing class
                $message = sprintf("<u>%d</u> Leute nicht einstellbar, da nur <u>%d</u> arbeitslos sind!",
                        $amountArray[0],
index 381aa4ce8f665e37cbf4457d291d277da0b7b12e..d3ab6985dec4c5d08e602f645dcaa330de337044 100644 (file)
@@ -63,7 +63,15 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        private $contractList    = null;
 
        /**
-        * Main constructor
+        * Database result instance
+        */
+       private $resultInstance = null;
+
+       // Exception constants
+       const EXCEPTION_USER_OWNS_NO_COMPANY = 0x200;
+
+       /**
+        * Protected constructor
         *
         * @return      void
         */
@@ -72,7 +80,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                parent::__construct(__CLASS__);
 
                // Set description
-               $this->setObjectDescription("Reederei");
+               $this->setObjectDescription("A shipping company class");
 
                // Generate unique ID number
                $this->generateUniqueId();
@@ -81,76 +89,79 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                $this->removeSystemArray();
        }
 
-       // Reederei gruenden (create wegen Namenskonvention)
-       public final static function createShippingCompany ($companyName, Harbor $hqInstance) {
+       /**
+        * Creates an instance of this company class or throws an exception if the
+        * given user owns no company.
+        *
+        * @param       $userInstance           A user class
+        * @return      $companyInstance        Prepared company instance
+        * @throws      NoShippingCompanyOwnedException         If the user owns no shipping companies
+        */
+       public final static function createShippingCompany (BaseUser $userInstance) {
                // Get new instance
                $companyInstance = new ShippingCompany();
 
-               if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $companyInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> wird gegr&uuml;ndet.",
-                       __CLASS__,
-                       __LINE__,
-                       $companyName
-               ));
+               // Does the given user owns a company?
+               if (!$companyInstance->ifUserOwnsShippingCompany($userInstance)) {
+                       // Throw an exception here
+                       throw new NoShippingCompanyOwnedException(array($companyInstance, $userInstance), self::EXCEPTION_USER_OWNS_NO_COMPANY);
+               } // END - if
 
-               // Firmennamen setzen
-               $companyInstance->setCompanyName($companyName);
+               // Set the user instance. We don't care here if he is founder or employee.
+               $companyInstance->setUserInstance($userInstance);
 
-               // Kuerzel setzen
-               $companyInstance->createShortName();
+               // Init all lists
+               $companyInstance->initCompanyLists();
 
-               // Sitz festlegen
-               $companyInstance->setHQInstance($hqInstance);
+               // Return instance
+               return $companyInstance;
+       }
 
-               // Werftenliste erstellen
-               $companyInstance->createshipyardList();
+       /**
+        * Checks wether the given user owns a company or not
+        *
+        * @param       $userInstance   An instance of a user class
+        * @return      $ownsCompany    Wether the user owns at least one company
+        */
+       protected function ifUserOwnsShippingCompany (BaseUser $userInstance)  {
+               // By default no user owns any company... ;)
+               $ownsCompany = false;
 
-               // Angestellten-Liste erstellen
-               $companyInstance->createEmployeeList();
+               // Get a company database wrapper class
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class');
 
-               // Auftragsliste erstellen
-               $companyInstance->createContractList();
+               // Get a search criteria class
+               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
-               // Clean up a little
-               $companyInstance->removeWidth();
-               $companyInstance->removeHeight();
-               $companyInstance->removeLength();
-               $companyInstance->removeDraught();
-               $companyInstance->removePartInstance();
+               // Add the user primary key as a search criteria
+               $criteriaInstance->addCriteria('company_owner', $userInstance->getPrimaryKey());
+               $criteriaInstance->setLimit(1);
 
-               // Instanz zurueckgeben
-               return $companyInstance;
+               // Get the result back
+               $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+               $resultInstance->debugInstance();
        }
 
-       // Angestellten-Liste erstellen
-       private function createEmployeeList () {
-               if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erh&auml;lt eine Angestelltenliste.",
-                       __CLASS__,
-                       __LINE__,
-                       $this->getCompanyName()
-               ));
+       /**
+        * Intialize all lists
+        *
+        * @return      void
+        */
+       protected function initCompanyLists () {
+               // Employees
                $this->employeeList = new FrameworkArrayObject("FakedEmployeeList");
-       }
 
-       // Werftenliste erstellen
-       public function createShipyardList () {
-               if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erh&auml;lt eine Werftsliste.",
-                       __CLASS__,
-                       __LINE__,
-                       $this->getCompanyName()
-               ));
+               // Ship yards
                $this->shipyardList = new FrameworkArrayObject("FakedShipyardList");
-       }
 
-       // Auftragsliste erstellen
-       public function createContractList () {
-               if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erh&auml;lt eine Auftragsliste.",
-                       __CLASS__,
-                       __LINE__,
-                       $this->getCompanyName()
-               ));
+               // Contracts
                $this->contractList = new FrameworkArrayObject("FakedContractList");
        }
 
+       //----------------------------------------------------------------------------
+       // From here is very old code which needs to be translated and changed heavily
+       //----------------------------------------------------------------------------
+
        // Setter-Methode fuer Firmennamen
        public final function setCompanyName ($companyName) {
                $this->companyName = (string) $companyName;
@@ -167,12 +178,12 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        // Kuerzel setzen
-       private function createShortName () {
+       private function initShortName () {
                // Mindestens eine Leerstelle?
                $dummy = explode(" ", $this->getCompanyName());
                foreach ($dummy as $part) {
                        $this->shortName .= substr($part, 0, 1);
-               }
+               } // END - if
        }
 
        // Reedereien Werften bauen lassen
index 05559cc836e3643ca6c0a153fc35088502b6ba2a..86b1ba0d42ee944af5607f0351d64c0acad01c94 100644 (file)
@@ -371,9 +371,6 @@ class SimulatorPersonell extends BasePersonell {
         * @throws      ContainerMaybeDamagedException  If the container item
         *                                                                                      is missing the indexes
         *                                                                                      'name' and/or 'value'
-        * @see         SerializationContainer  A special container class which
-        *                                                                      helps storing only some attributes
-        *                                                                      of a class.
         */
        public function loadPersonellList ($idNumber) {
                // Cleared because old code
diff --git a/application/ship-simu/main/wrapper/.htaccess b/application/ship-simu/main/wrapper/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php b/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php
new file mode 100644 (file)
index 0000000..d403d18
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * A wrapper for database access to shipping company data
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @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
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class CompanyDatabaseWrapper extends BaseDatabaseWrapper {
+       // Constants for database tables
+       const DB_TABLE_COMPANY = "company";
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("A wrapper for database access to company data");
+
+               // Create unique ID number
+               $this->generateUniqueId();
+       }
+
+       /**
+        * Creates an instance of this wrapper class
+        *
+        * @return      $wrapperInstance        An instance of this wrapper class
+        */
+       public final static function createCompanyDatabaseWrapper () {
+               // Create a new instance
+               $wrapperInstance = new CompanyDatabaseWrapper();
+
+               // Set (primary!) table name
+               $wrapperInstance->setTableName(self::DB_TABLE_COMPANY);
+
+               // Return the instance
+               return $wrapperInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/ship-simu/templates/de/code/block_persona_data.ctp b/application/ship-simu/templates/de/code/block_persona_data.ctp
new file mode 100644 (file)
index 0000000..02a84d9
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+// Get a helper instance for the profile link (and maybe later more!)
+$helperInstance = WebLinkHelper::createWebLinkHelper($this, 'profile_link');
+
+// Prefetch user instance
+$helperInstance->prefetchValueInstance('user');
+
+// Flush the content out
+$helperInstance->flushContent();
+
+// End of PHP commands
+?>
+<div class="gamer_name_div">
+       Spielername: <span class="gamer_name">{?block_username?}</span>
+</div>
+<div class="gamer_profile_div">
+       {?profile_link?}
+</div>
+<div class="gamer_registered_div">
+       Angemeldet seit: <span class="registered">{?block_registered?}</span>
+</div>
index b059c7f778ebb8b1d3286ebfff13843b58b2e6fa..3326c51f4405e4c7f7c2bcca1cd686d4b1ed8eeb 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+///////////////////////////////
+// Assign personal user data //
+///////////////////////////////
+
 // Get a new instance for personal data
 $blockInstance = WebBlockHelper::createWebBlockHelper($this, 'persona_data');
 
@@ -17,6 +21,22 @@ if ($blockInstance->ifIncludeRegistrationStamp()) {
 // Flush the content out to a template variable
 $blockInstance->flushContent();
 
+//////////////////////////////////////
+// Assign the shipping company data //
+//////////////////////////////////////
+
+// Get a new instance for personal data
+$blockInstance = WebBlockHelper::createWebBlockHelper($this, 'company_data');
+
+// Get the user instance 
+$userInstance = Registry::getRegistry()->getInstance('user');
+
+// Get a shipping company instance ready
+$companyInstance = ObjectFactory::createObjectByConfiguredName('company_class', array($userInstance));
+
+// Flush the content out to a template variable
+//$blockInstance->flushContent();
+
 // End of all PHP commands
 ?>
 <div id="content_header">
index 7d9467ad68457fec86e222066c58ce7a5b760235..de854be0232e2d440c09d9784daf581896c765ec 100644 (file)
@@ -1109,6 +1109,30 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Return the code
                return $markedCode;
        }
+
+       /**
+        * Filter a given timestamp to make it look more beatifull for web-based
+        * front-ends. If null is given a message id null_timestamp will be
+        * resolved and returned.
+        *
+        * @param       $timestamp      Timestamp to prepare (filter) for display
+        * @return      $readable       A readable timestamp
+        */
+       public function doFilterFormatTimestamp ($timestamp) {
+               // Default value to return
+               $readable = "???";
+
+               // Is the timestamp null?
+               if (is_null($timestamp)) {
+                       // Get a message string
+                       $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
+               } else {
+                       $this->partialStub("Do further analysis on timestamp {$timestamp}.");
+               }
+
+               // Return the stamp
+               return $readable;
+       }
 }
 
 // [EOF]
index 7e43565fd0d9a1cdbce270442d027b22f8621fe2..61bdb32596e628db6a0b8aac6b1f237ff1329558 100644 (file)
@@ -38,6 +38,11 @@ class DataSetCriteria extends BaseFrameworkSystem implements StoreableCriteria {
         */
        private $uniqueKey = "";
 
+       /**
+        * Primary key
+        */
+       private $primaryKey = "";
+
        /**
         * Protected constructor
         *
@@ -61,12 +66,16 @@ class DataSetCriteria extends BaseFrameworkSystem implements StoreableCriteria {
        /**
         * Creates an instance of this criteria
         *
-        * @return $criteriaInstance    An instance of this criteria
+        * @param       $tableName                      Name of the table
+        * @return      $criteriaInstance       An instance of this criteria
         */
-       public final static function createDataSetCriteria () {
+       public final static function createDataSetCriteria ($tableName) {
                // Get a new instance
                $criteriaInstance = new DataSetCriteria();
 
+               // Set table name
+               $criteriaInstance->setTableName($tableName);
+
                // Return the instance
                return $criteriaInstance;
        }
@@ -150,6 +159,34 @@ class DataSetCriteria extends BaseFrameworkSystem implements StoreableCriteria {
        public final function getCriteriaArray () {
                return $this->tableColumns;
        }
+
+       /**
+        * Getter for primary key or unique key if not set
+        *
+        * @return      $primaryKey             Primary key or unique key if not set
+        */
+       public final function getPrimaryKey () {
+               // Get primary key by default
+               $primaryKey = $this->primaryKey;
+
+               if (empty($primaryKey)) {
+                       // Get uniqueKey
+                       $primaryKey = $this->getUniqueKey();
+               } // END - if
+
+               // Return it
+               return $primaryKey;
+       }
+
+       /**
+        * Setter for primary key
+        *
+        * @param       $primaryKey             Primary key to set
+        * @return      void
+        */
+       public final function setPrimaryKey ($primaryKey) {
+               $this->primaryKey = (string) $primaryKey;
+       }
 }
 
 // [EOF]
index 5c17fb7c9a0b407d1834f5d0109648bf3ef2f293..7a4ee57fb57328259956521f7d56f01d14028c21 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseDatabaseWrapper extends BaseFrameworkSystem {
+       /**
+        * Cache instance
+        */
+       private $cacheInstance = null;
+
+       /**
+        * Current table name to use
+        */
+       private $tableName = "unknown";
+
        /**
         * Protected constructor
         *
@@ -31,10 +41,97 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
                // Call parent constructor
                parent::__construct($class);
 
+               // Initialize the cache instance
+               $this->initCacheInstance();
+
                // Clean up a little
                $this->removeNumberFormaters();
                $this->removeSystemArray();
        }
+
+       /**
+        * Initializes the cache instance with a new object
+        *
+        * @return      void
+        */
+       private final function initCacheInstance () {
+               // Set the new instance
+               $this->cacheInstance = CacheFactory::getFactory()->createConfiguredCache();
+       }
+
+       /**
+        * Do a "select" query on the current table with the given search criteria and
+        * store it in cache for later usage
+        *
+        * @param       $criteriaInstance       An instance of a Criteria class
+        * @return      $resultInstance         An instance of a database result class
+        */
+       public function doSelectByCriteria (Criteria $criteriaInstance) {
+               // First get a key suitable for our cache and extend it with this class name
+               $cacheKey = sprintf("%s@%s",
+                       $this->__toString(),
+                       $criteriaInstance->getCacheKey()
+               );
+
+               // Does this key exists in cache?
+               if ($this->cacheInstance->offsetExists($cacheKey)) {
+                       // Then use this result
+                       $result = $cacheInstance->offsetGet($cacheKey);
+               } else {
+                       // Now it's time to ask the database layer for this select statement
+                       $result = $this->getDatabaseInstance()->doSelectByTableCriteria($this->getTableName(), $criteriaInstance);
+
+                       // Cache the result if not null
+                       if (!is_null($result)) {
+                               // A valid result has returned from the database layer
+                               $this->cacheInstance->offsetSet($cacheKey, $result);
+                       } else {
+                               // This invalid result must be wrapped
+                               $result = array(
+                                       'status'                => "invalid",
+                                       'exception'             => $this->getDatabaseInstance()->getLastException()
+                               );
+                       }
+               }
+
+               // Create an instance of a DatabaseResult class with the given result
+               $resultInstance = DatabaseResult::createDatabaseResult($result);
+
+               // And return the instance
+               return $resultInstance;
+       }
+
+       /**
+        * Setter for table name
+        *
+        * @param       $tableName      Name of table name to set
+        * @return      void
+        */
+       protected final function setTableName ($tableName) {
+               $this->tableName = (string) $tableName;
+       }
+
+       /**
+        * Getter for table name
+        *
+        * @return      $tableName      Name of table name to set
+        */
+       protected final function getTableName () {
+               return $this->tableName;
+       }
+
+       /**
+        * Getter for primary key used in wrapped table
+        *
+        * @return      $primaryKey             Primary key used in wrapped table
+        */
+       public final function getPrimaryKeyValue () {
+               // Get the table name and a database instance and ask for it
+               $primaryKey = $this->getDatabaseInstance()->getPrimaryKeyOfTable($this->getTableName());
+
+               // Return value
+               return $primaryKey;
+       }
 }
 
 // [EOF]
index ef5c2ba0c4a4df118bec2e1e780db4ae49b99124..60fb4d32011cb16527f8f225dbb822a57f62d0ac 100644 (file)
@@ -65,6 +65,11 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
         */
        private $lastException = null;
 
+       /**
+        * Table information array
+        */
+       private $tableInfo = array();
+
        /**
         * The protected constructor. Do never instance from outside! You need to
         * set a local file path. The class will then validate it.
@@ -163,6 +168,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
         * @throws      NoArrayCreatedException         If explode() fails to create an array
         * @throws      InvalidArrayCountException      If the array contains less or
         *                                                                      more than two elements
+        * @deprecated
         */
        public function isUniqueIdUsed ($uniqueID, $inConstructor = false) {
                // Currently not used... ;-)
@@ -210,7 +216,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
 
                // Initialize the search loop
                $isValid = false;
-               while ($dataFile = $dirInstance->readDirectoryExcept(array(".", "..", ".htaccess", ".svn"))) {
+               while ($dataFile = $dirInstance->readDirectoryExcept(array(".", "..", ".htaccess", ".svn", "info." . $this->getFileExtension()))) {
                        // Generate FQFN for testing
                        $fqfn = sprintf("%s/%s", $pathName, $dataFile);
                        $this->setLastFile($fqfn);
@@ -349,6 +355,74 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                $fileInstance->closeFile();
        }
 
+       /**
+        * Getter for table information file contents or an empty if the info file was not created
+        *
+        * @param       $dataSetInstance        An instance of a database set class
+        * @return      $infoArray                      An array with all table informations
+        */
+       private function getContentsFromTableInfoFile (StoreableCriteria $dataSetInstance) {
+               // Default content is no data
+               $infoArray = array();
+
+               // Create FQFN for getting the table information file
+               $fqfn = $this->getSavePath() . $dataSetInstance->getTableName() . '/info.' . $this->getFileExtension();
+
+               // Get the file contents
+               try {
+                       $infoArray = $this->getDataArrayFromFile($fqfn);
+               } catch (FileNotFoundException $e) {
+                       // Not found, so ignore it here
+               }
+
+               // ... and return it
+               return $infoArray;
+       }
+
+       /**
+        * Creates the table info file from given dataset instance
+        *
+        * @param       $dataSetInstance        An instance of a database set class
+        * @return      void
+        */
+       private function createTableInfoFile (StoreableCriteria $dataSetInstance) {
+               // Create FQFN for creating the table information file
+               $fqfn = $this->getSavePath() . $dataSetInstance->getTableName() . '/info.' . $this->getFileExtension();
+
+               // Get the data out from dataset in a local array
+               $this->tableInfo[$dataSetInstance->getTableName()] = array(
+                       'primary'      => $dataSetInstance->getPrimaryKey(),
+                       'created'      => time(),
+                       'last_updated' => time()
+               );
+
+               // Write the data to the file
+               $this->writeDataArrayToFqfn($fqfn, $this->tableInfo[$dataSetInstance->getTableName()]);
+       }
+
+       /**
+        * Updates the primary key information or creates the table info file if not found
+        *
+        * @param       $dataSetInstance        An instance of a database set class
+        * @return      void
+        */
+       private function updatePrimaryKey (StoreableCriteria $dataSetInstance) {
+               // Get the information array from lower method
+               $infoArray = $this->getContentsFromTableInfoFile($dataSetInstance);
+
+               // Is the primary key there?
+               if (!isset($this->tableInfo['primary'])) {
+                       // Then create the info file
+                       $this->createTableInfoFile($dataSetInstance);
+               } elseif (($this->getConfigInstance()->readConfig('db_update_primary_forced') === "Y") && ($dataSetInstance->getPrimaryKey() != $this->tableInfo['primary'])) {
+                       // Set the array element
+                       $this->tableInfo[$dataSetInstance->getTableName()]['primary'] = $dataSetInstance->getPrimaryKey();
+
+                       // Update the entry
+                       $this->updateTableInfoFile($dataSetInstance);
+               }
+       }
+
        /**
         * Makes sure that the database connection is alive
         *
@@ -389,10 +463,17 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        );
 
                        // Initialize limit/skip
-                       $limitFound = 0; $skipFound = 0;
+                       $limitFound = 0;
+                       $skipFound = 0;
 
                        // Read the directory with some exceptions
-                       while (($dataFile = $directoryInstance->readDirectoryExcept(array(".", "..", ".htaccess", ".svn"))) && ($limitFound < $criteriaInstance->getLimit())) {
+                       while (($dataFile = $directoryInstance->readDirectoryExcept(array(".", "..", ".htaccess", ".svn", "info." . $this->getFileExtension()))) && ($limitFound < $criteriaInstance->getLimit())) {
+                               // Does the extension match?
+                               if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) {
+                                       // Skip this file!
+                                       continue;
+                               }
+
                                // Read the file
                                $dataArray = $this->getDataArrayFromFile($pathName . $dataFile);
 
@@ -424,7 +505,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                                        } // END - foreach
                                } else {
                                        // Throw an exception here
-                                       throw new SqlException(sprintf("File &#39;%s&#39; contains invalid data.", $dataFile), self::DB_CODE_DATA_FILE_CORRUPT);
+                                       throw new SqlException(array($this, sprintf("File &#39;%s&#39; contains invalid data.", $dataFile), self::DB_CODE_DATA_FILE_CORRUPT), self::EXCEPTION_SQL_QUERY);
                                }
                        } // END - while
 
@@ -472,6 +553,9 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        // Write the data away
                        $this->writeDataArrayToFqfn($fqfn, $dataSetInstance->getCriteriaArray());
 
+                       // Update the primary key
+                       $this->updatePrimaryKey($dataSetInstance);
+
                        // Reset last error message and exception
                        $this->resetLastError();
                } catch (FrameworkException $e) {
@@ -501,7 +585,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        $directoryInstance = FrameworkDirectoryPointer::createFrameworkDirectoryPointer($pathName);
 
                        // Initialize limit/skip
-                       $limitFound = 0; $skipFound = 0;
+                       $limitFound = 0;
+                       $skipFound = 0;
 
                        // Get the criteria array from the dataset
                        $criteriaArray = $dataSetInstance->getCriteriaArray();
@@ -510,7 +595,13 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        $searchInstance = $dataSetInstance->getSearchInstance();
 
                        // Read the directory with some exceptions
-                       while (($dataFile = $directoryInstance->readDirectoryExcept(array(".", "..", ".htaccess", ".svn"))) && ($limitFound < $searchInstance->getLimit())) {
+                       while (($dataFile = $directoryInstance->readDirectoryExcept(array(".", "..", ".htaccess", ".svn", "info." . $this->getFileExtension()))) && ($limitFound < $searchInstance->getLimit())) {
+                               // Does the extension match?
+                               if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) {
+                                       // Skip this file!
+                                       continue;
+                               }
+
                                // Open this file for reading
                                $dataArray = $this->getDataArrayFromFile($pathName . $dataFile);
 
@@ -553,6 +644,9 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        // Close the file pointer
                        $directoryInstance->closeDirectory();
 
+                       // Update the primary key
+                       $this->updatePrimaryKey($dataSetInstance);
+
                        // Reset last error message and exception
                        $this->resetLastError();
                } catch (FrameworkException $e) {
@@ -561,9 +655,30 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        $this->lastError = $e->getMessage();
 
                        // Throw an SQL exception
-                       throw new SqlException (array($this, sprintf("Cannot write data to table &#39;%s&#39;", $tableName), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY);
+                       throw new SqlException (array($this, sprintf("Cannot write data to table &#39;%s&#39;", $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY);
                }
        }
+
+       /**
+        * Getter for primary key of specified table or if not found null will be
+        * returned. This must be database-specific.
+        *
+        * @param       $tableName              Name of the table we need the primary key from
+        * @return      $primaryKey             Primary key column of the given table
+        */
+       public function getPrimaryKeyOfTable ($tableName) {
+               // Default key is null
+               $primaryKey = null;
+
+               // Does the table information exist?
+               if (isset($this->tableInfo[$tableName])) {
+                       // Then return the primary key
+                       $primaryKey = $this->tableInfo[$tableName]['primary'];
+               } // END - if
+
+               // Return the column
+               return $primaryKey;
+       }
 }
 
 // [EOF]
index 09574b1857ab380d28f225086e940ad837aa9cac..73b7a21938105fe5a1c389a15eda197123603e09 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class NewsDatabaseWrapper extends BaseDatabaseWrapper {
-       /**
-        * Cache instance
-        */
-       private $cacheInstance = null;
-
-       // Constants for exceptions
-       const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x160;
-
-       // Constants for database columns
-
        // Constants for database table names
        const DB_TABLE_NEWS = "news";
 
@@ -60,64 +50,12 @@ class NewsDatabaseWrapper extends BaseDatabaseWrapper {
                // Get a new instance
                $wrapperInstance = new NewsDatabaseWrapper();
 
-               // Initialize the cache instance
-               $wrapperInstance->initCacheInstance();
+               // Set (primary!) table name
+               $wrapperInstance->setTableName(self::DB_TABLE_NEWS);
 
                // Return the instance
                return $wrapperInstance;
        }
-
-       /**
-        * Initializes the cache instance with a new object
-        *
-        * @return      void
-        */
-       protected function initCacheInstance () {
-               // Set the new instance
-               $this->cacheInstance = CacheFactory::getFactory()->createConfiguredCache();
-       }
-
-       /**
-        * Do a "select" query on the user table with the given search criteria and
-        * store it in cache for later usage
-        *
-        * @param       $criteriaInstance       An instance of a Criteria class
-        * @return      $resultInstance         An instance of a database result class
-        */
-       public function doSelectByCriteria (Criteria $criteriaInstance) {
-               // First get a key suitable for our cache and extend it with this class name
-               $cacheKey = sprintf("%s@%s",
-                       $this->__toString(),
-                       $criteriaInstance->getCacheKey()
-               );
-
-               // Does this key exists in cache?
-               if ($this->cacheInstance->offsetExists($cacheKey)) {
-                       // Then use this result
-                       $result = $cacheInstance->offsetGet($cacheKey);
-               } else {
-                       // Now it's time to ask the database layer for this select statement
-                       $result = $this->getDatabaseInstance()->doSelectByTableCriteria(self::DB_TABLE_NEWS, $criteriaInstance);
-
-                       // Cache the result if not null
-                       if (!is_null($result)) {
-                               // A valid result has returned from the database layer
-                               $this->cacheInstance->offsetSet($cacheKey, $result);
-                       } else {
-                               // This invalid result must be wrapped
-                               $result = array(
-                                       'status'                => "invalid",
-                                       'exception'             => $this->getDatabaseInstance()->getLastException()
-                               );
-                       }
-               }
-
-               // Create an instance of a DatabaseResult class with the given result
-               $resultInstance = DatabaseResult::createDatabaseResult($result);
-
-               // And return the instance
-               return $resultInstance;
-       }
 }
 
 // [EOF]
index a9c4f2f69cf19e350a65b7c2211f0b729de4b856..9b480db18b4de7e456f70f253cbe2fed5827d0f0 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class UserDatabaseWrapper extends BaseDatabaseWrapper {
-       /**
-        * Cache instance
-        */
-       private $cacheInstance = null;
-
        // Constants for exceptions
        const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x180;
 
@@ -64,65 +59,13 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
                // Get a new instance
                $wrapperInstance = new UserDatabaseWrapper();
 
-               // Initialize the cache instance
-               $wrapperInstance->initCacheInstance();
+               // Set (primary!) table name
+               $wrapperInstance->setTableName(self::DB_TABLE_USER);
 
                // Return the instance
                return $wrapperInstance;
        }
 
-       /**
-        * Initializes the cache instance with a new object
-        *
-        * @return      void
-        */
-       protected function initCacheInstance () {
-               // Set the new instance
-               $this->cacheInstance = CacheFactory::getFactory()->createConfiguredCache();
-       }
-
-       /**
-        * Do a "select" query on the user table with the given search criteria and
-        * store it in cache for later usage
-        *
-        * @param       $criteriaInstance       An instance of a Criteria class
-        * @return      $resultInstance         An instance of a database result class
-        */
-       public function doSelectByCriteria (Criteria $criteriaInstance) {
-               // First get a key suitable for our cache and extend it with this class name
-               $cacheKey = sprintf("%s@%s",
-                       $this->__toString(),
-                       $criteriaInstance->getCacheKey()
-               );
-
-               // Does this key exists in cache?
-               if ($this->cacheInstance->offsetExists($cacheKey)) {
-                       // Then use this result
-                       $result = $cacheInstance->offsetGet($cacheKey);
-               } else {
-                       // Now it's time to ask the database layer for this select statement
-                       $result = $this->getDatabaseInstance()->doSelectByTableCriteria(self::DB_TABLE_USER, $criteriaInstance);
-
-                       // Cache the result if not null
-                       if (!is_null($result)) {
-                               // A valid result has returned from the database layer
-                               $this->cacheInstance->offsetSet($cacheKey, $result);
-                       } else {
-                               // This invalid result must be wrapped
-                               $result = array(
-                                       'status'                => "invalid",
-                                       'exception'             => $this->getDatabaseInstance()->getLastException()
-                               );
-                       }
-               }
-
-               // Create an instance of a DatabaseResult class with the given result
-               $resultInstance = DatabaseResult::createDatabaseResult($result);
-
-               // And return the instance
-               return $resultInstance;
-       }
-
        /**
         * Handles inserting the registration data from a registration instance into the database
         *
@@ -131,8 +74,10 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
         */
        public function insertRegistrationObject (UserRegister $registrationInstance) {
                // Generate a data set for the request
-               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class');
-               $dataSetInstance->setTableName(self::DB_TABLE_USER);
+               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER));
+
+               // Set the primary key
+               $dataSetInstance->setUniqueKey('username');
 
                // Add registration elements to the dataset
                $registrationInstance->addElementsToDataSet($dataSetInstance);
@@ -149,8 +94,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
         */
        public function doUpdateByResult (UpdateableResult $resultInstance) {
                // Generate a data set object
-               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class');
-               $dataSetInstance->setTableName(self::DB_TABLE_USER);
+               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER));
 
                // Add all update criteria to the database set
                $resultInstance->addElementsToDataSet($dataSetInstance);
@@ -158,7 +102,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
                // Add seach criteria
                $dataSetInstance->setSearchInstance($resultInstance->getSearchInstance());
 
-               // Add the primary key
+               // Set the primary key
                $dataSetInstance->setUniqueKey('username');
 
                // "Update" this request with the database
diff --git a/inc/classes/main/extended/.htaccess b/inc/classes/main/extended/.htaccess
deleted file mode 100644 (file)
index 3a42882..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Deny from all
diff --git a/inc/classes/main/extended/class_ObjectLimits.php b/inc/classes/main/extended/class_ObjectLimits.php
deleted file mode 100644 (file)
index fbfda6c..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-/**
- * This object limits other objects. This is mostly being used to prepare
- * objects to the datatabase connection or else a lot heap would be saved.
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @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
- * @deprecated
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class ObjectLimits extends BaseFrameworkSystem {
-       /**
-        * Limitation array for storing all attribute names we will use later
-        * only.
-        */
-       private $limitArray = null;
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-
-               // Set part description
-               $this->setObjectDescription("Class for &quot;limiting&quot; other classes. See description for details.");
-
-               // Create unique ID number
-               $this->generateUniqueId();
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-       }
-
-       /**
-        * Create a new ObjectLimits object and (maybe prepare it a little)
-        *
-        * @param               $limitationArray        The limitation array we "walk" through
-        * @return      $limitInstance          The instance to an ObjectLimits object
-        */
-       public final static function createObjectLimits (array $limitationArray) {
-               // Is there a limitation array given?
-               if (count($limitationArray) > 0) {
-                       // Get instance
-                       $limitInstance = new ObjectLimits();
-
-                       // Get all limitations and do them
-                       foreach ($limitationArray as $limit) {
-                               // What shall we limitate?
-                               if ($limit instanceof FrameworkInterface) {
-                                       // Add an object
-                                       $limitInstance->addObject($limit);
-                               } elseif (is_string($limit)) {
-                                       // Add a string
-                                       $limitInstance->addString($limit);
-                               } else {
-                                       // Others are not supported (yet)
-                                       throw new UnsupportedLimitationPartException($limit, self::EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED);
-                               }
-                       }
-
-                       // Return instance
-                       return $limitInstance;
-               } else {
-                       // No limitation given so we send "null" back
-                       return null;
-               }
-       }
-
-       /**
-        * Add an object's name to the limitation list
-        *
-        * @param               $object The object's name we shall add to the list
-        * @return      void
-        */
-       private final function addObject (FrameworkInterface $object) {
-               // Auto-initialization
-               if (is_null($this->limitArray)) {
-                       // Initialize this array
-                       $this->limitArray = new FrameworkArrayObject('FakedLimitArray');
-               }
-
-               // Add the object's name to it
-               $this->limitArray->append($object->__toString());
-       }
-
-       /**
-        * Add a string directly to the limitation list
-        *
-        * @param               $str            The string we want to add directly
-        * @return      void
-        */
-       private final function addString ($str) {
-               // Auto-initialization
-               if (is_null($this->limitArray)) {
-                       // Initialize this array
-                       $this->limitArray = new FrameworkArrayObject("FakedLimitArray");
-               }
-
-               // Add the direct string to ArrayObject
-               $this->limitArray->append($str);
-       }
-
-       /**
-        * Getter for limitArray
-        *
-        * @return      $limitArray     The object ArrayObject which holds limitations
-        */
-       public final function getLimitArray () {
-               return $this->limitArray;
-       }
-}
-
-// [EOF]
-?>
diff --git a/inc/classes/main/extended/class_SerializationContainer.php b/inc/classes/main/extended/class_SerializationContainer.php
deleted file mode 100644 (file)
index 9843912..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-/**
- * This class contains object attributes which we can now send together to
- * other classes
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @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
- * @deprecated
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class SerializationContainer extends FrameworkArrayObject {
-       /**
-        * Protected constructor, must stay as public... *sigh*
-        *
-        * @return      void
-        */
-       public function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Create a SerializationContainer object by applying the limitations
-        * in $limitInstance on $object. The resulting data container will only
-        * hold the attributed and their values which we have specified in
-        * the limitation object.
-        *
-        * @param       $limitInstance          The instance to the object ObjectLimits
-        * @param       $object                         The origin object. We don't touch it here.
-        * @return      $containerInstance      An instance of SerializationContainer
-        * @throws      GetterNotFoundException If a getter was not found
-        */
-       public final static function createSerializationContainer (ObjectLimits $limitInstance, FrameworkInterface $object) {
-               // Get an instance
-               $containerInstance = new SerializationContainer();
-
-               // Iterate through the whole limitation array
-               for ($idx = $limitInstance->getLimitArray()->getIterator(); $idx->valid(); $idx->next()) {
-                       // Get current item from list
-                       $curr = ucfirst($idx->current());
-
-                       // Is the required method available?
-                       if (method_exists($object, sprintf("get%s", $curr))) {
-                               // Generate call-back function
-                               $value = call_user_func_array(array($object, sprintf("get%s", $curr)));
-
-                               // Add this item to the container list
-                               $containerInstance->append(array(
-                                       'name'  => $curr,
-                                       'value' => $value
-                               ));
-                       } else {
-                               // Throw an exception
-                               throw new GetterNotFoundException(array($object, $curr), self::EXCEPTION_GETTER_IS_MISSING);
-                       }
-               } // END - for
-
-               // Return container instance
-               return $containerInstance;
-       }
-}
-
-// [EOF]
-?>
index 0bafe36965f7ccccfa436139a0fb3655b32814c2..6e28c9f0f00f2ad6d0509264607aab5ec0d90e9e 100644 (file)
@@ -88,7 +88,7 @@ class ImageHelper extends BaseCaptcha implements HelpableTemplate {
         *
         * @param       $templateInstance       An instance of a template engine
         * @param       $imageType                      Type of the image
-        * @return      $helperInstance         A preparedf instance of this class
+        * @return      $helperInstance         A preparedf instance of this helper
         */
        public final static function createImageHelper (CompileableTemplate $templateInstance, $imageType) {
                // Get new instance
index eb1723df8565b0dde0d06b9ca38f29f3dbeb3669..ba6cb0ee12d297f9b82096d9bb680c7a6c402e59 100644 (file)
@@ -38,7 +38,7 @@ class ???Helper extends BaseHelper {
        /**
         * Creates the helper class
         *
-        * @return      $helperInstance         A prepared instance of this class
+        * @return      $helperInstance         A prepared instance of this helper
         */
        public final static function create???Helper () {
                // Get new instance
index bd27e03df04ed591089896ac4e9908d5a4505aa4..dab6791f0e8830a4bdd4b2abce2fff30d4b3f4b7 100644 (file)
@@ -81,11 +81,8 @@ class BaseHelper extends BaseFrameworkSystem {
                // Get the value from value instance
                $fieldValue = $this->getField($fieldName);
 
-               // Add a group
-               $this->getTemplateInstance()->setVariableGroup('values');
-
                // Assign it with a template variable
-               $this->getTemplateInstance()->addGroupVariable($fieldName, $fieldValue);
+               $this->getTemplateInstance()->assignVariable("block_" . $fieldName, $fieldValue);
        }
 
        /**
@@ -95,19 +92,17 @@ class BaseHelper extends BaseFrameworkSystem {
         * @param       $fieldName              Name of the field to assign
         * @param       $filterMethod   Method name to call of the value instance
         * @return      void
+        * @todo        Rewrite this method using a helper class for filtering data
         */
        public function assignFieldWithFilter ($fieldName, $filterMethod) {
                // Get the value
                $fieldValue = $this->getField($fieldName);
 
                // Now filter it through the value through the filter method
-               $filteredValue = call_user_func_array(array($this->valueInstance, "doFilter" . ucfirst($filterMethod)), array($fieldValue));
-
-               // Add a group
-               $this->getTemplateInstance()->setVariableGroup('values');
+               $filteredValue = call_user_func_array(array($this, "doFilter" . ucfirst($filterMethod)), array($fieldValue));
 
                // Assign it with a template variable
-               $this->getTemplateInstance()->addGroupVariable($fieldName, $fieldValue);
+               $this->getTemplateInstance()->assignVariable("block_" . $fieldName, $filteredValue);
        }
 
        /**
index 104f1b817d790cd2879890106999963a39daacd1..a71b36d71d944dde9b7ccb59cf980938e296e4b0 100644 (file)
@@ -45,7 +45,7 @@ class WebBlockHelper extends BaseWebHelper implements HelpableTemplate {
         *
         * @param       $templateInstance       An instance of a template engine
         * @param       $blockName                      Name of the block we shall generate
-        * @return      $helperInstance         A prepared instance of this class
+        * @return      $helperInstance         A prepared instance of this helper
         */
        public final static function createWebBlockHelper (CompileableTemplate $templateInstance, $blockName) {
                // Get new instance
@@ -96,7 +96,14 @@ class WebBlockHelper extends BaseWebHelper implements HelpableTemplate {
         * @return      void
         */
        public function flushContent () {
-               $this->partialStub();
+               // Get template instance
+               $templateInstance = $this->getTemplateInstance();
+
+               // Get the template named like this block
+               $templateInstance->loadCodeTemplate("block_" . $this->getBlockName());
+
+               // Transfer it to the template instance
+               $templateInstance->assignVariable($this->getBlockName(), $templateInstance->getRawTemplateData());
        }
 }
 
diff --git a/inc/classes/main/helper/web/class_ b/inc/classes/main/helper/web/class_
new file mode 100644 (file)
index 0000000..7c61ec8
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+/**
+ * 
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @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
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class Web???Helper extends BaseWebHelper implements HelpableTemplate {
+       /**
+        * Name of the ???
+        */
+       private $???Name = "";
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("");
+       }
+
+       /**
+        * Creates the helper class
+        *
+        * @param       $templateInstance       An instance of a template engine
+        * @param       $???Name                        Name of the ??? we shall generate
+        * @return      $helperInstance         A prepared instance of this helper
+        */
+       public final static function createWeb???Helper (CompileableTemplate $templateInstance, $???Name) {
+               // Get new instance
+               $helperInstance = new Web???Helper();
+
+               // Set template instance
+               $helperInstance->setTemplateInstance($templateInstance);
+
+               // Set ??? name
+               $helperInstance->set???Name($???Name);
+
+               // Return the prepared instance
+               return $helperInstance;
+       }
+
+       /**
+        * Flush the content out,e g. to a template variable
+        *
+        * @return      void
+        */
+       public function flushContent () {
+               $this->partialStub("Please implement this method.");
+       }
+}
+
+// [EOF]
+?>
index 1fc561eebbcc366d25d0d0f7116c9cd5d8273ef8..d423448dc486a01e1b4161ebe78263ccb5568815 100644 (file)
@@ -87,7 +87,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
         * @param       $formName                       Name of the form
         * @param       $formId                         Value for "id" attribute (default: $formName)
         * @param       $withForm                       Wether include the form tag
-        * @return      $helperInstance         A preparedf instance of this class
+        * @return      $helperInstance         A preparedf instance of this helper
         */
        public final static function createWebFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false, $withForm = true) {
                // Get new instance
diff --git a/inc/classes/main/helper/web/links/.htaccess b/inc/classes/main/helper/web/links/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/helper/web/links/class_WebLinkHelper.php b/inc/classes/main/helper/web/links/class_WebLinkHelper.php
new file mode 100644 (file)
index 0000000..4121cd2
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+/**
+ * A helper for web links
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @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
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
+       /**
+        * Name of the link
+        */
+       private $linkName = "";
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("A helper for generating web links");
+       }
+
+       /**
+        * Creates the helper class
+        *
+        * @param       $templateInstance       An instance of a template engine
+        * @param       $linkName                       Name of the link we shall generate
+        * @return      $helperInstance         A prepared instance of this helper
+        */
+       public final static function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName) {
+               // Get new instance
+               $helperInstance = new WebLinkHelper();
+
+               // Set template instance
+               $helperInstance->setTemplateInstance($templateInstance);
+
+               // Set Link name
+               $helperInstance->setLinkName($linkName);
+
+               // Return the prepared instance
+               return $helperInstance;
+       }
+
+       /**
+        * Setter for link name
+        *
+        * @param       $linkName       Name of the link we shall generate
+        * @return      void
+        */
+       protected final function setLinkName ($linkName) {
+               $this->linkName = (string) $linkName;
+       }
+
+       /**
+        * Getter for link name
+        *
+        * @return      $linkName       Name of the link we shall generate
+        */
+       public final function getLinkName () {
+               return $this->linkName;
+       }
+
+       /**
+        * Flush the content out,e g. to a template variable
+        *
+        * @return      void
+        */
+       public function flushContent () {
+               $this->partialStub("Please implement this method.");
+       }
+}
+
+// [EOF]
+?>
index 632f3ea393ea02d78adf01e2ac8cf90f079addba..e7e4541e70623d0dcaf99a6150777ece46fa41b7 100644 (file)
@@ -250,7 +250,7 @@ class BaseUser extends BaseFrameworkSystem {
         *
         * @return      $passHash       User's password hash from database result
         */
-       public function getPasswordHash () {
+       public final function getPasswordHash () {
                // Default is missing password hash
                $passHash = null;
 
@@ -274,7 +274,7 @@ class BaseUser extends BaseFrameworkSystem {
         * @return      $fieldValue             Field value from the user
         * @todo        Do we need to secure this here against missing results?
         */
-       public function getField ($fieldName) {
+       public final function getField ($fieldName) {
                // Default field value
                $fieldValue = null;
 
@@ -290,6 +290,25 @@ class BaseUser extends BaseFrameworkSystem {
                // Return it
                return $fieldValue;
        }
+
+       /**
+        * Getter for primary key value
+        *
+        * @return      $primaryValue   Value of the primary key based on database type
+        */
+       public final function getPrimaryKey () {
+               // Get a user database wrapper
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+
+               // Get the primary key back from the wrapper
+               $primaryKey = $wrapperInstance->getPrimaryKeyValue();
+
+               // Get that field
+               $primaryValue = $this->getField($primaryKey);
+
+               // Return the value
+               return $primaryValue;
+       }
 }
 
 // [EOF]
index 34091867e66f88d2d0de74568b38fbaf3089453f..0b8be63adf39e2c687876a972acb85fbb0ca5ad8 100644 (file)
@@ -179,6 +179,23 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Re
                // Ask the database layer
                $this->dbLayer->queryUpdateDataSet($dataSetInstance);
        }
+
+       /**
+        * Getter for primary key column of specified table name
+        *
+        * @param       $tableName              Name of table we need the primary key column from
+        * @return      $primaryKey             Primary key column of requested table
+        */
+       public function getPrimaryKeyOfTable ($tableName) {
+               // Connect to the database
+               $this->dbLayer->connectToDatabase();
+
+               // Ask the database layer
+               $primaryKey = $this->dbLayer->getPrimaryKeyOfTable($tableName);
+
+               // Return the value
+               return $primaryKey;
+       }
 }
 
 // [EOF]
index 4c7c2714976171ea4e40c6669f299b25459fb26c..ec15729d04f62e7f200cbec40a692e615e5199d5 100644 (file)
@@ -281,5 +281,8 @@ $cfg->setConfigEntry('cookie_ssl', (isset($_SERVER['HTTPS'])));
 // CFG: CRYPT-FIXED-SALT
 $cfg->setConfigEntry('crypt_fixed_salt', "N");
 
+// CFG: DB-UPDATE-PRIMARY-FORCED
+$cfg->setConfigEntry('db_update_primary_forced', "Y");
+
 // [EOF]
 ?>
index 857b1561ba6e88ae5e09a3c20ef388835583df1a..9ad3a004105a12bfcd8a035112395d454870a184 100644 (file)
--- a/index.php
+++ b/index.php
@@ -12,7 +12,7 @@ define('DEVELOPER', true);
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @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
  *
@@ -49,15 +49,17 @@ class ApplicationEntryPoint {
        /**
         * The application's emergency exit
         *
-        * @param               $message        The optional message we shall output on exit
+        * @param       $message        The optional message we shall output on exit
+        * @param       $code           Error code from exception
+        * @param       $extraData      Extra information from exceptions
         * @return      void
         */
-       public static function app_die ($message = "") {
+       public static function app_die ($message = "", $code = false, $extraData = "") {
                // Is this method already called?
                if (defined('EMERGENCY_EXIT_CALLED')) {
                        // Then output the text directly
                        die($message);
-               }
+               } // END - if
 
                // This method shall not be called twice
                define('EMERGENCY_EXIT_CALLED', true);
@@ -73,6 +75,9 @@ class ApplicationEntryPoint {
                $lang = LanguageSystem::getInstance();
                $io = FileIoHandler::getInstance();
 
+               // Get response instance
+               $responseInstance = ApplicationHelper::getInstance()->getResponseInstance();
+
                // Is the template engine loaded?
                if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) {
                        // Use the template engine for putting out (nicer look) the message
@@ -105,10 +110,12 @@ class ApplicationEntryPoint {
                                if (!isset($trace['line'])) $trace['line'] = 5;
                                if (!isset($trace['args'])) $trace['args'] = array();
                                $backtrace .= "<span class=\"backtrace_file\">".basename($trace['file'])."</span>:".$trace['line'].", <span class=\"backtrace_function\">".$trace['function']."(".count($trace['args']).")</span><br />";
-                       }
+                       } // END - foreach
 
                        // Assign variables
                        $tplEngine->assignVariable('message', $message);
+                       $tplEngine->assignVariable('code', $code);
+                       $tplEngine->assignVariable('extra', $extraData);
                        $tplEngine->assignVariable('backtrace', $backtrace);
                        $tplEngine->assignVariable('total_includes', ClassLoader::getInstance()->getTotal());
                        $tplEngine->assignVariable('total_objects', ObjectFactory::getTotal());
@@ -122,8 +129,11 @@ class ApplicationEntryPoint {
                        // Compile all variables
                        $tplEngine->compileVariables();
 
-                       // Output all
-                       $tplEngine->output();
+                       // Transfer data to response
+                       $tplEngine->transferToResponse($responseInstance);
+
+                       // Flush the response
+                       $responseInstance->flushBuffer();
 
                        // Good bye...
                        exit();