root/trunk/lib/model/om/BaseSnippetUser.php

Revision 2, 41.3 kB (checked in by fabien, 6 years ago)

initial import

  • Property svn:mime-type set to text/x-php
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 require_once 'propel/om/BaseObject.php';
4
5 require_once 'propel/om/Persistent.php';
6
7
8 include_once 'propel/util/Criteria.php';
9
10 include_once 'model/SnippetUserPeer.php';
11
12 /**
13  * Base class that represents a row from the 'sn_user' table.
14  *
15  *
16  *
17  * @package model.om
18  */
19 abstract class BaseSnippetUser extends BaseObject  implements Persistent {
20
21
22     /**
23      * The Peer class.
24      * Instance provides a convenient way of calling static methods on a class
25      * that calling code may not be able to identify.
26      * @var SnippetUserPeer
27      */
28     protected static $peer;
29
30
31     /**
32      * The value for the id field.
33      * @var int
34      */
35     protected $id;
36
37
38     /**
39      * The value for the login field.
40      * @var string
41      */
42     protected $login;
43
44
45     /**
46      * The value for the password field.
47      * @var string
48      */
49     protected $password;
50
51
52     /**
53      * The value for the email field.
54      * @var string
55      */
56     protected $email;
57
58
59     /**
60      * The value for the first_name field.
61      * @var string
62      */
63     protected $first_name;
64
65
66     /**
67      * The value for the last_name field.
68      * @var string
69      */
70     protected $last_name;
71
72
73     /**
74      * The value for the is_admin field.
75      * @var boolean
76      */
77     protected $is_admin = false;
78
79
80     /**
81      * The value for the created_at field.
82      * @var int
83      */
84     protected $created_at;
85
86     /**
87      * Collection to store aggregation of collSnippetSnippets.
88      * @var array
89      */
90     protected $collSnippetSnippets;
91     
92     /**
93      * The criteria used to select the current contents of collSnippetSnippets.
94      * @var Criteria
95      */
96     private $lastSnippetSnippetCriteria = null;
97
98     /**
99      * Collection to store aggregation of collSnippetTags.
100      * @var array
101      */
102     protected $collSnippetTags;
103     
104     /**
105      * The criteria used to select the current contents of collSnippetTags.
106      * @var Criteria
107      */
108     private $lastSnippetTagCriteria = null;
109
110     /**
111      * Collection to store aggregation of collSnippetComments.
112      * @var array
113      */
114     protected $collSnippetComments;
115     
116     /**
117      * The criteria used to select the current contents of collSnippetComments.
118      * @var Criteria
119      */
120     private $lastSnippetCommentCriteria = null;
121
122     /**
123      * Collection to store aggregation of collSnippetVotes.
124      * @var array
125      */
126     protected $collSnippetVotes;
127     
128     /**
129      * The criteria used to select the current contents of collSnippetVotes.
130      * @var Criteria
131      */
132     private $lastSnippetVoteCriteria = null;
133
134     /**
135      * Flag to prevent endless save loop, if this object is referenced
136      * by another object which falls in this transaction.
137      * @var boolean
138      */
139     protected $alreadyInSave = false;
140
141     /**
142      * Flag to prevent endless validation loop, if this object is referenced
143      * by another object which falls in this transaction.
144      * @var boolean
145      */
146     protected $alreadyInValidation = false;
147
148     /**
149      * Get the [id] column value.
150      *
151      * @return int
152      */
153     public function getId()
154     {
155
156         return $this->id;
157     }
158
159     /**
160      * Get the [login] column value.
161      *
162      * @return string
163      */
164     public function getLogin()
165     {
166
167         return $this->login;
168     }
169
170     /**
171      * Get the [password] column value.
172      *
173      * @return string
174      */
175     public function getPassword()
176     {
177
178         return $this->password;
179     }
180
181     /**
182      * Get the [email] column value.
183      *
184      * @return string
185      */
186     public function getEmail()
187     {
188
189         return $this->email;
190     }
191
192     /**
193      * Get the [first_name] column value.
194      *
195      * @return string
196      */
197     public function getFirstName()
198     {
199
200         return $this->first_name;
201     }
202
203     /**
204      * Get the [last_name] column value.
205      *
206      * @return string
207      */
208     public function getLastName()
209     {
210
211         return $this->last_name;
212     }
213
214     /**
215      * Get the [is_admin] column value.
216      *
217      * @return boolean
218      */
219     public function getIsAdmin()
220     {
221
222         return $this->is_admin;
223     }
224
225     /**
226      * Get the [optionally formatted] [created_at] column value.
227      *
228      * @param string $format The date/time format string (either date()-style or strftime()-style).
229      *                            If format is NULL, then the integer unix timestamp will be returned.
230      * @return mixed Formatted date/time value as string or integer unix timestamp (if format is NULL).
231      * @throws PropelException - if unable to convert the date/time to timestamp.
232      */
233     public function getCreatedAt($format = 'Y-m-d H:i:s')
234     {
235
236         if ($this->created_at === null || $this->created_at === '') {
237             return null;
238         } elseif (!is_int($this->created_at)) {
239             // a non-timestamp value was set externally, so we convert it
240             $ts = strtotime($this->created_at);
241             if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
242                 throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
243             }
244         } else {
245             $ts = $this->created_at;
246         }
247         if ($format === null) {
248             return $ts;
249         } elseif (strpos($format, '%') !== false) {
250             return strftime($format, $ts);
251         } else {
252             return date($format, $ts);
253         }
254     }
255
256     /**
257      * Set the value of [id] column.
258      *
259      * @param int $v new value
260      * @return void
261      */
262     public function setId($v)
263     {
264
265         if ($this->id !== $v) {
266             $this->id = $v;
267             $this->modifiedColumns[] = SnippetUserPeer::ID;
268         }
269
270     } // setId()
271
272     /**
273      * Set the value of [login] column.
274      *
275      * @param string $v new value
276      * @return void
277      */
278     public function setLogin($v)
279     {
280
281         if ($this->login !== $v) {
282             $this->login = $v;
283             $this->modifiedColumns[] = SnippetUserPeer::LOGIN;
284         }
285
286     } // setLogin()
287
288     /**
289      * Set the value of [password] column.
290      *
291      * @param string $v new value
292      * @return void
293      */
294     public function setPassword($v)
295     {
296
297         if ($this->password !== $v) {
298             $this->password = $v;
299             $this->modifiedColumns[] = SnippetUserPeer::PASSWORD;
300         }
301
302     } // setPassword()
303
304     /**
305      * Set the value of [email] column.
306      *
307      * @param string $v new value
308      * @return void
309      */
310     public function setEmail($v)
311     {
312
313         if ($this->email !== $v) {
314             $this->email = $v;
315             $this->modifiedColumns[] = SnippetUserPeer::EMAIL;
316         }
317
318     } // setEmail()
319
320     /**
321      * Set the value of [first_name] column.
322      *
323      * @param string $v new value
324      * @return void
325      */
326     public function setFirstName($v)
327     {
328
329         if ($this->first_name !== $v) {
330             $this->first_name = $v;
331             $this->modifiedColumns[] = SnippetUserPeer::FIRST_NAME;
332         }
333
334     } // setFirstName()
335
336     /**
337      * Set the value of [last_name] column.
338      *
339      * @param string $v new value
340      * @return void
341      */
342     public function setLastName($v)
343     {
344
345         if ($this->last_name !== $v) {
346             $this->last_name = $v;
347             $this->modifiedColumns[] = SnippetUserPeer::LAST_NAME;
348         }
349
350     } // setLastName()
351
352     /**
353      * Set the value of [is_admin] column.
354      *
355      * @param boolean $v new value
356      * @return void
357      */
358     public function setIsAdmin($v)
359     {
360
361         if ($this->is_admin !== $v || $v === false) {
362             $this->is_admin = $v;
363             $this->modifiedColumns[] = SnippetUserPeer::IS_ADMIN;
364         }
365
366     } // setIsAdmin()
367
368     /**
369      * Set the value of [created_at] column.
370      *
371      * @param int $v new value
372      * @return void
373      */
374     public function setCreatedAt($v)
375     {
376
377         if ($v !== null && !is_int($v)) {
378             $ts = strtotime($v);
379             if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
380                 throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
381             }
382         } else {
383             $ts = $v;
384         }
385         if ($this->created_at !== $ts) {
386             $this->created_at = $ts;
387             $this->modifiedColumns[] = SnippetUserPeer::CREATED_AT;
388         }
389
390     } // setCreatedAt()
391
392     /**
393      * Hydrates (populates) the object variables with values from the database resultset.
394      *
395      * An offset (1-based "start column") is specified so that objects can be hydrated
396      * with a subset of the columns in the resultset rows.  This is needed, for example,
397      * for results of JOIN queries where the resultset row includes columns from two or
398      * more tables.
399      *
400      * @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos.
401      * @param int $startcol 1-based offset column which indicates which restultset column to start with.
402      * @return int next starting column
403      * @throws PropelException  - Any caught Exception will be rewrapped as a PropelException.
404      */
405     public function hydrate(ResultSet $rs, $startcol = 1)
406     {
407         try {
408
409             $this->id = $rs->getInt($startcol + 0);
410
411             $this->login = $rs->getString($startcol + 1);
412
413             $this->password = $rs->getString($startcol + 2);
414
415             $this->email = $rs->getString($startcol + 3);
416
417             $this->first_name = $rs->getString($startcol + 4);
418
419             $this->last_name = $rs->getString($startcol + 5);
420
421             $this->is_admin = $rs->getBoolean($startcol + 6);
422
423             $this->created_at = $rs->getTimestamp($startcol + 7, null);
424
425             $this->resetModified();
426
427             $this->setNew(false);
428
429             // FIXME - using NUM_COLUMNS may be clearer.
430             return $startcol + 8; // 8 = SnippetUserPeer::NUM_COLUMNS - SnippetUserPeer::NUM_LAZY_LOAD_COLUMNS).
431
432         } catch (Exception $e) {
433             throw new PropelException("Error populating SnippetUser object", $e);
434         }
435     }
436
437     /**
438      * Removes this object from datastore and sets delete attribute.
439      *
440      * @param Connection $con
441      * @return void
442      * @throws PropelException
443      * @see BaseObject::setDeleted()
444      * @see BaseObject::isDeleted()
445      */
446     public function delete($con = null)
447     {
448         if ($this->isDeleted()) {
449             throw new PropelException("This object has already been deleted.");
450         }
451
452         if ($con === null) {
453             $con = Propel::getConnection(SnippetUserPeer::DATABASE_NAME);
454         }
455
456         try {
457             $con->begin();
458             SnippetUserPeer::doDelete($this, $con);
459             $this->setDeleted(true);
460             $con->commit();
461         } catch (PropelException $e) {
462             $con->rollback();
463             throw $e;
464         }
465     }
466
467     /**
468      * Stores the object in the database.  If the object is new,
469      * it inserts it; otherwise an update is performed.  This method
470      * wraps the doSave() worker method in a transaction.
471      *
472      * @param Connection $con
473      * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
474      * @throws PropelException
475      * @see doSave()
476      */
477     public function save($con = null)
478     {
479     if ($this->isNew() && !$this->isColumnModified('created_at'))
480     {
481       $this->setCreatedAt(time());
482     }
483
484         if ($this->isDeleted()) {
485             throw new PropelException("You cannot save an object that has been deleted.");
486         }
487
488         if ($con === null) {
489             $con = Propel::getConnection(SnippetUserPeer::DATABASE_NAME);
490         }
491         
492         try {
493             $con->begin();
494             $affectedRows = $this->doSave($con);
495             $con->commit();
496             return $affectedRows;
497         } catch (PropelException $e) {
498             $con->rollback();
499             throw $e;
500         }
501     }
502
503     /**
504      * Stores the object in the database.
505      *
506      * If the object is new, it inserts it; otherwise an update is performed.
507      * All related objects are also updated in this method.
508      *
509      * @param Connection $con
510      * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
511      * @throws PropelException
512      * @see save()
513      */
514     protected function doSave($con)
515     {
516         $affectedRows = 0; // initialize var to track total num of affected rows   
517         if (!$this->alreadyInSave) {
518             $this->alreadyInSave = true;
519     
520
521             // If this object has been modified, then save it to the database.
522             if ($this->isModified()) {
523                 if ($this->isNew()) {
524                     $pk = SnippetUserPeer::doInsert($this, $con);
525                     $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
526                                          // should always be true here (even though technically
527                                          // BasePeer::doInsert() can insert multiple rows).
528
529                     $this->setId($pk);  //[IMV] update autoincrement primary key
530
531                     $this->setNew(false);
532                 } else {
533                     $affectedRows += SnippetUserPeer::doUpdate($this, $con);
534                 }
535                 $this->resetModified(); // [HL] After being saved an object is no longer 'modified'
536             }
537
538             if ($this->collSnippetSnippets !== null) {
539                 foreach($this->collSnippetSnippets as $referrerFK) {
540                     if (!$referrerFK->isDeleted()) {
541                         $affectedRows += $referrerFK->save($con);
542                     }
543                 }
544             }
545
546             if ($this->collSnippetTags !== null) {
547                 foreach($this->collSnippetTags as $referrerFK) {
548                     if (!$referrerFK->isDeleted()) {
549                         $affectedRows += $referrerFK->save($con);
550                     }
551                 }
552             }
553
554             if ($this->collSnippetComments !== null) {
555                 foreach($this->collSnippetComments as $referrerFK) {
556                     if (!$referrerFK->isDeleted()) {
557                         $affectedRows += $referrerFK->save($con);
558                     }
559                 }
560             }
561
562             if ($this->collSnippetVotes !== null) {
563                 foreach($this->collSnippetVotes as $referrerFK) {
564                     if (!$referrerFK->isDeleted()) {
565                         $affectedRows += $referrerFK->save($con);
566                     }
567                 }
568             }
569
570             $this->alreadyInSave = false;
571         }
572         return $affectedRows;
573     } // doSave()
574
575     /**
576      * Array of ValidationFailed objects.
577      * @var array ValidationFailed[]
578      */
579     protected $validationFailures = array();
580
581     /**
582      * Gets any ValidationFailed objects that resulted from last call to validate().
583      *
584      *
585      * @return array ValidationFailed[]
586      * @see validate()
587      */
588     public function getValidationFailures()
589     {
590         return $this->validationFailures;
591     }
592
593     /**
594      * Validates the objects modified field values and all objects related to this table.
595      *
596      * If $columns is either a column name or an array of column names
597      * only those columns are validated.
598      *
599      * @param mixed $columns Column name or an array of column names.
600      * @return boolean Whether all columns pass validation.
601      * @see doValidate()
602      * @see getValidationFailures()
603      */
604     public function validate($columns = null)
605     {
606         $res = $this->doValidate($columns);
607         if ($res === true) {
608             $this->validationFailures = array();
609             return true;
610         } else {
611             $this->validationFailures = $res;
612             return false;
613         }
614     }
615
616     /**
617      * This function performs the validation work for complex object models.
618      *
619      * In addition to checking the current object, all related objects will
620      * also be validated.  If all pass then <code>true</code> is returned; otherwise
621      * an aggreagated array of ValidationFailed objects will be returned.
622      *
623      * @param array $columns Array of column names to validate.
624      * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
625      */
626     protected function doValidate($columns = null)
627     {
628         if (!$this->alreadyInValidation) {
629             $this->alreadyInValidation = true;
630             $retval = null;
631
632             $failureMap = array();
633
634
635             if (($retval = SnippetUserPeer::doValidate($this, $columns)) !== true) {
636                 $failureMap = array_merge($failureMap, $retval);
637             }
638
639
640                 if ($this->collSnippetSnippets !== null) {
641                     foreach($this->collSnippetSnippets as $referrerFK) {
642                         if (!$referrerFK->validate($columns)) {
643                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
644                         }
645                     }
646                 }
647
648                 if ($this->collSnippetTags !== null) {
649                     foreach($this->collSnippetTags as $referrerFK) {
650                         if (!$referrerFK->validate($columns)) {
651                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
652                         }
653                     }
654                 }
655
656                 if ($this->collSnippetComments !== null) {
657                     foreach($this->collSnippetComments as $referrerFK) {
658                         if (!$referrerFK->validate($columns)) {
659                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
660                         }
661                     }
662                 }
663
664                 if ($this->collSnippetVotes !== null) {
665                     foreach($this->collSnippetVotes as $referrerFK) {
666                         if (!$referrerFK->validate($columns)) {
667                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
668                         }
669                     }
670                 }
671
672
673             $this->alreadyInValidation = false;
674         }
675
676         return (!empty($failureMap) ? $failureMap : true);
677     }
678
679     /**
680      * Retrieves a field from the object by name passed in as a string.
681      *
682      * @param string $name name
683      * @param string $type The type of fieldname the $name is of:
684      *                     one of the class type constants TYPE_PHPNAME,
685      *                     TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
686      * @return mixed Value of field.
687      */
688     public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
689     {
690         $pos = SnippetUserPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
691         return $this->getByPosition($pos);
692     }
693
694     /**
695      * Retrieves a field from the object by Position as specified in the xml schema.
696      * Zero-based.
697      *
698      * @param int $pos position in xml schema
699      * @return mixed Value of field at $pos
700      */
701     public function getByPosition($pos)
702     {
703         switch($pos) {
704             case 0:
705                 return $this->getId();
706                 break;
707             case 1:
708                 return $this->getLogin();
709                 break;
710             case 2:
711                 return $this->getPassword();
712                 break;
713             case 3:
714                 return $this->getEmail();
715                 break;
716             case 4:
717                 return $this->getFirstName();
718                 break;
719             case 5:
720                 return $this->getLastName();
721                 break;
722             case 6:
723                 return $this->getIsAdmin();
724                 break;
725             case 7:
726                 return $this->getCreatedAt();
727                 break;
728             default:
729                 return null;
730                 break;
731         } // switch()
732     }
733
734     /**
735      * Exports the object as an array.
736      *
737      * You can specify the key type of the array by passing one of the class
738      * type constants.
739      *
740      * @param string $keyType One of the class type constants TYPE_PHPNAME,
741      *                        TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
742      * @return an associative array containing the field names (as keys) and field values
743      */
744     public function toArray($keyType = BasePeer::TYPE_PHPNAME)
745     {
746         $keys = SnippetUserPeer::getFieldNames($keyType);
747         $result = array(
748             $keys[0] => $this->getId(),
749             $keys[1] => $this->getLogin(),
750             $keys[2] => $this->getPassword(),
751             $keys[3] => $this->getEmail(),
752             $keys[4] => $this->getFirstName(),
753             $keys[5] => $this->getLastName(),
754             $keys[6] => $this->getIsAdmin(),
755             $keys[7] => $this->getCreatedAt(),
756         );
757         return $result;
758     }
759
760     /**
761      * Sets a field from the object by name passed in as a string.
762      *
763      * @param string $name peer name
764      * @param mixed $value field value
765      * @param string $type The type of fieldname the $name is of:
766      *                     one of the class type constants TYPE_PHPNAME,
767      *                     TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
768      * @return void
769      */
770     public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
771     {
772         $pos = SnippetUserPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
773         return $this->setByPosition($pos, $value);
774     }
775
776     /**
777      * Sets a field from the object by Position as specified in the xml schema.
778      * Zero-based.
779      *
780      * @param int $pos position in xml schema
781      * @param mixed $value field value
782      * @return void
783      */
784     public function setByPosition($pos, $value)
785     {
786         switch($pos) {
787             case 0:
788                 $this->setId($value);
789                 break;
790             case 1:
791                 $this->setLogin($value);
792                 break;
793             case 2:
794                 $this->setPassword($value);
795                 break;
796             case 3:
797                 $this->setEmail($value);
798                 break;
799             case 4:
800                 $this->setFirstName($value);
801                 break;
802             case 5:
803                 $this->setLastName($value);
804                 break;
805             case 6:
806                 $this->setIsAdmin($value);
807                 break;
808             case 7:
809                 $this->setCreatedAt($value);
810                 break;
811         } // switch()
812     }
813
814     /**
815      * Populates the object using an array.
816      *
817      * This is particularly useful when populating an object from one of the
818      * request arrays (e.g. $_POST).  This method goes through the column
819      * names, checking to see whether a matching key exists in populated
820      * array. If so the setByName() method is called for that column.
821      *
822      * You can specify the key type of the array by additionally passing one
823      * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
824      * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
825      *
826      * @param array  $arr     An array to populate the object from.
827      * @param string $keyType The type of keys the array uses.
828      * @return void
829      */
830     public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
831     {
832         $keys = SnippetUserPeer::getFieldNames($keyType);
833
834         if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
835         if (array_key_exists($keys[1], $arr)) $this->setLogin($arr[$keys[1]]);
836         if (array_key_exists($keys[2], $arr)) $this->setPassword($arr[$keys[2]]);
837         if (array_key_exists($keys[3], $arr)) $this->setEmail($arr[$keys[3]]);
838         if (array_key_exists($keys[4], $arr)) $this->setFirstName($arr[$keys[4]]);
839         if (array_key_exists($keys[5], $arr)) $this->setLastName($arr[$keys[5]]);
840         if (array_key_exists($keys[6], $arr)) $this->setIsAdmin($arr[$keys[6]]);
841         if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]);
842     }
843
844     /**
845      * Build a Criteria object containing the values of all modified columns in this object.
846      *
847      * @return Criteria The Criteria object containing all modified values.
848      */
849     public function buildCriteria()
850     {
851         $criteria = new Criteria(SnippetUserPeer::DATABASE_NAME);
852
853         if ($this->isColumnModified(SnippetUserPeer::ID)) $criteria->add(SnippetUserPeer::ID, $this->id);
854         if ($this->isColumnModified(SnippetUserPeer::LOGIN)) $criteria->add(SnippetUserPeer::LOGIN, $this->login);
855         if ($this->isColumnModified(SnippetUserPeer::PASSWORD)) $criteria->add(SnippetUserPeer::PASSWORD, $this->password);
856         if ($this->isColumnModified(SnippetUserPeer::EMAIL)) $criteria->add(SnippetUserPeer::EMAIL, $this->email);
857         if ($this->isColumnModified(SnippetUserPeer::FIRST_NAME)) $criteria->add(SnippetUserPeer::FIRST_NAME, $this->first_name);
858         if ($this->isColumnModified(SnippetUserPeer::LAST_NAME)) $criteria->add(SnippetUserPeer::LAST_NAME, $this->last_name);
859         if ($this->isColumnModified(SnippetUserPeer::IS_ADMIN)) $criteria->add(SnippetUserPeer::IS_ADMIN, $this->is_admin);
860         if ($this->isColumnModified(SnippetUserPeer::CREATED_AT)) $criteria->add(SnippetUserPeer::CREATED_AT, $this->created_at);
861
862         return $criteria;
863     }
864
865     /**
866      * Builds a Criteria object containing the primary key for this object.
867      *
868      * Unlike buildCriteria() this method includes the primary key values regardless
869      * of whether or not they have been modified.
870      *
871      * @return Criteria The Criteria object containing value(s) for primary key(s).
872      */
873     public function buildPkeyCriteria()
874     {
875         $criteria = new Criteria(SnippetUserPeer::DATABASE_NAME);
876
877         $criteria->add(SnippetUserPeer::ID, $this->id);
878
879         return $criteria;
880     }
881
882     /**
883      * Returns the primary key for this object (row).
884      * @return int
885      */
886     public function getPrimaryKey()
887     {
888         return $this->getId();
889     }
890
891     /**
892      * Generic method to set the primary key (id column).
893      *
894      * @param int $key Primary key.
895      * @return void
896      */
897     public function setPrimaryKey($key)
898     {
899         $this->setId($key);
900     }
901
902     /**
903      * Sets contents of passed object to values from current object.
904      *
905      * If desired, this method can also make copies of all associated (fkey referrers)
906      * objects.
907      *
908      * @param object $copyObj An object of SnippetUser (or compatible) type.
909      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
910      * @throws PropelException
911      */
912     public function copyInto($copyObj, $deepCopy = false)
913     {
914
915         $copyObj->setLogin($this->login);
916
917         $copyObj->setPassword($this->password);
918
919         $copyObj->setEmail($this->email);
920
921         $copyObj->setFirstName($this->first_name);
922
923         $copyObj->setLastName($this->last_name);
924
925         $copyObj->setIsAdmin($this->is_admin);
926
927         $copyObj->setCreatedAt($this->created_at);
928
929
930         if ($deepCopy) {
931             // important: temporarily setNew(false) because this affects the behavior of
932             // the getter/setter methods for fkey referrer objects.
933             $copyObj->setNew(false);
934
935             foreach($this->getSnippetSnippets() as $relObj) {
936                 if($copyObj instanceof self && $this->getPrimaryKey() === $relObj->getPrimaryKey()) {
937                     continue;
938                 }
939                 $copyObj->addSnippetSnippet($relObj->copy($deepCopy));
940             }
941
942             foreach($this->getSnippetTags() as $relObj) {
943                 if($copyObj instanceof self && $this->getPrimaryKey() === $relObj->getPrimaryKey()) {
944                     continue;
945                 }
946                 $copyObj->addSnippetTag($relObj->copy($deepCopy));
947             }
948
949             foreach($this->getSnippetComments() as $relObj) {
950                 if($copyObj instanceof self && $this->getPrimaryKey() === $relObj->getPrimaryKey()) {
951                     continue;
952                 }
953                 $copyObj->addSnippetComment($relObj->copy($deepCopy));
954             }
955
956             foreach($this->getSnippetVotes() as $relObj) {
957                 if($copyObj instanceof self && $this->getPrimaryKey() === $relObj->getPrimaryKey()) {
958                     continue;
959                 }
960                 $copyObj->addSnippetVote($relObj->copy($deepCopy));
961             }
962
963         } // if ($deepCopy)
964
965
966         $copyObj->setNew(true);
967
968         $copyObj->setId(NULL); // this is a pkey column, so set to default value
969
970     }
971
972     /**
973      * Makes a copy of this object that will be inserted as a new row in table when saved.
974      * It creates a new object filling in the simple attributes, but skipping any primary
975      * keys that are defined for the table.
976      *
977      * If desired, this method can also make copies of all associated (fkey referrers)
978      * objects.
979      *
980      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
981      * @return SnippetUser Clone of current object.
982      * @throws PropelException
983      */
984     public function copy($deepCopy = false)
985     {
986         // we use get_class(), because this might be a subclass
987         $clazz = get_class($this);
988         $copyObj = new $clazz();
989         $this->copyInto($copyObj, $deepCopy);
990         return $copyObj;
991     }
992
993     /**
994      * Returns a peer instance associated with this om.
995      *
996      * Since Peer classes are not to have any instance attributes, this method returns the
997      * same instance for all member of this class. The method could therefore
998      * be static, but this would prevent one from overriding the behavior.
999      *
1000      * @return SnippetUserPeer
1001      */
1002     public function getPeer()
1003     {
1004         if (self::$peer === null) {
1005             self::$peer = new SnippetUserPeer();
1006         }
1007         return self::$peer;
1008     }
1009
1010     /**
1011      * Temporary storage of collSnippetSnippets to save a possible db hit in
1012      * the event objects are add to the collection, but the
1013      * complete collection is never requested.
1014      * @return void
1015      */
1016     public function initSnippetSnippets()
1017     {
1018         if ($this->collSnippetSnippets === null) {
1019             $this->collSnippetSnippets = array();
1020         }
1021     }
1022
1023     /**
1024      * If this collection has already been initialized with
1025      * an identical criteria, it returns the collection.
1026      * Otherwise if this SnippetUser has previously
1027      * been saved, it will retrieve related SnippetSnippets from storage.
1028      * If this SnippetUser is new, it will return
1029      * an empty collection or the current collection, the criteria
1030      * is ignored on a new object.
1031      *
1032      * @param Connection $con
1033      * @param Criteria $criteria
1034      * @throws PropelException
1035      */
1036     public function getSnippetSnippets($criteria = null, $con = null)
1037     {
1038         // include the Peer class
1039         include_once 'model/om/BaseSnippetSnippetPeer.php';
1040         if ($criteria === null) {
1041             $criteria = new Criteria();
1042         }
1043         elseif ($criteria instanceof Criteria)
1044         {
1045             $criteria = clone $criteria;
1046         }
1047
1048         if ($this->collSnippetSnippets === null) {
1049             if ($this->isNew()) {
1050                $this->collSnippetSnippets = array();
1051             } else {
1052
1053                 $criteria->add(SnippetSnippetPeer::USER_ID, $this->getId());
1054
1055                 SnippetSnippetPeer::addSelectColumns($criteria);
1056                 $this->collSnippetSnippets = SnippetSnippetPeer::doSelect($criteria, $con);
1057             }
1058         } else {
1059             // criteria has no effect for a new object
1060             if (!$this->isNew()) {
1061                 // the following code is to determine if a new query is
1062                 // called for.  If the criteria is the same as the last
1063                 // one, just return the collection.
1064
1065
1066                 $criteria->add(SnippetSnippetPeer::USER_ID, $this->getId());
1067
1068                 SnippetSnippetPeer::addSelectColumns($criteria);
1069                 if (!isset($this->lastSnippetSnippetCriteria) || !$this->lastSnippetSnippetCriteria->equals($criteria)) {
1070                     $this->collSnippetSnippets = SnippetSnippetPeer::doSelect($criteria, $con);
1071                 }
1072             }
1073         }
1074         $this->lastSnippetSnippetCriteria = $criteria;
1075         return $this->collSnippetSnippets;
1076     }
1077
1078     /**
1079      * Returns the number of related SnippetSnippets.
1080      *
1081      * @param Criteria $criteria
1082      * @param boolean $distinct
1083      * @param Connection $con
1084      * @throws PropelException
1085      */
1086     public function countSnippetSnippets($criteria = null, $distinct = false, $con = null)
1087     {
1088         // include the Peer class
1089         include_once 'model/om/BaseSnippetSnippetPeer.php';
1090         if ($criteria === null) {
1091             $criteria = new Criteria();
1092         }
1093         elseif ($criteria instanceof Criteria)
1094         {
1095             $criteria = clone $criteria;
1096         }
1097
1098         $criteria->add(SnippetSnippetPeer::USER_ID, $this->getId());
1099
1100         return SnippetSnippetPeer::doCount($criteria, $distinct, $con);
1101     }
1102
1103     /**
1104      * Method called to associate a SnippetSnippet object to this object
1105      * through the SnippetSnippet foreign key attribute
1106      *
1107      * @param SnippetSnippet $l SnippetSnippet
1108      * @return void
1109      * @throws PropelException
1110      */
1111     public function addSnippetSnippet(SnippetSnippet $l)
1112     {
1113         $this->collSnippetSnippets[] = $l;
1114         $l->setSnippetUser($this);
1115     }
1116
1117     /**
1118      * Temporary storage of collSnippetTags to save a possible db hit in
1119      * the event objects are add to the collection, but the
1120      * complete collection is never requested.
1121      * @return void
1122      */
1123     public function initSnippetTags()
1124     {
1125         if ($this->collSnippetTags === null) {
1126             $this->collSnippetTags = array();
1127         }
1128     }
1129
1130     /**
1131      * If this collection has already been initialized with
1132      * an identical criteria, it returns the collection.
1133      * Otherwise if this SnippetUser has previously
1134      * been saved, it will retrieve related SnippetTags from storage.
1135      * If this SnippetUser is new, it will return
1136      * an empty collection or the current collection, the criteria
1137      * is ignored on a new object.
1138      *
1139      * @param Connection $con
1140      * @param Criteria $criteria
1141      * @throws PropelException
1142      */
1143     public function getSnippetTags($criteria = null, $con = null)
1144     {
1145         // include the Peer class
1146         include_once 'model/om/BaseSnippetTagPeer.php';
1147         if ($criteria === null) {
1148             $criteria = new Criteria();
1149         }
1150         elseif ($criteria instanceof Criteria)
1151         {
1152             $criteria = clone $criteria;
1153         }
1154
1155         if ($this->collSnippetTags === null) {
1156             if ($this->isNew()) {
1157                $this->collSnippetTags = array();
1158             } else {
1159
1160                 $criteria->add(SnippetTagPeer::USER_ID, $this->getId());
1161
1162                 SnippetTagPeer::addSelectColumns($criteria);
1163                 $this->collSnippetTags = SnippetTagPeer::doSelect($criteria, $con);
1164             }
1165         } else {
1166             // criteria has no effect for a new object
1167             if (!$this->isNew()) {
1168                 // the following code is to determine if a new query is
1169                 // called for.  If the criteria is the same as the last
1170                 // one, just return the collection.
1171
1172
1173                 $criteria->add(SnippetTagPeer::USER_ID, $this->getId());
1174
1175                 SnippetTagPeer::addSelectColumns($criteria);
1176                 if (!isset($this->lastSnippetTagCriteria) || !$this->lastSnippetTagCriteria->equals($criteria)) {
1177                     $this->collSnippetTags = SnippetTagPeer::doSelect($criteria, $con);
1178                 }
1179             }
1180         }
1181         $this->lastSnippetTagCriteria = $criteria;
1182         return $this->collSnippetTags;
1183     }
1184
1185     /**
1186      * Returns the number of related SnippetTags.
1187      *
1188      * @param Criteria $criteria
1189      * @param boolean $distinct
1190      * @param Connection $con
1191      * @throws PropelException
1192      */
1193     public function countSnippetTags($criteria = null, $distinct = false, $con = null)
1194     {
1195         // include the Peer class
1196         include_once 'model/om/BaseSnippetTagPeer.php';
1197         if ($criteria === null) {
1198             $criteria = new Criteria();
1199         }
1200         elseif ($criteria instanceof Criteria)
1201         {
1202             $criteria = clone $criteria;
1203         }
1204
1205         $criteria->add(SnippetTagPeer::USER_ID, $this->getId());
1206
1207         return SnippetTagPeer::doCount($criteria, $distinct, $con);
1208     }
1209
1210     /**
1211      * Method called to associate a SnippetTag object to this object
1212      * through the SnippetTag foreign key attribute
1213      *
1214      * @param SnippetTag $l SnippetTag
1215      * @return void
1216      * @throws PropelException
1217      */
1218     public function addSnippetTag(SnippetTag $l)
1219     {
1220         $this->collSnippetTags[] = $l;
1221         $l->setSnippetUser($this);
1222     }
1223
1224
1225     /**
1226      * If this collection has already been initialized with
1227      * an identical criteria, it returns the collection.
1228      * Otherwise if this SnippetUser is new, it will return
1229      * an empty collection; or if this SnippetUser has previously
1230      * been saved, it will retrieve related SnippetTags from storage.
1231      *
1232      * This method is protected by default in order to keep the public
1233      * api reasonable.  You can provide public methods for those you
1234      * actually need in SnippetUser.
1235      */
1236     public function getSnippetTagsJoinSnippetSnippet($criteria = null, $con = null)
1237     {
1238         // include the Peer class
1239         include_once 'model/om/BaseSnippetTagPeer.php';
1240         if ($criteria === null) {
1241             $criteria = new Criteria();
1242         }
1243         elseif ($criteria instanceof Criteria)
1244         {
1245             $criteria = clone $criteria;
1246         }
1247
1248         if ($this->collSnippetTags === null) {
1249             if ($this->isNew()) {
1250                 $this->collSnippetTags = array();
1251             } else {
1252
1253                 $criteria->add(SnippetTagPeer::USER_ID, $this->getId());
1254
1255                 $this->collSnippetTags = SnippetTagPeer::doSelectJoinSnippetSnippet($criteria, $con);
1256             }
1257         } else {
1258             // the following code is to determine if a new query is
1259             // called for.  If the criteria is the same as the last
1260             // one, just return the collection.
1261
1262             $criteria->add(SnippetTagPeer::USER_ID, $this->getId());
1263
1264             if (!isset($this->lastSnippetTagCriteria) || !$this->lastSnippetTagCriteria->equals($criteria)) {
1265                 $this->collSnippetTags = SnippetTagPeer::doSelectJoinSnippetSnippet($criteria, $con);
1266             }
1267         }
1268         $this->lastSnippetTagCriteria = $criteria;
1269
1270         return $this->collSnippetTags;
1271     }
1272
1273     /**
1274      * Temporary storage of collSnippetComments to save a possible db hit in
1275      * the event objects are add to the collection, but the
1276      * complete collection is never requested.
1277      * @return void
1278      */
1279     public function initSnippetComments()
1280     {
1281         if ($this->collSnippetComments === null) {
1282             $this->collSnippetComments = array();
1283         }
1284     }
1285
1286     /**
1287      * If this collection has already been initialized with
1288      * an identical criteria, it returns the collection.
1289      * Otherwise if this SnippetUser has previously
1290      * been saved, it will retrieve related SnippetComments from storage.
1291      * If this SnippetUser is new, it will return
1292      * an empty collection or the current collection, the criteria
1293      * is ignored on a new object.
1294      *
1295      * @param Connection $con
1296      * @param Criteria $criteria
1297      * @throws PropelException
1298      */
1299     public function getSnippetComments($criteria = null, $con = null)
1300     {
1301         // include the Peer class
1302         include_once 'model/om/BaseSnippetCommentPeer.php';
1303         if ($criteria === null) {
1304             $criteria = new Criteria();
1305         }
1306         elseif ($criteria instanceof Criteria)
1307         {
1308             $criteria = clone $criteria;
1309         }
1310
1311         if ($this->collSnippetComments === null) {
1312             if ($this->isNew()) {
1313                $this->collSnippetComments = array();
1314             } else {
1315
1316                 $criteria->add(SnippetCommentPeer::USER_ID, $this->getId());
1317
1318                 SnippetCommentPeer::addSelectColumns($criteria);
1319                 $this->collSnippetComments = SnippetCommentPeer::doSelect($criteria, $con);
1320             }
1321         } else {
1322             // criteria has no effect for a new object
1323             if (!$this->isNew()) {
1324                 // the following code is to determine if a new query is
1325                 // called for.  If the criteria is the same as the last
1326                 // one, just return the collection.
1327
1328
1329                 $criteria->add(SnippetCommentPeer::USER_ID, $this->getId());
1330
1331                 SnippetCommentPeer::addSelectColumns($criteria);
1332                 if (!isset($this->lastSnippetCommentCriteria) || !$this->lastSnippetCommentCriteria->equals($criteria)) {
1333                     $this->collSnippetComments = SnippetCommentPeer::doSelect($criteria, $con);
1334                 }
1335             }
1336         }
1337         $this->lastSnippetCommentCriteria = $criteria;
1338         return $this->collSnippetComments;
1339     }
1340
1341     /**
1342      * Returns the number of related SnippetComments.
1343      *
1344      * @param Criteria $criteria
1345      * @param boolean $distinct
1346      * @param Connection $con
1347      * @throws PropelException
1348      */
1349     public function countSnippetComments($criteria = null, $distinct = false, $con = null)
1350     {
1351         // include the Peer class
1352         include_once 'model/om/BaseSnippetCommentPeer.php';
1353         if ($criteria === null) {
1354             $criteria = new Criteria();
1355         }
1356         elseif ($criteria instanceof Criteria)
1357         {
1358             $criteria = clone $criteria;
1359         }
1360
1361         $criteria->add(SnippetCommentPeer::USER_ID, $this->getId());
1362
1363         return SnippetCommentPeer::doCount($criteria, $distinct, $con);
1364     }
1365
1366     /**
1367      * Method called to associate a SnippetComment object to this object
1368      * through the SnippetComment foreign key attribute
1369      *
1370      * @param SnippetComment $l SnippetComment
1371      * @return void
1372      * @throws PropelException
1373      */
1374     public function addSnippetComment(SnippetComment $l)
1375     {
1376         $this->collSnippetComments[] = $l;
1377         $l->setSnippetUser($this);
1378     }
1379
1380
1381     /**
1382      * If this collection has already been initialized with
1383      * an identical criteria, it returns the collection.
1384      * Otherwise if this SnippetUser is new, it will return
1385      * an empty collection; or if this SnippetUser has previously
1386      * been saved, it will retrieve related SnippetComments from storage.
1387      *
1388      * This method is protected by default in order to keep the public
1389      * api reasonable.  You can provide public methods for those you
1390      * actually need in SnippetUser.
1391      */
1392     public function getSnippetCommentsJoinSnippetSnippet($criteria = null, $con = null)
1393     {
1394         // include the Peer class
1395         include_once 'model/om/BaseSnippetCommentPeer.php';
1396         if ($criteria === null) {
1397             $criteria = new Criteria();
1398         }
1399         elseif ($criteria instanceof Criteria)
1400         {
1401             $criteria = clone $criteria;
1402         }
1403
1404         if ($this->collSnippetComments === null) {
1405             if ($this->isNew()) {
1406                 $this->collSnippetComments = array();
1407             } else {
1408
1409                 $criteria->add(SnippetCommentPeer::USER_ID, $this->getId());
1410
1411                 $this->collSnippetComments = SnippetCommentPeer::doSelectJoinSnippetSnippet($criteria, $con);
1412             }
1413         } else {
1414             // the following code is to determine if a new query is
1415             // called for.  If the criteria is the same as the last
1416             // one, just return the collection.
1417
1418             $criteria->add(SnippetCommentPeer::USER_ID, $this->getId());
1419
1420             if (!isset($this->lastSnippetCommentCriteria) || !$this->lastSnippetCommentCriteria->equals($criteria)) {
1421                 $this->collSnippetComments = SnippetCommentPeer::doSelectJoinSnippetSnippet($criteria, $con);
1422             }
1423         }
1424         $this->lastSnippetCommentCriteria = $criteria;
1425
1426         return $this->collSnippetComments;
1427     }
1428
1429     /**
1430      * Temporary storage of collSnippetVotes to save a possible db hit in
1431      * the event objects are add to the collection, but the
1432      * complete collection is never requested.
1433      * @return void
1434      */
1435     public function initSnippetVotes()
1436     {
1437         if ($this->collSnippetVotes === null) {
1438             $this->collSnippetVotes = array();
1439         }
1440     }
1441
1442     /**
1443      * If this collection has already been initialized with
1444      * an identical criteria, it returns the collection.
1445      * Otherwise if this SnippetUser has previously
1446      * been saved, it will retrieve related SnippetVotes from storage.
1447      * If this SnippetUser is new, it will return
1448      * an empty collection or the current collection, the criteria
1449      * is ignored on a new object.
1450      *
1451      * @param Connection $con
1452      * @param Criteria $criteria
1453      * @throws PropelException
1454      */
1455     public function getSnippetVotes($criteria = null, $con = null)
1456     {
1457         // include the Peer class
1458         include_once 'model/om/BaseSnippetVotePeer.php';
1459         if ($criteria === null) {
1460             $criteria = new Criteria();
1461         }
1462         elseif ($criteria instanceof Criteria)
1463         {
1464             $criteria = clone $criteria;
1465         }
1466
1467         if ($this->collSnippetVotes === null) {
1468             if ($this->isNew()) {
1469                $this->collSnippetVotes = array();
1470             } else {
1471
1472                 $criteria->add(SnippetVotePeer::USER_ID, $this->getId());
1473
1474                 SnippetVotePeer::addSelectColumns($criteria);
1475                 $this->collSnippetVotes = SnippetVotePeer::doSelect($criteria, $con);
1476             }
1477         } else {
1478             // criteria has no effect for a new object
1479             if (!$this->isNew()) {
1480                 // the following code is to determine if a new query is
1481                 // called for.  If the criteria is the same as the last
1482                 // one, just return the collection.
1483
1484
1485                 $criteria->add(SnippetVotePeer::USER_ID, $this->getId());
1486
1487                 SnippetVotePeer::addSelectColumns($criteria);
1488                 if (!isset($this->lastSnippetVoteCriteria) || !$this->lastSnippetVoteCriteria->equals($criteria)) {
1489                     $this->collSnippetVotes = SnippetVotePeer::doSelect($criteria, $con);
1490                 }
1491             }
1492         }
1493         $this->lastSnippetVoteCriteria = $criteria;
1494         return $this->collSnippetVotes;
1495     }
1496
1497     /**
1498      * Returns the number of related SnippetVotes.
1499      *
1500      * @param Criteria $criteria
1501      * @param boolean $distinct
1502      * @param Connection $con
1503      * @throws PropelException
1504      */
1505     public function countSnippetVotes($criteria = null, $distinct = false, $con = null)
1506     {
1507         // include the Peer class
1508         include_once 'model/om/BaseSnippetVotePeer.php';
1509         if ($criteria === null) {
1510             $criteria = new Criteria();
1511         }
1512         elseif ($criteria instanceof Criteria)
1513         {
1514             $criteria = clone $criteria;
1515         }
1516
1517         $criteria->add(SnippetVotePeer::USER_ID, $this->getId());
1518
1519         return SnippetVotePeer::doCount($criteria, $distinct, $con);
1520     }
1521
1522     /**
1523      * Method called to associate a SnippetVote object to this object
1524      * through the SnippetVote foreign key attribute
1525      *
1526      * @param SnippetVote $l SnippetVote
1527      * @return void
1528      * @throws PropelException
1529      */
1530     public function addSnippetVote(SnippetVote $l)
1531     {
1532         $this->collSnippetVotes[] = $l;
1533         $l->setSnippetUser($this);
1534     }
1535
1536
1537     /**
1538      * If this collection has already been initialized with
1539      * an identical criteria, it returns the collection.
1540      * Otherwise if this SnippetUser is new, it will return
1541      * an empty collection; or if this SnippetUser has previously
1542      * been saved, it will retrieve related SnippetVotes from storage.
1543      *
1544      * This method is protected by default in order to keep the public
1545      * api reasonable.  You can provide public methods for those you
1546      * actually need in SnippetUser.
1547      */
1548     public function getSnippetVotesJoinSnippetSnippet($criteria = null, $con = null)
1549     {
1550         // include the Peer class
1551         include_once 'model/om/BaseSnippetVotePeer.php';
1552         if ($criteria === null) {
1553             $criteria = new Criteria();
1554         }
1555         elseif ($criteria instanceof Criteria)
1556         {
1557             $criteria = clone $criteria;
1558         }
1559
1560         if ($this->collSnippetVotes === null) {
1561             if ($this->isNew()) {
1562                 $this->collSnippetVotes = array();
1563             } else {
1564
1565                 $criteria->add(SnippetVotePeer::USER_ID, $this->getId());
1566
1567                 $this->collSnippetVotes = SnippetVotePeer::doSelectJoinSnippetSnippet($criteria, $con);
1568             }
1569         } else {
1570             // the following code is to determine if a new query is
1571             // called for.  If the criteria is the same as the last
1572             // one, just return the collection.
1573
1574             $criteria->add(SnippetVotePeer::USER_ID, $this->getId());
1575
1576             if (!isset($this->lastSnippetVoteCriteria) || !$this->lastSnippetVoteCriteria->equals($criteria)) {
1577                 $this->collSnippetVotes = SnippetVotePeer::doSelectJoinSnippetSnippet($criteria, $con);
1578             }
1579         }
1580         $this->lastSnippetVoteCriteria = $criteria;
1581
1582         return $this->collSnippetVotes;
1583     }
1584
1585 } // BaseSnippetUser
1586
Note: See TracBrowser for help on using the browser.