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