7e43565fd0d9a1cdbce270442d027b22f8621fe2
[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          * Protected constructor
43          *
44          * @return      void
45          */
46         protected function __construct() {
47                 // Call parent constructor
48                 parent::__construct(__CLASS__);
49
50                 // Set part description
51                 $this->setObjectDescription("Storeable data set for databases");
52
53                 // Create unique ID number
54                 $this->generateUniqueId();
55
56                 // Clean up a little
57                 $this->removeNumberFormaters();
58                 $this->removeSystemArray();
59         }
60
61         /**
62          * Creates an instance of this criteria
63          *
64          * @return $criteriaInstance    An instance of this criteria
65          */
66         public final static function createDataSetCriteria () {
67                 // Get a new instance
68                 $criteriaInstance = new DataSetCriteria();
69
70                 // Return the instance
71                 return $criteriaInstance;
72         }
73
74         /**
75          * Add criteria
76          *
77          * @param       $criteriaKey    Criteria key
78          * @param       $criteriaValue  Criteria value
79          * @return      void
80          */
81         public function addCriteria ($criteriaKey, $criteriaValue) {
82                 $this->tableColumns[(string) $criteriaKey] = $criteriaValue;
83         }
84
85         /**
86          * Add configured criteria
87          *
88          * @param       $criteriaKey    Criteria key
89          * @param       $configEntry    Configuration entry
90          * @return      void
91          */
92         public function addConfiguredCriteria ($criteriaKey, $configEntry) {
93                 // Add configuration entry as criteria
94                 $value = $this->getConfigInstance()->readConfig($configEntry);
95                 $this->addCriteria($criteriaKey, $value);
96         }
97
98         /**
99          * Setter for table name
100          *
101          * @param       $tableName      Name of the table to set
102          * @return      void
103          */
104         public final function setTableName ($tableName) {
105                 $this->tableName = (string) $tableName;
106         }
107
108         /**
109          * Getter for table name
110          *
111          * @return      $tableName      Name of the table to set
112          */
113         public final function getTableName () {
114                 return $this->tableName;
115         }
116
117         /**
118          * Setter for unique key
119          *
120          * @param       $uniqueKey      Column to use as unique key
121          * @return      void
122          */
123         public final function setUniqueKey ($uniqueKey) {
124                 $this->uniqueKey = (string) $uniqueKey;
125         }
126
127         /**
128          * Getter for unique key
129          *
130          * @return      $uniqueKey      Column to use as unique key
131          */
132         public final function getUniqueKey () {
133                 return $this->uniqueKey;
134         }
135
136         /**
137          * Getter for unique key value
138          *
139          * @return      $uniqueValue    Value of the unique key
140          */
141         public final function getUniqueValue () {
142                 return $this->tableColumns[$this->getUniqueKey()];
143         }
144
145         /**
146          * Getter for criteria array
147          *
148          * @return      $tableColumns
149          */
150         public final function getCriteriaArray () {
151                 return $this->tableColumns;
152         }
153 }
154
155 // [EOF]
156 ?>