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