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

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

initial import

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 require_once 'propel/util/BasePeer.php';
4 // The object class -- needed for instanceof checks in this class.
5 // actual class may be a subclass -- as returned by SnippetCommentPeer::getOMClass()
6 include_once 'model/SnippetComment.php';
7
8 /**
9  * Base static class for performing query and update operations on the 'sn_comment' table.
10  *
11  *
12  *
13  * @package model.om
14  */
15 abstract class BaseSnippetCommentPeer {
16
17     /** the default database name for this class */
18     const DATABASE_NAME = 'propel';
19
20     /** the table name for this class */
21     const TABLE_NAME = 'sn_comment';
22
23     /** A class that can be returned by this peer. */
24     const CLASS_DEFAULT = 'model.SnippetComment';
25
26     /** The total number of columns. */
27     const NUM_COLUMNS = 6;
28
29     /** The number of lazy-loaded columns. */
30     const NUM_LAZY_LOAD_COLUMNS = 0;
31
32
33     /** the column name for the ID field */
34     const ID = 'sn_comment.ID';
35
36     /** the column name for the USER_ID field */
37     const USER_ID = 'sn_comment.USER_ID';
38
39     /** the column name for the SNIPPET_ID field */
40     const SNIPPET_ID = 'sn_comment.SNIPPET_ID';
41
42     /** the column name for the BODY field */
43     const BODY = 'sn_comment.BODY';
44
45     /** the column name for the HTML_BODY field */
46     const HTML_BODY = 'sn_comment.HTML_BODY';
47
48     /** the column name for the CREATED_AT field */
49     const CREATED_AT = 'sn_comment.CREATED_AT';
50
51     /** The PHP to DB Name Mapping */
52     private static $phpNameMap = null;
53
54
55     /**
56      * holds an array of fieldnames
57      *
58      * first dimension keys are the type constants
59      * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
60      */
61     private static $fieldNames = array (
62         BasePeer::TYPE_PHPNAME => array ('Id', 'UserId', 'SnippetId', 'Body', 'HtmlBody', 'CreatedAt', ),
63         BasePeer::TYPE_COLNAME => array (SnippetCommentPeer::ID, SnippetCommentPeer::USER_ID, SnippetCommentPeer::SNIPPET_ID, SnippetCommentPeer::BODY, SnippetCommentPeer::HTML_BODY, SnippetCommentPeer::CREATED_AT, ),
64         BasePeer::TYPE_FIELDNAME => array ('id', 'user_id', 'snippet_id', 'body', 'html_body', 'created_at', ),
65         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, )
66     );
67
68     /**
69      * holds an array of keys for quick access to the fieldnames array
70      *
71      * first dimension keys are the type constants
72      * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
73      */
74     private static $fieldKeys = array (
75         BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'UserId' => 1, 'SnippetId' => 2, 'Body' => 3, 'HtmlBody' => 4, 'CreatedAt' => 5, ),
76         BasePeer::TYPE_COLNAME => array (SnippetCommentPeer::ID => 0, SnippetCommentPeer::USER_ID => 1, SnippetCommentPeer::SNIPPET_ID => 2, SnippetCommentPeer::BODY => 3, SnippetCommentPeer::HTML_BODY => 4, SnippetCommentPeer::CREATED_AT => 5, ),
77         BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'user_id' => 1, 'snippet_id' => 2, 'body' => 3, 'html_body' => 4, 'created_at' => 5, ),
78         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, )
79     );
80
81     /**
82      * @return MapBuilder the map builder for this peer
83      * @throws PropelException Any exceptions caught during processing will be
84      *         rethrown wrapped into a PropelException.
85      */
86     public static function getMapBuilder()
87     {
88         include_once 'model/map/SnippetCommentMapBuilder.php';
89         return BasePeer::getMapBuilder('model.map.SnippetCommentMapBuilder');
90     }
91     /**
92      * Gets a map (hash) of PHP names to DB column names.
93      *
94      * @return array The PHP to DB name map for this peer
95      * @throws PropelException Any exceptions caught during processing will be
96      *         rethrown wrapped into a PropelException.
97      * @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
98      */
99     public static function getPhpNameMap()
100     {
101         if (self::$phpNameMap === null) {
102             $map = SnippetCommentPeer::getTableMap();
103             $columns = $map->getColumns();
104             $nameMap = array();
105             foreach ($columns as $column) {
106                 $nameMap[$column->getPhpName()] = $column->getColumnName();
107             }
108             self::$phpNameMap = $nameMap;
109         }
110         return self::$phpNameMap;
111     }
112     /**
113      * Translates a fieldname to another type
114      *
115      * @param string $name field name
116      * @param string $fromType One of the class type constants TYPE_PHPNAME,
117      *                         TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
118      * @param string $toType   One of the class type constants
119      * @return string translated name of the field.
120      */
121     static public function translateFieldName($name, $fromType, $toType)
122     {
123         $toNames = self::getFieldNames($toType);
124         $key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
125         if ($key === null) {
126             throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
127         }
128         return $toNames[$key];
129     }
130
131     /**
132      * Returns an array of of field names.
133      *
134      * @param  string $type The type of fieldnames to return:
135      *                      One of the class type constants TYPE_PHPNAME,
136      *                      TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
137      * @return array A list of field names
138      */
139
140     static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
141     {
142         if (!array_key_exists($type, self::$fieldNames)) {
143             throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
144         }
145         return self::$fieldNames[$type];
146     }
147
148     /**
149      * Convenience method which changes table.column to alias.column.
150      *
151      * Using this method you can maintain SQL abstraction while using column aliases.
152      * <code>
153      *        $c->addAlias("alias1", TablePeer::TABLE_NAME);
154      *        $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
155      * </code>
156      * @param string $alias The alias for the current table.
157      * @param string $column The column name for current table. (i.e. SnippetCommentPeer::COLUMN_NAME).
158      * @return string
159      */
160     public static function alias($alias, $column)
161     {
162         return str_replace(SnippetCommentPeer::TABLE_NAME.'.', $alias.'.', $column);
163     }
164
165     /**
166      * Add all the columns needed to create a new object.
167      *
168      * Note: any columns that were marked with lazyLoad="true" in the
169      * XML schema will not be added to the select list and only loaded
170      * on demand.
171      *
172      * @param criteria object containing the columns to add.
173      * @throws PropelException Any exceptions caught during processing will be
174      *         rethrown wrapped into a PropelException.
175      */
176     public static function addSelectColumns(Criteria $criteria)
177     {
178
179         $criteria->addSelectColumn(SnippetCommentPeer::ID);
180
181         $criteria->addSelectColumn(SnippetCommentPeer::USER_ID);
182
183         $criteria->addSelectColumn(SnippetCommentPeer::SNIPPET_ID);
184
185         $criteria->addSelectColumn(SnippetCommentPeer::BODY);
186
187         $criteria->addSelectColumn(SnippetCommentPeer::HTML_BODY);
188
189         $criteria->addSelectColumn(SnippetCommentPeer::CREATED_AT);
190
191     }
192
193     const COUNT = 'COUNT(sn_comment.ID)';
194     const COUNT_DISTINCT = 'COUNT(DISTINCT sn_comment.ID)';
195
196     /**
197      * Returns the number of rows matching criteria.
198      *
199      * @param Criteria $criteria
200      * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
201      * @param Connection $con
202      * @return int Number of matching rows.
203      */
204     public static function doCount(Criteria $criteria, $distinct = false, $con = null)
205     {
206         // we're going to modify criteria, so copy it first
207         $criteria = clone $criteria;
208
209         // clear out anything that might confuse the ORDER BY clause
210         $criteria->clearSelectColumns()->clearOrderByColumns();
211         if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
212             $criteria->addSelectColumn(SnippetCommentPeer::COUNT_DISTINCT);
213         } else {
214             $criteria->addSelectColumn(SnippetCommentPeer::COUNT);
215         }
216
217         // just in case we're grouping: add those columns to the select statement
218         foreach($criteria->getGroupByColumns() as $column)
219         {
220             $criteria->addSelectColumn($column);
221         }
222
223         $rs = SnippetCommentPeer::doSelectRS($criteria, $con);
224         if ($rs->next()) {
225             return $rs->getInt(1);
226         } else {
227             // no rows returned; we infer that means 0 matches.
228             return 0;
229         }
230     }
231     /**
232      * Method to select one object from the DB.
233      *
234      * @param Criteria $criteria object used to create the SELECT statement.
235      * @param Connection $con
236      * @return SnippetComment
237      * @throws PropelException Any exceptions caught during processing will be
238      *         rethrown wrapped into a PropelException.
239      */
240     public static function doSelectOne(Criteria $criteria, $con = null)
241     {
242         $critcopy = clone $criteria;
243         $critcopy->setLimit(1);
244         $objects = SnippetCommentPeer::doSelect($critcopy, $con);
245         if ($objects) {
246             return $objects[0];
247         }
248         return null;
249     }
250     /**
251      * Method to do selects.
252      *
253      * @param Criteria $criteria The Criteria object used to build the SELECT statement.
254      * @param Connection $con
255      * @return array Array of selected Objects
256      * @throws PropelException Any exceptions caught during processing will be
257      *         rethrown wrapped into a PropelException.
258      */
259     public static function doSelect(Criteria $criteria, $con = null)
260     {
261         return SnippetCommentPeer::populateObjects(SnippetCommentPeer::doSelectRS($criteria, $con));
262     }
263     /**
264      * Prepares the Criteria object and uses the parent doSelect()
265      * method to get a ResultSet.
266      *
267      * Use this method directly if you want to just get the resultset
268      * (instead of an array of objects).
269      *
270      * @param Criteria $criteria The Criteria object used to build the SELECT statement.
271      * @param Connection $con the connection to use
272      * @throws PropelException Any exceptions caught during processing will be
273      *         rethrown wrapped into a PropelException.
274      * @return ResultSet The resultset object with numerically-indexed fields.
275      * @see BasePeer::doSelect()
276      */
277     public static function doSelectRS(Criteria $criteria, $con = null)
278     {
279         if ($con === null) {
280             $con = Propel::getConnection(self::DATABASE_NAME);
281         }
282
283         if (!$criteria->getSelectColumns()) {
284             $criteria = clone $criteria;
285             SnippetCommentPeer::addSelectColumns($criteria);
286         }
287
288         // Set the correct dbName
289         $criteria->setDbName(self::DATABASE_NAME);
290
291         // BasePeer returns a Creole ResultSet, set to return
292         // rows indexed numerically.
293         return BasePeer::doSelect($criteria, $con);
294     }
295     /**
296      * The returned array will contain objects of the default type or
297      * objects that inherit from the default.
298      *
299      * @throws PropelException Any exceptions caught during processing will be
300      *         rethrown wrapped into a PropelException.
301      */
302     public static function populateObjects(ResultSet $rs)
303     {
304         $results = array();
305     
306         // set the class once to avoid overhead in the loop
307         $cls = SnippetCommentPeer::getOMClass();
308         $cls = Propel::import($cls);
309         // populate the object(s)
310         while($rs->next()) {
311         
312             $obj = new $cls();
313             $obj->hydrate($rs);
314             $results[] = $obj;
315             
316         }
317         return $results;
318     }
319
320     /**
321      * Returns the number of rows matching criteria, joining the related SnippetUser table
322      *
323      * @param Criteria $c
324      * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
325      * @param Connection $con
326      * @return int Number of matching rows.
327      */
328     public static function doCountJoinSnippetUser(Criteria $criteria, $distinct = false, $con = null)
329     {
330         // we're going to modify criteria, so copy it first
331         $criteria = clone $criteria;
332         
333         // clear out anything that might confuse the ORDER BY clause
334         $criteria->clearSelectColumns()->clearOrderByColumns();
335         if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
336             $criteria->addSelectColumn(SnippetCommentPeer::COUNT_DISTINCT);
337         } else {
338             $criteria->addSelectColumn(SnippetCommentPeer::COUNT);
339         }
340         
341         // just in case we're grouping: add those columns to the select statement
342         foreach($criteria->getGroupByColumns() as $column)
343         {
344             $criteria->addSelectColumn($column);
345         }
346
347         $criteria->addJoin(SnippetCommentPeer::USER_ID, SnippetUserPeer::ID);
348
349         $rs = SnippetCommentPeer::doSelectRS($criteria, $con);
350         if ($rs->next()) {
351             return $rs->getInt(1);
352         } else {
353             // no rows returned; we infer that means 0 matches.
354             return 0;
355         }
356     }
357
358
359     /**
360      * Returns the number of rows matching criteria, joining the related SnippetSnippet table
361      *
362      * @param Criteria $c
363      * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
364      * @param Connection $con
365      * @return int Number of matching rows.
366      */
367     public static function doCountJoinSnippetSnippet(Criteria $criteria, $distinct = false, $con = null)
368     {
369         // we're going to modify criteria, so copy it first
370         $criteria = clone $criteria;
371         
372         // clear out anything that might confuse the ORDER BY clause
373         $criteria->clearSelectColumns()->clearOrderByColumns();
374         if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
375             $criteria->addSelectColumn(SnippetCommentPeer::COUNT_DISTINCT);
376         } else {
377             $criteria->addSelectColumn(SnippetCommentPeer::COUNT);
378         }
379         
380         // just in case we're grouping: add those columns to the select statement
381         foreach($criteria->getGroupByColumns() as $column)
382         {
383             $criteria->addSelectColumn($column);
384         }
385
386         $criteria->addJoin(SnippetCommentPeer::SNIPPET_ID, SnippetSnippetPeer::ID);
387
388         $rs = SnippetCommentPeer::doSelectRS($criteria, $con);
389         if ($rs->next()) {
390             return $rs->getInt(1);
391         } else {
392             // no rows returned; we infer that means 0 matches.
393             return 0;
394         }
395     }
396
397
398     /**
399      * Selects a collection of SnippetComment objects pre-filled with their SnippetUser objects.
400      *
401      * @return array Array of SnippetComment objects.
402      * @throws PropelException Any exceptions caught during processing will be
403      *         rethrown wrapped into a PropelException.
404      */
405     public static function doSelectJoinSnippetUser(Criteria $c, $con = null)
406     {
407         $c = clone $c;
408
409         // Set the correct dbName if it has not been overridden
410         if ($c->getDbName() == Propel::getDefaultDB()) {
411             $c->setDbName(self::DATABASE_NAME);
412         }
413
414         SnippetCommentPeer::addSelectColumns($c);
415         $startcol = (SnippetCommentPeer::NUM_COLUMNS - SnippetCommentPeer::NUM_LAZY_LOAD_COLUMNS) + 1;
416         SnippetUserPeer::addSelectColumns($c);
417
418         $c->addJoin(SnippetCommentPeer::USER_ID, SnippetUserPeer::ID);
419         $rs = BasePeer::doSelect($c, $con);
420         $results = array();
421
422         while($rs->next()) {
423
424             $omClass = SnippetCommentPeer::getOMClass();
425
426             $cls = Propel::import($omClass);
427             $obj1 = new $cls();
428             $obj1->hydrate($rs);
429
430             $omClass = SnippetUserPeer::getOMClass();
431
432             $cls = Propel::import($omClass);
433             $obj2 = new $cls();
434             $obj2->hydrate($rs, $startcol);
435
436             $newObject = true;
437             foreach($results as $temp_obj1) {
438                 $temp_obj2 = $temp_obj1->getSnippetUser(); //CHECKME
439                 if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
440                     $newObject = false;
441                     // e.g. $author->addBookRelatedByBookId()
442                     $temp_obj2->addSnippetComment($obj1); //CHECKME
443                     break;
444                 }
445             }
446             if ($newObject) {
447                 $obj2->initSnippetComments();
448                 $obj2->addSnippetComment($obj1); //CHECKME
449             }
450             $results[] = $obj1;
451         }
452         return $results;
453     }
454
455
456     /**
457      * Selects a collection of SnippetComment objects pre-filled with their SnippetSnippet objects.
458      *
459      * @return array Array of SnippetComment objects.
460      * @throws PropelException Any exceptions caught during processing will be
461      *         rethrown wrapped into a PropelException.
462      */
463     public static function doSelectJoinSnippetSnippet(Criteria $c, $con = null)
464     {
465         $c = clone $c;
466
467         // Set the correct dbName if it has not been overridden
468         if ($c->getDbName() == Propel::getDefaultDB()) {
469             $c->setDbName(self::DATABASE_NAME);
470         }
471
472         SnippetCommentPeer::addSelectColumns($c);
473         $startcol = (SnippetCommentPeer::NUM_COLUMNS - SnippetCommentPeer::NUM_LAZY_LOAD_COLUMNS) + 1;
474         SnippetSnippetPeer::addSelectColumns($c);
475
476         $c->addJoin(SnippetCommentPeer::SNIPPET_ID, SnippetSnippetPeer::ID);
477         $rs = BasePeer::doSelect($c, $con);
478         $results = array();
479
480         while($rs->next()) {
481
482             $omClass = SnippetCommentPeer::getOMClass();
483
484             $cls = Propel::import($omClass);
485             $obj1 = new $cls();
486             $obj1->hydrate($rs);
487
488             $omClass = SnippetSnippetPeer::getOMClass();
489
490             $cls = Propel::import($omClass);
491             $obj2 = new $cls();
492             $obj2->hydrate($rs, $startcol);
493
494             $newObject = true;
495             foreach($results as $temp_obj1) {
496                 $temp_obj2 = $temp_obj1->getSnippetSnippet(); //CHECKME
497                 if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
498                     $newObject = false;
499                     // e.g. $author->addBookRelatedByBookId()
500                     $temp_obj2->addSnippetComment($obj1); //CHECKME
501                     break;
502                 }
503             }
504             if ($newObject) {
505                 $obj2->initSnippetComments();
506                 $obj2->addSnippetComment($obj1); //CHECKME
507             }
508             $results[] = $obj1;
509         }
510         return $results;
511     }
512
513
514     /**
515      * Returns the number of rows matching criteria, joining all related tables
516      *
517      * @param Criteria $c
518      * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
519      * @param Connection $con
520      * @return int Number of matching rows.
521      */
522     public static function doCountJoinAll(Criteria $criteria, $distinct = false, $con = null)
523     {
524         $criteria = clone $criteria;
525
526         // clear out anything that might confuse the ORDER BY clause
527         $criteria->clearSelectColumns()->clearOrderByColumns();
528         if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
529             $criteria->addSelectColumn(SnippetCommentPeer::COUNT_DISTINCT);
530         } else {
531             $criteria->addSelectColumn(SnippetCommentPeer::COUNT);
532         }
533         
534         // just in case we're grouping: add those columns to the select statement
535         foreach($criteria->getGroupByColumns() as $column)
536         {
537             $criteria->addSelectColumn($column);
538         }
539
540         $criteria->addJoin(SnippetCommentPeer::USER_ID, SnippetUserPeer::ID);
541
542         $criteria->addJoin(SnippetCommentPeer::SNIPPET_ID, SnippetSnippetPeer::ID);
543
544         $rs = SnippetCommentPeer::doSelectRS($criteria, $con);
545         if ($rs->next()) {
546             return $rs->getInt(1);
547         } else {
548             // no rows returned; we infer that means 0 matches.
549             return 0;
550         }
551     }
552
553
554     /**
555      * Selects a collection of SnippetComment objects pre-filled with all related objects.
556      *
557      * @return array Array of SnippetComment objects.
558      * @throws PropelException Any exceptions caught during processing will be
559      *         rethrown wrapped into a PropelException.
560      */
561     public static function doSelectJoinAll(Criteria $c, $con = null)
562     {
563         $c = clone $c;
564
565         // Set the correct dbName if it has not been overridden
566         if ($c->getDbName() == Propel::getDefaultDB()) {
567             $c->setDbName(self::DATABASE_NAME);
568         }
569
570         SnippetCommentPeer::addSelectColumns($c);
571         $startcol2 = (SnippetCommentPeer::NUM_COLUMNS - SnippetCommentPeer::NUM_LAZY_LOAD_COLUMNS) + 1;
572
573         SnippetUserPeer::addSelectColumns($c);
574         $startcol3 = $startcol2 + SnippetUserPeer::NUM_COLUMNS;
575
576         SnippetSnippetPeer::addSelectColumns($c);
577         $startcol4 = $startcol3 + SnippetSnippetPeer::NUM_COLUMNS;
578
579         $c->addJoin(SnippetCommentPeer::USER_ID, SnippetUserPeer::ID);
580
581         $c->addJoin(SnippetCommentPeer::SNIPPET_ID, SnippetSnippetPeer::ID);
582
583         $rs = BasePeer::doSelect($c, $con);
584         $results = array();
585         
586         while($rs->next()) {
587
588             $omClass = SnippetCommentPeer::getOMClass();
589
590             
591             $cls = Propel::import($omClass);
592             $obj1 = new $cls();
593             $obj1->hydrate($rs);
594
595                 
596                 // Add objects for joined SnippetUser rows
597     
598             $omClass = SnippetUserPeer::getOMClass();
599
600     
601             $cls = Propel::import($omClass);
602             $obj2 = new $cls();
603             $obj2->hydrate($rs, $startcol2);
604             
605             $newObject = true;
606             for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
607                 $temp_obj1 = $results[$j];
608                 $temp_obj2 = $temp_obj1->getSnippetUser(); // CHECKME
609                 if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
610                     $newObject = false;
611                     $temp_obj2->addSnippetComment($obj1); // CHECKME
612                     break;
613                 }
614             }
615             
616             if ($newObject) {
617                 $obj2->initSnippetComments();
618                 $obj2->addSnippetComment($obj1);
619             }
620
621                 
622                 // Add objects for joined SnippetSnippet rows
623     
624             $omClass = SnippetSnippetPeer::getOMClass();
625
626     
627             $cls = Propel::import($omClass);
628             $obj3 = new $cls();
629             $obj3->hydrate($rs, $startcol3);
630             
631             $newObject = true;
632             for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
633                 $temp_obj1 = $results[$j];
634                 $temp_obj3 = $temp_obj1->getSnippetSnippet(); // CHECKME
635                 if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) {
636                     $newObject = false;
637                     $temp_obj3->addSnippetComment($obj1); // CHECKME
638                     break;
639                 }
640             }
641             
642             if ($newObject) {
643                 $obj3->initSnippetComments();
644                 $obj3->addSnippetComment($obj1);
645             }
646
647             $results[] = $obj1;
648         }
649         return $results;
650     }
651
652
653     /**
654      * Returns the number of rows matching criteria, joining the related SnippetUser table
655      *
656      * @param Criteria $c
657      * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
658      * @param Connection $con
659      * @return int Number of matching rows.
660      */
661     public static function doCountJoinAllExceptSnippetUser(Criteria $criteria, $distinct = false, $con = null)
662     {
663         // we're going to modify criteria, so copy it first
664         $criteria = clone $criteria;
665         
666         // clear out anything that might confuse the ORDER BY clause
667         $criteria->clearSelectColumns()->clearOrderByColumns();
668         if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
669             $criteria->addSelectColumn(SnippetCommentPeer::COUNT_DISTINCT);
670         } else {
671             $criteria->addSelectColumn(SnippetCommentPeer::COUNT);
672         }
673         
674         // just in case we're grouping: add those columns to the select statement
675         foreach($criteria->getGroupByColumns() as $column)
676         {
677             $criteria->addSelectColumn($column);
678         }
679
680         $criteria->addJoin(SnippetCommentPeer::SNIPPET_ID, SnippetSnippetPeer::ID);
681
682         $rs = SnippetCommentPeer::doSelectRS($criteria, $con);
683         if ($rs->next()) {
684             return $rs->getInt(1);
685         } else {
686             // no rows returned; we infer that means 0 matches.
687             return 0;
688         }
689     }
690
691
692     /**
693      * Returns the number of rows matching criteria, joining the related SnippetSnippet table
694      *
695      * @param Criteria $c
696      * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
697      * @param Connection $con
698      * @return int Number of matching rows.
699      */
700     public static function doCountJoinAllExceptSnippetSnippet(Criteria $criteria, $distinct = false, $con = null)
701     {
702         // we're going to modify criteria, so copy it first
703         $criteria = clone $criteria;
704         
705         // clear out anything that might confuse the ORDER BY clause
706         $criteria->clearSelectColumns()->clearOrderByColumns();
707         if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
708             $criteria->addSelectColumn(SnippetCommentPeer::COUNT_DISTINCT);
709         } else {
710             $criteria->addSelectColumn(SnippetCommentPeer::COUNT);
711         }
712         
713         // just in case we're grouping: add those columns to the select statement
714         foreach($criteria->getGroupByColumns() as $column)
715         {
716             $criteria->addSelectColumn($column);
717         }
718
719         $criteria->addJoin(SnippetCommentPeer::USER_ID, SnippetUserPeer::ID);
720
721         $rs = SnippetCommentPeer::doSelectRS($criteria, $con);
722         if ($rs->next()) {
723             return $rs->getInt(1);
724         } else {
725             // no rows returned; we infer that means 0 matches.
726             return 0;
727         }
728     }
729
730
731     /**
732      * Selects a collection of SnippetComment objects pre-filled with all related objects except SnippetUser.
733      *
734      * @return array Array of SnippetComment objects.
735      * @throws PropelException Any exceptions caught during processing will be
736      *         rethrown wrapped into a PropelException.
737      */
738     public static function doSelectJoinAllExceptSnippetUser(Criteria $c, $con = null)
739     {
740         $c = clone $c;
741
742         // Set the correct dbName if it has not been overridden
743         // $c->getDbName() will return the same object if not set to another value
744         // so == check is okay and faster
745         if ($c->getDbName() == Propel::getDefaultDB()) {
746             $c->setDbName(self::DATABASE_NAME);
747         }
748
749         SnippetCommentPeer::addSelectColumns($c);
750         $startcol2 = (SnippetCommentPeer::NUM_COLUMNS - SnippetCommentPeer::NUM_LAZY_LOAD_COLUMNS) + 1;
751
752         SnippetSnippetPeer::addSelectColumns($c);
753         $startcol3 = $startcol2 + SnippetSnippetPeer::NUM_COLUMNS;
754
755         $c->addJoin(SnippetCommentPeer::SNIPPET_ID, SnippetSnippetPeer::ID);
756
757
758         $rs = BasePeer::doSelect($c, $con);
759         $results = array();
760         
761         while($rs->next()) {
762
763             $omClass = SnippetCommentPeer::getOMClass();
764
765             $cls = Propel::import($omClass);
766             $obj1 = new $cls();
767             $obj1->hydrate($rs);       
768
769             $omClass = SnippetSnippetPeer::getOMClass();
770
771     
772             $cls = Propel::import($omClass);
773             $obj2  = new $cls();
774             $obj2->hydrate($rs, $startcol2);
775             
776             $newObject = true;
777             for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
778                 $temp_obj1 = $results[$j];
779                 $temp_obj2 = $temp_obj1->getSnippetSnippet(); //CHECKME
780                 if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
781                     $newObject = false;
782                     $temp_obj2->addSnippetComment($obj1);
783                     break;
784                 }
785             }
786             
787             if ($newObject) {
788                 $obj2->initSnippetComments();
789                 $obj2->addSnippetComment($obj1);
790             }
791
792             $results[] = $obj1;
793         }
794         return $results;
795     }
796
797
798     /**
799      * Selects a collection of SnippetComment objects pre-filled with all related objects except SnippetSnippet.
800      *
801      * @return array Array of SnippetComment objects.
802      * @throws PropelException Any exceptions caught during processing will be
803      *         rethrown wrapped into a PropelException.
804      */
805     public static function doSelectJoinAllExceptSnippetSnippet(Criteria $c, $con = null)
806     {
807         $c = clone $c;
808
809         // Set the correct dbName if it has not been overridden
810         // $c->getDbName() will return the same object if not set to another value
811         // so == check is okay and faster
812         if ($c->getDbName() == Propel::getDefaultDB()) {
813             $c->setDbName(self::DATABASE_NAME);
814         }
815
816         SnippetCommentPeer::addSelectColumns($c);
817         $startcol2 = (SnippetCommentPeer::NUM_COLUMNS - SnippetCommentPeer::NUM_LAZY_LOAD_COLUMNS) + 1;
818
819         SnippetUserPeer::addSelectColumns($c);
820         $startcol3 = $startcol2 + SnippetUserPeer::NUM_COLUMNS;
821
822         $c->addJoin(SnippetCommentPeer::USER_ID, SnippetUserPeer::ID);
823
824
825         $rs = BasePeer::doSelect($c, $con);
826         $results = array();
827         
828         while($rs->next()) {
829
830             $omClass = SnippetCommentPeer::getOMClass();
831
832             $cls = Propel::import($omClass);
833             $obj1 = new $cls();
834             $obj1->hydrate($rs);       
835
836             $omClass = SnippetUserPeer::getOMClass();
837
838     
839             $cls = Propel::import($omClass);
840             $obj2  = new $cls();
841             $obj2->hydrate($rs, $startcol2);
842             
843             $newObject = true;
844             for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
845                 $temp_obj1 = $results[$j];
846                 $temp_obj2 = $temp_obj1->getSnippetUser(); //CHECKME
847                 if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
848                     $newObject = false;
849                     $temp_obj2->addSnippetComment($obj1);
850                     break;
851                 }
852             }
853             
854             if ($newObject) {
855                 $obj2->initSnippetComments();
856                 $obj2->addSnippetComment($obj1);
857             }
858
859             $results[] = $obj1;
860         }
861         return $results;
862     }
863
864     /**
865      * Returns the TableMap related to this peer.
866      * This method is not needed for general use but a specific application could have a need.
867      * @return TableMap
868      * @throws PropelException Any exceptions caught during processing will be
869      *         rethrown wrapped into a PropelException.
870      */
871     public static function getTableMap()
872     {
873         return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
874     }
875
876     /**
877      * The class that the Peer will make instances of.
878      *
879      * This uses a dot-path notation which is tranalted into a path
880      * relative to a location on the PHP include_path.
881      * (e.g. path.to.MyClass -> 'path/to/MyClass.php')
882      *
883      * @return string path.to.ClassName
884      */
885     public static function getOMClass()
886     {
887         return SnippetCommentPeer::CLASS_DEFAULT;
888     }
889
890     /**
891      * Method perform an INSERT on the database, given a SnippetComment or Criteria object.
892      *
893      * @param mixed $values Criteria or SnippetComment object containing data that is used to create the INSERT statement.
894      * @param Connection $con the connection to use
895      * @return mixed The new primary key.
896      * @throws PropelException Any exceptions caught during processing will be
897      *         rethrown wrapped into a PropelException.
898      */
899     public static function doInsert($values, $con = null)
900     {
901         if ($con === null) {
902             $con = Propel::getConnection(self::DATABASE_NAME);
903         }
904
905         if ($values instanceof Criteria) {
906             $criteria = clone $values; // rename for clarity
907         } else {
908             $criteria = $values->buildCriteria(); // build Criteria from SnippetComment object
909         }
910
911         $criteria->remove(SnippetCommentPeer::ID); // remove pkey col since this table uses auto-increment
912
913
914         // Set the correct dbName
915         $criteria->setDbName(self::DATABASE_NAME);
916
917         try {
918             // use transaction because $criteria could contain info
919             // for more than one table (I guess, conceivably)
920             $con->begin();
921             $pk = BasePeer::doInsert($criteria, $con);
922             $con->commit();
923         } catch(PropelException $e) {
924             $con->rollback();
925             throw $e;
926         }
927
928         return $pk;
929     }
930
931     /**
932      * Method perform an UPDATE on the database, given a SnippetComment or Criteria object.
933      *
934      * @param mixed $values Criteria or SnippetComment object containing data that is used to create the UPDATE statement.
935      * @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
936      * @return int The number of affected rows (if supported by underlying database driver).
937      * @throws PropelException Any exceptions caught during processing will be
938      *         rethrown wrapped into a PropelException.
939      */
940     public static function doUpdate($values, $con = null)
941     {
942         if ($con === null) {
943             $con = Propel::getConnection(self::DATABASE_NAME);
944         }
945
946         $selectCriteria = new Criteria(self::DATABASE_NAME);
947
948         if ($values instanceof Criteria) {
949             $criteria = clone $values; // rename for clarity
950
951             $comparison = $criteria->getComparison(SnippetCommentPeer::ID);
952             $selectCriteria->add(SnippetCommentPeer::ID, $criteria->remove(SnippetCommentPeer::ID), $comparison);
953
954         } else { // $values is SnippetComment object
955             $criteria = $values->buildCriteria(); // gets full criteria
956             $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
957         }
958
959         // set the correct dbName
960         $criteria->setDbName(self::DATABASE_NAME);
961
962         return BasePeer::doUpdate($selectCriteria, $criteria, $con);
963     }
964
965     /**
966      * Method to DELETE all rows from the sn_comment table.
967      *
968      * @return int The number of affected rows (if supported by underlying database driver).
969      */
970     public static function doDeleteAll($con = null)
971     {
972         if ($con === null) {
973             $con = Propel::getConnection(self::DATABASE_NAME);
974         }
975         $affectedRows = 0; // initialize var to track total num of affected rows
976         try {
977             // use transaction because $criteria could contain info
978             // for more than one table or we could emulating ON DELETE CASCADE, etc.
979             $con->begin();
980             $affectedRows += BasePeer::doDeleteAll(SnippetCommentPeer::TABLE_NAME, $con);
981             $con->commit();
982             return $affectedRows;
983         } catch (PropelException $e) {
984             $con->rollback();
985             throw $e;
986         }
987     }
988
989     /**
990      * Method perform a DELETE on the database, given a SnippetComment or Criteria object OR a primary key value.
991      *
992      * @param mixed $values Criteria or SnippetComment object or primary key or array of primary keys
993      *              which is used to create the DELETE statement
994      * @param Connection $con the connection to use
995      * @return int     The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
996      *                if supported by native driver or if emulated using Propel.
997      * @throws PropelException Any exceptions caught during processing will be
998      *         rethrown wrapped into a PropelException.
999      */
1000      public static function doDelete($values, $con = null)
1001      {
1002         if ($con === null) {
1003             $con = Propel::getConnection(SnippetCommentPeer::DATABASE_NAME);
1004         }
1005
1006         if ($values instanceof Criteria) {
1007             $criteria = clone $values; // rename for clarity
1008         } elseif ($values instanceof SnippetComment) {
1009
1010             $criteria = $values->buildPkeyCriteria();
1011         } else {
1012             // it must be the primary key
1013             $criteria = new Criteria(self::DATABASE_NAME);
1014             $criteria->add(SnippetCommentPeer::ID, (array) $values, Criteria::IN);
1015         }
1016
1017         // Set the correct dbName
1018         $criteria->setDbName(self::DATABASE_NAME);
1019
1020         $affectedRows = 0; // initialize var to track total num of affected rows
1021
1022         try {
1023             // use transaction because $criteria could contain info
1024             // for more than one table or we could emulating ON DELETE CASCADE, etc.
1025             $con->begin();
1026             
1027             $affectedRows += BasePeer::doDelete($criteria, $con);
1028             $con->commit();
1029             return $affectedRows;
1030         } catch (PropelException $e) {
1031             $con->rollback();
1032             throw $e;
1033         }
1034     }
1035
1036     /**
1037      * Validates all modified columns of given SnippetComment object.
1038      * If parameter $columns is either a single column name or an array of column names
1039      * than only those columns are validated.
1040      *
1041      * NOTICE: This does not apply to primary or foreign keys for now.
1042      *
1043      * @param SnippetComment $obj The object to validate.
1044      * @param mixed $cols Column name or array of column names.
1045      *
1046      * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
1047      */
1048     public static function doValidate(SnippetComment $obj, $cols = null)
1049     {
1050         $columns = array();
1051
1052         if ($cols) {
1053             $dbMap = Propel::getDatabaseMap(SnippetCommentPeer::DATABASE_NAME);
1054             $tableMap = $dbMap->getTable(SnippetCommentPeer::TABLE_NAME);
1055
1056             if (! is_array($cols)) {
1057                 $cols = array($cols);
1058             }
1059
1060             foreach($cols as $colName) {
1061                 if ($tableMap->containsColumn($colName)) {
1062                     $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
1063                     $columns[$colName] = $obj->$get();
1064                 }
1065             }
1066         } else {
1067
1068         }
1069
1070         $res BasePeer::doValidate(SnippetCommentPeer::DATABASE_NAME, SnippetCommentPeer::TABLE_NAME, $columns);
1071     if ($res !== true) {
1072         $request = sfContext::getInstance()->getRequest();
1073         foreach ($res as $failed) {
1074             $col = SnippetCommentPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
1075             $request->setError($col, $failed->getMessage());
1076         }
1077     }
1078
1079     return $res;
1080     }
1081
1082     /**
1083      * Retrieve a single object by pkey.
1084      *
1085      * @param mixed $pk the primary key.
1086      * @param Connection $con the connection to use
1087      * @return SnippetComment
1088      */
1089     public static function retrieveByPK($pk, $con = null)
1090     {
1091         if ($con === null) {
1092             $con = Propel::getConnection(self::DATABASE_NAME);
1093         }
1094
1095         $criteria = new Criteria(SnippetCommentPeer::DATABASE_NAME);
1096
1097         $criteria->add(SnippetCommentPeer::ID, $pk);
1098
1099
1100         $v = SnippetCommentPeer::doSelect($criteria, $con);
1101
1102         return !empty($v) > 0 ? $v[0] : null;
1103     }
1104
1105     /**
1106      * Retrieve multiple objects by pkey.
1107      *
1108      * @param array $pks List of primary keys
1109      * @param Connection $con the connection to use
1110      * @throws PropelException Any exceptions caught during processing will be
1111      *         rethrown wrapped into a PropelException.
1112      */
1113     public static function retrieveByPKs($pks, $con = null)
1114     {
1115         if ($con === null) {
1116             $con = Propel::getConnection(self::DATABASE_NAME);
1117         }
1118
1119         $objs = null;
1120         if (empty($pks)) {
1121             $objs = array();
1122         } else {
1123             $criteria = new Criteria();
1124             $criteria->add(SnippetCommentPeer::ID, $pks, Criteria::IN);
1125             $objs = SnippetCommentPeer::doSelect($criteria, $con);
1126         }
1127         return $objs;
1128     }
1129
1130 } // BaseSnippetCommentPeer
1131
1132 // static code to register the map builder for this Peer with the main Propel class
1133 if (Propel::isInit()) {
1134     // the MapBuilder classes register themselves with Propel during initialization
1135     // so we need to load them here.
1136     try {
1137         BaseSnippetCommentPeer::getMapBuilder();
1138     } catch (Exception $e) {
1139         Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
1140     }
1141 } else {
1142     // even if Propel is not yet initialized, the map builder class can be registered
1143     // now and then it will be loaded when Propel initializes.
1144     require_once 'model/map/SnippetCommentMapBuilder.php';
1145     Propel::registerMapBuilder('model.map.SnippetCommentMapBuilder');
1146 }
1147
Note: See TracBrowser for help on using the browser.