# File core/lib/Thelia/Model/om/BaseFeaturePeer.php | thelia

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