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

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