<?php
require_once 'propel/om/BaseObject.php';
require_once 'propel/om/Persistent.php';
include_once 'propel/util/Criteria.php';
include_once 'diy-blog/model/PagePeer.php';
/**
* Base class that represents a row from the 'Page' table.
*
*
*
* This class was autogenerated by Propel on:
*
* 09/26/07 22:26:19
*
* @package diy-blog.model.om
*/
abstract class BasePage extends BaseObject implements Persistent {
/**
* The Peer class.
* Instance provides a convenient way of calling static methods on a class
* that calling code may not be able to identify.
* @var PagePeer
*/
protected static $peer;
/**
* The value for the id field.
* @var int
*/
protected $id;
/**
* The value for the title field.
* @var string
*/
protected $title;
/**
* The value for the content field.
* @var string
*/
protected $content;
/**
* The value for the datetime field.
* @var int
*/
protected $datetime;
/**
* The value for the username field.
* @var string
*/
protected $username;
/**
* The value for the frontenduri field.
* @var string
*/
protected $frontenduri;
/**
* The value for the backenduri field.
* @var string
*/
protected $backenduri;
/**
* The value for the type field.
* @var string
*/
protected $type = 'Page';
/**
* @var FrontEndResource
*/
protected $aFrontEndResource;
/**
* @var BackEndResource
*/
protected $aBackEndResource;
/**
* @var User
*/
protected $aUser;
/**
* Collection to store aggregation of collComments.
* @var array
*/
protected $collComments;
/**
* The criteria used to select the current contents of collComments.
* @var Criteria
*/
protected $lastCommentCriteria = null;
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
* @var boolean
*/
protected $alreadyInSave = false;
/**
* Flag to prevent endless validation loop, if this object is referenced
* by another object which falls in this transaction.
* @var boolean
*/
protected $alreadyInValidation = false;
/**
* Get the [id] column value.
*
* @return int
*/
public function getID()
{
return $this->id;
}
/**
* Get the [title] column value.
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Get the [content] column value.
*
* @return string
*/
public function getContent()
{
return $this->content;
}
/**
* Get the [optionally formatted] [datetime] column value.
*
* @param string $format The date/time format string (either date()-style or strftime()-style).
* If format is NULL, then the integer unix timestamp will be returned.
* @return mixed Formatted date/time value as string or integer unix timestamp (if format is NULL).
* @throws PropelException - if unable to convert the date/time to timestamp.
*/
public function getDateTime($format = 'Y-m-d H:i:s')
{
if ($this->datetime === null || $this->datetime === '') {
return null;
} elseif (!is_int($this->datetime)) {
// a non-timestamp value was set externally, so we convert it
$ts = strtotime($this->datetime);
if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
throw new PropelException("Unable to parse value of [datetime] as date/time value: " . var_export($this->datetime, true));
}
} else {
$ts = $this->datetime;
}
if ($format === null) {
return $ts;
} elseif (strpos($format, '%') !== false) {
return strftime($format, $ts);
} else {
return date($format, $ts);
}
}
/**
* Get the [username] column value.
*
* @return string
*/
public function getUserName()
{
return $this->username;
}
/**
* Get the [frontenduri] column value.
*
* @return string
*/
public function getFrontEndURI()
{
return $this->frontenduri;
}
/**
* Get the [backenduri] column value.
*
* @return string
*/
public function getBackEndURI()
{
return $this->backenduri;
}
/**
* Get the [type] column value.
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set the value of [id] column.
*
* @param int $v new value
* @return void
*/
public function setID($v)
{
// Since the native PHP type for this column is integer,
// we will cast the input value to an int (if it is not).
if ($v !== null && !is_int($v) && is_numeric($v)) {
$v = (int) $v;
}
if ($this->id !== $v) {
$this->id = $v;
$this->modifiedColumns[] = PagePeer::ID;
}
} // setID()
/**
* Set the value of [title] column.
*
* @param string $v new value
* @return void
*/
public function setTitle($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->title !== $v) {
$this->title = $v;
$this->modifiedColumns[] = PagePeer::TITLE;
}
} // setTitle()
/**
* Set the value of [content] column.
*
* @param string $v new value
* @return void
*/
public function setContent($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->content !== $v) {
$this->content = $v;
$this->modifiedColumns[] = PagePeer::CONTENT;
}
} // setContent()
/**
* Set the value of [datetime] column.
*
* @param int $v new value
* @return void
*/
public function setDateTime($v)
{
if ($v !== null && !is_int($v)) {
$ts = strtotime($v);
if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
throw new PropelException("Unable to parse date/time value for [datetime] from input: " . var_export($v, true));
}
} else {
$ts = $v;
}
if ($this->datetime !== $ts) {
$this->datetime = $ts;
$this->modifiedColumns[] = PagePeer::DATETIME;
}
} // setDateTime()
/**
* Set the value of [username] column.
*
* @param string $v new value
* @return void
*/
public function setUserName($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->username !== $v) {
$this->username = $v;
$this->modifiedColumns[] = PagePeer::USERNAME;
}
if ($this->aUser !== null && $this->aUser->getName() !== $v) {
$this->aUser = null;
}
} // setUserName()
/**
* Set the value of [frontenduri] column.
*
* @param string $v new value
* @return void
*/
public function setFrontEndURI($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->frontenduri !== $v) {
$this->frontenduri = $v;
$this->modifiedColumns[] = PagePeer::FRONTENDURI;
}
if ($this->aFrontEndResource !== null && $this->aFrontEndResource->getURI() !== $v) {
$this->aFrontEndResource = null;
}
} // setFrontEndURI()
/**
* Set the value of [backenduri] column.
*
* @param string $v new value
* @return void
*/
public function setBackEndURI($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->backenduri !== $v) {
$this->backenduri = $v;
$this->modifiedColumns[] = PagePeer::BACKENDURI;
}
if ($this->aBackEndResource !== null && $this->aBackEndResource->getURI() !== $v) {
$this->aBackEndResource = null;
}
} // setBackEndURI()
/**
* Set the value of [type] column.
*
* @param string $v new value
* @return void
*/
public function setType($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->type !== $v || $v === 'Page') {
$this->type = $v;
$this->modifiedColumns[] = PagePeer::TYPE;
}
} // setType()
/**
* Hydrates (populates) the object variables with values from the database resultset.
*
* An offset (1-based "start column") is specified so that objects can be hydrated
* with a subset of the columns in the resultset rows. This is needed, for example,
* for results of JOIN queries where the resultset row includes columns from two or
* more tables.
*
* @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos.
* @param int $startcol 1-based offset column which indicates which restultset column to start with.
* @return int next starting column
* @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
*/
public function hydrate(ResultSet $rs, $startcol = 1)
{
try {
$this->id = $rs->getInt($startcol + 0);
$this->title = $rs->getString($startcol + 1);
$this->content = $rs->getString($startcol + 2);
$this->datetime = $rs->getTimestamp($startcol + 3, null);
$this->username = $rs->getString($startcol + 4);
$this->frontenduri = $rs->getString($startcol + 5);
$this->backenduri = $rs->getString($startcol + 6);
$this->type = $rs->getString($startcol + 7);
$this->resetModified();
$this->setNew(false);
// FIXME - using NUM_COLUMNS may be clearer.
return $startcol + 8; // 8 = PagePeer::NUM_COLUMNS - PagePeer::NUM_LAZY_LOAD_COLUMNS).
} catch (Exception $e) {
throw new PropelException("Error populating Page object", $e);
}
}
/**
* Removes this object from datastore and sets delete attribute.
*
* @param Connection $con
* @return void
* @throws PropelException
* @see BaseObject::setDeleted()
* @see BaseObject::isDeleted()
*/
public function delete($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("This object has already been deleted.");
}
if ($con === null) {
$con = Propel::getConnection(PagePeer::DATABASE_NAME);
}
try {
$con->begin();
PagePeer::doDelete($this, $con);
$this->setDeleted(true);
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Stores the object in the database. If the object is new,
* it inserts it; otherwise an update is performed. This method
* wraps the doSave() worker method in a transaction.
*
* @param Connection $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see doSave()
*/
public function save($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("You cannot save an object that has been deleted.");
}
if ($con === null) {
$con = Propel::getConnection(PagePeer::DATABASE_NAME);
}
try {
$con->begin();
$affectedRows = $this->doSave($con);
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
/**
* Stores the object in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param Connection $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave($con)
{
$affectedRows = 0; // initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aFrontEndResource !== null) {
if ($this->aFrontEndResource->isModified()) {
$affectedRows += $this->aFrontEndResource->save($con);
}
$this->setFrontEndResource($this->aFrontEndResource);
}
if ($this->aBackEndResource !== null) {
if ($this->aBackEndResource->isModified()) {
$affectedRows += $this->aBackEndResource->save($con);
}
$this->setBackEndResource($this->aBackEndResource);
}
if ($this->aUser !== null) {
if ($this->aUser->isModified()) {
$affectedRows += $this->aUser->save($con);
}
$this->setUser($this->aUser);
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = PagePeer::doInsert($this, $con);
$affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setID($pk); //[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += PagePeer::doUpdate($this, $con);
}
$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
}
if ($this->collComments !== null) {
foreach($this->collComments as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
} // doSave()
/**
* Array of ValidationFailed objects.
* @var array ValidationFailed[]
*/
protected $validationFailures = array();
/**
* Gets any ValidationFailed objects that resulted from last call to validate().
*
*
* @return array ValidationFailed[]
* @see validate()
*/
public function getValidationFailures()
{
return $this->validationFailures;
}
/**
* Validates the objects modified field values and all objects related to this table.
*
* If $columns is either a column name or an array of column names
* only those columns are validated.
*
* @param mixed $columns Column name or an array of column names.
* @return boolean Whether all columns pass validation.
* @see doValidate()
* @see getValidationFailures()
*/
public function validate($columns = null)
{
$res = $this->doValidate($columns);
if ($res === true) {
$this->validationFailures = array();
return true;
} else {
$this->validationFailures = $res;
return false;
}
}
/**
* This function performs the validation work for complex object models.
*
* In addition to checking the current object, all related objects will
* also be validated. If all pass then <code>true</code> is returned; otherwise
* an aggreagated array of ValidationFailed objects will be returned.
*
* @param array $columns Array of column names to validate.
* @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
*/
protected function doValidate($columns = null)
{
if (!$this->alreadyInValidation) {
$this->alreadyInValidation = true;
$retval = null;
$failureMap = array();
// We call the validate method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aFrontEndResource !== null) {
if (!$this->aFrontEndResource->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aFrontEndResource->getValidationFailures());
}
}
if ($this->aBackEndResource !== null) {
if (!$this->aBackEndResource->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aBackEndResource->getValidationFailures());
}
}
if ($this->aUser !== null) {
if (!$this->aUser->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aUser->getValidationFailures());
}
}
if (($retval = PagePeer::doValidate($this, $columns)) !== true) {
$failureMap = array_merge($failureMap, $retval);
}
if ($this->collComments !== null) {
foreach($this->collComments as $referrerFK) {
if (!$referrerFK->validate($columns)) {
$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
}
}
}
$this->alreadyInValidation = false;
}
return (!empty($failureMap) ? $failureMap : true);
}
/**
* Build a Criteria object containing the values of all modified columns in this object.
*
* @return Criteria The Criteria object containing all modified values.
*/
public function buildCriteria()
{
$criteria = new Criteria(PagePeer::DATABASE_NAME);
if ($this->isColumnModified(PagePeer::ID)) $criteria->add(PagePeer::ID, $this->id);
if ($this->isColumnModified(PagePeer::TITLE)) $criteria->add(PagePeer::TITLE, $this->title);
if ($this->isColumnModified(PagePeer::CONTENT)) $criteria->add(PagePeer::CONTENT, $this->content);
if ($this->isColumnModified(PagePeer::DATETIME)) $criteria->add(PagePeer::DATETIME, $this->datetime);
if ($this->isColumnModified(PagePeer::USERNAME)) $criteria->add(PagePeer::USERNAME, $this->username);
if ($this->isColumnModified(PagePeer::FRONTENDURI)) $criteria->add(PagePeer::FRONTENDURI, $this->frontenduri);
if ($this->isColumnModified(PagePeer::BACKENDURI)) $criteria->add(PagePeer::BACKENDURI, $this->backenduri);
if ($this->isColumnModified(PagePeer::TYPE)) $criteria->add(PagePeer::TYPE, $this->type);
return $criteria;
}
/**
* Builds a Criteria object containing the primary key for this object.
*
* Unlike buildCriteria() this method includes the primary key values regardless
* of whether or not they have been modified.
*
* @return Criteria The Criteria object containing value(s) for primary key(s).
*/
public function buildPkeyCriteria()
{
$criteria = new Criteria(PagePeer::DATABASE_NAME);
$criteria->add(PagePeer::ID, $this->id);
return $criteria;
}
/**
* Returns the primary key for this object (row).
* @return int
*/
public function getPrimaryKey()
{
return $this->getID();
}
/**
* Generic method to set the primary key (id column).
*
* @param int $key Primary key.
* @return void
*/
public function setPrimaryKey($key)
{
$this->setID($key);
}
/**
* Sets contents of passed object to values from current object.
*
* If desired, this method can also make copies of all associated (fkey referrers)
* objects.
*
* @param object $copyObj An object of Page (or compatible) type.
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
* @throws PropelException
*/
public function copyInto($copyObj, $deepCopy = false)
{
$copyObj->setTitle($this->title);
$copyObj->setContent($this->content);
$copyObj->setDateTime($this->datetime);
$copyObj->setUserName($this->username);
$copyObj->setFrontEndURI($this->frontenduri);
$copyObj->setBackEndURI($this->backenduri);
$copyObj->setType($this->type);
if ($deepCopy) {
// important: temporarily setNew(false) because this affects the behavior of
// the getter/setter methods for fkey referrer objects.
$copyObj->setNew(false);
foreach($this->getComments() as $relObj) {
$copyObj->addComment($relObj->copy($deepCopy));
}
} // if ($deepCopy)
$copyObj->setNew(true);
$copyObj->setID(NULL); // this is a pkey column, so set to default value
}
/**
* Makes a copy of this object that will be inserted as a new row in table when saved.
* It creates a new object filling in the simple attributes, but skipping any primary
* keys that are defined for the table.
*
* If desired, this method can also make copies of all associated (fkey referrers)
* objects.
*
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
* @return Page Clone of current object.
* @throws PropelException
*/
public function copy($deepCopy = false)
{
// we use get_class(), because this might be a subclass
$clazz = get_class($this);
$copyObj = new $clazz();
$this->copyInto($copyObj, $deepCopy);
return $copyObj;
}
/**
* Returns a peer instance associated with this om.
*
* Since Peer classes are not to have any instance attributes, this method returns the
* same instance for all member of this class. The method could therefore
* be static, but this would prevent one from overriding the behavior.
*
* @return PagePeer
*/
public function getPeer()
{
if (self::$peer === null) {
self::$peer = new PagePeer();
}
return self::$peer;
}
/**
* Declares an association between this object and a FrontEndResource object.
*
* @param FrontEndResource $v
* @return void
* @throws PropelException
*/
public function setFrontEndResource($v)
{
if ($v === null) {
$this->setFrontEndURI(NULL);
} else {
$this->setFrontEndURI($v->getURI());
}
$this->aFrontEndResource = $v;
}
/**
* Get the associated FrontEndResource object
*
* @param Connection Optional Connection object.
* @return FrontEndResource The associated FrontEndResource object.
* @throws PropelException
*/
public function getFrontEndResource($con = null)
{
// include the related Peer class
include_once 'diy-blog/model/om/BaseFrontEndResourcePeer.php';
if ($this->aFrontEndResource === null && (($this->frontenduri !== "" && $this->frontenduri !== null))) {
$this->aFrontEndResource = FrontEndResourcePeer::retrieveByPK($this->frontenduri, $con);
/* The following can be used instead of the line above to
guarantee the related object contains a reference
to this object, but this level of coupling
may be undesirable in many circumstances.
As it can lead to a db query with many results that may
never be used.
$obj = FrontEndResourcePeer::retrieveByPK($this->frontenduri, $con);
$obj->addFrontEndResources($this);
*/
}
return $this->aFrontEndResource;
}
/**
* Declares an association between this object and a BackEndResource object.
*
* @param BackEndResource $v
* @return void
* @throws PropelException
*/
public function setBackEndResource($v)
{
if ($v === null) {
$this->setBackEndURI(NULL);
} else {
$this->setBackEndURI($v->getURI());
}
$this->aBackEndResource = $v;
}
/**
* Get the associated BackEndResource object
*
* @param Connection Optional Connection object.
* @return BackEndResource The associated BackEndResource object.
* @throws PropelException
*/
public function getBackEndResource($con = null)
{
// include the related Peer class
include_once 'diy-blog/model/om/BaseBackEndResourcePeer.php';
if ($this->aBackEndResource === null && (($this->backenduri !== "" && $this->backenduri !== null))) {
$this->aBackEndResource = BackEndResourcePeer::retrieveByPK($this->backenduri, $con);
/* The following can be used instead of the line above to
guarantee the related object contains a reference
to this object, but this level of coupling
may be undesirable in many circumstances.
As it can lead to a db query with many results that may
never be used.
$obj = BackEndResourcePeer::retrieveByPK($this->backenduri, $con);
$obj->addBackEndResources($this);
*/
}
return $this->aBackEndResource;
}
/**
* Declares an association between this object and a User object.
*
* @param User $v
* @return void
* @throws PropelException
*/
public function setUser($v)
{
if ($v === null) {
$this->setUserName(NULL);
} else {
$this->setUserName($v->getName());
}
$this->aUser = $v;
}
/**
* Get the associated User object
*
* @param Connection Optional Connection object.
* @return User The associated User object.
* @throws PropelException
*/
public function getUser($con = null)
{
// include the related Peer class
include_once 'diy-blog/model/om/BaseUserPeer.php';
if ($this->aUser === null && (($this->username !== "" && $this->username !== null))) {
$this->aUser = UserPeer::retrieveByPK($this->username, $con);
/* The following can be used instead of the line above to
guarantee the related object contains a reference
to this object, but this level of coupling
may be undesirable in many circumstances.
As it can lead to a db query with many results that may
never be used.
$obj = UserPeer::retrieveByPK($this->username, $con);
$obj->addUsers($this);
*/
}
return $this->aUser;
}
/**
* Temporary storage of collComments to save a possible db hit in
* the event objects are add to the collection, but the
* complete collection is never requested.
* @return void
*/
public function initComments()
{
if ($this->collComments === null) {
$this->collComments = array();
}
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this Page has previously
* been saved, it will retrieve related Comments from storage.
* If this Page is new, it will return
* an empty collection or the current collection, the criteria
* is ignored on a new object.
*
* @param Connection $con
* @param Criteria $criteria
* @throws PropelException
*/
public function getComments($criteria = null, $con = null)
{
// include the Peer class
include_once 'diy-blog/model/om/BaseCommentPeer.php';
if ($criteria === null) {
$criteria = new Criteria();
}
elseif ($criteria instanceof Criteria)
{
$criteria = clone $criteria;
}
if ($this->collComments === null) {
if ($this->isNew()) {
$this->collComments = array();
} else {
$criteria->add(CommentPeer::PAGEID, $this->getID());
CommentPeer::addSelectColumns($criteria);
$this->collComments = CommentPeer::doSelect($criteria, $con);
}
} else {
// criteria has no effect for a new object
if (!$this->isNew()) {
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return the collection.
$criteria->add(CommentPeer::PAGEID, $this->getID());
CommentPeer::addSelectColumns($criteria);
if (!isset($this->lastCommentCriteria) || !$this->lastCommentCriteria->equals($criteria)) {
$this->collComments = CommentPeer::doSelect($criteria, $con);
}
}
}
$this->lastCommentCriteria = $criteria;
return $this->collComments;
}
/**
* Returns the number of related Comments.
*
* @param Criteria $criteria
* @param boolean $distinct
* @param Connection $con
* @throws PropelException
*/
public function countComments($criteria = null, $distinct = false, $con = null)
{
// include the Peer class
include_once 'diy-blog/model/om/BaseCommentPeer.php';
if ($criteria === null) {
$criteria = new Criteria();
}
elseif ($criteria instanceof Criteria)
{
$criteria = clone $criteria;
}
$criteria->add(CommentPeer::PAGEID, $this->getID());
return CommentPeer::doCount($criteria, $distinct, $con);
}
/**
* Method called to associate a Comment object to this object
* through the Comment foreign key attribute
*
* @param Comment $l Comment
* @return void
* @throws PropelException
*/
public function addComment(Comment $l)
{
$this->collComments[] = $l;
$l->setPage($this);
}
} // BasePage