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__);
56 $this->removeNumberFormaters();
57 $this->removeSystemArray();
61 * Creates an instance of this criteria
63 * @param $tableName Name of the table
64 * @return $criteriaInstance An instance of this criteria
66 public final static function createDataSetCriteria ($tableName) {
68 $criteriaInstance = new DataSetCriteria();
71 $criteriaInstance->setTableName($tableName);
73 // Return the instance
74 return $criteriaInstance;
80 * @param $criteriaKey Criteria key
81 * @param $criteriaValue Criteria value
84 public function addCriteria ($criteriaKey, $criteriaValue) {
85 $this->tableColumns[(string) $criteriaKey] = $criteriaValue;
89 * Add configured criteria
91 * @param $criteriaKey Criteria key
92 * @param $configEntry Configuration entry
95 public function addConfiguredCriteria ($criteriaKey, $configEntry) {
96 // Add configuration entry as criteria
97 $value = $this->getConfigInstance()->readConfig($configEntry);
98 $this->addCriteria($criteriaKey, $value);
102 * Setter for table name
104 * @param $tableName Name of the table to set
107 public final function setTableName ($tableName) {
108 $this->tableName = (string) $tableName;
112 * Getter for table name
114 * @return $tableName Name of the table to set
116 public final function getTableName () {
117 return $this->tableName;
121 * Setter for unique key
123 * @param $uniqueKey Column to use as unique key
126 public final function setUniqueKey ($uniqueKey) {
127 $this->uniqueKey = (string) $uniqueKey;
131 * Getter for unique key
133 * @return $uniqueKey Column to use as unique key
135 public final function getUniqueKey () {
136 return $this->uniqueKey;
140 * Getter for unique key value
142 * @return $uniqueValue Value of the unique key
144 public final function getUniqueValue () {
145 return $this->tableColumns[$this->getUniqueKey()];
149 * Getter for criteria array
151 * @return $tableColumns
153 public final function getCriteriaArray () {
154 return $this->tableColumns;
158 * Getter for primary key or unique key if not set
160 * @return $primaryKey Primary key or unique key if not set
162 public final function getPrimaryKey () {
163 // Get primary key by default
164 $primaryKey = $this->primaryKey;
166 if (empty($primaryKey)) {
168 $primaryKey = $this->getUniqueKey();
176 * Setter for primary key
178 * @param $primaryKey Primary key to set
181 public final function setPrimaryKey ($primaryKey) {
182 $this->primaryKey = (string) $primaryKey;