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