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