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