       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\CouponPeer;
      13: use Thelia\Model\CouponRule;
      14: use Thelia\Model\CouponRulePeer;
      15: use Thelia\Model\map\CouponRuleTableMap;
      16:
      17: /**
      18:  * Base static class for performing query and update operations on the 'coupon_rule' table.
      19:  *
      20:  *
      21:  *
      22:  * @package propel.generator.Thelia.Model.om
      23:  */
      24: abstract class BaseCouponRulePeer
      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_rule';
      32:
      33:     /** the related Propel class for this table */
      34:     const OM_CLASS = 'Thelia\\Model\\CouponRule';
      35:
      36:     /** the related TableMap class for this table */
      37:     const TM_CLASS = 'CouponRuleTableMap';
      38:
      39:     /** The total number of columns. */
      40:     const NUM_COLUMNS = 7;
      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 = 7;
      47:
      48:     /** the column name for the id field */
      49:     const ID = 'coupon_rule.id';
      50:
      51:     /** the column name for the coupon_id field */
      52:     const COUPON_ID = 'coupon_rule.coupon_id';
      53:
      54:     /** the column name for the controller field */
      55:     const CONTROLLER = 'coupon_rule.controller';
      56:
      57:     /** the column name for the operation field */
      58:     const OPERATION = 'coupon_rule.operation';
      59:
      60:     /** the column name for the value field */
      61:     const VALUE = 'coupon_rule.value';
      62:
      63:     /** the column name for the created_at field */
      64:     const CREATED_AT = 'coupon_rule.created_at';
      65:
      66:     /** the column name for the updated_at field */
      67:     const UPDATED_AT = 'coupon_rule.updated_at';
      68:
      69:     /** The default string format for model objects of the related table **/
      70:     const DEFAULT_STRING_FORMAT = 'YAML';
      71:
      72:     /**
      73:      * An identiy map to hold any loaded instances of CouponRule objects.
      74:      * This must be public so that other peer classes can access this when hydrating from JOIN
      75:      * queries.
      76:      * @var        array CouponRule[]
      77:      */
      78:     public static $instances = array();
      79:
      80:
      81:     /**
      82:      * holds an array of fieldnames
      83:      *
      84:      * first dimension keys are the type constants
      85:      * e.g. CouponRulePeer::$fieldNames[CouponRulePeer::TYPE_PHPNAME][0] = 'Id'
      86:      */
      87:     protected static $fieldNames = array (
      88:         BasePeer::TYPE_PHPNAME => array ('Id', 'CouponId', 'Controller', 'Operation', 'Value', 'CreatedAt', 'UpdatedAt', ),
      89:         BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'couponId', 'controller', 'operation', 'value', 'createdAt', 'updatedAt', ),
      90:         BasePeer::TYPE_COLNAME => array (CouponRulePeer::ID, CouponRulePeer::COUPON_ID, CouponRulePeer::CONTROLLER, CouponRulePeer::OPERATION, CouponRulePeer::VALUE, CouponRulePeer::CREATED_AT, CouponRulePeer::UPDATED_AT, ),
      91:         BasePeer::TYPE_RAW_COLNAME => array ('ID', 'COUPON_ID', 'CONTROLLER', 'OPERATION', 'VALUE', 'CREATED_AT', 'UPDATED_AT', ),
      92:         BasePeer::TYPE_FIELDNAME => array ('id', 'coupon_id', 'controller', 'operation', 'value', 'created_at', 'updated_at', ),
      93:         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, )
      94:     );
      95:
      96:     /**
      97:      * holds an array of keys for quick access to the fieldnames array
      98:      *
      99:      * first dimension keys are the type constants
     100:      * e.g. CouponRulePeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
     101:      */
     102:     protected static $fieldKeys = array (
     103:         BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'CouponId' => 1, 'Controller' => 2, 'Operation' => 3, 'Value' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ),
     104:         BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'couponId' => 1, 'controller' => 2, 'operation' => 3, 'value' => 4, 'createdAt' => 5, 'updatedAt' => 6, ),
     105:         BasePeer::TYPE_COLNAME => array (CouponRulePeer::ID => 0, CouponRulePeer::COUPON_ID => 1, CouponRulePeer::CONTROLLER => 2, CouponRulePeer::OPERATION => 3, CouponRulePeer::VALUE => 4, CouponRulePeer::CREATED_AT => 5, CouponRulePeer::UPDATED_AT => 6, ),
     106:         BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'COUPON_ID' => 1, 'CONTROLLER' => 2, 'OPERATION' => 3, 'VALUE' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ),
     107:         BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'coupon_id' => 1, 'controller' => 2, 'operation' => 3, 'value' => 4, 'created_at' => 5, 'updated_at' => 6, ),
     108:         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, )
     109:     );
     110:
     111:     /**
     112:      * Translates a fieldname to another type
     113:      *
     114:      * @param      string $name field name
     115:      * @param      string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     116:      *                         BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
     117:      * @param      string $toType   One of the class type constants
     118:      * @return string          translated name of the field.
     119:      * @throws PropelException - if the specified name could not be found in the fieldname mappings.
     120:      */
     121:     public static function translateFieldName($name, $fromType, $toType)
     122:     {
     123:         $toNames = CouponRulePeer::getFieldNames($toType);
     124:         $key = isset(CouponRulePeer::$fieldKeys[$fromType][$name]) ? CouponRulePeer::$fieldKeys[$fromType][$name] : null;
     125:         if ($key === null) {
     126:             throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(CouponRulePeer::$fieldKeys[$fromType], true));
     127:         }
     128:
     129:         return $toNames[$key];
     130:     }
     131:
     132:     /**
     133:      * Returns an array of field names.
     134:      *
     135:      * @param      string $type The type of fieldnames to return:
     136:      *                      One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     137:      *                      BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
     138:      * @return array           A list of field names
     139:      * @throws PropelException - if the type is not valid.
     140:      */
     141:     public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
     142:     {
     143:         if (!array_key_exists($type, CouponRulePeer::$fieldNames)) {
     144:             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.');
     145:         }
     146:
     147:         return CouponRulePeer::$fieldNames[$type];
     148:     }
     149:
     150:     /**
     151:      * Convenience method which changes table.column to alias.column.
     152:      *
     153:      * Using this method you can maintain SQL abstraction while using column aliases.
     154:      * <code>
     155:      *      $c->addAlias("alias1", TablePeer::TABLE_NAME);
     156:      *      $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
     157:      * </code>
     158:      * @param      string $alias The alias for the current table.
     159:      * @param      string $column The column name for current table. (i.e. CouponRulePeer::COLUMN_NAME).
     160:      * @return string
     161:      */
     162:     public static function alias($alias, $column)
     163:     {
     164:         return str_replace(CouponRulePeer::TABLE_NAME.'.', $alias.'.', $column);
     165:     }
     166:
     167:     /**
     168:      * Add all the columns needed to create a new object.
     169:      *
     170:      * Note: any columns that were marked with lazyLoad="true" in the
     171:      * XML schema will not be added to the select list and only loaded
     172:      * on demand.
     173:      *
     174:      * @param      Criteria $criteria object containing the columns to add.
     175:      * @param      string   $alias    optional table alias
     176:      * @throws PropelException Any exceptions caught during processing will be
     177:      *       rethrown wrapped into a PropelException.
     178:      */
     179:     public static function addSelectColumns(Criteria $criteria, $alias = null)
     180:     {
     181:         if (null === $alias) {
     182:             $criteria->addSelectColumn(CouponRulePeer::ID);
     183:             $criteria->addSelectColumn(CouponRulePeer::COUPON_ID);
     184:             $criteria->addSelectColumn(CouponRulePeer::CONTROLLER);
     185:             $criteria->addSelectColumn(CouponRulePeer::OPERATION);
     186:             $criteria->addSelectColumn(CouponRulePeer::VALUE);
     187:             $criteria->addSelectColumn(CouponRulePeer::CREATED_AT);
     188:             $criteria->addSelectColumn(CouponRulePeer::UPDATED_AT);
     189:         } else {
     190:             $criteria->addSelectColumn($alias . '.id');
     191:             $criteria->addSelectColumn($alias . '.coupon_id');
     192:             $criteria->addSelectColumn($alias . '.controller');
     193:             $criteria->addSelectColumn($alias . '.operation');
     194:             $criteria->addSelectColumn($alias . '.value');
     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(CouponRulePeer::TABLE_NAME);
     217:
     218:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     219:             $criteria->setDistinct();
     220:         }
     221:
     222:         if (!$criteria->hasSelectClause()) {
     223:             CouponRulePeer::addSelectColumns($criteria);
     224:         }
     225:
     226:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     227:         $criteria->setDbName(CouponRulePeer::DATABASE_NAME); // Set the correct dbName
     228:
     229:         if ($con === null) {
     230:             $con = Propel::getConnection(CouponRulePeer::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                 CouponRule
     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 = CouponRulePeer::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 CouponRulePeer::populateObjects(CouponRulePeer::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 directly (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(CouponRulePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     294:         }
     295:
     296:         if (!$criteria->hasSelectClause()) {
     297:             $criteria = clone $criteria;
     298:             CouponRulePeer::addSelectColumns($criteria);
     299:         }
     300:
     301:         // Set the correct dbName
     302:         $criteria->setDbName(CouponRulePeer::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      CouponRule $obj A CouponRule 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:             CouponRulePeer::$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 CouponRule 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 CouponRule) {
     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 CouponRule object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
     352:                 throw $e;
     353:             }
     354:
     355:             unset(CouponRulePeer::$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   CouponRule 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(CouponRulePeer::$instances[$key])) {
     373:                 return CouponRulePeer::$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($and_clear_all_references = false)
     386:     {
     387:       if ($and_clear_all_references)
     388:       {
     389:         foreach (CouponRulePeer::$instances as $instance)
     390:         {
     391:           $instance->clearAllReferences(true);
     392:         }
     393:       }
     394:         CouponRulePeer::$instances = array();
     395:     }
     396:
     397:     /**
     398:      * Method to invalidate the instance pool of all tables related to coupon_rule
     399:      * by a foreign key with ON DELETE CASCADE
     400:      */
     401:     public static function clearRelatedInstancePool()
     402:     {
     403:     }
     404:
     405:     /**
     406:      * 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.
     407:      *
     408:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     409:      * a multi-column primary key, a serialize()d version of the primary key will be returned.
     410:      *
     411:      * @param      array $row PropelPDO resultset row.
     412:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     413:      * @return string A string version of PK or null if the components of primary key in result array are all null.
     414:      */
     415:     public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
     416:     {
     417:         // If the PK cannot be derived from the row, return null.
     418:         if ($row[$startcol] === null) {
     419:             return null;
     420:         }
     421:
     422:         return (string) $row[$startcol];
     423:     }
     424:
     425:     /**
     426:      * Retrieves the primary key from the DB resultset row
     427:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     428:      * a multi-column primary key, an array of the primary key columns will be returned.
     429:      *
     430:      * @param      array $row PropelPDO resultset row.
     431:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     432:      * @return mixed The primary key of the row
     433:      */
     434:     public static function getPrimaryKeyFromRow($row, $startcol = 0)
     435:     {
     436:
     437:         return (int) $row[$startcol];
     438:     }
     439:
     440:     /**
     441:      * The returned array will contain objects of the default type or
     442:      * objects that inherit from the default.
     443:      *
     444:      * @throws PropelException Any exceptions caught during processing will be
     445:      *       rethrown wrapped into a PropelException.
     446:      */
     447:     public static function populateObjects(PDOStatement $stmt)
     448:     {
     449:         $results = array();
     450:
     451:         // set the class once to avoid overhead in the loop
     452:         $cls = CouponRulePeer::getOMClass();
     453:         // populate the object(s)
     454:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     455:             $key = CouponRulePeer::getPrimaryKeyHashFromRow($row, 0);
     456:             if (null !== ($obj = CouponRulePeer::getInstanceFromPool($key))) {
     457:                 // We no longer rehydrate the object, since this can cause data loss.
     458:                 // See http://www.propelorm.org/ticket/509
     459:                 // $obj->hydrate($row, 0, true); // rehydrate
     460:                 $results[] = $obj;
     461:             } else {
     462:                 $obj = new $cls();
     463:                 $obj->hydrate($row);
     464:                 $results[] = $obj;
     465:                 CouponRulePeer::addInstanceToPool($obj, $key);
     466:             } // if key exists
     467:         }
     468:         $stmt->closeCursor();
     469:
     470:         return $results;
     471:     }
     472:     /**
     473:      * Populates an object of the default type or an object that inherit from the default.
     474:      *
     475:      * @param      array $row PropelPDO resultset row.
     476:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     477:      * @throws PropelException Any exceptions caught during processing will be
     478:      *       rethrown wrapped into a PropelException.
     479:      * @return array (CouponRule object, last column rank)
     480:      */
     481:     public static function populateObject($row, $startcol = 0)
     482:     {
     483:         $key = CouponRulePeer::getPrimaryKeyHashFromRow($row, $startcol);
     484:         if (null !== ($obj = CouponRulePeer::getInstanceFromPool($key))) {
     485:             // We no longer rehydrate the object, since this can cause data loss.
     486:             // See http://www.propelorm.org/ticket/509
     487:             // $obj->hydrate($row, $startcol, true); // rehydrate
     488:             $col = $startcol + CouponRulePeer::NUM_HYDRATE_COLUMNS;
     489:         } else {
     490:             $cls = CouponRulePeer::OM_CLASS;
     491:             $obj = new $cls();
     492:             $col = $obj->hydrate($row, $startcol);
     493:             CouponRulePeer::addInstanceToPool($obj, $key);
     494:         }
     495:
     496:         return array($obj, $col);
     497:     }
     498:
     499:
     500:     /**
     501:      * Returns the number of rows matching criteria, joining the related Coupon table
     502:      *
     503:      * @param      Criteria $criteria
     504:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     505:      * @param      PropelPDO $con
     506:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     507:      * @return int Number of matching rows.
     508:      */
     509:     public static function doCountJoinCoupon(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     510:     {
     511:         // we're going to modify criteria, so copy it first
     512:         $criteria = clone $criteria;
     513:
     514:         // We need to set the primary table name, since in the case that there are no WHERE columns
     515:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     516:         // tables go into the FROM clause.
     517:         $criteria->setPrimaryTableName(CouponRulePeer::TABLE_NAME);
     518:
     519:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     520:             $criteria->setDistinct();
     521:         }
     522:
     523:         if (!$criteria->hasSelectClause()) {
     524:             CouponRulePeer::addSelectColumns($criteria);
     525:         }
     526:
     527:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     528:
     529:         // Set the correct dbName
     530:         $criteria->setDbName(CouponRulePeer::DATABASE_NAME);
     531:
     532:         if ($con === null) {
     533:             $con = Propel::getConnection(CouponRulePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     534:         }
     535:
     536:         $criteria->addJoin(CouponRulePeer::COUPON_ID, CouponPeer::ID, $join_behavior);
     537:
     538:         $stmt = BasePeer::doCount($criteria, $con);
     539:
     540:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     541:             $count = (int) $row[0];
     542:         } else {
     543:             $count = 0; // no rows returned; we infer that means 0 matches.
     544:         }
     545:         $stmt->closeCursor();
     546:
     547:         return $count;
     548:     }
     549:
     550:
     551:     /**
     552:      * Selects a collection of CouponRule objects pre-filled with their Coupon objects.
     553:      * @param      Criteria  $criteria
     554:      * @param      PropelPDO $con
     555:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     556:      * @return array           Array of CouponRule objects.
     557:      * @throws PropelException Any exceptions caught during processing will be
     558:      *       rethrown wrapped into a PropelException.
     559:      */
     560:     public static function doSelectJoinCoupon(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     561:     {
     562:         $criteria = clone $criteria;
     563:
     564:         // Set the correct dbName if it has not been overridden
     565:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     566:             $criteria->setDbName(CouponRulePeer::DATABASE_NAME);
     567:         }
     568:
     569:         CouponRulePeer::addSelectColumns($criteria);
     570:         $startcol = CouponRulePeer::NUM_HYDRATE_COLUMNS;
     571:         CouponPeer::addSelectColumns($criteria);
     572:
     573:         $criteria->addJoin(CouponRulePeer::COUPON_ID, CouponPeer::ID, $join_behavior);
     574:
     575:         $stmt = BasePeer::doSelect($criteria, $con);
     576:         $results = array();
     577:
     578:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     579:             $key1 = CouponRulePeer::getPrimaryKeyHashFromRow($row, 0);
     580:             if (null !== ($obj1 = CouponRulePeer::getInstanceFromPool($key1))) {
     581:                 // We no longer rehydrate the object, since this can cause data loss.
     582:                 // See http://www.propelorm.org/ticket/509
     583:                 // $obj1->hydrate($row, 0, true); // rehydrate
     584:             } else {
     585:
     586:                 $cls = CouponRulePeer::getOMClass();
     587:
     588:                 $obj1 = new $cls();
     589:                 $obj1->hydrate($row);
     590:                 CouponRulePeer::addInstanceToPool($obj1, $key1);
     591:             } // if $obj1 already loaded
     592:
     593:             $key2 = CouponPeer::getPrimaryKeyHashFromRow($row, $startcol);
     594:             if ($key2 !== null) {
     595:                 $obj2 = CouponPeer::getInstanceFromPool($key2);
     596:                 if (!$obj2) {
     597:
     598:                     $cls = CouponPeer::getOMClass();
     599:
     600:                     $obj2 = new $cls();
     601:                     $obj2->hydrate($row, $startcol);
     602:                     CouponPeer::addInstanceToPool($obj2, $key2);
     603:                 } // if obj2 already loaded
     604:
     605:                 // Add the $obj1 (CouponRule) to $obj2 (Coupon)
     606:                 $obj2->addCouponRule($obj1);
     607:
     608:             } // if joined row was not null
     609:
     610:             $results[] = $obj1;
     611:         }
     612:         $stmt->closeCursor();
     613:
     614:         return $results;
     615:     }
     616:
     617:
     618:     /**
     619:      * Returns the number of rows matching criteria, joining all related tables
     620:      *
     621:      * @param      Criteria $criteria
     622:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     623:      * @param      PropelPDO $con
     624:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     625:      * @return int Number of matching rows.
     626:      */
     627:     public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     628:     {
     629:         // we're going to modify criteria, so copy it first
     630:         $criteria = clone $criteria;
     631:
     632:         // We need to set the primary table name, since in the case that there are no WHERE columns
     633:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     634:         // tables go into the FROM clause.
     635:         $criteria->setPrimaryTableName(CouponRulePeer::TABLE_NAME);
     636:
     637:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     638:             $criteria->setDistinct();
     639:         }
     640:
     641:         if (!$criteria->hasSelectClause()) {
     642:             CouponRulePeer::addSelectColumns($criteria);
     643:         }
     644:
     645:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     646:
     647:         // Set the correct dbName
     648:         $criteria->setDbName(CouponRulePeer::DATABASE_NAME);
     649:
     650:         if ($con === null) {
     651:             $con = Propel::getConnection(CouponRulePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     652:         }
     653:
     654:         $criteria->addJoin(CouponRulePeer::COUPON_ID, CouponPeer::ID, $join_behavior);
     655:
     656:         $stmt = BasePeer::doCount($criteria, $con);
     657:
     658:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     659:             $count = (int) $row[0];
     660:         } else {
     661:             $count = 0; // no rows returned; we infer that means 0 matches.
     662:         }
     663:         $stmt->closeCursor();
     664:
     665:         return $count;
     666:     }
     667:
     668:     /**
     669:      * Selects a collection of CouponRule objects pre-filled with all related objects.
     670:      *
     671:      * @param      Criteria  $criteria
     672:      * @param      PropelPDO $con
     673:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     674:      * @return array           Array of CouponRule objects.
     675:      * @throws PropelException Any exceptions caught during processing will be
     676:      *       rethrown wrapped into a PropelException.
     677:      */
     678:     public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     679:     {
     680:         $criteria = clone $criteria;
     681:
     682:         // Set the correct dbName if it has not been overridden
     683:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     684:             $criteria->setDbName(CouponRulePeer::DATABASE_NAME);
     685:         }
     686:
     687:         CouponRulePeer::addSelectColumns($criteria);
     688:         $startcol2 = CouponRulePeer::NUM_HYDRATE_COLUMNS;
     689:
     690:         CouponPeer::addSelectColumns($criteria);
     691:         $startcol3 = $startcol2 + CouponPeer::NUM_HYDRATE_COLUMNS;
     692:
     693:         $criteria->addJoin(CouponRulePeer::COUPON_ID, CouponPeer::ID, $join_behavior);
     694:
     695:         $stmt = BasePeer::doSelect($criteria, $con);
     696:         $results = array();
     697:
     698:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     699:             $key1 = CouponRulePeer::getPrimaryKeyHashFromRow($row, 0);
     700:             if (null !== ($obj1 = CouponRulePeer::getInstanceFromPool($key1))) {
     701:                 // We no longer rehydrate the object, since this can cause data loss.
     702:                 // See http://www.propelorm.org/ticket/509
     703:                 // $obj1->hydrate($row, 0, true); // rehydrate
     704:             } else {
     705:                 $cls = CouponRulePeer::getOMClass();
     706:
     707:                 $obj1 = new $cls();
     708:                 $obj1->hydrate($row);
     709:                 CouponRulePeer::addInstanceToPool($obj1, $key1);
     710:             } // if obj1 already loaded
     711:
     712:             // Add objects for joined Coupon rows
     713:
     714:             $key2 = CouponPeer::getPrimaryKeyHashFromRow($row, $startcol2);
     715:             if ($key2 !== null) {
     716:                 $obj2 = CouponPeer::getInstanceFromPool($key2);
     717:                 if (!$obj2) {
     718:
     719:                     $cls = CouponPeer::getOMClass();
     720:
     721:                     $obj2 = new $cls();
     722:                     $obj2->hydrate($row, $startcol2);
     723:                     CouponPeer::addInstanceToPool($obj2, $key2);
     724:                 } // if obj2 loaded
     725:
     726:                 // Add the $obj1 (CouponRule) to the collection in $obj2 (Coupon)
     727:                 $obj2->addCouponRule($obj1);
     728:             } // if joined row not null
     729:
     730:             $results[] = $obj1;
     731:         }
     732:         $stmt->closeCursor();
     733:
     734:         return $results;
     735:     }
     736:
     737:     /**
     738:      * Returns the TableMap related to this peer.
     739:      * This method is not needed for general use but a specific application could have a need.
     740:      * @return TableMap
     741:      * @throws PropelException Any exceptions caught during processing will be
     742:      *       rethrown wrapped into a PropelException.
     743:      */
     744:     public static function getTableMap()
     745:     {
     746:         return Propel::getDatabaseMap(CouponRulePeer::DATABASE_NAME)->getTable(CouponRulePeer::TABLE_NAME);
     747:     }
     748:
     749:     /**
     750:      * Add a TableMap instance to the database for this peer class.
     751:      */
     752:     public static function buildTableMap()
     753:     {
     754:       $dbMap = Propel::getDatabaseMap(BaseCouponRulePeer::DATABASE_NAME);
     755:       if (!$dbMap->hasTable(BaseCouponRulePeer::TABLE_NAME)) {
     756:         $dbMap->addTableObject(new CouponRuleTableMap());
     757:       }
     758:     }
     759:
     760:     /**
     761:      * The class that the Peer will make instances of.
     762:      *
     763:      *
     764:      * @return string ClassName
     765:      */
     766:     public static function getOMClass($row = 0, $colnum = 0)
     767:     {
     768:         return CouponRulePeer::OM_CLASS;
     769:     }
     770:
     771:     /**
     772:      * Performs an INSERT on the database, given a CouponRule or Criteria object.
     773:      *
     774:      * @param      mixed $values Criteria or CouponRule object containing data that is used to create the INSERT statement.
     775:      * @param      PropelPDO $con the PropelPDO connection to use
     776:      * @return mixed           The new primary key.
     777:      * @throws PropelException Any exceptions caught during processing will be
     778:      *       rethrown wrapped into a PropelException.
     779:      */
     780:     public static function doInsert($values, PropelPDO $con = null)
     781:     {
     782:         if ($con === null) {
     783:             $con = Propel::getConnection(CouponRulePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     784:         }
     785:
     786:         if ($values instanceof Criteria) {
     787:             $criteria = clone $values; // rename for clarity
     788:         } else {
     789:             $criteria = $values->buildCriteria(); // build Criteria from CouponRule object
     790:         }
     791:
     792:         if ($criteria->containsKey(CouponRulePeer::ID) && $criteria->keyContainsValue(CouponRulePeer::ID) ) {
     793:             throw new PropelException('Cannot insert a value for auto-increment primary key ('.CouponRulePeer::ID.')');
     794:         }
     795:
     796:
     797:         // Set the correct dbName
     798:         $criteria->setDbName(CouponRulePeer::DATABASE_NAME);
     799:
     800:         try {
     801:             // use transaction because $criteria could contain info
     802:             // for more than one table (I guess, conceivably)
     803:             $con->beginTransaction();
     804:             $pk = BasePeer::doInsert($criteria, $con);
     805:             $con->commit();
     806:         } catch (PropelException $e) {
     807:             $con->rollBack();
     808:             throw $e;
     809:         }
     810:
     811:         return $pk;
     812:     }
     813:
     814:     /**
     815:      * Performs an UPDATE on the database, given a CouponRule or Criteria object.
     816:      *
     817:      * @param      mixed $values Criteria or CouponRule object containing data that is used to create the UPDATE statement.
     818:      * @param      PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
     819:      * @return int             The number of affected rows (if supported by underlying database driver).
     820:      * @throws PropelException Any exceptions caught during processing will be
     821:      *       rethrown wrapped into a PropelException.
     822:      */
     823:     public static function doUpdate($values, PropelPDO $con = null)
     824:     {
     825:         if ($con === null) {
     826:             $con = Propel::getConnection(CouponRulePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     827:         }
     828:
     829:         $selectCriteria = new Criteria(CouponRulePeer::DATABASE_NAME);
     830:
     831:         if ($values instanceof Criteria) {
     832:             $criteria = clone $values; // rename for clarity
     833:
     834:             $comparison = $criteria->getComparison(CouponRulePeer::ID);
     835:             $value = $criteria->remove(CouponRulePeer::ID);
     836:             if ($value) {
     837:                 $selectCriteria->add(CouponRulePeer::ID, $value, $comparison);
     838:             } else {
     839:                 $selectCriteria->setPrimaryTableName(CouponRulePeer::TABLE_NAME);
     840:             }
     841:
     842:         } else { // $values is CouponRule object
     843:             $criteria = $values->buildCriteria(); // gets full criteria
     844:             $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
     845:         }
     846:
     847:         // set the correct dbName
     848:         $criteria->setDbName(CouponRulePeer::DATABASE_NAME);
     849:
     850:         return BasePeer::doUpdate($selectCriteria, $criteria, $con);
     851:     }
     852:
     853:     /**
     854:      * Deletes all rows from the coupon_rule table.
     855:      *
     856:      * @param      PropelPDO $con the connection to use
     857:      * @return int             The number of affected rows (if supported by underlying database driver).
     858:      * @throws PropelException
     859:      */
     860:     public static function doDeleteAll(PropelPDO $con = null)
     861:     {
     862:         if ($con === null) {
     863:             $con = Propel::getConnection(CouponRulePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     864:         }
     865:         $affectedRows = 0; // initialize var to track total num of affected rows
     866:         try {
     867:             // use transaction because $criteria could contain info
     868:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
     869:             $con->beginTransaction();
     870:             $affectedRows += BasePeer::doDeleteAll(CouponRulePeer::TABLE_NAME, $con, CouponRulePeer::DATABASE_NAME);
     871:             // Because this db requires some delete cascade/set null emulation, we have to
     872:             // clear the cached instance *after* the emulation has happened (since
     873:             // instances get re-added by the select statement contained therein).
     874:             CouponRulePeer::clearInstancePool();
     875:             CouponRulePeer::clearRelatedInstancePool();
     876:             $con->commit();
     877:
     878:             return $affectedRows;
     879:         } catch (PropelException $e) {
     880:             $con->rollBack();
     881:             throw $e;
     882:         }
     883:     }
     884:
     885:     /**
     886:      * Performs a DELETE on the database, given a CouponRule or Criteria object OR a primary key value.
     887:      *
     888:      * @param      mixed $values Criteria or CouponRule object or primary key or array of primary keys
     889:      *              which is used to create the DELETE statement
     890:      * @param      PropelPDO $con the connection to use
     891:      * @return int The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
     892:      *              if supported by native driver or if emulated using Propel.
     893:      * @throws PropelException Any exceptions caught during processing will be
     894:      *       rethrown wrapped into a PropelException.
     895:      */
     896:      public static function doDelete($values, PropelPDO $con = null)
     897:      {
     898:         if ($con === null) {
     899:             $con = Propel::getConnection(CouponRulePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     900:         }
     901:
     902:         if ($values instanceof Criteria) {
     903:             // invalidate the cache for all objects of this type, since we have no
     904:             // way of knowing (without running a query) what objects should be invalidated
     905:             // from the cache based on this Criteria.
     906:             CouponRulePeer::clearInstancePool();
     907:             // rename for clarity
     908:             $criteria = clone $values;
     909:         } elseif ($values instanceof CouponRule) { // it's a model object
     910:             // invalidate the cache for this single object
     911:             CouponRulePeer::removeInstanceFromPool($values);
     912:             // create criteria based on pk values
     913:             $criteria = $values->buildPkeyCriteria();
     914:         } else { // it's a primary key, or an array of pks
     915:             $criteria = new Criteria(CouponRulePeer::DATABASE_NAME);
     916:             $criteria->add(CouponRulePeer::ID, (array) $values, Criteria::IN);
     917:             // invalidate the cache for this object(s)
     918:             foreach ((array) $values as $singleval) {
     919:                 CouponRulePeer::removeInstanceFromPool($singleval);
     920:             }
     921:         }
     922:
     923:         // Set the correct dbName
     924:         $criteria->setDbName(CouponRulePeer::DATABASE_NAME);
     925:
     926:         $affectedRows = 0; // initialize var to track total num of affected rows
     927:
     928:         try {
     929:             // use transaction because $criteria could contain info
     930:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
     931:             $con->beginTransaction();
     932:
     933:             $affectedRows += BasePeer::doDelete($criteria, $con);
     934:             CouponRulePeer::clearRelatedInstancePool();
     935:             $con->commit();
     936:
     937:             return $affectedRows;
     938:         } catch (PropelException $e) {
     939:             $con->rollBack();
     940:             throw $e;
     941:         }
     942:     }
     943:
     944:     /**
     945:      * Validates all modified columns of given CouponRule object.
     946:      * If parameter $columns is either a single column name or an array of column names
     947:      * than only those columns are validated.
     948:      *
     949:      * NOTICE: This does not apply to primary or foreign keys for now.
     950:      *
     951:      * @param      CouponRule $obj The object to validate.
     952:      * @param      mixed $cols Column name or array of column names.
     953:      *
     954:      * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
     955:      */
     956:     public static function doValidate($obj, $cols = null)
     957:     {
     958:         $columns = array();
     959:
     960:         if ($cols) {
     961:             $dbMap = Propel::getDatabaseMap(CouponRulePeer::DATABASE_NAME);
     962:             $tableMap = $dbMap->getTable(CouponRulePeer::TABLE_NAME);
     963:
     964:             if (! is_array($cols)) {
     965:                 $cols = array($cols);
     966:             }
     967:
     968:             foreach ($cols as $colName) {
     969:                 if ($tableMap->hasColumn($colName)) {
     970:                     $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
     971:                     $columns[$colName] = $obj->$get();
     972:                 }
     973:             }
     974:         } else {
     975:
     976:         }
     977:
     978:         return BasePeer::doValidate(CouponRulePeer::DATABASE_NAME, CouponRulePeer::TABLE_NAME, $columns);
     979:     }
     980:
     981:     /**
     982:      * Retrieve a single object by pkey.
     983:      *
     984:      * @param      int $pk the primary key.
     985:      * @param      PropelPDO $con the connection to use
     986:      * @return CouponRule
     987:      */
     988:     public static function retrieveByPK($pk, PropelPDO $con = null)
     989:     {
     990:
     991:         if (null !== ($obj = CouponRulePeer::getInstanceFromPool((string) $pk))) {
     992:             return $obj;
     993:         }
     994:
     995:         if ($con === null) {
     996:             $con = Propel::getConnection(CouponRulePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     997:         }
     998:
     999:         $criteria = new Criteria(CouponRulePeer::DATABASE_NAME);
    1000:         $criteria->add(CouponRulePeer::ID, $pk);
    1001:
    1002:         $v = CouponRulePeer::doSelect($criteria, $con);
    1003:
    1004:         return !empty($v) > 0 ? $v[0] : null;
    1005:     }
    1006:
    1007:     /**
    1008:      * Retrieve multiple objects by pkey.
    1009:      *
    1010:      * @param      array $pks List of primary keys
    1011:      * @param      PropelPDO $con the connection to use
    1012:      * @return CouponRule[]
    1013:      * @throws PropelException Any exceptions caught during processing will be
    1014:      *       rethrown wrapped into a PropelException.
    1015:      */
    1016:     public static function retrieveByPKs($pks, PropelPDO $con = null)
    1017:     {
    1018:         if ($con === null) {
    1019:             $con = Propel::getConnection(CouponRulePeer::DATABASE_NAME, Propel::CONNECTION_READ);
    1020:         }
    1021:
    1022:         $objs = null;
    1023:         if (empty($pks)) {
    1024:             $objs = array();
    1025:         } else {
    1026:             $criteria = new Criteria(CouponRulePeer::DATABASE_NAME);
    1027:             $criteria->add(CouponRulePeer::ID, $pks, Criteria::IN);
    1028:             $objs = CouponRulePeer::doSelect($criteria, $con);
    1029:         }
    1030:
    1031:         return $objs;
    1032:     }
    1033:
    1034: } // BaseCouponRulePeer
    1035:
    1036: // This is the static code needed to register the TableMap for this table with the main Propel class.
    1037: //
    1038: BaseCouponRulePeer::buildTableMap();
    1039:
    1040: