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