source: pro-bachkim-filespace/sourcecode/api.violet.vn/www/lib/model/om/BaseTblspacefile.php @ 275

Last change on this file since 275 was 19, checked in by dungnv, 11 years ago
File size: 14.0 KB
Line 
1<?php
2
3
4abstract class BaseTblspacefile extends BaseObject  implements Persistent {
5
6
7       
8        protected static $peer;
9
10       
11        protected $file_id;
12
13       
14        protected $file_resource;
15
16       
17        protected $file_category;
18
19       
20        protected $file_user;
21
22       
23        protected $file_name;
24
25       
26        protected $file_type;
27
28       
29        protected $file_date;
30
31       
32        protected $aTblspaceresource;
33
34       
35        protected $alreadyInSave = false;
36
37       
38        protected $alreadyInValidation = false;
39
40       
41        public function __construct()
42        {
43                parent::__construct();
44                $this->applyDefaultValues();
45        }
46
47       
48        public function applyDefaultValues()
49        {
50        }
51
52       
53        public function getFileId()
54        {
55                return $this->file_id;
56        }
57
58       
59        public function getFileResource()
60        {
61                return $this->file_resource;
62        }
63
64       
65        public function getFileCategory()
66        {
67                return $this->file_category;
68        }
69
70       
71        public function getFileUser()
72        {
73                return $this->file_user;
74        }
75
76       
77        public function getFileName()
78        {
79                return $this->file_name;
80        }
81
82       
83        public function getFileType()
84        {
85                return $this->file_type;
86        }
87
88       
89        public function getFileDate($format = 'Y-m-d H:i:s')
90        {
91                if ($this->file_date === null) {
92                        return null;
93                }
94
95
96                if ($this->file_date === '0000-00-00 00:00:00') {
97                                                                        return null;
98                } else {
99                        try {
100                                $dt = new DateTime($this->file_date);
101                        } catch (Exception $x) {
102                                throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->file_date, true), $x);
103                        }
104                }
105
106                if ($format === null) {
107                                                return $dt;
108                } elseif (strpos($format, '%') !== false) {
109                        return strftime($format, $dt->format('U'));
110                } else {
111                        return $dt->format($format);
112                }
113        }
114
115       
116        public function setFileId($v)
117        {
118                if ($v !== null) {
119                        $v = (int) $v;
120                }
121
122                if ($this->file_id !== $v) {
123                        $this->file_id = $v;
124                        $this->modifiedColumns[] = TblspacefilePeer::FILE_ID;
125                }
126
127                return $this;
128        }
129       
130        public function setFileResource($v)
131        {
132                if ($v !== null) {
133                        $v = (int) $v;
134                }
135
136                if ($this->file_resource !== $v) {
137                        $this->file_resource = $v;
138                        $this->modifiedColumns[] = TblspacefilePeer::FILE_RESOURCE;
139                }
140
141                if ($this->aTblspaceresource !== null && $this->aTblspaceresource->getResId() !== $v) {
142                        $this->aTblspaceresource = null;
143                }
144
145                return $this;
146        }
147       
148        public function setFileCategory($v)
149        {
150                if ($v !== null) {
151                        $v = (int) $v;
152                }
153
154                if ($this->file_category !== $v) {
155                        $this->file_category = $v;
156                        $this->modifiedColumns[] = TblspacefilePeer::FILE_CATEGORY;
157                }
158
159                return $this;
160        }
161       
162        public function setFileUser($v)
163        {
164                if ($v !== null) {
165                        $v = (int) $v;
166                }
167
168                if ($this->file_user !== $v) {
169                        $this->file_user = $v;
170                        $this->modifiedColumns[] = TblspacefilePeer::FILE_USER;
171                }
172
173                return $this;
174        }
175       
176        public function setFileName($v)
177        {
178                if ($v !== null) {
179                        $v = (string) $v;
180                }
181
182                if ($this->file_name !== $v) {
183                        $this->file_name = $v;
184                        $this->modifiedColumns[] = TblspacefilePeer::FILE_NAME;
185                }
186
187                return $this;
188        }
189       
190        public function setFileType($v)
191        {
192                if ($v !== null) {
193                        $v = (string) $v;
194                }
195
196                if ($this->file_type !== $v) {
197                        $this->file_type = $v;
198                        $this->modifiedColumns[] = TblspacefilePeer::FILE_TYPE;
199                }
200
201                return $this;
202        }
203       
204        public function setFileDate($v)
205        {
206                                                if ($v === null || $v === '') {
207                        $dt = null;
208                } elseif ($v instanceof DateTime) {
209                        $dt = $v;
210                } else {
211                                                                        try {
212                                if (is_numeric($v)) {                                   $dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
213                                                                                                                        $dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
214                                } else {
215                                        $dt = new DateTime($v);
216                                }
217                        } catch (Exception $x) {
218                                throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
219                        }
220                }
221
222                if ( $this->file_date !== null || $dt !== null ) {
223                       
224                        $currNorm = ($this->file_date !== null && $tmpDt = new DateTime($this->file_date)) ? $tmpDt->format('Y-m-d H:i:s') : null;
225                        $newNorm = ($dt !== null) ? $dt->format('Y-m-d H:i:s') : null;
226
227                        if ( ($currNorm !== $newNorm)                                   )
228                        {
229                                $this->file_date = ($dt ? $dt->format('Y-m-d H:i:s') : null);
230                                $this->modifiedColumns[] = TblspacefilePeer::FILE_DATE;
231                        }
232                }
233                return $this;
234        }
235       
236        public function hasOnlyDefaultValues()
237        {
238                                                if (array_diff($this->modifiedColumns, array())) {
239                                return false;
240                        }
241
242                                return true;
243        }
244       
245        public function hydrate($row, $startcol = 0, $rehydrate = false)
246        {
247                try {
248
249                        $this->file_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
250                        $this->file_resource = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
251                        $this->file_category = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
252                        $this->file_user = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null;
253                        $this->file_name = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
254                        $this->file_type = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
255                        $this->file_date = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
256                        $this->resetModified();
257
258                        $this->setNew(false);
259
260                        if ($rehydrate) {
261                                $this->ensureConsistency();
262                        }
263
264                                                return $startcol + 7;
265                } catch (Exception $e) {
266                        throw new PropelException("Error populating Tblspacefile object", $e);
267                }
268        }
269
270       
271        public function ensureConsistency()
272        {
273
274                if ($this->aTblspaceresource !== null && $this->file_resource !== $this->aTblspaceresource->getResId()) {
275                        $this->aTblspaceresource = null;
276                }
277        }
278       
279        public function reload($deep = false, PropelPDO $con = null)
280        {
281                if ($this->isDeleted()) {
282                        throw new PropelException("Cannot reload a deleted object.");
283                }
284
285                if ($this->isNew()) {
286                        throw new PropelException("Cannot reload an unsaved object.");
287                }
288
289                if ($con === null) {
290                        $con = Propel::getConnection(TblspacefilePeer::DATABASE_NAME, Propel::CONNECTION_READ);
291                }
292
293                               
294                $stmt = TblspacefilePeer::doSelectStmt($this->buildPkeyCriteria(), $con);
295                $row = $stmt->fetch(PDO::FETCH_NUM);
296                $stmt->closeCursor();
297                if (!$row) {
298                        throw new PropelException('Cannot find matching row in the database to reload object values.');
299                }
300                $this->hydrate($row, 0, true);
301                if ($deep) { 
302                        $this->aTblspaceresource = null;
303                }       }
304
305       
306        public function delete(PropelPDO $con = null)
307        {
308                if ($this->isDeleted()) {
309                        throw new PropelException("This object has already been deleted.");
310                }
311
312                if ($con === null) {
313                        $con = Propel::getConnection(TblspacefilePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
314                }
315               
316                $con->beginTransaction();
317                try {
318                        TblspacefilePeer::doDelete($this, $con);
319                        $this->setDeleted(true);
320                        $con->commit();
321                } catch (PropelException $e) {
322                        $con->rollBack();
323                        throw $e;
324                }
325        }
326
327       
328        public function save(PropelPDO $con = null)
329        {
330                if ($this->isDeleted()) {
331                        throw new PropelException("You cannot save an object that has been deleted.");
332                }
333
334                if ($con === null) {
335                        $con = Propel::getConnection(TblspacefilePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
336                }
337               
338                $con->beginTransaction();
339                try {
340                        $affectedRows = $this->doSave($con);
341                        $con->commit();
342                        TblspacefilePeer::addInstanceToPool($this);
343                        return $affectedRows;
344                } catch (PropelException $e) {
345                        $con->rollBack();
346                        throw $e;
347                }
348        }
349
350       
351        protected function doSave(PropelPDO $con)
352        {
353                $affectedRows = 0;              if (!$this->alreadyInSave) {
354                        $this->alreadyInSave = true;
355
356                                                                                               
357                        if ($this->aTblspaceresource !== null) {
358                                if ($this->aTblspaceresource->isModified() || $this->aTblspaceresource->isNew()) {
359                                        $affectedRows += $this->aTblspaceresource->save($con);
360                                }
361                                $this->setTblspaceresource($this->aTblspaceresource);
362                        }
363
364                        if ($this->isNew() ) {
365                                $this->modifiedColumns[] = TblspacefilePeer::FILE_ID;
366                        }
367
368                                                if ($this->isModified()) {
369                                if ($this->isNew()) {
370                                        $pk = TblspacefilePeer::doInsert($this, $con);
371                                        $affectedRows += 1;                                                                                                                                                             
372                                        $this->setFileId($pk); 
373                                        $this->setNew(false);
374                                } else {
375                                        $affectedRows += TblspacefilePeer::doUpdate($this, $con);
376                                }
377
378                                $this->resetModified();                         }
379
380                        $this->alreadyInSave = false;
381
382                }
383                return $affectedRows;
384        }
385       
386        protected $validationFailures = array();
387
388       
389        public function getValidationFailures()
390        {
391                return $this->validationFailures;
392        }
393
394       
395        public function validate($columns = null)
396        {
397                $res = $this->doValidate($columns);
398                if ($res === true) {
399                        $this->validationFailures = array();
400                        return true;
401                } else {
402                        $this->validationFailures = $res;
403                        return false;
404                }
405        }
406
407       
408        protected function doValidate($columns = null)
409        {
410                if (!$this->alreadyInValidation) {
411                        $this->alreadyInValidation = true;
412                        $retval = null;
413
414                        $failureMap = array();
415
416
417                                                                                               
418                        if ($this->aTblspaceresource !== null) {
419                                if (!$this->aTblspaceresource->validate($columns)) {
420                                        $failureMap = array_merge($failureMap, $this->aTblspaceresource->getValidationFailures());
421                                }
422                        }
423
424
425                        if (($retval = TblspacefilePeer::doValidate($this, $columns)) !== true) {
426                                $failureMap = array_merge($failureMap, $retval);
427                        }
428
429
430
431                        $this->alreadyInValidation = false;
432                }
433
434                return (!empty($failureMap) ? $failureMap : true);
435        }
436
437       
438        public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
439        {
440                $pos = TblspacefilePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
441                $field = $this->getByPosition($pos);
442                return $field;
443        }
444
445       
446        public function getByPosition($pos)
447        {
448                switch($pos) {
449                        case 0:
450                                return $this->getFileId();
451                                break;
452                        case 1:
453                                return $this->getFileResource();
454                                break;
455                        case 2:
456                                return $this->getFileCategory();
457                                break;
458                        case 3:
459                                return $this->getFileUser();
460                                break;
461                        case 4:
462                                return $this->getFileName();
463                                break;
464                        case 5:
465                                return $this->getFileType();
466                                break;
467                        case 6:
468                                return $this->getFileDate();
469                                break;
470                        default:
471                                return null;
472                                break;
473                }       }
474
475       
476        public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
477        {
478                $keys = TblspacefilePeer::getFieldNames($keyType);
479                $result = array(
480                        $keys[0] => $this->getFileId(),
481                        $keys[1] => $this->getFileResource(),
482                        $keys[2] => $this->getFileCategory(),
483                        $keys[3] => $this->getFileUser(),
484                        $keys[4] => $this->getFileName(),
485                        $keys[5] => $this->getFileType(),
486                        $keys[6] => $this->getFileDate(),
487                );
488                return $result;
489        }
490
491       
492        public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
493        {
494                $pos = TblspacefilePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
495                return $this->setByPosition($pos, $value);
496        }
497
498       
499        public function setByPosition($pos, $value)
500        {
501                switch($pos) {
502                        case 0:
503                                $this->setFileId($value);
504                                break;
505                        case 1:
506                                $this->setFileResource($value);
507                                break;
508                        case 2:
509                                $this->setFileCategory($value);
510                                break;
511                        case 3:
512                                $this->setFileUser($value);
513                                break;
514                        case 4:
515                                $this->setFileName($value);
516                                break;
517                        case 5:
518                                $this->setFileType($value);
519                                break;
520                        case 6:
521                                $this->setFileDate($value);
522                                break;
523                }       }
524
525       
526        public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
527        {
528                $keys = TblspacefilePeer::getFieldNames($keyType);
529
530                if (array_key_exists($keys[0], $arr)) $this->setFileId($arr[$keys[0]]);
531                if (array_key_exists($keys[1], $arr)) $this->setFileResource($arr[$keys[1]]);
532                if (array_key_exists($keys[2], $arr)) $this->setFileCategory($arr[$keys[2]]);
533                if (array_key_exists($keys[3], $arr)) $this->setFileUser($arr[$keys[3]]);
534                if (array_key_exists($keys[4], $arr)) $this->setFileName($arr[$keys[4]]);
535                if (array_key_exists($keys[5], $arr)) $this->setFileType($arr[$keys[5]]);
536                if (array_key_exists($keys[6], $arr)) $this->setFileDate($arr[$keys[6]]);
537        }
538
539       
540        public function buildCriteria()
541        {
542                $criteria = new Criteria(TblspacefilePeer::DATABASE_NAME);
543
544                if ($this->isColumnModified(TblspacefilePeer::FILE_ID)) $criteria->add(TblspacefilePeer::FILE_ID, $this->file_id);
545                if ($this->isColumnModified(TblspacefilePeer::FILE_RESOURCE)) $criteria->add(TblspacefilePeer::FILE_RESOURCE, $this->file_resource);
546                if ($this->isColumnModified(TblspacefilePeer::FILE_CATEGORY)) $criteria->add(TblspacefilePeer::FILE_CATEGORY, $this->file_category);
547                if ($this->isColumnModified(TblspacefilePeer::FILE_USER)) $criteria->add(TblspacefilePeer::FILE_USER, $this->file_user);
548                if ($this->isColumnModified(TblspacefilePeer::FILE_NAME)) $criteria->add(TblspacefilePeer::FILE_NAME, $this->file_name);
549                if ($this->isColumnModified(TblspacefilePeer::FILE_TYPE)) $criteria->add(TblspacefilePeer::FILE_TYPE, $this->file_type);
550                if ($this->isColumnModified(TblspacefilePeer::FILE_DATE)) $criteria->add(TblspacefilePeer::FILE_DATE, $this->file_date);
551
552                return $criteria;
553        }
554
555       
556        public function buildPkeyCriteria()
557        {
558                $criteria = new Criteria(TblspacefilePeer::DATABASE_NAME);
559
560                $criteria->add(TblspacefilePeer::FILE_ID, $this->file_id);
561
562                return $criteria;
563        }
564
565       
566        public function getPrimaryKey()
567        {
568                return $this->getFileId();
569        }
570
571       
572        public function setPrimaryKey($key)
573        {
574                $this->setFileId($key);
575        }
576
577       
578        public function copyInto($copyObj, $deepCopy = false)
579        {
580
581                $copyObj->setFileResource($this->file_resource);
582
583                $copyObj->setFileCategory($this->file_category);
584
585                $copyObj->setFileUser($this->file_user);
586
587                $copyObj->setFileName($this->file_name);
588
589                $copyObj->setFileType($this->file_type);
590
591                $copyObj->setFileDate($this->file_date);
592
593
594                $copyObj->setNew(true);
595
596                $copyObj->setFileId(NULL);
597        }
598
599       
600        public function copy($deepCopy = false)
601        {
602                                $clazz = get_class($this);
603                $copyObj = new $clazz();
604                $this->copyInto($copyObj, $deepCopy);
605                return $copyObj;
606        }
607
608       
609        public function getPeer()
610        {
611                if (self::$peer === null) {
612                        self::$peer = new TblspacefilePeer();
613                }
614                return self::$peer;
615        }
616
617       
618        public function setTblspaceresource(Tblspaceresource $v = null)
619        {
620                if ($v === null) {
621                        $this->setFileResource(NULL);
622                } else {
623                        $this->setFileResource($v->getResId());
624                }
625
626                $this->aTblspaceresource = $v;
627
628                                                if ($v !== null) {
629                        $v->addTblspacefile($this);
630                }
631
632                return $this;
633        }
634
635
636       
637        public function getTblspaceresource(PropelPDO $con = null)
638        {
639                if ($this->aTblspaceresource === null && ($this->file_resource !== null)) {
640                        $this->aTblspaceresource = TblspaceresourcePeer::retrieveByPK($this->file_resource, $con);
641                       
642                }
643                return $this->aTblspaceresource;
644        }
645
646       
647        public function clearAllReferences($deep = false)
648        {
649                if ($deep) {
650                }
651                        $this->aTblspaceresource = null;
652        }
653
654}
Note: See TracBrowser for help on using the repository browser.