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