Skip to content

Instantly share code, notes, and snippets.

@fzaninotto
Created March 23, 2010 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fzaninotto/341322 to your computer and use it in GitHub Desktop.
Save fzaninotto/341322 to your computer and use it in GitHub Desktop.
<?php
/**
* Base class that represents a row from the 'user' table.
*
*
*
* @package propel.generator.many2many.om
*/
abstract class BaseUser extends BaseObject implements Persistent
{
/**
* Peer class name
*/
const PEER = 'UserPeer';
/**
* 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 UserPeer
*/
protected static $peer;
/**
* The value for the id field.
* @var int
*/
protected $id;
/**
* The value for the vestiging_id field.
* @var int
*/
protected $vestiging_id;
/**
* The value for the username field.
* @var string
*/
protected $username;
/**
* The value for the password field.
* @var string
*/
protected $password;
/**
* The value for the salt field.
* @var string
*/
protected $salt;
/**
* The value for the created_at field.
* @var string
*/
protected $created_at;
/**
* The value for the updated_at field.
* @var string
*/
protected $updated_at;
/**
* @var Vestiging
*/
protected $aVestiging;
/**
* @var array User2Role[] Collection to store aggregation of User2Role objects.
*/
protected $collUser2Roles;
/**
* @var array User2Permission[] Collection to store aggregation of User2Permission objects.
*/
protected $collUser2Permissions;
/**
* @var array Role[] Collection to store aggregation of Role objects.
*/
protected $collRoles;
/**
* @var array Permission[] Collection to store aggregation of Permission objects.
*/
protected $collPermissions;
/**
* 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 [vestiging_id] column value.
*
* @return int
*/
public function getVestigingId()
{
return $this->vestiging_id;
}
/**
* Get the [username] column value.
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Get the [password] column value.
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Get the [salt] column value.
*
* @return string
*/
public function getSalt()
{
return $this->salt;
}
/**
* Get the [optionally formatted] temporal [created_at] column value.
*
*
* @param string $format The date/time format string (either date()-style or strftime()-style).
* If format is NULL, then the raw DateTime object will be returned.
* @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
* @throws PropelException - if unable to parse/validate the date/time value.
*/
public function getCreatedAt($format = 'Y-m-d H:i:s')
{
if ($this->created_at === null) {
return null;
}
try {
$dt = new DateTime($this->created_at);
} catch (Exception $x) {
throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
}
if ($format === null) {
// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
return $dt;
} elseif (strpos($format, '%') !== false) {
return strftime($format, $dt->format('U'));
} else {
return $dt->format($format);
}
}
/**
* Get the [optionally formatted] temporal [updated_at] column value.
*
*
* @param string $format The date/time format string (either date()-style or strftime()-style).
* If format is NULL, then the raw DateTime object will be returned.
* @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
* @throws PropelException - if unable to parse/validate the date/time value.
*/
public function getUpdatedAt($format = 'Y-m-d H:i:s')
{
if ($this->updated_at === null) {
return null;
}
try {
$dt = new DateTime($this->updated_at);
} catch (Exception $x) {
throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
}
if ($format === null) {
// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
return $dt;
} elseif (strpos($format, '%') !== false) {
return strftime($format, $dt->format('U'));
} else {
return $dt->format($format);
}
}
/**
* Set the value of [id] column.
*
* @param int $v new value
* @return User The current object (for fluent API support)
*/
public function setId($v)
{
if ($v !== null) {
$v = (int) $v;
}
if ($this->id !== $v) {
$this->id = $v;
$this->modifiedColumns[] = UserPeer::ID;
}
return $this;
} // setId()
/**
* Set the value of [vestiging_id] column.
*
* @param int $v new value
* @return User The current object (for fluent API support)
*/
public function setVestigingId($v)
{
if ($v !== null) {
$v = (int) $v;
}
if ($this->vestiging_id !== $v) {
$this->vestiging_id = $v;
$this->modifiedColumns[] = UserPeer::VESTIGING_ID;
}
if ($this->aVestiging !== null && $this->aVestiging->getId() !== $v) {
$this->aVestiging = null;
}
return $this;
} // setVestigingId()
/**
* Set the value of [username] column.
*
* @param string $v new value
* @return User The current object (for fluent API support)
*/
public function setUsername($v)
{
if ($v !== null) {
$v = (string) $v;
}
if ($this->username !== $v) {
$this->username = $v;
$this->modifiedColumns[] = UserPeer::USERNAME;
}
return $this;
} // setUsername()
/**
* Set the value of [password] column.
*
* @param string $v new value
* @return User The current object (for fluent API support)
*/
public function setPassword($v)
{
if ($v !== null) {
$v = (string) $v;
}
if ($this->password !== $v) {
$this->password = $v;
$this->modifiedColumns[] = UserPeer::PASSWORD;
}
return $this;
} // setPassword()
/**
* Set the value of [salt] column.
*
* @param string $v new value
* @return User The current object (for fluent API support)
*/
public function setSalt($v)
{
if ($v !== null) {
$v = (string) $v;
}
if ($this->salt !== $v) {
$this->salt = $v;
$this->modifiedColumns[] = UserPeer::SALT;
}
return $this;
} // setSalt()
/**
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
*
* @param mixed $v string, integer (timestamp), or DateTime value. Empty string will
* be treated as NULL for temporal objects.
* @return User The current object (for fluent API support)
*/
public function setCreatedAt($v)
{
// we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
// -- which is unexpected, to say the least.
if ($v === null || $v === '') {
$dt = null;
} elseif ($v instanceof DateTime) {
$dt = $v;
} else {
// some string/numeric value passed; we normalize that so that we can
// validate it.
try {
if (is_numeric($v)) { // if it's a unix timestamp
$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
// We have to explicitly specify and then change the time zone because of a
// DateTime bug: http://bugs.php.net/bug.php?id=43003
$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
} else {
$dt = new DateTime($v);
}
} catch (Exception $x) {
throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
}
}
if ( $this->created_at !== null || $dt !== null ) {
// (nested ifs are a little easier to read in this case)
$currNorm = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d\\TH:i:sO') : null;
$newNorm = ($dt !== null) ? $dt->format('Y-m-d\\TH:i:sO') : null;
if ( ($currNorm !== $newNorm) // normalized values don't match
)
{
$this->created_at = ($dt ? $dt->format('Y-m-d\\TH:i:sO') : null);
$this->modifiedColumns[] = UserPeer::CREATED_AT;
}
} // if either are not null
return $this;
} // setCreatedAt()
/**
* Sets the value of [updated_at] column to a normalized version of the date/time value specified.
*
* @param mixed $v string, integer (timestamp), or DateTime value. Empty string will
* be treated as NULL for temporal objects.
* @return User The current object (for fluent API support)
*/
public function setUpdatedAt($v)
{
// we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
// -- which is unexpected, to say the least.
if ($v === null || $v === '') {
$dt = null;
} elseif ($v instanceof DateTime) {
$dt = $v;
} else {
// some string/numeric value passed; we normalize that so that we can
// validate it.
try {
if (is_numeric($v)) { // if it's a unix timestamp
$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
// We have to explicitly specify and then change the time zone because of a
// DateTime bug: http://bugs.php.net/bug.php?id=43003
$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
} else {
$dt = new DateTime($v);
}
} catch (Exception $x) {
throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
}
}
if ( $this->updated_at !== null || $dt !== null ) {
// (nested ifs are a little easier to read in this case)
$currNorm = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d\\TH:i:sO') : null;
$newNorm = ($dt !== null) ? $dt->format('Y-m-d\\TH:i:sO') : null;
if ( ($currNorm !== $newNorm) // normalized values don't match
)
{
$this->updated_at = ($dt ? $dt->format('Y-m-d\\TH:i:sO') : null);
$this->modifiedColumns[] = UserPeer::UPDATED_AT;
}
} // if either are not null
return $this;
} // setUpdatedAt()
/**
* Indicates whether the columns in this object are only set to default values.
*
* This method can be used in conjunction with isModified() to indicate whether an object is both
* modified _and_ has some values set which are non-default.
*
* @return boolean Whether the columns in this object are only been set with default values.
*/
public function hasOnlyDefaultValues()
{
// otherwise, everything was equal, so return TRUE
return true;
} // hasOnlyDefaultValues()
/**
* Hydrates (populates) the object variables with values from the database resultset.
*
* An offset (0-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 array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
* @param int $startcol 0-based offset column which indicates which restultset column to start with.
* @param boolean $rehydrate Whether this object is being re-hydrated from the database.
* @return int next starting column
* @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
*/
public function hydrate($row, $startcol = 0, $rehydrate = false)
{
try {
$this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
$this->vestiging_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
$this->username = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
$this->password = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
$this->salt = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
$this->created_at = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
$this->updated_at = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
$this->resetModified();
$this->setNew(false);
if ($rehydrate) {
$this->ensureConsistency();
}
return $startcol + 7; // 7 = UserPeer::NUM_COLUMNS - UserPeer::NUM_LAZY_LOAD_COLUMNS).
} catch (Exception $e) {
throw new PropelException("Error populating User object", $e);
}
}
/**
* Checks and repairs the internal consistency of the object.
*
* This method is executed after an already-instantiated object is re-hydrated
* from the database. It exists to check any foreign keys to make sure that
* the objects related to the current object are correct based on foreign key.
*
* You can override this method in the stub class, but you should always invoke
* the base method from the overridden method (i.e. parent::ensureConsistency()),
* in case your model changes.
*
* @throws PropelException
*/
public function ensureConsistency()
{
if ($this->aVestiging !== null && $this->vestiging_id !== $this->aVestiging->getId()) {
$this->aVestiging = null;
}
} // ensureConsistency
/**
* Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
*
* This will only work if the object has been saved and has a valid primary key set.
*
* @param boolean $deep (optional) Whether to also de-associated any related objects.
* @param PropelPDO $con (optional) The PropelPDO connection to use.
* @return void
* @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
*/
public function reload($deep = false, PropelPDO $con = null)
{
if ($this->isDeleted()) {
throw new PropelException("Cannot reload a deleted object.");
}
if ($this->isNew()) {
throw new PropelException("Cannot reload an unsaved object.");
}
if ($con === null) {
$con = Propel::getConnection(UserPeer::DATABASE_NAME, Propel::CONNECTION_READ);
}
// We don't need to alter the object instance pool; we're just modifying this instance
// already in the pool.
$stmt = UserPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
$row = $stmt->fetch(PDO::FETCH_NUM);
$stmt->closeCursor();
if (!$row) {
throw new PropelException('Cannot find matching row in the database to reload object values.');
}
$this->hydrate($row, 0, true); // rehydrate
if ($deep) { // also de-associate any related objects?
$this->aVestiging = null;
$this->collUser2Roles = null;
$this->collUser2Permissions = null;
} // if (deep)
}
/**
* Removes this object from datastore and sets delete attribute.
*
* @param PropelPDO $con
* @return void
* @throws PropelException
* @see BaseObject::setDeleted()
* @see BaseObject::isDeleted()
*/
public function delete(PropelPDO $con = null)
{
if ($this->isDeleted()) {
throw new PropelException("This object has already been deleted.");
}
if ($con === null) {
$con = Propel::getConnection(UserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
$con->beginTransaction();
try {
$ret = $this->preDelete($con);
if ($ret) {
UserQuery::create()
->filterByPrimaryKey($this->getPrimaryKey())
->delete($con);
$this->postDelete($con);
$con->commit();
$this->setDeleted(true);
} else {
$con->commit();
}
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
/**
* Persists this object to the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All modified related objects will also be persisted in the doSave()
* method. This method wraps all precipitate database operations in a
* single transaction.
*
* @param PropelPDO $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(PropelPDO $con = null)
{
if ($this->isDeleted()) {
throw new PropelException("You cannot save an object that has been deleted.");
}
if ($con === null) {
$con = Propel::getConnection(UserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
$con->beginTransaction();
$isInsert = $this->isNew();
try {
$ret = $this->preSave($con);
// timestampable behavior
if (!$this->isColumnModified(UserPeer::UPDATED_AT)) {
$this->setUpdatedAt(time());
}
if ($isInsert) {
$ret = $ret && $this->preInsert($con);
// timestampable behavior
if (!$this->isColumnModified(UserPeer::CREATED_AT)) {
$this->setCreatedAt(time());
}
} else {
$ret = $ret && $this->preUpdate($con);
}
if ($ret) {
$affectedRows = $this->doSave($con);
if ($isInsert) {
$this->postInsert($con);
} else {
$this->postUpdate($con);
}
$this->postSave($con);
UserPeer::addInstanceToPool($this);
} else {
$affectedRows = 0;
}
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
/**
* Performs the work of inserting or updating the row 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 PropelPDO $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(PropelPDO $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->aVestiging !== null) {
if ($this->aVestiging->isModified() || $this->aVestiging->isNew()) {
$affectedRows += $this->aVestiging->save($con);
}
$this->setVestiging($this->aVestiging);
}
if ($this->isNew() ) {
$this->modifiedColumns[] = UserPeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$criteria = $this->buildCriteria();
if ($criteria->keyContainsValue(UserPeer::ID) ) {
throw new PropelException('Cannot insert a value for auto-increment primary key ('.UserPeer::ID.')');
}
$pk = BasePeer::doInsert($criteria, $con);
$affectedRows += 1;
$this->setId($pk); //[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += UserPeer::doUpdate($this, $con);
}
$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
}
if ($this->collUser2Roles !== null) {
foreach ($this->collUser2Roles as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
if ($this->collUser2Permissions !== null) {
foreach ($this->collUser2Permissions 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->aVestiging !== null) {
if (!$this->aVestiging->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aVestiging->getValidationFailures());
}
}
if (($retval = UserPeer::doValidate($this, $columns)) !== true) {
$failureMap = array_merge($failureMap, $retval);
}
if ($this->collUser2Roles !== null) {
foreach ($this->collUser2Roles as $referrerFK) {
if (!$referrerFK->validate($columns)) {
$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
}
}
}
if ($this->collUser2Permissions !== null) {
foreach ($this->collUser2Permissions 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(UserPeer::DATABASE_NAME);
if ($this->isColumnModified(UserPeer::ID)) $criteria->add(UserPeer::ID, $this->id);
if ($this->isColumnModified(UserPeer::VESTIGING_ID)) $criteria->add(UserPeer::VESTIGING_ID, $this->vestiging_id);
if ($this->isColumnModified(UserPeer::USERNAME)) $criteria->add(UserPeer::USERNAME, $this->username);
if ($this->isColumnModified(UserPeer::PASSWORD)) $criteria->add(UserPeer::PASSWORD, $this->password);
if ($this->isColumnModified(UserPeer::SALT)) $criteria->add(UserPeer::SALT, $this->salt);
if ($this->isColumnModified(UserPeer::CREATED_AT)) $criteria->add(UserPeer::CREATED_AT, $this->created_at);
if ($this->isColumnModified(UserPeer::UPDATED_AT)) $criteria->add(UserPeer::UPDATED_AT, $this->updated_at);
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(UserPeer::DATABASE_NAME);
$criteria->add(UserPeer::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);
}
/**
* Returns true if the primary key for this object is null.
* @return boolean
*/
public function isPrimaryKeyNull()
{
return null === $this->getId();
}
/**
* 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 User (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->setVestigingId($this->vestiging_id);
$copyObj->setUsername($this->username);
$copyObj->setPassword($this->password);
$copyObj->setSalt($this->salt);
$copyObj->setCreatedAt($this->created_at);
$copyObj->setUpdatedAt($this->updated_at);
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->getUser2Roles() as $relObj) {
if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
$copyObj->addUser2Role($relObj->copy($deepCopy));
}
}
foreach ($this->getUser2Permissions() as $relObj) {
if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
$copyObj->addUser2Permission($relObj->copy($deepCopy));
}
}
} // if ($deepCopy)
$copyObj->setNew(true);
$copyObj->setId(NULL); // this is a auto-increment 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 User 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 UserPeer
*/
public function getPeer()
{
if (self::$peer === null) {
self::$peer = new UserPeer();
}
return self::$peer;
}
/**
* Declares an association between this object and a Vestiging object.
*
* @param Vestiging $v
* @return User The current object (for fluent API support)
* @throws PropelException
*/
public function setVestiging(Vestiging $v = null)
{
if ($v === null) {
$this->setVestigingId(NULL);
} else {
$this->setVestigingId($v->getId());
}
$this->aVestiging = $v;
// Add binding for other direction of this n:n relationship.
// If this object has already been added to the Vestiging object, it will not be re-added.
if ($v !== null) {
$v->addUser($this);
}
return $this;
}
/**
* Get the associated Vestiging object
*
* @param PropelPDO Optional Connection object.
* @return Vestiging The associated Vestiging object.
* @throws PropelException
*/
public function getVestiging(PropelPDO $con = null)
{
if ($this->aVestiging === null && ($this->vestiging_id !== null)) {
$this->aVestiging = VestigingQuery::create()->findPk($this->vestiging_id);
/* The following can be used additionally to
guarantee the related object contains a reference
to this object. This level of coupling may, however, be
undesirable since it could result in an only partially populated collection
in the referenced object.
$this->aVestiging->addUsers($this);
*/
}
return $this->aVestiging;
}
/**
* Clears out the collUser2Roles collection
*
* This does not modify the database; however, it will remove any associated objects, causing
* them to be refetched by subsequent calls to accessor method.
*
* @return void
* @see addUser2Roles()
*/
public function clearUser2Roles()
{
$this->collUser2Roles = null; // important to set this to NULL since that means it is uninitialized
}
/**
* Initializes the collUser2Roles collection.
*
* By default this just sets the collUser2Roles collection to an empty array (like clearcollUser2Roles());
* however, you may wish to override this method in your stub class to provide setting appropriate
* to your application -- for example, setting the initial array to the values stored in database.
*
* @return void
*/
public function initUser2Roles()
{
$this->collUser2Roles = new PropelObjectCollection();
$this->collUser2Roles->setModel('User2Role');
}
/**
* Gets an array of User2Role objects which contain a foreign key that references this object.
*
* If the $criteria is not null, it is used to always fetch the results from the database.
* Otherwise the results are fetched from the database the first time, then cached.
* Next time the same method is called without $criteria, the cached collection is returned.
* If this User is new, it will return
* an empty collection or the current collection; the criteria is ignored on a new object.
*
* @param Criteria $criteria
* @param PropelPDO $con
* @return PropelCollection|array User2Role[] List of User2Role objects
* @throws PropelException
*/
public function getUser2Roles($criteria = null, PropelPDO $con = null)
{
if(null === $this->collUser2Roles || null !== $criteria) {
if ($this->isNew() && null === $this->collUser2Roles) {
// return empty collection
$this->initUser2Roles();
} else {
$collUser2Roles = User2RoleQuery::create(null, $criteria)
->filterByUser($this)
->find($con);
if (null !== $criteria) {
return $collUser2Roles;
}
$this->collUser2Roles = $collUser2Roles;
}
}
return $this->collUser2Roles;
}
/**
* Returns the number of related User2Role objects.
*
* @param Criteria $criteria
* @param boolean $distinct
* @param PropelPDO $con
* @return int Count of related User2Role objects.
* @throws PropelException
*/
public function countUser2Roles(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
{
if(null === $this->collUser2Roles || null !== $criteria) {
if ($this->isNew() && null === $this->collUser2Roles) {
return 0;
} else {
$query = User2RoleQuery::create(null, $criteria);
if($distinct) {
$query->distinct();
}
return $query
->filterByUser($this)
->count($con);
}
} else {
return count($this->collUser2Roles);
}
}
/**
* Method called to associate a User2Role object to this object
* through the User2Role foreign key attribute.
*
* @param User2Role $l User2Role
* @return void
* @throws PropelException
*/
public function addUser2Role(User2Role $l)
{
if ($this->collUser2Roles === null) {
$this->initUser2Roles();
}
if (!$this->collUser2Roles->contains($l)) { // only add it if the **same** object is not already associated
$this->collUser2Roles[]= $l;
$l->setUser($this);
}
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this User is new, it will return
* an empty collection; or if this User has previously
* been saved, it will retrieve related User2Roles from storage.
*
* This method is protected by default in order to keep the public
* api reasonable. You can provide public methods for those you
* actually need in User.
*/
public function getUser2RolesJoinRole($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
{
$query = User2RoleQuery::create(null, $criteria);
$query->joinWith('User2Role.Role', $join_behavior);
return $this->getUser2Roles($query, $con);
}
/**
* Clears out the collUser2Permissions collection
*
* This does not modify the database; however, it will remove any associated objects, causing
* them to be refetched by subsequent calls to accessor method.
*
* @return void
* @see addUser2Permissions()
*/
public function clearUser2Permissions()
{
$this->collUser2Permissions = null; // important to set this to NULL since that means it is uninitialized
}
/**
* Initializes the collUser2Permissions collection.
*
* By default this just sets the collUser2Permissions collection to an empty array (like clearcollUser2Permissions());
* however, you may wish to override this method in your stub class to provide setting appropriate
* to your application -- for example, setting the initial array to the values stored in database.
*
* @return void
*/
public function initUser2Permissions()
{
$this->collUser2Permissions = new PropelObjectCollection();
$this->collUser2Permissions->setModel('User2Permission');
}
/**
* Gets an array of User2Permission objects which contain a foreign key that references this object.
*
* If the $criteria is not null, it is used to always fetch the results from the database.
* Otherwise the results are fetched from the database the first time, then cached.
* Next time the same method is called without $criteria, the cached collection is returned.
* If this User is new, it will return
* an empty collection or the current collection; the criteria is ignored on a new object.
*
* @param Criteria $criteria
* @param PropelPDO $con
* @return PropelCollection|array User2Permission[] List of User2Permission objects
* @throws PropelException
*/
public function getUser2Permissions($criteria = null, PropelPDO $con = null)
{
if(null === $this->collUser2Permissions || null !== $criteria) {
if ($this->isNew() && null === $this->collUser2Permissions) {
// return empty collection
$this->initUser2Permissions();
} else {
$collUser2Permissions = User2PermissionQuery::create(null, $criteria)
->filterByUser($this)
->find($con);
if (null !== $criteria) {
return $collUser2Permissions;
}
$this->collUser2Permissions = $collUser2Permissions;
}
}
return $this->collUser2Permissions;
}
/**
* Returns the number of related User2Permission objects.
*
* @param Criteria $criteria
* @param boolean $distinct
* @param PropelPDO $con
* @return int Count of related User2Permission objects.
* @throws PropelException
*/
public function countUser2Permissions(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
{
if(null === $this->collUser2Permissions || null !== $criteria) {
if ($this->isNew() && null === $this->collUser2Permissions) {
return 0;
} else {
$query = User2PermissionQuery::create(null, $criteria);
if($distinct) {
$query->distinct();
}
return $query
->filterByUser($this)
->count($con);
}
} else {
return count($this->collUser2Permissions);
}
}
/**
* Method called to associate a User2Permission object to this object
* through the User2Permission foreign key attribute.
*
* @param User2Permission $l User2Permission
* @return void
* @throws PropelException
*/
public function addUser2Permission(User2Permission $l)
{
if ($this->collUser2Permissions === null) {
$this->initUser2Permissions();
}
if (!$this->collUser2Permissions->contains($l)) { // only add it if the **same** object is not already associated
$this->collUser2Permissions[]= $l;
$l->setUser($this);
}
}
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this User is new, it will return
* an empty collection; or if this User has previously
* been saved, it will retrieve related User2Permissions from storage.
*
* This method is protected by default in order to keep the public
* api reasonable. You can provide public methods for those you
* actually need in User.
*/
public function getUser2PermissionsJoinPermission($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
{
$query = User2PermissionQuery::create(null, $criteria);
$query->joinWith('User2Permission.Permission', $join_behavior);
return $this->getUser2Permissions($query, $con);
}
/**
* Clears out the collRoles collection
*
* This does not modify the database; however, it will remove any associated objects, causing
* them to be refetched by subsequent calls to accessor method.
*
* @return void
* @see addRoles()
*/
public function clearRoles()
{
$this->collRoles = null; // important to set this to NULL since that means it is uninitialized
}
/**
* Initializes the collRoles collection.
*
* By default this just sets the collRoles collection to an empty collection (like clearRoles());
* however, you may wish to override this method in your stub class to provide setting appropriate
* to your application -- for example, setting the initial array to the values stored in database.
*
* @return void
*/
public function initRoles()
{
$this->collRoles = new PropelObjectCollection();
$this->collRoles->setModel('Role');
}
/**
* Gets a collection of Role objects related by a many-to-many relationship
* to the current object by way of the user_2_role cross-reference table.
*
* If the $criteria is not null, it is used to always fetch the results from the database.
* Otherwise the results are fetched from the database the first time, then cached.
* Next time the same method is called without $criteria, the cached collection is returned.
* If this User is new, it will return
* an empty collection or the current collection; the criteria is ignored on a new object.
*
* @param Criteria $criteria Optional query object to filter the query
* @param PropelPDO $con Optional connection object
*
* @return PropelCollection|array Role[] List of Role objects
*/
public function getRoles($criteria = null, PropelPDO $con = null)
{
if(null === $this->collRoles || null !== $criteria) {
if ($this->isNew() && null === $this->collRoles) {
// return empty collection
$this->initRoles();
} else {
$collRoles = RoleQuery::create(null, $criteria)
->filterByUser($this)
->find($con);
if (null !== $criteria) {
return $collRoles;
}
$this->collRoles = $collRoles;
}
}
return $this->collRoles;
}
/**
* Gets the number of Role objects related by a many-to-many relationship
* to the current object by way of the user_2_role cross-reference table.
*
* @param Criteria $criteria Optional query object to filter the query
* @param boolean $distinct Set to true to force count distinct
* @param PropelPDO $con Optional connection object
*
* @return int the number of related Role objects
*/
public function countRoles($criteria = null, $distinct = false, PropelPDO $con = null)
{
if(null === $this->collRoles || null !== $criteria) {
if ($this->isNew() && null === $this->collRoles) {
return 0;
} else {
$query = RoleQuery::create(null, $criteria);
if($distinct) {
$query->distinct();
}
return $query
->filterByUser($this)
->count($con);
}
} else {
return count($this->collRoles);
}
}
/**
* Associate a Role object to this object
* through the user_2_role cross reference table.
*
* @param Role $role The User2Role object to relate
* @return void
*/
public function addRole($role)
{
if ($this->collRoles === null) {
$this->initRoles();
}
if (!$this->collRoles->contains($role)) { // only add it if the **same** object is not already associated
$user2Role = new User2Role();
$user2Role->setRole($role);
$this->addUser2Role($user2Role);
$this->collRoles[]= $role;
}
}
/**
* Clears out the collPermissions collection
*
* This does not modify the database; however, it will remove any associated objects, causing
* them to be refetched by subsequent calls to accessor method.
*
* @return void
* @see addPermissions()
*/
public function clearPermissions()
{
$this->collPermissions = null; // important to set this to NULL since that means it is uninitialized
}
/**
* Initializes the collPermissions collection.
*
* By default this just sets the collPermissions collection to an empty collection (like clearPermissions());
* however, you may wish to override this method in your stub class to provide setting appropriate
* to your application -- for example, setting the initial array to the values stored in database.
*
* @return void
*/
public function initPermissions()
{
$this->collPermissions = new PropelObjectCollection();
$this->collPermissions->setModel('Permission');
}
/**
* Gets a collection of Permission objects related by a many-to-many relationship
* to the current object by way of the user_2_permission cross-reference table.
*
* If the $criteria is not null, it is used to always fetch the results from the database.
* Otherwise the results are fetched from the database the first time, then cached.
* Next time the same method is called without $criteria, the cached collection is returned.
* If this User is new, it will return
* an empty collection or the current collection; the criteria is ignored on a new object.
*
* @param Criteria $criteria Optional query object to filter the query
* @param PropelPDO $con Optional connection object
*
* @return PropelCollection|array Permission[] List of Permission objects
*/
public function getPermissions($criteria = null, PropelPDO $con = null)
{
if(null === $this->collPermissions || null !== $criteria) {
if ($this->isNew() && null === $this->collPermissions) {
// return empty collection
$this->initPermissions();
} else {
$collPermissions = PermissionQuery::create(null, $criteria)
->filterByUser($this)
->find($con);
if (null !== $criteria) {
return $collPermissions;
}
$this->collPermissions = $collPermissions;
}
}
return $this->collPermissions;
}
/**
* Gets the number of Permission objects related by a many-to-many relationship
* to the current object by way of the user_2_permission cross-reference table.
*
* @param Criteria $criteria Optional query object to filter the query
* @param boolean $distinct Set to true to force count distinct
* @param PropelPDO $con Optional connection object
*
* @return int the number of related Permission objects
*/
public function countPermissions($criteria = null, $distinct = false, PropelPDO $con = null)
{
if(null === $this->collPermissions || null !== $criteria) {
if ($this->isNew() && null === $this->collPermissions) {
return 0;
} else {
$query = PermissionQuery::create(null, $criteria);
if($distinct) {
$query->distinct();
}
return $query
->filterByUser($this)
->count($con);
}
} else {
return count($this->collPermissions);
}
}
/**
* Associate a Permission object to this object
* through the user_2_permission cross reference table.
*
* @param Permission $permission The User2Permission object to relate
* @return void
*/
public function addPermission($permission)
{
if ($this->collPermissions === null) {
$this->initPermissions();
}
if (!$this->collPermissions->contains($permission)) { // only add it if the **same** object is not already associated
$user2Permission = new User2Permission();
$user2Permission->setPermission($permission);
$this->addUser2Permission($user2Permission);
$this->collPermissions[]= $permission;
}
}
/**
* Clears the current object and sets all attributes to their default values
*/
public function clear()
{
$this->id = null;
$this->vestiging_id = null;
$this->username = null;
$this->password = null;
$this->salt = null;
$this->created_at = null;
$this->updated_at = null;
$this->clearAllReferences();
$this->setNew(true);
}
/**
* Resets all collections of referencing foreign keys.
*
* This method is a user-space workaround for PHP's inability to garbage collect objects
* with circular references. This is currently necessary when using Propel in certain
* daemon or large-volumne/high-memory operations.
*
* @param boolean $deep Whether to also clear the references on all associated objects.
*/
public function clearAllReferences($deep = false)
{
if ($deep) {
if ($this->collUser2Roles) {
foreach ((array) $this->collUser2Roles as $o) {
$o->clearAllReferences($deep);
}
}
if ($this->collUser2Permissions) {
foreach ((array) $this->collUser2Permissions as $o) {
$o->clearAllReferences($deep);
}
}
} // if ($deep)
$this->collUser2Roles = null;
$this->collUser2Permissions = null;
$this->aVestiging = null;
}
// timestampable behavior
/**
* Mark the current object so that the update date doesn't get updated during next save
*
* @return User The current object (for fluent API support)
*/
public function keepUpdateDateUnchanged()
{
$this->modifiedColumns[] = UserPeer::UPDATED_AT;
return $this;
}
/**
* Catches calls to virtual methods
*/
public function __call($name, $params)
{
if (preg_match('/get(\w+)/', $name, $matches) && $this->hasVirtualColumn($matches[1])) {
return $this->getVirtualColumn($matches[1]);
}
throw new PropelException('Call to undefined method: ' . $name);
}
} // BaseUser
<?xml version="1.0" encoding="utf-8"?>
<database name="propel" defaultIdMethod="native">
<table name="user">
<column name="id" type="integer" primaryKey="true" autoIncrement="true" required="true" />
<column name="vestiging_id" type="integer" />
<column name="username" type="varchar" size="40" required="true" />
<column name="password" type="varchar" size="40" required="true" />
<column name="salt" type="varchar" size="40" required="true" />
<behavior name="timestampable" />
<unique>
<unique-column name="username" />
</unique>
<foreign-key foreignTable="vestiging" onDelete="cascade">
<reference local="vestiging_id" foreign="id" />
</foreign-key>
</table>
<table name="role">
<column name="id" type="integer" primaryKey="true" autoIncrement="true" required="true" />
<column name="name" type="varchar" size="40" required="true" />
<behavior name="timestampable" />
</table>
<table name="permission">
<column name="id" type="integer" primaryKey="true" autoIncrement="true" required="true" />
<column name="name" type="varchar" size="40" required="true" />
<behavior name="timestampable" />
</table>
<table name="vestiging">
<column name="id" type="integer" primaryKey="true" autoIncrement="true" required="true" />
<behavior name="timestampable" />
</table>
<table name="user_2_role" isCrossRef="true">
<column name="user_id" type="integer" primaryKey="true" />
<column name="role_id" type="integer" primaryKey="true" />
<foreign-key foreignTable="user" onDelete="cascade">
<reference local="user_id" foreign="id" />
</foreign-key>
<foreign-key foreignTable="role" onDelete="cascade">
<reference local="role_id" foreign="id" />
</foreign-key>
</table>
<table name="user_2_permission" isCrossRef="true">
<column name="user_id" type="integer" primaryKey="true" />
<column name="permission_id" type="integer" primaryKey="true" />
<foreign-key foreignTable="user" onDelete="cascade">
<reference local="user_id" foreign="id" />
</foreign-key>
<foreign-key foreignTable="permission" onDelete="cascade">
<reference local="permission_id" foreign="id" />
</foreign-key>
</table>
<table name="role_2_permission" isCrossRef="true">
<column name="role_id" type="integer" primaryKey="true" />
<column name="permission_id" type="integer" primaryKey="true" />
<foreign-key foreignTable="role" onDelete="cascade">
<reference local="role_id" foreign="id" />
</foreign-key>
<foreign-key foreignTable="permission" onDelete="cascade">
<reference local="permission_id" foreign="id" />
</foreign-key>
</table>
</database>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment