]> git.mxchange.org Git - shipsimu.git/blob - inc/classes/main/criteria/class_DataSetCriteria.php
Following things are changed: (in order of class names)
[shipsimu.git] / inc / classes / main / criteria / class_DataSetCriteria.php
1 <?php
2 /**
3  * A set of data storeable in databases
4  *
5  * @see                 DatabaseFrontendInterface - An interface for database frontends (front-end to the application)
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0.0
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
11  *
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.
16  *
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.
21  *
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/>.
24  */
25 class DataSetCriteria extends BaseFrameworkSystem implements StoreableCriteria {
26         /**
27          * Table name
28          */
29         private $tableName = "";
30
31         /**
32          * Table columns (criteria) to store
33          */
34         private $tableColumns = array();
35
36         /**
37          * Unique key
38          */
39         private $uniqueKey = "";
40
41         /**
42          * Primary key
43          */
44         private $primaryKey = "";
45
46         /**
47          * Protected constructor
48          *
49          * @return      void
50          */
51         protected function __construct() {
52                 // Call parent constructor
53                 parent::__construct(__CLASS__);
54
55                 // Set part description
56                 $this->setObjectDescription("Storeable data set for databases");
57
58                 // Create unique ID number
59                 $this->generateUniqueId();
60
61                 // Clean up a little
62                 $this->removeNumberFormaters();
63                 $this->removeSystemArray();
64         }
65
66         /**
67          * Creates an instance of this criteria
68          *
69          * @param       $tableName                      Name of the table
70          * @return      $criteriaInstance       An instance of this criteria
71          */
72         public final static function createDataSetCriteria ($tableName) {
73                 // Get a new instance
74                 $criteriaInstance = new DataSetCriteria();
75
76                 // Set table name
77                 $criteriaInstance->setTableName($tableName);
78
79                 // Return the instance
80                 return $criteriaInstance;
81         }
82
83         /**
84          * Add criteria
85          *
86          * @param       $criteriaKey    Criteria key
87          * @param       $criteriaValue  Criteria value
88          * @return      void
89          */
90         public function addCriteria ($criteriaKey, $criteriaValue) {
91                 $this->tableColumns[(string) $criteriaKey] = $criteriaValue;
92         }
93
94         /**
95          * Add configured criteria
96          *
97          * @param       $criteriaKey    Criteria key
98          * @param       $configEntry    Configuration entry
99          * @return      void
100          */
101         public function addConfiguredCriteria ($criteriaKey, $configEntry) {
102                 // Add configuration entry as criteria
103                 $value = $this->getConfigInstance()->readConfig($configEntry);
104                 $this->addCriteria($criteriaKey, $value);
105         }
106
107         /**
108          * Setter for table name
109          *
110          * @param       $tableName      Name of the table to set
111          * @return      void
112          */
113         public final function setTableName ($tableName) {
114                 $this->tableName = (string) $tableName;
115         }
116
117         /**
118          * Getter for table name
119          *
120          * @return      $tableName      Name of the table to set
121          */
122         public final function getTableName () {
123                 return $this->tableName;
124         }
125
126         /**
127          * Setter for unique key
128          *
129          * @param       $uniqueKey      Column to use as unique key
130          * @return      void
131          */
132         public final function setUniqueKey ($uniqueKey) {
133                 $this->uniqueKey = (string) $uniqueKey;
134         }
135
136         /**
137          * Getter for unique key
138          *
139          * @return      $uniqueKey      Column to use as unique key
140          */
141         public final function getUniqueKey () {
142                 return $this->uniqueKey;
143         }
144
145         /**
146          * Getter for unique key value
147          *
148          * @return      $uniqueValue    Value of the unique key
149          */
150         public final function getUniqueValue () {
151                 return $this->tableColumns[$this->getUniqueKey()];
152         }
153
154         /**
155          * Getter for criteria array
156          *
157          * @return      $tableColumns
158          */
159         public final function getCriteriaArray () {
160                 return $this->tableColumns;
161         }
162
163         /**
164          * Getter for primary key or unique key if not set
165          *
166          * @return      $primaryKey             Primary key or unique key if not set
167          */
168         public final function getPrimaryKey () {
169                 // Get primary key by default
170                 $primaryKey = $this->primaryKey;
171
172                 if (empty($primaryKey)) {
173                         // Get uniqueKey
174                         $primaryKey = $this->getUniqueKey();
175                 } // END - if
176
177                 // Return it
178                 return $primaryKey;
179         }
180
181         /**
182          * Setter for primary key
183          *
184          * @param       $primaryKey             Primary key to set
185          * @return      void
186          */
187         public final function setPrimaryKey ($primaryKey) {
188                 $this->primaryKey = (string) $primaryKey;
189         }
190 }
191
192 // [EOF]
193 ?>