From: Roland Häder Date: Fri, 27 Jun 2008 22:58:07 +0000 (+0000) Subject: Following things are changed: (in order of class names) X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=commitdiff_plain;h=6019ae86707cb6decaddc63f191e3ef6eb5e4d44 Following things are changed: (in order of class names) - 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 --- diff --git a/.gitattributes b/.gitattributes index beb5226..9598bc1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index dceca29..1a71aea 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -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 index 0000000..8611b6e --- /dev/null +++ b/application/ship-simu/exceptions/class_NoShippingCompanyOwnedException.php @@ -0,0 +1,46 @@ + + * @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 . + */ +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 %s) does not own any shipping companies.", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1]->__toString() + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/application/ship-simu/exceptions/class_ToMuchEmployeesException.php b/application/ship-simu/exceptions/class_ToMuchEmployeesException.php index 69e76c8..ca07ecf 100644 --- a/application/ship-simu/exceptions/class_ToMuchEmployeesException.php +++ b/application/ship-simu/exceptions/class_ToMuchEmployeesException.php @@ -22,10 +22,7 @@ * along with this program. If not, see . */ 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("%d Leute nicht einstellbar, da nur %d arbeitslos sind!", $amountArray[0], diff --git a/application/ship-simu/main/companies/class_ShippingCompany.php b/application/ship-simu/main/companies/class_ShippingCompany.php index 381aa4c..d3ab698 100644 --- a/application/ship-simu/main/companies/class_ShippingCompany.php +++ b/application/ship-simu/main/companies/class_ShippingCompany.php @@ -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 %s wird gegrü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 %s erhä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 %s erhä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 %s erhä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 diff --git a/application/ship-simu/main/personell/class_SimulatorPersonell.php b/application/ship-simu/main/personell/class_SimulatorPersonell.php index 05559cc..86b1ba0 100644 --- a/application/ship-simu/main/personell/class_SimulatorPersonell.php +++ b/application/ship-simu/main/personell/class_SimulatorPersonell.php @@ -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 index 0000000..3a42882 --- /dev/null +++ b/application/ship-simu/main/wrapper/.htaccess @@ -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 index 0000000..d403d18 --- /dev/null +++ b/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php @@ -0,0 +1,62 @@ + + * @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 . + */ +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 index 0000000..02a84d9 --- /dev/null +++ b/application/ship-simu/templates/de/code/block_persona_data.ctp @@ -0,0 +1,21 @@ +prefetchValueInstance('user'); + +// Flush the content out +$helperInstance->flushContent(); + +// End of PHP commands +?> +
+ Spielername: {?block_username?} +
+
+ {?profile_link?} +
+
+ Angemeldet seit: {?block_registered?} +
diff --git a/application/ship-simu/templates/de/code/login_main.ctp b/application/ship-simu/templates/de/code/login_main.ctp index b059c7f..3326c51 100644 --- a/application/ship-simu/templates/de/code/login_main.ctp +++ b/application/ship-simu/templates/de/code/login_main.ctp @@ -1,4 +1,8 @@ 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 ?>
diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 7d9467a..de854be 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -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] diff --git a/inc/classes/main/criteria/class_DataSetCriteria.php b/inc/classes/main/criteria/class_DataSetCriteria.php index 7e43565..61bdb32 100644 --- a/inc/classes/main/criteria/class_DataSetCriteria.php +++ b/inc/classes/main/criteria/class_DataSetCriteria.php @@ -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] diff --git a/inc/classes/main/database/class_BaseDatabaseWrapper.php b/inc/classes/main/database/class_BaseDatabaseWrapper.php index 5c17fb7..7a4ee57 100644 --- a/inc/classes/main/database/class_BaseDatabaseWrapper.php +++ b/inc/classes/main/database/class_BaseDatabaseWrapper.php @@ -22,6 +22,16 @@ * along with this program. If not, see . */ 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] diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index ef5c2ba..60fb4d3 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -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 '%s' contains invalid data.", $dataFile), self::DB_CODE_DATA_FILE_CORRUPT); + throw new SqlException(array($this, sprintf("File '%s' 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 '%s'", $tableName), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY); + throw new SqlException (array($this, sprintf("Cannot write data to table '%s'", $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] diff --git a/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php index 09574b1..73b7a21 100644 --- a/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php @@ -22,16 +22,6 @@ * along with this program. If not, see . */ 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] diff --git a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php index a9c4f2f..9b480db 100644 --- a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ 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 index 3a42882..0000000 --- a/inc/classes/main/extended/.htaccess +++ /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 index fbfda6c..0000000 --- a/inc/classes/main/extended/class_ObjectLimits.php +++ /dev/null @@ -1,132 +0,0 @@ - - * @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 . - */ -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 "limiting" 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 index 9843912..0000000 --- a/inc/classes/main/extended/class_SerializationContainer.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @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 . - */ -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] -?> diff --git a/inc/classes/main/helper/captcha/images/class_ImageHelper.php b/inc/classes/main/helper/captcha/images/class_ImageHelper.php index 0bafe36..6e28c9f 100644 --- a/inc/classes/main/helper/captcha/images/class_ImageHelper.php +++ b/inc/classes/main/helper/captcha/images/class_ImageHelper.php @@ -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 diff --git a/inc/classes/main/helper/class_ b/inc/classes/main/helper/class_ index eb1723d..ba6cb0e 100644 --- a/inc/classes/main/helper/class_ +++ b/inc/classes/main/helper/class_ @@ -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 diff --git a/inc/classes/main/helper/class_BaseHelper.php b/inc/classes/main/helper/class_BaseHelper.php index bd27e03..dab6791 100644 --- a/inc/classes/main/helper/class_BaseHelper.php +++ b/inc/classes/main/helper/class_BaseHelper.php @@ -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); } /** diff --git a/inc/classes/main/helper/web/blocks/class_WebBlockHelper.php b/inc/classes/main/helper/web/blocks/class_WebBlockHelper.php index 104f1b8..a71b36d 100644 --- a/inc/classes/main/helper/web/blocks/class_WebBlockHelper.php +++ b/inc/classes/main/helper/web/blocks/class_WebBlockHelper.php @@ -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 index 0000000..7c61ec8 --- /dev/null +++ b/inc/classes/main/helper/web/class_ @@ -0,0 +1,75 @@ + + * @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 . + */ +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] +?> diff --git a/inc/classes/main/helper/web/forms/class_WebFormHelper.php b/inc/classes/main/helper/web/forms/class_WebFormHelper.php index 1fc561e..d423448 100644 --- a/inc/classes/main/helper/web/forms/class_WebFormHelper.php +++ b/inc/classes/main/helper/web/forms/class_WebFormHelper.php @@ -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 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/helper/web/links/.htaccess @@ -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 index 0000000..4121cd2 --- /dev/null +++ b/inc/classes/main/helper/web/links/class_WebLinkHelper.php @@ -0,0 +1,94 @@ + + * @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 . + */ +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] +?> diff --git a/inc/classes/main/user/class_BaseUser.php b/inc/classes/main/user/class_BaseUser.php index 632f3ea..e7e4541 100644 --- a/inc/classes/main/user/class_BaseUser.php +++ b/inc/classes/main/user/class_BaseUser.php @@ -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] diff --git a/inc/classes/middleware/database/class_DatabaseConnection.php b/inc/classes/middleware/database/class_DatabaseConnection.php index 3409186..0b8be63 100644 --- a/inc/classes/middleware/database/class_DatabaseConnection.php +++ b/inc/classes/middleware/database/class_DatabaseConnection.php @@ -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] diff --git a/inc/config.php b/inc/config.php index 4c7c271..ec15729 100644 --- a/inc/config.php +++ b/inc/config.php @@ -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] ?> diff --git a/index.php b/index.php index 857b156..9ad3a00 100644 --- a/index.php +++ b/index.php @@ -12,7 +12,7 @@ define('DEVELOPER', true); * * @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 * @@ -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 .= "".basename($trace['file']).":".$trace['line'].", ".$trace['function']."(".count($trace['args']).")
"; - } + } // 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();