Copyright updated
[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 - 2012 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          * Unique key
33          */
34         private $uniqueKey = '';
35
36         /**
37          * Primary key
38          */
39         private $primaryKey = '';
40
41         /**
42          * Protected constructor
43          *
44          * @return      void
45          */
46         protected function __construct () {
47                 // Call parent constructor
48                 parent::__construct(__CLASS__);
49         }
50
51         /**
52          * Creates an instance of this criteria
53          *
54          * @param       $tableName                      Name of the table
55          * @return      $criteriaInstance       An instance of this criteria
56          */
57         public static final function createDataSetCriteria ($tableName) {
58                 // Get a new instance
59                 $criteriaInstance = new DataSetCriteria();
60
61                 // Set table name
62                 $criteriaInstance->setTableName($tableName);
63
64                 // Return the instance
65                 return $criteriaInstance;
66         }
67
68         /**
69          * Setter for table name
70          *
71          * @param       $tableName      Name of the table to set
72          * @return      void
73          */
74         public final function setTableName ($tableName) {
75                 $this->tableName = (string) $tableName;
76         }
77
78         /**
79          * Getter for table name
80          *
81          * @return      $tableName      Name of the table to set
82          */
83         public final function getTableName () {
84                 return $this->tableName;
85         }
86
87         /**
88          * Setter for unique key
89          *
90          * @param       $uniqueKey      Column to use as unique key
91          * @return      void
92          */
93         public final function setUniqueKey ($uniqueKey) {
94                 $this->uniqueKey = (string) $uniqueKey;
95         }
96
97         /**
98          * Getter for unique key
99          *
100          * @return      $uniqueKey      Column to use as unique key
101          */
102         public final function getUniqueKey () {
103                 return $this->uniqueKey;
104         }
105
106         /**
107          * Getter for unique key value
108          *
109          * @return      $uniqueValue    Value of the unique key
110          */
111         public final function getUniqueValue () {
112                 return $this->getCriteriaElemnent($this->getUniqueKey());
113         }
114
115         /**
116          * Getter for primary key or unique key if not set
117          *
118          * @return      $primaryKey             Primary key or unique key if not set
119          */
120         public final function getPrimaryKey () {
121                 // Get primary key by default
122                 $primaryKey = $this->primaryKey;
123
124                 if (empty($primaryKey)) {
125                         // Get uniqueKey
126                         $primaryKey = $this->getUniqueKey();
127                 } // END - if
128
129                 // Return it
130                 return $primaryKey;
131         }
132
133         /**
134          * Setter for primary key
135          *
136          * @param       $primaryKey             Primary key to set
137          * @return      void
138          */
139         public final function setPrimaryKey ($primaryKey) {
140                 $this->primaryKey = (string) $primaryKey;
141         }
142 }
143
144 // [EOF]
145 ?>