1: <?php
2:
3: namespace Thelia\Model\om;
4:
5: use \BasePeer;
6: use \Criteria;
7: use \PDO;
8: use \PDOStatement;
9: use \Propel;
10: use \PropelException;
11: use \PropelPDO;
12: use Thelia\Model\AreaPeer;
13: use Thelia\Model\Country;
14: use Thelia\Model\CountryI18nPeer;
15: use Thelia\Model\CountryPeer;
16: use Thelia\Model\TaxRuleCountryPeer;
17: use Thelia\Model\map\CountryTableMap;
18:
19: /**
20: * Base static class for performing query and update operations on the 'country' table.
21: *
22: *
23: *
24: * @package propel.generator.Thelia.Model.om
25: */
26: abstract class BaseCountryPeer
27: {
28:
29: /** the default database name for this class */
30: const DATABASE_NAME = 'thelia';
31:
32: /** the table name for this class */
33: const TABLE_NAME = 'country';
34:
35: /** the related Propel class for this table */
36: const OM_CLASS = 'Thelia\\Model\\Country';
37:
38: /** the related TableMap class for this table */
39: const TM_CLASS = 'CountryTableMap';
40:
41: /** The total number of columns. */
42: const NUM_COLUMNS = 7;
43:
44: /** The number of lazy-loaded columns. */
45: const NUM_LAZY_LOAD_COLUMNS = 0;
46:
47: /** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
48: const NUM_HYDRATE_COLUMNS = 7;
49:
50: /** the column name for the ID field */
51: const ID = 'country.ID';
52:
53: /** the column name for the AREA_ID field */
54: const AREA_ID = 'country.AREA_ID';
55:
56: /** the column name for the ISOCODE field */
57: const ISOCODE = 'country.ISOCODE';
58:
59: /** the column name for the ISOALPHA2 field */
60: const ISOALPHA2 = 'country.ISOALPHA2';
61:
62: /** the column name for the ISOALPHA3 field */
63: const ISOALPHA3 = 'country.ISOALPHA3';
64:
65: /** the column name for the CREATED_AT field */
66: const CREATED_AT = 'country.CREATED_AT';
67:
68: /** the column name for the UPDATED_AT field */
69: const UPDATED_AT = 'country.UPDATED_AT';
70:
71: /** The default string format for model objects of the related table **/
72: const DEFAULT_STRING_FORMAT = 'YAML';
73:
74: /**
75: * An identiy map to hold any loaded instances of Country objects.
76: * This must be public so that other peer classes can access this when hydrating from JOIN
77: * queries.
78: * @var array Country[]
79: */
80: public static $instances = array();
81:
82:
83: // i18n behavior
84:
85: /**
86: * The default locale to use for translations
87: * @var string
88: */
89: const DEFAULT_LOCALE = 'en_EN';
90: /**
91: * holds an array of fieldnames
92: *
93: * first dimension keys are the type constants
94: * e.g. CountryPeer::$fieldNames[CountryPeer::TYPE_PHPNAME][0] = 'Id'
95: */
96: protected static $fieldNames = array (
97: BasePeer::TYPE_PHPNAME => array ('Id', 'AreaId', 'Isocode', 'Isoalpha2', 'Isoalpha3', 'CreatedAt', 'UpdatedAt', ),
98: BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'areaId', 'isocode', 'isoalpha2', 'isoalpha3', 'createdAt', 'updatedAt', ),
99: BasePeer::TYPE_COLNAME => array (CountryPeer::ID, CountryPeer::AREA_ID, CountryPeer::ISOCODE, CountryPeer::ISOALPHA2, CountryPeer::ISOALPHA3, CountryPeer::CREATED_AT, CountryPeer::UPDATED_AT, ),
100: BasePeer::TYPE_RAW_COLNAME => array ('ID', 'AREA_ID', 'ISOCODE', 'ISOALPHA2', 'ISOALPHA3', 'CREATED_AT', 'UPDATED_AT', ),
101: BasePeer::TYPE_FIELDNAME => array ('id', 'area_id', 'isocode', 'isoalpha2', 'isoalpha3', 'created_at', 'updated_at', ),
102: BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, )
103: );
104:
105: /**
106: * holds an array of keys for quick access to the fieldnames array
107: *
108: * first dimension keys are the type constants
109: * e.g. CountryPeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
110: */
111: protected static $fieldKeys = array (
112: BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'AreaId' => 1, 'Isocode' => 2, 'Isoalpha2' => 3, 'Isoalpha3' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ),
113: BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'areaId' => 1, 'isocode' => 2, 'isoalpha2' => 3, 'isoalpha3' => 4, 'createdAt' => 5, 'updatedAt' => 6, ),
114: BasePeer::TYPE_COLNAME => array (CountryPeer::ID => 0, CountryPeer::AREA_ID => 1, CountryPeer::ISOCODE => 2, CountryPeer::ISOALPHA2 => 3, CountryPeer::ISOALPHA3 => 4, CountryPeer::CREATED_AT => 5, CountryPeer::UPDATED_AT => 6, ),
115: BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'AREA_ID' => 1, 'ISOCODE' => 2, 'ISOALPHA2' => 3, 'ISOALPHA3' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ),
116: BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'area_id' => 1, 'isocode' => 2, 'isoalpha2' => 3, 'isoalpha3' => 4, 'created_at' => 5, 'updated_at' => 6, ),
117: BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, )
118: );
119:
120: /**
121: * Translates a fieldname to another type
122: *
123: * @param string $name field name
124: * @param string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
125: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
126: * @param string $toType One of the class type constants
127: * @return string translated name of the field.
128: * @throws PropelException - if the specified name could not be found in the fieldname mappings.
129: */
130: public static function translateFieldName($name, $fromType, $toType)
131: {
132: $toNames = CountryPeer::getFieldNames($toType);
133: $key = isset(CountryPeer::$fieldKeys[$fromType][$name]) ? CountryPeer::$fieldKeys[$fromType][$name] : null;
134: if ($key === null) {
135: throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(CountryPeer::$fieldKeys[$fromType], true));
136: }
137:
138: return $toNames[$key];
139: }
140:
141: /**
142: * Returns an array of field names.
143: *
144: * @param string $type The type of fieldnames to return:
145: * One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
146: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
147: * @return array A list of field names
148: * @throws PropelException - if the type is not valid.
149: */
150: public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
151: {
152: if (!array_key_exists($type, CountryPeer::$fieldNames)) {
153: throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
154: }
155:
156: return CountryPeer::$fieldNames[$type];
157: }
158:
159: /**
160: * Convenience method which changes table.column to alias.column.
161: *
162: * Using this method you can maintain SQL abstraction while using column aliases.
163: * <code>
164: * $c->addAlias("alias1", TablePeer::TABLE_NAME);
165: * $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
166: * </code>
167: * @param string $alias The alias for the current table.
168: * @param string $column The column name for current table. (i.e. CountryPeer::COLUMN_NAME).
169: * @return string
170: */
171: public static function alias($alias, $column)
172: {
173: return str_replace(CountryPeer::TABLE_NAME.'.', $alias.'.', $column);
174: }
175:
176: /**
177: * Add all the columns needed to create a new object.
178: *
179: * Note: any columns that were marked with lazyLoad="true" in the
180: * XML schema will not be added to the select list and only loaded
181: * on demand.
182: *
183: * @param Criteria $criteria object containing the columns to add.
184: * @param string $alias optional table alias
185: * @throws PropelException Any exceptions caught during processing will be
186: * rethrown wrapped into a PropelException.
187: */
188: public static function addSelectColumns(Criteria $criteria, $alias = null)
189: {
190: if (null === $alias) {
191: $criteria->addSelectColumn(CountryPeer::ID);
192: $criteria->addSelectColumn(CountryPeer::AREA_ID);
193: $criteria->addSelectColumn(CountryPeer::ISOCODE);
194: $criteria->addSelectColumn(CountryPeer::ISOALPHA2);
195: $criteria->addSelectColumn(CountryPeer::ISOALPHA3);
196: $criteria->addSelectColumn(CountryPeer::CREATED_AT);
197: $criteria->addSelectColumn(CountryPeer::UPDATED_AT);
198: } else {
199: $criteria->addSelectColumn($alias . '.ID');
200: $criteria->addSelectColumn($alias . '.AREA_ID');
201: $criteria->addSelectColumn($alias . '.ISOCODE');
202: $criteria->addSelectColumn($alias . '.ISOALPHA2');
203: $criteria->addSelectColumn($alias . '.ISOALPHA3');
204: $criteria->addSelectColumn($alias . '.CREATED_AT');
205: $criteria->addSelectColumn($alias . '.UPDATED_AT');
206: }
207: }
208:
209: /**
210: * Returns the number of rows matching criteria.
211: *
212: * @param Criteria $criteria
213: * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
214: * @param PropelPDO $con
215: * @return int Number of matching rows.
216: */
217: public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
218: {
219: // we may modify criteria, so copy it first
220: $criteria = clone $criteria;
221:
222: // We need to set the primary table name, since in the case that there are no WHERE columns
223: // it will be impossible for the BasePeer::createSelectSql() method to determine which
224: // tables go into the FROM clause.
225: $criteria->setPrimaryTableName(CountryPeer::TABLE_NAME);
226:
227: if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
228: $criteria->setDistinct();
229: }
230:
231: if (!$criteria->hasSelectClause()) {
232: CountryPeer::addSelectColumns($criteria);
233: }
234:
235: $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
236: $criteria->setDbName(CountryPeer::DATABASE_NAME); // Set the correct dbName
237:
238: if ($con === null) {
239: $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
240: }
241: // BasePeer returns a PDOStatement
242: $stmt = BasePeer::doCount($criteria, $con);
243:
244: if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
245: $count = (int) $row[0];
246: } else {
247: $count = 0; // no rows returned; we infer that means 0 matches.
248: }
249: $stmt->closeCursor();
250:
251: return $count;
252: }
253: /**
254: * Selects one object from the DB.
255: *
256: * @param Criteria $criteria object used to create the SELECT statement.
257: * @param PropelPDO $con
258: * @return Country
259: * @throws PropelException Any exceptions caught during processing will be
260: * rethrown wrapped into a PropelException.
261: */
262: public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
263: {
264: $critcopy = clone $criteria;
265: $critcopy->setLimit(1);
266: $objects = CountryPeer::doSelect($critcopy, $con);
267: if ($objects) {
268: return $objects[0];
269: }
270:
271: return null;
272: }
273: /**
274: * Selects several row from the DB.
275: *
276: * @param Criteria $criteria The Criteria object used to build the SELECT statement.
277: * @param PropelPDO $con
278: * @return array Array of selected Objects
279: * @throws PropelException Any exceptions caught during processing will be
280: * rethrown wrapped into a PropelException.
281: */
282: public static function doSelect(Criteria $criteria, PropelPDO $con = null)
283: {
284: return CountryPeer::populateObjects(CountryPeer::doSelectStmt($criteria, $con));
285: }
286: /**
287: * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
288: *
289: * Use this method directly if you want to work with an executed statement durirectly (for example
290: * to perform your own object hydration).
291: *
292: * @param Criteria $criteria The Criteria object used to build the SELECT statement.
293: * @param PropelPDO $con The connection to use
294: * @throws PropelException Any exceptions caught during processing will be
295: * rethrown wrapped into a PropelException.
296: * @return PDOStatement The executed PDOStatement object.
297: * @see BasePeer::doSelect()
298: */
299: public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
300: {
301: if ($con === null) {
302: $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
303: }
304:
305: if (!$criteria->hasSelectClause()) {
306: $criteria = clone $criteria;
307: CountryPeer::addSelectColumns($criteria);
308: }
309:
310: // Set the correct dbName
311: $criteria->setDbName(CountryPeer::DATABASE_NAME);
312:
313: // BasePeer returns a PDOStatement
314: return BasePeer::doSelect($criteria, $con);
315: }
316: /**
317: * Adds an object to the instance pool.
318: *
319: * Propel keeps cached copies of objects in an instance pool when they are retrieved
320: * from the database. In some cases -- especially when you override doSelect*()
321: * methods in your stub classes -- you may need to explicitly add objects
322: * to the cache in order to ensure that the same objects are always returned by doSelect*()
323: * and retrieveByPK*() calls.
324: *
325: * @param Country $obj A Country object.
326: * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
327: */
328: public static function addInstanceToPool($obj, $key = null)
329: {
330: if (Propel::isInstancePoolingEnabled()) {
331: if ($key === null) {
332: $key = (string) $obj->getId();
333: } // if key === null
334: CountryPeer::$instances[$key] = $obj;
335: }
336: }
337:
338: /**
339: * Removes an object from the instance pool.
340: *
341: * Propel keeps cached copies of objects in an instance pool when they are retrieved
342: * from the database. In some cases -- especially when you override doDelete
343: * methods in your stub classes -- you may need to explicitly remove objects
344: * from the cache in order to prevent returning objects that no longer exist.
345: *
346: * @param mixed $value A Country object or a primary key value.
347: *
348: * @return void
349: * @throws PropelException - if the value is invalid.
350: */
351: public static function removeInstanceFromPool($value)
352: {
353: if (Propel::isInstancePoolingEnabled() && $value !== null) {
354: if (is_object($value) && $value instanceof Country) {
355: $key = (string) $value->getId();
356: } elseif (is_scalar($value)) {
357: // assume we've been passed a primary key
358: $key = (string) $value;
359: } else {
360: $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or Country object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
361: throw $e;
362: }
363:
364: unset(CountryPeer::$instances[$key]);
365: }
366: } // removeInstanceFromPool()
367:
368: /**
369: * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
370: *
371: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
372: * a multi-column primary key, a serialize()d version of the primary key will be returned.
373: *
374: * @param string $key The key (@see getPrimaryKeyHash()) for this instance.
375: * @return Country Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled.
376: * @see getPrimaryKeyHash()
377: */
378: public static function getInstanceFromPool($key)
379: {
380: if (Propel::isInstancePoolingEnabled()) {
381: if (isset(CountryPeer::$instances[$key])) {
382: return CountryPeer::$instances[$key];
383: }
384: }
385:
386: return null; // just to be explicit
387: }
388:
389: /**
390: * Clear the instance pool.
391: *
392: * @return void
393: */
394: public static function clearInstancePool()
395: {
396: CountryPeer::$instances = array();
397: }
398:
399: /**
400: * Method to invalidate the instance pool of all tables related to country
401: * by a foreign key with ON DELETE CASCADE
402: */
403: public static function clearRelatedInstancePool()
404: {
405: // Invalidate objects in TaxRuleCountryPeer instance pool,
406: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
407: TaxRuleCountryPeer::clearInstancePool();
408: // Invalidate objects in CountryI18nPeer instance pool,
409: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
410: CountryI18nPeer::clearInstancePool();
411: }
412:
413: /**
414: * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
415: *
416: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
417: * a multi-column primary key, a serialize()d version of the primary key will be returned.
418: *
419: * @param array $row PropelPDO resultset row.
420: * @param int $startcol The 0-based offset for reading from the resultset row.
421: * @return string A string version of PK or null if the components of primary key in result array are all null.
422: */
423: public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
424: {
425: // If the PK cannot be derived from the row, return null.
426: if ($row[$startcol] === null) {
427: return null;
428: }
429:
430: return (string) $row[$startcol];
431: }
432:
433: /**
434: * Retrieves the primary key from the DB resultset row
435: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
436: * a multi-column primary key, an array of the primary key columns will be returned.
437: *
438: * @param array $row PropelPDO resultset row.
439: * @param int $startcol The 0-based offset for reading from the resultset row.
440: * @return mixed The primary key of the row
441: */
442: public static function getPrimaryKeyFromRow($row, $startcol = 0)
443: {
444:
445: return (int) $row[$startcol];
446: }
447:
448: /**
449: * The returned array will contain objects of the default type or
450: * objects that inherit from the default.
451: *
452: * @throws PropelException Any exceptions caught during processing will be
453: * rethrown wrapped into a PropelException.
454: */
455: public static function populateObjects(PDOStatement $stmt)
456: {
457: $results = array();
458:
459: // set the class once to avoid overhead in the loop
460: $cls = CountryPeer::getOMClass();
461: // populate the object(s)
462: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
463: $key = CountryPeer::getPrimaryKeyHashFromRow($row, 0);
464: if (null !== ($obj = CountryPeer::getInstanceFromPool($key))) {
465: // We no longer rehydrate the object, since this can cause data loss.
466: // See http://www.propelorm.org/ticket/509
467: // $obj->hydrate($row, 0, true); // rehydrate
468: $results[] = $obj;
469: } else {
470: $obj = new $cls();
471: $obj->hydrate($row);
472: $results[] = $obj;
473: CountryPeer::addInstanceToPool($obj, $key);
474: } // if key exists
475: }
476: $stmt->closeCursor();
477:
478: return $results;
479: }
480: /**
481: * Populates an object of the default type or an object that inherit from the default.
482: *
483: * @param array $row PropelPDO resultset row.
484: * @param int $startcol The 0-based offset for reading from the resultset row.
485: * @throws PropelException Any exceptions caught during processing will be
486: * rethrown wrapped into a PropelException.
487: * @return array (Country object, last column rank)
488: */
489: public static function populateObject($row, $startcol = 0)
490: {
491: $key = CountryPeer::getPrimaryKeyHashFromRow($row, $startcol);
492: if (null !== ($obj = CountryPeer::getInstanceFromPool($key))) {
493: // We no longer rehydrate the object, since this can cause data loss.
494: // See http://www.propelorm.org/ticket/509
495: // $obj->hydrate($row, $startcol, true); // rehydrate
496: $col = $startcol + CountryPeer::NUM_HYDRATE_COLUMNS;
497: } else {
498: $cls = CountryPeer::OM_CLASS;
499: $obj = new $cls();
500: $col = $obj->hydrate($row, $startcol);
501: CountryPeer::addInstanceToPool($obj, $key);
502: }
503:
504: return array($obj, $col);
505: }
506:
507:
508: /**
509: * Returns the number of rows matching criteria, joining the related Area table
510: *
511: * @param Criteria $criteria
512: * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
513: * @param PropelPDO $con
514: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
515: * @return int Number of matching rows.
516: */
517: public static function doCountJoinArea(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
518: {
519: // we're going to modify criteria, so copy it first
520: $criteria = clone $criteria;
521:
522: // We need to set the primary table name, since in the case that there are no WHERE columns
523: // it will be impossible for the BasePeer::createSelectSql() method to determine which
524: // tables go into the FROM clause.
525: $criteria->setPrimaryTableName(CountryPeer::TABLE_NAME);
526:
527: if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
528: $criteria->setDistinct();
529: }
530:
531: if (!$criteria->hasSelectClause()) {
532: CountryPeer::addSelectColumns($criteria);
533: }
534:
535: $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
536:
537: // Set the correct dbName
538: $criteria->setDbName(CountryPeer::DATABASE_NAME);
539:
540: if ($con === null) {
541: $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
542: }
543:
544: $criteria->addJoin(CountryPeer::AREA_ID, AreaPeer::ID, $join_behavior);
545:
546: $stmt = BasePeer::doCount($criteria, $con);
547:
548: if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
549: $count = (int) $row[0];
550: } else {
551: $count = 0; // no rows returned; we infer that means 0 matches.
552: }
553: $stmt->closeCursor();
554:
555: return $count;
556: }
557:
558:
559: /**
560: * Selects a collection of Country objects pre-filled with their Area objects.
561: * @param Criteria $criteria
562: * @param PropelPDO $con
563: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
564: * @return array Array of Country objects.
565: * @throws PropelException Any exceptions caught during processing will be
566: * rethrown wrapped into a PropelException.
567: */
568: public static function doSelectJoinArea(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
569: {
570: $criteria = clone $criteria;
571:
572: // Set the correct dbName if it has not been overridden
573: if ($criteria->getDbName() == Propel::getDefaultDB()) {
574: $criteria->setDbName(CountryPeer::DATABASE_NAME);
575: }
576:
577: CountryPeer::addSelectColumns($criteria);
578: $startcol = CountryPeer::NUM_HYDRATE_COLUMNS;
579: AreaPeer::addSelectColumns($criteria);
580:
581: $criteria->addJoin(CountryPeer::AREA_ID, AreaPeer::ID, $join_behavior);
582:
583: $stmt = BasePeer::doSelect($criteria, $con);
584: $results = array();
585:
586: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
587: $key1 = CountryPeer::getPrimaryKeyHashFromRow($row, 0);
588: if (null !== ($obj1 = CountryPeer::getInstanceFromPool($key1))) {
589: // We no longer rehydrate the object, since this can cause data loss.
590: // See http://www.propelorm.org/ticket/509
591: // $obj1->hydrate($row, 0, true); // rehydrate
592: } else {
593:
594: $cls = CountryPeer::getOMClass();
595:
596: $obj1 = new $cls();
597: $obj1->hydrate($row);
598: CountryPeer::addInstanceToPool($obj1, $key1);
599: } // if $obj1 already loaded
600:
601: $key2 = AreaPeer::getPrimaryKeyHashFromRow($row, $startcol);
602: if ($key2 !== null) {
603: $obj2 = AreaPeer::getInstanceFromPool($key2);
604: if (!$obj2) {
605:
606: $cls = AreaPeer::getOMClass();
607:
608: $obj2 = new $cls();
609: $obj2->hydrate($row, $startcol);
610: AreaPeer::addInstanceToPool($obj2, $key2);
611: } // if obj2 already loaded
612:
613: // Add the $obj1 (Country) to $obj2 (Area)
614: $obj2->addCountry($obj1);
615:
616: } // if joined row was not null
617:
618: $results[] = $obj1;
619: }
620: $stmt->closeCursor();
621:
622: return $results;
623: }
624:
625:
626: /**
627: * Returns the number of rows matching criteria, joining all related tables
628: *
629: * @param Criteria $criteria
630: * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
631: * @param PropelPDO $con
632: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
633: * @return int Number of matching rows.
634: */
635: public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
636: {
637: // we're going to modify criteria, so copy it first
638: $criteria = clone $criteria;
639:
640: // We need to set the primary table name, since in the case that there are no WHERE columns
641: // it will be impossible for the BasePeer::createSelectSql() method to determine which
642: // tables go into the FROM clause.
643: $criteria->setPrimaryTableName(CountryPeer::TABLE_NAME);
644:
645: if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
646: $criteria->setDistinct();
647: }
648:
649: if (!$criteria->hasSelectClause()) {
650: CountryPeer::addSelectColumns($criteria);
651: }
652:
653: $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
654:
655: // Set the correct dbName
656: $criteria->setDbName(CountryPeer::DATABASE_NAME);
657:
658: if ($con === null) {
659: $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
660: }
661:
662: $criteria->addJoin(CountryPeer::AREA_ID, AreaPeer::ID, $join_behavior);
663:
664: $stmt = BasePeer::doCount($criteria, $con);
665:
666: if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
667: $count = (int) $row[0];
668: } else {
669: $count = 0; // no rows returned; we infer that means 0 matches.
670: }
671: $stmt->closeCursor();
672:
673: return $count;
674: }
675:
676: /**
677: * Selects a collection of Country objects pre-filled with all related objects.
678: *
679: * @param Criteria $criteria
680: * @param PropelPDO $con
681: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
682: * @return array Array of Country objects.
683: * @throws PropelException Any exceptions caught during processing will be
684: * rethrown wrapped into a PropelException.
685: */
686: public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
687: {
688: $criteria = clone $criteria;
689:
690: // Set the correct dbName if it has not been overridden
691: if ($criteria->getDbName() == Propel::getDefaultDB()) {
692: $criteria->setDbName(CountryPeer::DATABASE_NAME);
693: }
694:
695: CountryPeer::addSelectColumns($criteria);
696: $startcol2 = CountryPeer::NUM_HYDRATE_COLUMNS;
697:
698: AreaPeer::addSelectColumns($criteria);
699: $startcol3 = $startcol2 + AreaPeer::NUM_HYDRATE_COLUMNS;
700:
701: $criteria->addJoin(CountryPeer::AREA_ID, AreaPeer::ID, $join_behavior);
702:
703: $stmt = BasePeer::doSelect($criteria, $con);
704: $results = array();
705:
706: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
707: $key1 = CountryPeer::getPrimaryKeyHashFromRow($row, 0);
708: if (null !== ($obj1 = CountryPeer::getInstanceFromPool($key1))) {
709: // We no longer rehydrate the object, since this can cause data loss.
710: // See http://www.propelorm.org/ticket/509
711: // $obj1->hydrate($row, 0, true); // rehydrate
712: } else {
713: $cls = CountryPeer::getOMClass();
714:
715: $obj1 = new $cls();
716: $obj1->hydrate($row);
717: CountryPeer::addInstanceToPool($obj1, $key1);
718: } // if obj1 already loaded
719:
720: // Add objects for joined Area rows
721:
722: $key2 = AreaPeer::getPrimaryKeyHashFromRow($row, $startcol2);
723: if ($key2 !== null) {
724: $obj2 = AreaPeer::getInstanceFromPool($key2);
725: if (!$obj2) {
726:
727: $cls = AreaPeer::getOMClass();
728:
729: $obj2 = new $cls();
730: $obj2->hydrate($row, $startcol2);
731: AreaPeer::addInstanceToPool($obj2, $key2);
732: } // if obj2 loaded
733:
734: // Add the $obj1 (Country) to the collection in $obj2 (Area)
735: $obj2->addCountry($obj1);
736: } // if joined row not null
737:
738: $results[] = $obj1;
739: }
740: $stmt->closeCursor();
741:
742: return $results;
743: }
744:
745: /**
746: * Returns the TableMap related to this peer.
747: * This method is not needed for general use but a specific application could have a need.
748: * @return TableMap
749: * @throws PropelException Any exceptions caught during processing will be
750: * rethrown wrapped into a PropelException.
751: */
752: public static function getTableMap()
753: {
754: return Propel::getDatabaseMap(CountryPeer::DATABASE_NAME)->getTable(CountryPeer::TABLE_NAME);
755: }
756:
757: /**
758: * Add a TableMap instance to the database for this peer class.
759: */
760: public static function buildTableMap()
761: {
762: $dbMap = Propel::getDatabaseMap(BaseCountryPeer::DATABASE_NAME);
763: if (!$dbMap->hasTable(BaseCountryPeer::TABLE_NAME)) {
764: $dbMap->addTableObject(new CountryTableMap());
765: }
766: }
767:
768: /**
769: * The class that the Peer will make instances of.
770: *
771: *
772: * @return string ClassName
773: */
774: public static function getOMClass()
775: {
776: return CountryPeer::OM_CLASS;
777: }
778:
779: /**
780: * Performs an INSERT on the database, given a Country or Criteria object.
781: *
782: * @param mixed $values Criteria or Country object containing data that is used to create the INSERT statement.
783: * @param PropelPDO $con the PropelPDO connection to use
784: * @return mixed The new primary key.
785: * @throws PropelException Any exceptions caught during processing will be
786: * rethrown wrapped into a PropelException.
787: */
788: public static function doInsert($values, PropelPDO $con = null)
789: {
790: if ($con === null) {
791: $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
792: }
793:
794: if ($values instanceof Criteria) {
795: $criteria = clone $values; // rename for clarity
796: } else {
797: $criteria = $values->buildCriteria(); // build Criteria from Country object
798: }
799:
800:
801: // Set the correct dbName
802: $criteria->setDbName(CountryPeer::DATABASE_NAME);
803:
804: try {
805: // use transaction because $criteria could contain info
806: // for more than one table (I guess, conceivably)
807: $con->beginTransaction();
808: $pk = BasePeer::doInsert($criteria, $con);
809: $con->commit();
810: } catch (PropelException $e) {
811: $con->rollBack();
812: throw $e;
813: }
814:
815: return $pk;
816: }
817:
818: /**
819: * Performs an UPDATE on the database, given a Country or Criteria object.
820: *
821: * @param mixed $values Criteria or Country object containing data that is used to create the UPDATE statement.
822: * @param PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
823: * @return int The number of affected rows (if supported by underlying database driver).
824: * @throws PropelException Any exceptions caught during processing will be
825: * rethrown wrapped into a PropelException.
826: */
827: public static function doUpdate($values, PropelPDO $con = null)
828: {
829: if ($con === null) {
830: $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
831: }
832:
833: $selectCriteria = new Criteria(CountryPeer::DATABASE_NAME);
834:
835: if ($values instanceof Criteria) {
836: $criteria = clone $values; // rename for clarity
837:
838: $comparison = $criteria->getComparison(CountryPeer::ID);
839: $value = $criteria->remove(CountryPeer::ID);
840: if ($value) {
841: $selectCriteria->add(CountryPeer::ID, $value, $comparison);
842: } else {
843: $selectCriteria->setPrimaryTableName(CountryPeer::TABLE_NAME);
844: }
845:
846: } else { // $values is Country object
847: $criteria = $values->buildCriteria(); // gets full criteria
848: $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
849: }
850:
851: // set the correct dbName
852: $criteria->setDbName(CountryPeer::DATABASE_NAME);
853:
854: return BasePeer::doUpdate($selectCriteria, $criteria, $con);
855: }
856:
857: /**
858: * Deletes all rows from the country table.
859: *
860: * @param PropelPDO $con the connection to use
861: * @return int The number of affected rows (if supported by underlying database driver).
862: * @throws PropelException
863: */
864: public static function doDeleteAll(PropelPDO $con = null)
865: {
866: if ($con === null) {
867: $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
868: }
869: $affectedRows = 0; // initialize var to track total num of affected rows
870: try {
871: // use transaction because $criteria could contain info
872: // for more than one table or we could emulating ON DELETE CASCADE, etc.
873: $con->beginTransaction();
874: $affectedRows += BasePeer::doDeleteAll(CountryPeer::TABLE_NAME, $con, CountryPeer::DATABASE_NAME);
875: // Because this db requires some delete cascade/set null emulation, we have to
876: // clear the cached instance *after* the emulation has happened (since
877: // instances get re-added by the select statement contained therein).
878: CountryPeer::clearInstancePool();
879: CountryPeer::clearRelatedInstancePool();
880: $con->commit();
881:
882: return $affectedRows;
883: } catch (PropelException $e) {
884: $con->rollBack();
885: throw $e;
886: }
887: }
888:
889: /**
890: * Performs a DELETE on the database, given a Country or Criteria object OR a primary key value.
891: *
892: * @param mixed $values Criteria or Country object or primary key or array of primary keys
893: * which is used to create the DELETE statement
894: * @param PropelPDO $con the connection to use
895: * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
896: * if supported by native driver or if emulated using Propel.
897: * @throws PropelException Any exceptions caught during processing will be
898: * rethrown wrapped into a PropelException.
899: */
900: public static function doDelete($values, PropelPDO $con = null)
901: {
902: if ($con === null) {
903: $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
904: }
905:
906: if ($values instanceof Criteria) {
907: // invalidate the cache for all objects of this type, since we have no
908: // way of knowing (without running a query) what objects should be invalidated
909: // from the cache based on this Criteria.
910: CountryPeer::clearInstancePool();
911: // rename for clarity
912: $criteria = clone $values;
913: } elseif ($values instanceof Country) { // it's a model object
914: // invalidate the cache for this single object
915: CountryPeer::removeInstanceFromPool($values);
916: // create criteria based on pk values
917: $criteria = $values->buildPkeyCriteria();
918: } else { // it's a primary key, or an array of pks
919: $criteria = new Criteria(CountryPeer::DATABASE_NAME);
920: $criteria->add(CountryPeer::ID, (array) $values, Criteria::IN);
921: // invalidate the cache for this object(s)
922: foreach ((array) $values as $singleval) {
923: CountryPeer::removeInstanceFromPool($singleval);
924: }
925: }
926:
927: // Set the correct dbName
928: $criteria->setDbName(CountryPeer::DATABASE_NAME);
929:
930: $affectedRows = 0; // initialize var to track total num of affected rows
931:
932: try {
933: // use transaction because $criteria could contain info
934: // for more than one table or we could emulating ON DELETE CASCADE, etc.
935: $con->beginTransaction();
936:
937: $affectedRows += BasePeer::doDelete($criteria, $con);
938: CountryPeer::clearRelatedInstancePool();
939: $con->commit();
940:
941: return $affectedRows;
942: } catch (PropelException $e) {
943: $con->rollBack();
944: throw $e;
945: }
946: }
947:
948: /**
949: * Validates all modified columns of given Country object.
950: * If parameter $columns is either a single column name or an array of column names
951: * than only those columns are validated.
952: *
953: * NOTICE: This does not apply to primary or foreign keys for now.
954: *
955: * @param Country $obj The object to validate.
956: * @param mixed $cols Column name or array of column names.
957: *
958: * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
959: */
960: public static function doValidate($obj, $cols = null)
961: {
962: $columns = array();
963:
964: if ($cols) {
965: $dbMap = Propel::getDatabaseMap(CountryPeer::DATABASE_NAME);
966: $tableMap = $dbMap->getTable(CountryPeer::TABLE_NAME);
967:
968: if (! is_array($cols)) {
969: $cols = array($cols);
970: }
971:
972: foreach ($cols as $colName) {
973: if ($tableMap->hasColumn($colName)) {
974: $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
975: $columns[$colName] = $obj->$get();
976: }
977: }
978: } else {
979:
980: }
981:
982: return BasePeer::doValidate(CountryPeer::DATABASE_NAME, CountryPeer::TABLE_NAME, $columns);
983: }
984:
985: /**
986: * Retrieve a single object by pkey.
987: *
988: * @param int $pk the primary key.
989: * @param PropelPDO $con the connection to use
990: * @return Country
991: */
992: public static function retrieveByPK($pk, PropelPDO $con = null)
993: {
994:
995: if (null !== ($obj = CountryPeer::getInstanceFromPool((string) $pk))) {
996: return $obj;
997: }
998:
999: if ($con === null) {
1000: $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
1001: }
1002:
1003: $criteria = new Criteria(CountryPeer::DATABASE_NAME);
1004: $criteria->add(CountryPeer::ID, $pk);
1005:
1006: $v = CountryPeer::doSelect($criteria, $con);
1007:
1008: return !empty($v) > 0 ? $v[0] : null;
1009: }
1010:
1011: /**
1012: * Retrieve multiple objects by pkey.
1013: *
1014: * @param array $pks List of primary keys
1015: * @param PropelPDO $con the connection to use
1016: * @return Country[]
1017: * @throws PropelException Any exceptions caught during processing will be
1018: * rethrown wrapped into a PropelException.
1019: */
1020: public static function retrieveByPKs($pks, PropelPDO $con = null)
1021: {
1022: if ($con === null) {
1023: $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
1024: }
1025:
1026: $objs = null;
1027: if (empty($pks)) {
1028: $objs = array();
1029: } else {
1030: $criteria = new Criteria(CountryPeer::DATABASE_NAME);
1031: $criteria->add(CountryPeer::ID, $pks, Criteria::IN);
1032: $objs = CountryPeer::doSelect($criteria, $con);
1033: }
1034:
1035: return $objs;
1036: }
1037:
1038: } // BaseCountryPeer
1039:
1040: // This is the static code needed to register the TableMap for this table with the main Propel class.
1041: //
1042: BaseCountryPeer::buildTableMap();
1043:
1044: