<?php


abstract class BaseTblcomplain extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $cp_id;

	
	protected $cp_user;

	
	protected $cp_note;

	
	protected $cp_date;

	
	protected $cp_solveduser;

	
	protected $cp_solveddate;

	
	protected $cp_category;

	
	protected $cp_blog;

	
	protected $cp_entry;

	
	protected $cp_type;

	
	protected $cp_solvedtype;

	
	protected $aTbluser;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

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

	
	public function applyDefaultValues()
	{
	}

	
	public function getCpId()
	{
		return $this->cp_id;
	}

	
	public function getCpUser()
	{
		return $this->cp_user;
	}

	
	public function getCpNote()
	{
		return $this->cp_note;
	}

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


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

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

	
	public function getCpSolveduser()
	{
		return $this->cp_solveduser;
	}

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


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

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

	
	public function getCpCategory()
	{
		return $this->cp_category;
	}

	
	public function getCpBlog()
	{
		return $this->cp_blog;
	}

	
	public function getCpEntry()
	{
		return $this->cp_entry;
	}

	
	public function getCpType()
	{
		return $this->cp_type;
	}

	
	public function getCpSolvedtype()
	{
		return $this->cp_solvedtype;
	}

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

		if ($this->cp_id !== $v) {
			$this->cp_id = $v;
			$this->modifiedColumns[] = TblcomplainPeer::CP_ID;
		}

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

		if ($this->cp_user !== $v) {
			$this->cp_user = $v;
			$this->modifiedColumns[] = TblcomplainPeer::CP_USER;
		}

		if ($this->aTbluser !== null && $this->aTbluser->getUsId() !== $v) {
			$this->aTbluser = null;
		}

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

		if ($this->cp_note !== $v) {
			$this->cp_note = $v;
			$this->modifiedColumns[] = TblcomplainPeer::CP_NOTE;
		}

		return $this;
	} 
	
	public function setCpDate($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->cp_date !== null || $dt !== null ) {
			
			$currNorm = ($this->cp_date !== null && $tmpDt = new DateTime($this->cp_date)) ? $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->cp_date = ($dt ? $dt->format('Y-m-d H:i:s') : null);
				$this->modifiedColumns[] = TblcomplainPeer::CP_DATE;
			}
		} 
		return $this;
	} 
	
	public function setCpSolveduser($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->cp_solveduser !== $v) {
			$this->cp_solveduser = $v;
			$this->modifiedColumns[] = TblcomplainPeer::CP_SOLVEDUSER;
		}

		return $this;
	} 
	
	public function setCpSolveddate($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->cp_solveddate !== null || $dt !== null ) {
			
			$currNorm = ($this->cp_solveddate !== null && $tmpDt = new DateTime($this->cp_solveddate)) ? $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->cp_solveddate = ($dt ? $dt->format('Y-m-d H:i:s') : null);
				$this->modifiedColumns[] = TblcomplainPeer::CP_SOLVEDDATE;
			}
		} 
		return $this;
	} 
	
	public function setCpCategory($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->cp_category !== $v) {
			$this->cp_category = $v;
			$this->modifiedColumns[] = TblcomplainPeer::CP_CATEGORY;
		}

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

		if ($this->cp_blog !== $v) {
			$this->cp_blog = $v;
			$this->modifiedColumns[] = TblcomplainPeer::CP_BLOG;
		}

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

		if ($this->cp_entry !== $v) {
			$this->cp_entry = $v;
			$this->modifiedColumns[] = TblcomplainPeer::CP_ENTRY;
		}

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

		if ($this->cp_type !== $v) {
			$this->cp_type = $v;
			$this->modifiedColumns[] = TblcomplainPeer::CP_TYPE;
		}

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

		if ($this->cp_solvedtype !== $v) {
			$this->cp_solvedtype = $v;
			$this->modifiedColumns[] = TblcomplainPeer::CP_SOLVEDTYPE;
		}

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

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

			$this->cp_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->cp_user = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
			$this->cp_note = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
			$this->cp_date = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->cp_solveduser = ($row[$startcol + 4] !== null) ? (int) $row[$startcol + 4] : null;
			$this->cp_solveddate = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->cp_category = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
			$this->cp_blog = ($row[$startcol + 7] !== null) ? (int) $row[$startcol + 7] : null;
			$this->cp_entry = ($row[$startcol + 8] !== null) ? (int) $row[$startcol + 8] : null;
			$this->cp_type = ($row[$startcol + 9] !== null) ? (int) $row[$startcol + 9] : null;
			$this->cp_solvedtype = ($row[$startcol + 10] !== null) ? (int) $row[$startcol + 10] : null;
			$this->resetModified();

			$this->setNew(false);

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

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

	
	public function ensureConsistency()
	{

		if ($this->aTbluser !== null && $this->cp_user !== $this->aTbluser->getUsId()) {
			$this->aTbluser = null;
		}
	} 
	
	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(TblcomplainPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = TblcomplainPeer::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) {  
			$this->aTbluser = null;
		} 	}

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

		if ($con === null) {
			$con = Propel::getConnection(TblcomplainPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			TblcomplainPeer::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(TblcomplainPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			TblcomplainPeer::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->aTbluser !== null) {
				if ($this->aTbluser->isModified() || $this->aTbluser->isNew()) {
					$affectedRows += $this->aTbluser->save($con);
				}
				$this->setTbluser($this->aTbluser);
			}

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

						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TblcomplainPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setCpId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TblcomplainPeer::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 ($this->aTbluser !== null) {
				if (!$this->aTbluser->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTbluser->getValidationFailures());
				}
			}


			if (($retval = TblcomplainPeer::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 = TblcomplainPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getCpId();
				break;
			case 1:
				return $this->getCpUser();
				break;
			case 2:
				return $this->getCpNote();
				break;
			case 3:
				return $this->getCpDate();
				break;
			case 4:
				return $this->getCpSolveduser();
				break;
			case 5:
				return $this->getCpSolveddate();
				break;
			case 6:
				return $this->getCpCategory();
				break;
			case 7:
				return $this->getCpBlog();
				break;
			case 8:
				return $this->getCpEntry();
				break;
			case 9:
				return $this->getCpType();
				break;
			case 10:
				return $this->getCpSolvedtype();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = TblcomplainPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getCpId(),
			$keys[1] => $this->getCpUser(),
			$keys[2] => $this->getCpNote(),
			$keys[3] => $this->getCpDate(),
			$keys[4] => $this->getCpSolveduser(),
			$keys[5] => $this->getCpSolveddate(),
			$keys[6] => $this->getCpCategory(),
			$keys[7] => $this->getCpBlog(),
			$keys[8] => $this->getCpEntry(),
			$keys[9] => $this->getCpType(),
			$keys[10] => $this->getCpSolvedtype(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setCpId($value);
				break;
			case 1:
				$this->setCpUser($value);
				break;
			case 2:
				$this->setCpNote($value);
				break;
			case 3:
				$this->setCpDate($value);
				break;
			case 4:
				$this->setCpSolveduser($value);
				break;
			case 5:
				$this->setCpSolveddate($value);
				break;
			case 6:
				$this->setCpCategory($value);
				break;
			case 7:
				$this->setCpBlog($value);
				break;
			case 8:
				$this->setCpEntry($value);
				break;
			case 9:
				$this->setCpType($value);
				break;
			case 10:
				$this->setCpSolvedtype($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setCpId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCpUser($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setCpNote($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCpDate($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCpSolveduser($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setCpSolveddate($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setCpCategory($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setCpBlog($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setCpEntry($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setCpType($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setCpSolvedtype($arr[$keys[10]]);
	}

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

		if ($this->isColumnModified(TblcomplainPeer::CP_ID)) $criteria->add(TblcomplainPeer::CP_ID, $this->cp_id);
		if ($this->isColumnModified(TblcomplainPeer::CP_USER)) $criteria->add(TblcomplainPeer::CP_USER, $this->cp_user);
		if ($this->isColumnModified(TblcomplainPeer::CP_NOTE)) $criteria->add(TblcomplainPeer::CP_NOTE, $this->cp_note);
		if ($this->isColumnModified(TblcomplainPeer::CP_DATE)) $criteria->add(TblcomplainPeer::CP_DATE, $this->cp_date);
		if ($this->isColumnModified(TblcomplainPeer::CP_SOLVEDUSER)) $criteria->add(TblcomplainPeer::CP_SOLVEDUSER, $this->cp_solveduser);
		if ($this->isColumnModified(TblcomplainPeer::CP_SOLVEDDATE)) $criteria->add(TblcomplainPeer::CP_SOLVEDDATE, $this->cp_solveddate);
		if ($this->isColumnModified(TblcomplainPeer::CP_CATEGORY)) $criteria->add(TblcomplainPeer::CP_CATEGORY, $this->cp_category);
		if ($this->isColumnModified(TblcomplainPeer::CP_BLOG)) $criteria->add(TblcomplainPeer::CP_BLOG, $this->cp_blog);
		if ($this->isColumnModified(TblcomplainPeer::CP_ENTRY)) $criteria->add(TblcomplainPeer::CP_ENTRY, $this->cp_entry);
		if ($this->isColumnModified(TblcomplainPeer::CP_TYPE)) $criteria->add(TblcomplainPeer::CP_TYPE, $this->cp_type);
		if ($this->isColumnModified(TblcomplainPeer::CP_SOLVEDTYPE)) $criteria->add(TblcomplainPeer::CP_SOLVEDTYPE, $this->cp_solvedtype);

		return $criteria;
	}

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

		$criteria->add(TblcomplainPeer::CP_ID, $this->cp_id);

		return $criteria;
	}

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

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

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

		$copyObj->setCpUser($this->cp_user);

		$copyObj->setCpNote($this->cp_note);

		$copyObj->setCpDate($this->cp_date);

		$copyObj->setCpSolveduser($this->cp_solveduser);

		$copyObj->setCpSolveddate($this->cp_solveddate);

		$copyObj->setCpCategory($this->cp_category);

		$copyObj->setCpBlog($this->cp_blog);

		$copyObj->setCpEntry($this->cp_entry);

		$copyObj->setCpType($this->cp_type);

		$copyObj->setCpSolvedtype($this->cp_solvedtype);


		$copyObj->setNew(true);

		$copyObj->setCpId(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 TblcomplainPeer();
		}
		return self::$peer;
	}

	
	public function setTbluser(Tbluser $v = null)
	{
		if ($v === null) {
			$this->setCpUser(NULL);
		} else {
			$this->setCpUser($v->getUsId());
		}

		$this->aTbluser = $v;

						if ($v !== null) {
			$v->addTblcomplain($this);
		}

		return $this;
	}


	
	public function getTbluser(PropelPDO $con = null)
	{
		if ($this->aTbluser === null && ($this->cp_user !== null)) {
			$this->aTbluser = TbluserPeer::retrieveByPK($this->cp_user, $con);
			
		}
		return $this->aTbluser;
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
		} 
			$this->aTbluser = null;
	}

} 