3 * A set of data storeable in databases
5 * @see DatabaseFrontendInterface - An interface for database frontends (front-end to the application)
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.ship-simu.org
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class DataSetCriteria extends BaseFrameworkSystem implements StoreableCriteria {
29 private $tableName = "";
32 * Table columns (criteria) to store
34 private $tableColumns = array();
39 private $uniqueKey = "";
44 private $primaryKey = "";
47 * Protected constructor
51 protected function __construct() {
52 // Call parent constructor
53 parent::__construct(__CLASS__);
55 // Set part description
56 $this->setObjectDescription("Storeable data set for databases");
58 // Create unique ID number
59 $this->generateUniqueId();
62 $this->removeNumberFormaters();
63 $this->removeSystemArray();
67 * Creates an instance of this criteria
69 * @param $tableName Name of the table
70 * @return $criteriaInstance An instance of this criteria
72 public final static function createDataSetCriteria ($tableName) {
74 $criteriaInstance = new DataSetCriteria();
77 $criteriaInstance->setTableName($tableName);
79 // Return the instance
80 return $criteriaInstance;
86 * @param $criteriaKey Criteria key
87 * @param $criteriaValue Criteria value
90 public function addCriteria ($criteriaKey, $criteriaValue) {
91 $this->tableColumns[(string) $criteriaKey] = $criteriaValue;
95 * Add configured criteria
97 * @param $criteriaKey Criteria key
98 * @param $configEntry Configuration entry
101 public function addConfiguredCriteria ($criteriaKey, $configEntry) {
102 // Add configuration entry as criteria
103 $value = $this->getConfigInstance()->readConfig($configEntry);
104 $this->addCriteria($criteriaKey, $value);
108 * Setter for table name
110 * @param $tableName Name of the table to set
113 public final function setTableName ($tableName) {
114 $this->tableName = (string) $tableName;
118 * Getter for table name
120 * @return $tableName Name of the table to set
122 public final function getTableName () {
123 return $this->tableName;
127 * Setter for unique key
129 * @param $uniqueKey Column to use as unique key
132 public final function setUniqueKey ($uniqueKey) {
133 $this->uniqueKey = (string) $uniqueKey;
137 * Getter for unique key
139 * @return $uniqueKey Column to use as unique key
141 public final function getUniqueKey () {
142 return $this->uniqueKey;
146 * Getter for unique key value
148 * @return $uniqueValue Value of the unique key
150 public final function getUniqueValue () {
151 return $this->tableColumns[$this->getUniqueKey()];
155 * Getter for criteria array
157 * @return $tableColumns
159 public final function getCriteriaArray () {
160 return $this->tableColumns;
164 * Getter for primary key or unique key if not set
166 * @return $primaryKey Primary key or unique key if not set
168 public final function getPrimaryKey () {
169 // Get primary key by default
170 $primaryKey = $this->primaryKey;
172 if (empty($primaryKey)) {
174 $primaryKey = $this->getUniqueKey();
182 * Setter for primary key
184 * @param $primaryKey Primary key to set
187 public final function setPrimaryKey ($primaryKey) {
188 $this->primaryKey = (string) $primaryKey;