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