<?php


abstract class BaseTblusermessage extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $ms_id;

	
	protected $ms_subject;

	
	protected $ms_content;

	
	protected $ms_from;

	
	protected $ms_to;

	
	protected $ms_time;

	
	protected $ms_prev;

	
	protected $ms_next;

	
	protected $ms_status;

	
	protected $ms_deleted;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	
	public function applyDefaultValues()
	{
		$this->ms_status = 0;
		$this->ms_deleted = 0;
	}

	
	public function getMsId()
	{
		return $this->ms_id;
	}

	
	public function getMsSubject()
	{
		return $this->ms_subject;
	}

	
	public function getMsContent()
	{
		return $this->ms_content;
	}

	
	public function getMsFrom()
	{
		return $this->ms_from;
	}

	
	public function getMsTo()
	{
		return $this->ms_to;
	}

	
	public function getMsTime($format = 'Y-m-d H:i:s')
	{
		if ($this->ms_time === null) {
			return null;
		}


		if ($this->ms_time === '0000-00-00 00:00:00') {
									return null;
		} else {
			try {
				$dt = new DateTime($this->ms_time);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->ms_time, true), $x);
			}
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getMsPrev()
	{
		return $this->ms_prev;
	}

	
	public function getMsNext()
	{
		return $this->ms_next;
	}

	
	public function getMsStatus()
	{
		return $this->ms_status;
	}

	
	public function getMsDeleted()
	{
		return $this->ms_deleted;
	}

	
	public function setMsId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->ms_id !== $v) {
			$this->ms_id = $v;
			$this->modifiedColumns[] = TblusermessagePeer::MS_ID;
		}

		return $this;
	} 
	
	public function setMsSubject($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->ms_subject !== $v) {
			$this->ms_subject = $v;
			$this->modifiedColumns[] = TblusermessagePeer::MS_SUBJECT;
		}

		return $this;
	} 
	
	public function setMsContent($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->ms_content !== $v) {
			$this->ms_content = $v;
			$this->modifiedColumns[] = TblusermessagePeer::MS_CONTENT;
		}

		return $this;
	} 
	
	public function setMsFrom($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->ms_from !== $v) {
			$this->ms_from = $v;
			$this->modifiedColumns[] = TblusermessagePeer::MS_FROM;
		}

		return $this;
	} 
	
	public function setMsTo($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->ms_to !== $v) {
			$this->ms_to = $v;
			$this->modifiedColumns[] = TblusermessagePeer::MS_TO;
		}

		return $this;
	} 
	
	public function setMsTime($v)
	{
						if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$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->ms_time !== null || $dt !== null ) {
			
			$currNorm = ($this->ms_time !== null && $tmpDt = new DateTime($this->ms_time)) ? $tmpDt->format('Y-m-d H:i:s') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d H:i:s') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->ms_time = ($dt ? $dt->format('Y-m-d H:i:s') : null);
				$this->modifiedColumns[] = TblusermessagePeer::MS_TIME;
			}
		} 
		return $this;
	} 
	
	public function setMsPrev($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->ms_prev !== $v) {
			$this->ms_prev = $v;
			$this->modifiedColumns[] = TblusermessagePeer::MS_PREV;
		}

		return $this;
	} 
	
	public function setMsNext($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->ms_next !== $v) {
			$this->ms_next = $v;
			$this->modifiedColumns[] = TblusermessagePeer::MS_NEXT;
		}

		return $this;
	} 
	
	public function setMsStatus($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->ms_status !== $v || $v === 0) {
			$this->ms_status = $v;
			$this->modifiedColumns[] = TblusermessagePeer::MS_STATUS;
		}

		return $this;
	} 
	
	public function setMsDeleted($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->ms_deleted !== $v || $v === 0) {
			$this->ms_deleted = $v;
			$this->modifiedColumns[] = TblusermessagePeer::MS_DELETED;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array(TblusermessagePeer::MS_STATUS,TblusermessagePeer::MS_DELETED))) {
				return false;
			}

			if ($this->ms_status !== 0) {
				return false;
			}

			if ($this->ms_deleted !== 0) {
				return false;
			}

				return true;
	} 
	
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->ms_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->ms_subject = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
			$this->ms_content = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
			$this->ms_from = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null;
			$this->ms_to = ($row[$startcol + 4] !== null) ? (int) $row[$startcol + 4] : null;
			$this->ms_time = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->ms_prev = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
			$this->ms_next = ($row[$startcol + 7] !== null) ? (int) $row[$startcol + 7] : null;
			$this->ms_status = ($row[$startcol + 8] !== null) ? (int) $row[$startcol + 8] : null;
			$this->ms_deleted = ($row[$startcol + 9] !== null) ? (int) $row[$startcol + 9] : null;
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

						return $startcol + 10; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Tblusermessage object", $e);
		}
	}

	
	public function ensureConsistency()
	{

	} 
	
	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(TblusermessagePeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = TblusermessagePeer::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); 
		if ($deep) {  
		} 	}

	
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TblusermessagePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			TblusermessagePeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	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(TblusermessagePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			TblusermessagePeer::addInstanceToPool($this);
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;

			if ($this->isNew() ) {
				$this->modifiedColumns[] = TblusermessagePeer::MS_ID;
			}

						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TblusermessagePeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setMsId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TblusermessagePeer::doUpdate($this, $con);
				}

				$this->resetModified(); 			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = TblusermessagePeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TblusermessagePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getMsId();
				break;
			case 1:
				return $this->getMsSubject();
				break;
			case 2:
				return $this->getMsContent();
				break;
			case 3:
				return $this->getMsFrom();
				break;
			case 4:
				return $this->getMsTo();
				break;
			case 5:
				return $this->getMsTime();
				break;
			case 6:
				return $this->getMsPrev();
				break;
			case 7:
				return $this->getMsNext();
				break;
			case 8:
				return $this->getMsStatus();
				break;
			case 9:
				return $this->getMsDeleted();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = TblusermessagePeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getMsId(),
			$keys[1] => $this->getMsSubject(),
			$keys[2] => $this->getMsContent(),
			$keys[3] => $this->getMsFrom(),
			$keys[4] => $this->getMsTo(),
			$keys[5] => $this->getMsTime(),
			$keys[6] => $this->getMsPrev(),
			$keys[7] => $this->getMsNext(),
			$keys[8] => $this->getMsStatus(),
			$keys[9] => $this->getMsDeleted(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TblusermessagePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setMsId($value);
				break;
			case 1:
				$this->setMsSubject($value);
				break;
			case 2:
				$this->setMsContent($value);
				break;
			case 3:
				$this->setMsFrom($value);
				break;
			case 4:
				$this->setMsTo($value);
				break;
			case 5:
				$this->setMsTime($value);
				break;
			case 6:
				$this->setMsPrev($value);
				break;
			case 7:
				$this->setMsNext($value);
				break;
			case 8:
				$this->setMsStatus($value);
				break;
			case 9:
				$this->setMsDeleted($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TblusermessagePeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setMsId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setMsSubject($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setMsContent($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setMsFrom($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setMsTo($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setMsTime($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setMsPrev($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setMsNext($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setMsStatus($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setMsDeleted($arr[$keys[9]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TblusermessagePeer::DATABASE_NAME);

		if ($this->isColumnModified(TblusermessagePeer::MS_ID)) $criteria->add(TblusermessagePeer::MS_ID, $this->ms_id);
		if ($this->isColumnModified(TblusermessagePeer::MS_SUBJECT)) $criteria->add(TblusermessagePeer::MS_SUBJECT, $this->ms_subject);
		if ($this->isColumnModified(TblusermessagePeer::MS_CONTENT)) $criteria->add(TblusermessagePeer::MS_CONTENT, $this->ms_content);
		if ($this->isColumnModified(TblusermessagePeer::MS_FROM)) $criteria->add(TblusermessagePeer::MS_FROM, $this->ms_from);
		if ($this->isColumnModified(TblusermessagePeer::MS_TO)) $criteria->add(TblusermessagePeer::MS_TO, $this->ms_to);
		if ($this->isColumnModified(TblusermessagePeer::MS_TIME)) $criteria->add(TblusermessagePeer::MS_TIME, $this->ms_time);
		if ($this->isColumnModified(TblusermessagePeer::MS_PREV)) $criteria->add(TblusermessagePeer::MS_PREV, $this->ms_prev);
		if ($this->isColumnModified(TblusermessagePeer::MS_NEXT)) $criteria->add(TblusermessagePeer::MS_NEXT, $this->ms_next);
		if ($this->isColumnModified(TblusermessagePeer::MS_STATUS)) $criteria->add(TblusermessagePeer::MS_STATUS, $this->ms_status);
		if ($this->isColumnModified(TblusermessagePeer::MS_DELETED)) $criteria->add(TblusermessagePeer::MS_DELETED, $this->ms_deleted);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TblusermessagePeer::DATABASE_NAME);

		$criteria->add(TblusermessagePeer::MS_ID, $this->ms_id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getMsId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setMsId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setMsSubject($this->ms_subject);

		$copyObj->setMsContent($this->ms_content);

		$copyObj->setMsFrom($this->ms_from);

		$copyObj->setMsTo($this->ms_to);

		$copyObj->setMsTime($this->ms_time);

		$copyObj->setMsPrev($this->ms_prev);

		$copyObj->setMsNext($this->ms_next);

		$copyObj->setMsStatus($this->ms_status);

		$copyObj->setMsDeleted($this->ms_deleted);


		$copyObj->setNew(true);

		$copyObj->setMsId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TblusermessagePeer();
		}
		return self::$peer;
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
		} 
	}

} 