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