readConfig() is not naming convention, renamed to getConfigEntry()
[core.git] / inc / classes / main / criteria / dataset / 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, 2009 Core Developer Team
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 BaseCriteria 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
56         /**
57          * Creates an instance of this criteria
58          *
59          * @param       $tableName                      Name of the table
60          * @return      $criteriaInstance       An instance of this criteria
61          */
62         public final static function createDataSetCriteria ($tableName) {
63                 // Get a new instance
64                 $criteriaInstance = new DataSetCriteria();
65
66                 // Set table name
67                 $criteriaInstance->setTableName($tableName);
68
69                 // Return the instance
70                 return $criteriaInstance;
71         }
72
73         /**
74          * Add criteria
75          *
76          * @param       $criteriaKey    Criteria key
77          * @param       $criteriaValue  Criteria value
78          * @return      void
79          */
80         public function addCriteria ($criteriaKey, $criteriaValue) {
81                 $this->tableColumns[(string) $criteriaKey] = $criteriaValue;
82         }
83
84         /**
85          * Add configured criteria
86          *
87          * @param       $criteriaKey    Criteria key
88          * @param       $configEntry    Configuration entry
89          * @return      void
90          */
91         public function addConfiguredCriteria ($criteriaKey, $configEntry) {
92                 // Add configuration entry as criteria
93                 $value = $this->getConfigInstance()->getConfigEntry($configEntry);
94                 $this->addCriteria($criteriaKey, $value);
95         }
96
97         /**
98          * Setter for table name
99          *
100          * @param       $tableName      Name of the table to set
101          * @return      void
102          */
103         public final function setTableName ($tableName) {
104                 $this->tableName = (string) $tableName;
105         }
106
107         /**
108          * Getter for table name
109          *
110          * @return      $tableName      Name of the table to set
111          */
112         public final function getTableName () {
113                 return $this->tableName;
114         }
115
116         /**
117          * Setter for unique key
118          *
119          * @param       $uniqueKey      Column to use as unique key
120          * @return      void
121          */
122         public final function setUniqueKey ($uniqueKey) {
123                 $this->uniqueKey = (string) $uniqueKey;
124         }
125
126         /**
127          * Getter for unique key
128          *
129          * @return      $uniqueKey      Column to use as unique key
130          */
131         public final function getUniqueKey () {
132                 return $this->uniqueKey;
133         }
134
135         /**
136          * Getter for unique key value
137          *
138          * @return      $uniqueValue    Value of the unique key
139          */
140         public final function getUniqueValue () {
141                 return $this->tableColumns[$this->getUniqueKey()];
142         }
143
144         /**
145          * Getter for criteria array
146          *
147          * @return      $tableColumns
148          */
149         public final function getCriteriaArray () {
150                 return $this->tableColumns;
151         }
152
153         /**
154          * Getter for primary key or unique key if not set
155          *
156          * @return      $primaryKey             Primary key or unique key if not set
157          */
158         public final function getPrimaryKey () {
159                 // Get primary key by default
160                 $primaryKey = $this->primaryKey;
161
162                 if (empty($primaryKey)) {
163                         // Get uniqueKey
164                         $primaryKey = $this->getUniqueKey();
165                 } // END - if
166
167                 // Return it
168                 return $primaryKey;
169         }
170
171         /**
172          * Setter for primary key
173          *
174          * @param       $primaryKey             Primary key to set
175          * @return      void
176          */
177         public final function setPrimaryKey ($primaryKey) {
178                 $this->primaryKey = (string) $primaryKey;
179         }
180 }
181
182 // [EOF]
183 ?>