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_US';
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 directly (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($and_clear_all_references = false)
423: {
424: if ($and_clear_all_references)
425: {
426: foreach (CategoryPeer::$instances as $instance)
427: {
428: $instance->clearAllReferences(true);
429: }
430: }
431: CategoryPeer::$instances = array();
432: }
433:
434: /**
435: * Method to invalidate the instance pool of all tables related to category
436: * by a foreign key with ON DELETE CASCADE
437: */
438: public static function clearRelatedInstancePool()
439: {
440: // Invalidate objects in ProductCategoryPeer instance pool,
441: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
442: ProductCategoryPeer::clearInstancePool();
443: // Invalidate objects in FeatureCategoryPeer instance pool,
444: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
445: FeatureCategoryPeer::clearInstancePool();
446: // Invalidate objects in AttributeCategoryPeer instance pool,
447: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
448: AttributeCategoryPeer::clearInstancePool();
449: // Invalidate objects in ContentAssocPeer instance pool,
450: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
451: ContentAssocPeer::clearInstancePool();
452: // Invalidate objects in ImagePeer instance pool,
453: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
454: ImagePeer::clearInstancePool();
455: // Invalidate objects in DocumentPeer instance pool,
456: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
457: DocumentPeer::clearInstancePool();
458: // Invalidate objects in RewritingPeer instance pool,
459: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
460: RewritingPeer::clearInstancePool();
461: // Invalidate objects in CategoryI18nPeer instance pool,
462: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
463: CategoryI18nPeer::clearInstancePool();
464: // Invalidate objects in CategoryVersionPeer instance pool,
465: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
466: CategoryVersionPeer::clearInstancePool();
467: }
468:
469: /**
470: * 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.
471: *
472: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
473: * a multi-column primary key, a serialize()d version of the primary key will be returned.
474: *
475: * @param array $row PropelPDO resultset row.
476: * @param int $startcol The 0-based offset for reading from the resultset row.
477: * @return string A string version of PK or null if the components of primary key in result array are all null.
478: */
479: public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
480: {
481: // If the PK cannot be derived from the row, return null.
482: if ($row[$startcol] === null) {
483: return null;
484: }
485:
486: return (string) $row[$startcol];
487: }
488:
489: /**
490: * Retrieves the primary key from the DB resultset row
491: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
492: * a multi-column primary key, an array of the primary key columns will be returned.
493: *
494: * @param array $row PropelPDO resultset row.
495: * @param int $startcol The 0-based offset for reading from the resultset row.
496: * @return mixed The primary key of the row
497: */
498: public static function getPrimaryKeyFromRow($row, $startcol = 0)
499: {
500:
501: return (int) $row[$startcol];
502: }
503:
504: /**
505: * The returned array will contain objects of the default type or
506: * objects that inherit from the default.
507: *
508: * @throws PropelException Any exceptions caught during processing will be
509: * rethrown wrapped into a PropelException.
510: */
511: public static function populateObjects(PDOStatement $stmt)
512: {
513: $results = array();
514:
515: // set the class once to avoid overhead in the loop
516: $cls = CategoryPeer::getOMClass();
517: // populate the object(s)
518: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
519: $key = CategoryPeer::getPrimaryKeyHashFromRow($row, 0);
520: if (null !== ($obj = CategoryPeer::getInstanceFromPool($key))) {
521: // We no longer rehydrate the object, since this can cause data loss.
522: // See http://www.propelorm.org/ticket/509
523: // $obj->hydrate($row, 0, true); // rehydrate
524: $results[] = $obj;
525: } else {
526: $obj = new $cls();
527: $obj->hydrate($row);
528: $results[] = $obj;
529: CategoryPeer::addInstanceToPool($obj, $key);
530: } // if key exists
531: }
532: $stmt->closeCursor();
533:
534: return $results;
535: }
536: /**
537: * Populates an object of the default type or an object that inherit from the default.
538: *
539: * @param array $row PropelPDO resultset row.
540: * @param int $startcol The 0-based offset for reading from the resultset row.
541: * @throws PropelException Any exceptions caught during processing will be
542: * rethrown wrapped into a PropelException.
543: * @return array (Category object, last column rank)
544: */
545: public static function populateObject($row, $startcol = 0)
546: {
547: $key = CategoryPeer::getPrimaryKeyHashFromRow($row, $startcol);
548: if (null !== ($obj = CategoryPeer::getInstanceFromPool($key))) {
549: // We no longer rehydrate the object, since this can cause data loss.
550: // See http://www.propelorm.org/ticket/509
551: // $obj->hydrate($row, $startcol, true); // rehydrate
552: $col = $startcol + CategoryPeer::NUM_HYDRATE_COLUMNS;
553: } else {
554: $cls = CategoryPeer::OM_CLASS;
555: $obj = new $cls();
556: $col = $obj->hydrate($row, $startcol);
557: CategoryPeer::addInstanceToPool($obj, $key);
558: }
559:
560: return array($obj, $col);
561: }
562:
563: /**
564: * Returns the TableMap related to this peer.
565: * This method is not needed for general use but a specific application could have a need.
566: * @return TableMap
567: * @throws PropelException Any exceptions caught during processing will be
568: * rethrown wrapped into a PropelException.
569: */
570: public static function getTableMap()
571: {
572: return Propel::getDatabaseMap(CategoryPeer::DATABASE_NAME)->getTable(CategoryPeer::TABLE_NAME);
573: }
574:
575: /**
576: * Add a TableMap instance to the database for this peer class.
577: */
578: public static function buildTableMap()
579: {
580: $dbMap = Propel::getDatabaseMap(BaseCategoryPeer::DATABASE_NAME);
581: if (!$dbMap->hasTable(BaseCategoryPeer::TABLE_NAME)) {
582: $dbMap->addTableObject(new CategoryTableMap());
583: }
584: }
585:
586: /**
587: * The class that the Peer will make instances of.
588: *
589: *
590: * @return string ClassName
591: */
592: public static function getOMClass($row = 0, $colnum = 0)
593: {
594: return CategoryPeer::OM_CLASS;
595: }
596:
597: /**
598: * Performs an INSERT on the database, given a Category or Criteria object.
599: *
600: * @param mixed $values Criteria or Category object containing data that is used to create the INSERT statement.
601: * @param PropelPDO $con the PropelPDO connection to use
602: * @return mixed The new primary key.
603: * @throws PropelException Any exceptions caught during processing will be
604: * rethrown wrapped into a PropelException.
605: */
606: public static function doInsert($values, PropelPDO $con = null)
607: {
608: if ($con === null) {
609: $con = Propel::getConnection(CategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
610: }
611:
612: if ($values instanceof Criteria) {
613: $criteria = clone $values; // rename for clarity
614: } else {
615: $criteria = $values->buildCriteria(); // build Criteria from Category object
616: }
617:
618: if ($criteria->containsKey(CategoryPeer::ID) && $criteria->keyContainsValue(CategoryPeer::ID) ) {
619: throw new PropelException('Cannot insert a value for auto-increment primary key ('.CategoryPeer::ID.')');
620: }
621:
622:
623: // Set the correct dbName
624: $criteria->setDbName(CategoryPeer::DATABASE_NAME);
625:
626: try {
627: // use transaction because $criteria could contain info
628: // for more than one table (I guess, conceivably)
629: $con->beginTransaction();
630: $pk = BasePeer::doInsert($criteria, $con);
631: $con->commit();
632: } catch (PropelException $e) {
633: $con->rollBack();
634: throw $e;
635: }
636:
637: return $pk;
638: }
639:
640: /**
641: * Performs an UPDATE on the database, given a Category or Criteria object.
642: *
643: * @param mixed $values Criteria or Category object containing data that is used to create the UPDATE statement.
644: * @param PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
645: * @return int The number of affected rows (if supported by underlying database driver).
646: * @throws PropelException Any exceptions caught during processing will be
647: * rethrown wrapped into a PropelException.
648: */
649: public static function doUpdate($values, PropelPDO $con = null)
650: {
651: if ($con === null) {
652: $con = Propel::getConnection(CategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
653: }
654:
655: $selectCriteria = new Criteria(CategoryPeer::DATABASE_NAME);
656:
657: if ($values instanceof Criteria) {
658: $criteria = clone $values; // rename for clarity
659:
660: $comparison = $criteria->getComparison(CategoryPeer::ID);
661: $value = $criteria->remove(CategoryPeer::ID);
662: if ($value) {
663: $selectCriteria->add(CategoryPeer::ID, $value, $comparison);
664: } else {
665: $selectCriteria->setPrimaryTableName(CategoryPeer::TABLE_NAME);
666: }
667:
668: } else { // $values is Category object
669: $criteria = $values->buildCriteria(); // gets full criteria
670: $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
671: }
672:
673: // set the correct dbName
674: $criteria->setDbName(CategoryPeer::DATABASE_NAME);
675:
676: return BasePeer::doUpdate($selectCriteria, $criteria, $con);
677: }
678:
679: /**
680: * Deletes all rows from the category table.
681: *
682: * @param PropelPDO $con the connection to use
683: * @return int The number of affected rows (if supported by underlying database driver).
684: * @throws PropelException
685: */
686: public static function doDeleteAll(PropelPDO $con = null)
687: {
688: if ($con === null) {
689: $con = Propel::getConnection(CategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
690: }
691: $affectedRows = 0; // initialize var to track total num of affected rows
692: try {
693: // use transaction because $criteria could contain info
694: // for more than one table or we could emulating ON DELETE CASCADE, etc.
695: $con->beginTransaction();
696: $affectedRows += BasePeer::doDeleteAll(CategoryPeer::TABLE_NAME, $con, CategoryPeer::DATABASE_NAME);
697: // Because this db requires some delete cascade/set null emulation, we have to
698: // clear the cached instance *after* the emulation has happened (since
699: // instances get re-added by the select statement contained therein).
700: CategoryPeer::clearInstancePool();
701: CategoryPeer::clearRelatedInstancePool();
702: $con->commit();
703:
704: return $affectedRows;
705: } catch (PropelException $e) {
706: $con->rollBack();
707: throw $e;
708: }
709: }
710:
711: /**
712: * Performs a DELETE on the database, given a Category or Criteria object OR a primary key value.
713: *
714: * @param mixed $values Criteria or Category object or primary key or array of primary keys
715: * which is used to create the DELETE statement
716: * @param PropelPDO $con the connection to use
717: * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
718: * if supported by native driver or if emulated using Propel.
719: * @throws PropelException Any exceptions caught during processing will be
720: * rethrown wrapped into a PropelException.
721: */
722: public static function doDelete($values, PropelPDO $con = null)
723: {
724: if ($con === null) {
725: $con = Propel::getConnection(CategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
726: }
727:
728: if ($values instanceof Criteria) {
729: // invalidate the cache for all objects of this type, since we have no
730: // way of knowing (without running a query) what objects should be invalidated
731: // from the cache based on this Criteria.
732: CategoryPeer::clearInstancePool();
733: // rename for clarity
734: $criteria = clone $values;
735: } elseif ($values instanceof Category) { // it's a model object
736: // invalidate the cache for this single object
737: CategoryPeer::removeInstanceFromPool($values);
738: // create criteria based on pk values
739: $criteria = $values->buildPkeyCriteria();
740: } else { // it's a primary key, or an array of pks
741: $criteria = new Criteria(CategoryPeer::DATABASE_NAME);
742: $criteria->add(CategoryPeer::ID, (array) $values, Criteria::IN);
743: // invalidate the cache for this object(s)
744: foreach ((array) $values as $singleval) {
745: CategoryPeer::removeInstanceFromPool($singleval);
746: }
747: }
748:
749: // Set the correct dbName
750: $criteria->setDbName(CategoryPeer::DATABASE_NAME);
751:
752: $affectedRows = 0; // initialize var to track total num of affected rows
753:
754: try {
755: // use transaction because $criteria could contain info
756: // for more than one table or we could emulating ON DELETE CASCADE, etc.
757: $con->beginTransaction();
758:
759: $affectedRows += BasePeer::doDelete($criteria, $con);
760: CategoryPeer::clearRelatedInstancePool();
761: $con->commit();
762:
763: return $affectedRows;
764: } catch (PropelException $e) {
765: $con->rollBack();
766: throw $e;
767: }
768: }
769:
770: /**
771: * Validates all modified columns of given Category object.
772: * If parameter $columns is either a single column name or an array of column names
773: * than only those columns are validated.
774: *
775: * NOTICE: This does not apply to primary or foreign keys for now.
776: *
777: * @param Category $obj The object to validate.
778: * @param mixed $cols Column name or array of column names.
779: *
780: * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
781: */
782: public static function doValidate($obj, $cols = null)
783: {
784: $columns = array();
785:
786: if ($cols) {
787: $dbMap = Propel::getDatabaseMap(CategoryPeer::DATABASE_NAME);
788: $tableMap = $dbMap->getTable(CategoryPeer::TABLE_NAME);
789:
790: if (! is_array($cols)) {
791: $cols = array($cols);
792: }
793:
794: foreach ($cols as $colName) {
795: if ($tableMap->hasColumn($colName)) {
796: $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
797: $columns[$colName] = $obj->$get();
798: }
799: }
800: } else {
801:
802: }
803:
804: return BasePeer::doValidate(CategoryPeer::DATABASE_NAME, CategoryPeer::TABLE_NAME, $columns);
805: }
806:
807: /**
808: * Retrieve a single object by pkey.
809: *
810: * @param int $pk the primary key.
811: * @param PropelPDO $con the connection to use
812: * @return Category
813: */
814: public static function retrieveByPK($pk, PropelPDO $con = null)
815: {
816:
817: if (null !== ($obj = CategoryPeer::getInstanceFromPool((string) $pk))) {
818: return $obj;
819: }
820:
821: if ($con === null) {
822: $con = Propel::getConnection(CategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
823: }
824:
825: $criteria = new Criteria(CategoryPeer::DATABASE_NAME);
826: $criteria->add(CategoryPeer::ID, $pk);
827:
828: $v = CategoryPeer::doSelect($criteria, $con);
829:
830: return !empty($v) > 0 ? $v[0] : null;
831: }
832:
833: /**
834: * Retrieve multiple objects by pkey.
835: *
836: * @param array $pks List of primary keys
837: * @param PropelPDO $con the connection to use
838: * @return Category[]
839: * @throws PropelException Any exceptions caught during processing will be
840: * rethrown wrapped into a PropelException.
841: */
842: public static function retrieveByPKs($pks, PropelPDO $con = null)
843: {
844: if ($con === null) {
845: $con = Propel::getConnection(CategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
846: }
847:
848: $objs = null;
849: if (empty($pks)) {
850: $objs = array();
851: } else {
852: $criteria = new Criteria(CategoryPeer::DATABASE_NAME);
853: $criteria->add(CategoryPeer::ID, $pks, Criteria::IN);
854: $objs = CategoryPeer::doSelect($criteria, $con);
855: }
856:
857: return $objs;
858: }
859:
860: // versionable behavior
861:
862: /**
863: * Checks whether versioning is enabled
864: *
865: * @return boolean
866: */
867: public static function isVersioningEnabled()
868: {
869: return self::$isVersioningEnabled;
870: }
871:
872: /**
873: * Enables versioning
874: */
875: public static function enableVersioning()
876: {
877: self::$isVersioningEnabled = true;
878: }
879:
880: /**
881: * Disables versioning
882: */
883: public static function disableVersioning()
884: {
885: self::$isVersioningEnabled = false;
886: }
887:
888: } // BaseCategoryPeer
889:
890: // This is the static code needed to register the TableMap for this table with the main Propel class.
891: //
892: BaseCategoryPeer::buildTableMap();
893:
894: