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

Revision 4, 32.1 kB (checked in by fabien, 7 years ago)

day 2 modifications

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