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