]> git.mxchange.org Git - mailer.git/blobdiff - inc/classes/main/database/databases/class_LocalFileDatabase.php
Code merged from ship-simu repository
[mailer.git] / inc / classes / main / database / databases / class_LocalFileDatabase.php
index 25cf9389f68b7708182e3767fedece739e04d8ec..dc4371efd13fcb5a08bbb64a1bb185ddcd5726fd 100644 (file)
@@ -70,6 +70,11 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
         */
        private $tableInfo = array();
 
+       /**
+        * Element for index
+        */
+       private $indexKey = "__idx";
+
        /**
         * The protected constructor. Do never instance from outside! You need to
         * set a local file path. The class will then validate it.
@@ -153,13 +158,12 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
        /**
         * Setter for the last read file
         *
-        * @param               $fqfn   The FQFN of the last read file
+        * @param       $fqfn   The FQFN of the last read file
         * @return      void
         */
        private final function setLastFile ($fqfn) {
-               // Cast string
-               $fqfn = (string) $fqfn;
-               $this->lastFile = $fqfn;
+               // Cast string and set it
+               $this->lastFile = (string) $fqfn;
        }
 
        /**
@@ -188,9 +192,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
         * @param               $contents               An array with header and data elements
         * @return      void
         */
-       private final function setLastFileContents ($contents) {
-               // Cast array
-               $contents = (array) $contents;
+       private final function setLastFileContents (array $contents) {
+               // Set array
                $this->lastContents = $contents;
        }
 
@@ -212,6 +215,15 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                return $this->fileExtension;
        }
 
+       /**
+        * Getter for index key
+        *
+        * @return      $indexKey       Index key
+        */
+       public final function getIndexKey () {
+               return $this->indexKey;
+       }
+
        /**
         * Reads a local data file  and returns it's contents in an array
         *
@@ -261,7 +273,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
        }
 
        /**
-        * Getter for table information file contents or an empty if the info file was not created
+        * Getter for table information file contents or an empty if info file was not created
         *
         * @param       $dataSetInstance        An instance of a database set class
         * @return      $infoArray                      An array with all table informations
@@ -370,6 +382,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        // Initialize limit/skip
                        $limitFound = 0;
                        $skipFound = 0;
+                       $idx = 1;
 
                        // Read the directory with some exceptions
                        while (($dataFile = $directoryInstance->readDirectoryExcept(array(".", "..", ".htaccess", ".svn", "info." . $this->getFileExtension()))) && ($limitFound < $criteriaInstance->getLimit())) {
@@ -377,7 +390,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                                if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) {
                                        // Skip this file!
                                        continue;
-                               }
+                               } // END - if
 
                                // Read the file
                                $dataArray = $this->getDataArrayFromFile($pathName . $dataFile);
@@ -402,8 +415,13 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                                                                } // END - if
                                                        } // END - if
 
+                                                       // Set id number
+                                                       $dataArray[$this->getIndexKey()] = $idx;
+
                                                        // Entry found!
                                                        $resultData['rows'][] = $dataArray;
+
+                                                       // Count found entries up
                                                        $limitFound++;
                                                        break;
                                                } // END - if
@@ -412,6 +430,9 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                                        // Throw an exception here
                                        throw new SqlException(array($this, sprintf("File &#39;%s&#39; contains invalid data.", $dataFile), self::DB_CODE_DATA_FILE_CORRUPT), self::EXCEPTION_SQL_QUERY);
                                }
+
+                               // Count entry up
+                               $idx++;
                        } // END - while
 
                        // Close directory and throw the instance away