source: pro-bachkim-filespace/sourcecode/api.violet.vn/www/plugins/sfPropel13Plugin/lib/vendor/propel/map/ColumnMap.php

Last change on this file was 19, checked in by dungnv, 11 years ago
File size: 10.1 KB
Line 
1<?php
2
3/*
4 *  $Id: ColumnMap.php 784 2007-11-08 10:15:50Z heltem $
5 *
6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 *
18 * This software consists of voluntary contributions made by many individuals
19 * and is licensed under the LGPL. For more information please see
20 * <http://propel.phpdb.org>.
21 */
22
23/**
24 * ColumnMap is used to model a column of a table in a database.
25 *
26 * GENERAL NOTE
27 * ------------
28 * The propel.map classes are abstract building-block classes for modeling
29 * the database at runtime.  These classes are similar (a lite version) to the
30 * propel.engine.database.model classes, which are build-time modeling classes.
31 * These classes in themselves do not do any database metadata lookups, but instead
32 * are used by the MapBuilder classes that were generated for your datamodel. The
33 * MapBuilder that was created for your datamodel build a representation of your
34 * database by creating instances of the DatabaseMap, TableMap, ColumnMap, etc.
35 * classes. See propel/templates/om/php5/MapBuilder.tpl and the classes generated
36 * by that template for your datamodel to further understand how these are put
37 * together.
38 *
39 * @author     Hans Lellelid <hans@xmpl.org> (Propel)
40 * @author     John D. McNally <jmcnally@collab.net> (Torque)
41 * @version    $Revision: 784 $
42 * @package    propel.map
43 */
44class ColumnMap {
45
46        /** @var        string Propel type of the column. */
47        private $type;
48
49        /** Size of the column. */
50        private $size = 0;
51
52        /** Is it a primary key? */
53        private $pk = false;
54
55        /** Is null value allowed ?*/
56        private $notNull = false;
57
58        /** The default value for this column. */
59        private $defaultValue;
60
61        /** Name of the table that this column is related to. */
62        private $relatedTableName = "";
63
64        /** Name of the column that this column is related to. */
65        private $relatedColumnName = "";
66
67        /** The TableMap for this column. */
68        private $table;
69
70        /** The name of the column. */
71        private $columnName;
72
73        /** The php name of the column. */
74        private $phpName;
75
76        /** validators for this column */
77        private $validators = array();
78
79        /**
80         * Constructor.
81         *
82         * @param      string $name The name of the column.
83         * @param      TableMap containingTable TableMap of the table this column is in.
84         */
85        public function __construct($name, TableMap $containingTable)
86        {
87                $this->columnName = $name;
88                $this->table = $containingTable;
89        }
90
91        /**
92         * Gets column name (DEPRECATED).
93         * @return     string
94         * @deprecated Use getName() instead.
95         */
96        public function getColumnName()
97        {
98                return $this->getName();
99        }
100
101        /**
102         * Get the name of a column.
103         *
104         * @return     string A String with the column name.
105         */
106        public function getName()
107        {
108                return $this->columnName;
109        }
110
111        /**
112         * Get the name of a column.
113         *
114         * @return     string A String with the column name.
115         */
116        public function getPhpName()
117        {
118                return $this->phpName;
119        }
120
121        /**
122         * Set the php anme of this column.
123         *
124         * @param      string $phpName A string representing the PHP name.
125         * @return     void
126         */
127        public function setPhpName($phpName)
128        {
129                $this->phpName = $phpName;
130        }
131
132        /**
133         * Get the table name + column name.
134         *
135         * @return     string A String with the full column name.
136         */
137        public function getFullyQualifiedName()
138        {
139                return $this->table->getName() . "." . $this->columnName;
140        }
141
142        /**
143         * Get the table map this column belongs to.
144         * @return     TableMap
145         */
146        public function getTable()
147        {
148                return $this->table;
149        }
150
151        /**
152         * Get the name of the table this column is in.
153         *
154         * @return     string A String with the table name.
155         */
156        public function getTableName()
157        {
158                return $this->table->getName();
159        }
160
161        /**
162         * Get the Propel type of this column.
163         *
164         * @return     string A string representing the Propel type (e.g. PropelColumnTypes::DATE).
165         */
166        public function getType()
167        {
168                return $this->type;
169        }
170
171        /**
172         * Set the Propel type of this column.
173         *
174         * @param      string $type A string representing the Propel type (e.g. PropelColumnTypes::DATE).
175         * @return     void
176         */
177        public function setType($type)
178        {
179                $this->type = $type;
180        }
181
182        /**
183         * Get the PHP type of this column.
184         *
185         * @return     int The PDO::PARMA_* value
186         */
187         /*
188        public function getPhpType()
189        {
190                return PropelColumnTypes::getPhpType($this->type);
191        }
192        */
193        /**
194         * Get the PDO type of this column.
195         *
196         * @return     int The PDO::PARMA_* value
197         */
198        public function getPdoType()
199        {
200                return PropelColumnTypes::getPdoType($this->type);
201        }
202
203        /**
204         * Whether this is a BLOB, LONGVARBINARY, or VARBINARY.
205         * @return     boolean
206         */
207        public function isLob()
208        {
209                return ($this->type == PropelColumnTypes::BLOB || $this->type == PropelColumnTypes::VARBINARY || $this->type == PropelColumnTypes::LONGVARBINARY);
210        }
211
212        /**
213         * Whether this is a DATE/TIME/TIMESTAMP column that is post-epoch (1970).
214         *
215         * PHP cannot handle pre-epoch timestamps well -- hence the need to differentiate
216         * between epoch and pre-epoch timestamps.
217         *
218         * @return     boolean
219         * @deprecated Propel supports non-epoch dates
220         */
221        public function isEpochTemporal()
222        {
223                return ($this->type == PropelColumnTypes::TIMESTAMP || $this->type == PropelColumnTypes::DATE || $this->type == PropelColumnTypes::TIME);
224        }
225
226        /**
227         * Whether this column is numeric (int, decimal, bigint etc).
228         * @return     boolean
229         */
230        public function isNumeric()
231        {
232                return ($this->type == PropelColumnTypes::NUMERIC || $this->type == PropelColumnTypes::DECIMAL || $this->type == PropelColumnTypes::TINYINT || $this->type == PropelColumnTypes::SMALLINT || $this->type == PropelColumnTypes::INTEGER || $this->type == PropelColumnTypes::BIGINT || $this->type == PropelColumnTypes::REAL || $this->type == PropelColumnTypes::FLOAT || $this->type == PropelColumnTypes::DOUBLE);
233        }
234
235        /**
236         * Whether this is a DATE/TIME/TIMESTAMP column.
237         *
238         * @return     boolean
239         * @since      1.3
240         */
241        public function isTemporal()
242        {
243                return ($this->type == PropelColumnTypes::TIMESTAMP || $this->type == PropelColumnTypes::DATE || $this->type == PropelColumnTypes::TIME || $this->type == PropelColumnTypes::BU_DATE  || $this->type == PropelColumnTypes::BU_TIMESTAMP);
244        }
245
246        /**
247         * Whether this column is a text column (varchar, char, longvarchar).
248         * @return     boolean
249         */
250        public function isText()
251        {
252                return ($this->type == PropelColumnTypes::VARCHAR || $this->type == PropelColumnTypes::LONGVARCHAR || $this->type == PropelColumnTypes::CHAR);
253        }
254
255        /**
256         * Set the size of this column.
257         *
258         * @param      int $size An int specifying the size.
259         * @return     void
260         */
261        public function setSize($size)
262        {
263                $this->size = $size;
264        }
265
266        /**
267         * Set if this column is a primary key or not.
268         *
269         * @param      boolean $pk True if column is a primary key.
270         * @return     void
271         */
272        public function setPrimaryKey($pk)
273        {
274                $this->pk = $pk;
275        }
276
277        /**
278         * Set if this column may be null.
279         *
280         * @param      boolean nn True if column may be null.
281         * @return     void
282         */
283        public function setNotNull($nn)
284        {
285                $this->notNull = $nn;
286        }
287
288        /**
289         * Gets the default value for this column.
290         * @return     mixed String or NULL
291         */
292        public function getDefaultValue()
293        {
294                return $this->defaultValue;
295        }
296
297        /**
298         * Set the foreign key for this column.
299         *
300         * @param      string tableName The name of the table that is foreign.
301         * @param      string columnName The name of the column that is foreign.
302         * @return     void
303         */
304        public function setForeignKey($tableName, $columnName)
305        {
306                if ($tableName && $columnName) {
307                        $this->relatedTableName = $tableName;
308                        $this->relatedColumnName = $columnName;
309                } else {
310                        $this->relatedTableName = "";
311                        $this->relatedColumnName = "";
312                }
313        }
314
315        public function addValidator($validator)
316        {
317          $this->validators[] = $validator;
318        }
319
320        public function hasValidators()
321        {
322          return count($this->validators) > 0;
323        }
324
325        public function getValidators()
326        {
327          return $this->validators;
328        }
329
330        /**
331         * Get the size of this column.
332         *
333         * @return     int An int specifying the size.
334         */
335        public function getSize()
336        {
337                return $this->size;
338        }
339
340        /**
341         * Is this column a primary key?
342         *
343         * @return     boolean True if column is a primary key.
344         */
345        public function isPrimaryKey()
346        {
347                return $this->pk;
348        }
349
350        /**
351         * Is null value allowed ?
352         *
353         * @return     boolean True if column may not be null.
354         */
355        public function isNotNull()
356        {
357                return ($this->notNull || $this->isPrimaryKey());
358        }
359
360        /**
361         * Is this column a foreign key?
362         *
363         * @return     boolean True if column is a foreign key.
364         */
365        public function isForeignKey()
366        {
367                if ($this->relatedTableName) {
368                        return true;
369                } else {
370                        return false;
371                }
372        }
373
374        /**
375         * Get the table.column that this column is related to.
376         *
377         * @return     string A String with the full name for the related column.
378         */
379        public function getRelatedName()
380        {
381                return $this->relatedTableName . "." . $this->relatedColumnName;
382        }
383
384        /**
385         * Get the table name that this column is related to.
386         *
387         * @return     string A String with the name for the related table.
388         */
389        public function getRelatedTableName()
390        {
391                return $this->relatedTableName;
392        }
393
394        /**
395         * Get the column name that this column is related to.
396         *
397         * @return     string A String with the name for the related column.
398         */
399        public function getRelatedColumnName()
400        {
401                return $this->relatedColumnName;
402        }
403
404        /**
405         * Performs DB-specific ignore case, but only if the column type necessitates it.
406         * @param      string $str The expression we want to apply the ignore case formatting to (e.g. the column name).
407         * @param      DBAdapter $db
408         */
409        public function ignoreCase($str, DBAdapter $db)
410        {
411                if ($this->isText()) {
412                        return $db->ignoreCase($str);
413                } else {
414                        return $str;
415                }
416        }
417}
Note: See TracBrowser for help on using the repository browser.