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

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