Updating/inserting points finished (basicly), flushing needed database updates moved...
[core.git] / inc / classes / main / criteria / dataset / class_DataSetCriteria.php
diff --git a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php
new file mode 100644 (file)
index 0000000..f342606
--- /dev/null
@@ -0,0 +1,183 @@
+<?php
+/**
+ * A set of data storeable in databases
+ *
+ * @see                        DatabaseFrontendInterface - An interface for database frontends (front-end to the application)
+ * @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 DataSetCriteria extends BaseCriteria implements StoreableCriteria {
+       /**
+        * Table name
+        */
+       private $tableName = "";
+
+       /**
+        * Table columns (criteria) to store
+        */
+       private $tableColumns = array();
+
+       /**
+        * Unique key
+        */
+       private $uniqueKey = "";
+
+       /**
+        * Primary key
+        */
+       private $primaryKey = "";
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct() {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this criteria
+        *
+        * @param       $tableName                      Name of the table
+        * @return      $criteriaInstance       An instance of this criteria
+        */
+       public final static function createDataSetCriteria ($tableName) {
+               // Get a new instance
+               $criteriaInstance = new DataSetCriteria();
+
+               // Set table name
+               $criteriaInstance->setTableName($tableName);
+
+               // Return the instance
+               return $criteriaInstance;
+       }
+
+       /**
+        * Add criteria
+        *
+        * @param       $criteriaKey    Criteria key
+        * @param       $criteriaValue  Criteria value
+        * @return      void
+        */
+       public function addCriteria ($criteriaKey, $criteriaValue) {
+               $this->tableColumns[(string) $criteriaKey] = $criteriaValue;
+       }
+
+       /**
+        * Add configured criteria
+        *
+        * @param       $criteriaKey    Criteria key
+        * @param       $configEntry    Configuration entry
+        * @return      void
+        */
+       public function addConfiguredCriteria ($criteriaKey, $configEntry) {
+               // Add configuration entry as criteria
+               $value = $this->getConfigInstance()->readConfig($configEntry);
+               $this->addCriteria($criteriaKey, $value);
+       }
+
+       /**
+        * Setter for table name
+        *
+        * @param       $tableName      Name of the table to set
+        * @return      void
+        */
+       public final function setTableName ($tableName) {
+               $this->tableName = (string) $tableName;
+       }
+
+       /**
+        * Getter for table name
+        *
+        * @return      $tableName      Name of the table to set
+        */
+       public final function getTableName () {
+               return $this->tableName;
+       }
+
+       /**
+        * Setter for unique key
+        *
+        * @param       $uniqueKey      Column to use as unique key
+        * @return      void
+        */
+       public final function setUniqueKey ($uniqueKey) {
+               $this->uniqueKey = (string) $uniqueKey;
+       }
+
+       /**
+        * Getter for unique key
+        *
+        * @return      $uniqueKey      Column to use as unique key
+        */
+       public final function getUniqueKey () {
+               return $this->uniqueKey;
+       }
+
+       /**
+        * Getter for unique key value
+        *
+        * @return      $uniqueValue    Value of the unique key
+        */
+       public final function getUniqueValue () {
+               return $this->tableColumns[$this->getUniqueKey()];
+       }
+
+       /**
+        * Getter for criteria array
+        *
+        * @return      $tableColumns
+        */
+       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]
+?>