]> git.mxchange.org Git - core.git/blobdiff - inc/classes/middleware/database/class_DatabaseConnection.php
Introduced isReachableFilePath() and isReadableFile().
[core.git] / inc / classes / middleware / database / class_DatabaseConnection.php
index 0a688c39638799f2a2d0cf01628ac2d21d350abf..d3225c410d6a5a9915404af922c430a082517607 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * Database selector class
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.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
@@ -36,7 +36,7 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Re
        private $dbLayer = NULL;
 
        // An instance of this class
-       private static $thisInstance = NULL;
+       private static $selfInstance = NULL;
 
        /**
         * Protected constructor
@@ -49,18 +49,15 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Re
        }
 
        // Create new database connection layer
-       public static final function createDatabaseConnection (DebugMiddleware $debugInstance, DatabaseFrontendInterface $dbLayer) {
+       public static final function createDatabaseConnection (DebugMiddleware $debugInstance, DatabaseBackend $dbLayer) {
                // Get instance
                $databaseInstance = new DatabaseConnection();
 
-               // Set debug output handler
-               $databaseInstance->setDebugInstance($debugInstance);
-
                // Set database layer
                $databaseInstance->setDatabaseLayer($dbLayer);
 
                // Set db instance
-               self::$thisInstance = $databaseInstance;
+               self::$selfInstance = $databaseInstance;
 
                // Return instance
                return $databaseInstance;
@@ -68,7 +65,7 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Re
 
        // Get an instance of this class
        public static final function getSelfInstance () {
-               return self::$thisInstance;
+               return self::$selfInstance;
        }
 
        // Public setter for database connection
@@ -94,7 +91,7 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Re
         * @param       $dbLayer        An instance of the real database layer
         * @return      void
         */
-       public final function setDatabaseLayer (DatabaseFrontendInterface $dbLayer) {
+       public final function setDatabaseLayer (DatabaseBackend $dbLayer) {
                $this->dbLayer = $dbLayer;
        }
 
@@ -180,6 +177,41 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Re
                // Return the value
                return $primaryKey;
        }
+
+       /**
+        * Removes non-public data from given array.
+        *
+        * @param       $data   An array with possible non-public data that needs to be removed.
+        * @return      $data   A cleaned up array with only public data.
+        */
+       public function removeNonPublicDataFromArray (array $data) {
+               // Connect to the database
+               $this->dbLayer->connectToDatabase();
+
+               // Call database backend
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DB-CONNECTION[' . $this->__toString() . ']: Calling this->dbLayer->removeNonPublicDataFromArray(data) ...');
+               $data = $this->dbLayer->removeNonPublicDataFromArray($data);
+
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DB-CONNECTION[' . $this->__toString() . ']: data[]=' . gettype($data));
+               return $data;
+       }
+
+       /**
+        * Count total table rows
+        *
+        * @param       $tableName      Table name
+        * @return      $count          Total row count
+        */
+       public function countTotalRows ($tableName) {
+               // Connect to the database
+               $this->dbLayer->connectToDatabase();
+
+               // Ask the database layer
+               $count = $this->dbLayer->countTotalRows($tableName);
+
+               // Return the value
+               return $count;
+       }
 }
 
 // [EOF]