<?php


abstract class BaseTblblogcheckinfo extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $ci_userid;

	
	protected $ci_birthday;

	
	protected $ci_phone;

	
	protected $ci_pr;

	
	protected $ci_numberid;

	
	protected $ci_position;

	
	protected $ci_school;

	
	protected $ci_district;

	
	protected $ci_province;

	
	protected $ci_badge;

	
	protected $ci_subject;

	
	protected $ci_score;

	
	protected $aTbluser;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

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

	
	public function applyDefaultValues()
	{
	}

	
	public function getCiUserid()
	{
		return $this->ci_userid;
	}

	
	public function getCiBirthday($format = '%x')
	{
		if ($this->ci_birthday === null) {
			return null;
		}


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

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

	
	public function getCiPhone()
	{
		return $this->ci_phone;
	}

	
	public function getCiPr()
	{
		return $this->ci_pr;
	}

	
	public function getCiNumberid()
	{
		return $this->ci_numberid;
	}

	
	public function getCiPosition()
	{
		return $this->ci_position;
	}

	
	public function getCiSchool()
	{
		return $this->ci_school;
	}

	
	public function getCiDistrict()
	{
		return $this->ci_district;
	}

	
	public function getCiProvince()
	{
		return $this->ci_province;
	}

	
	public function getCiBadge()
	{
		return $this->ci_badge;
	}

	
	public function getCiSubject()
	{
		return $this->ci_subject;
	}

	
	public function getCiScore()
	{
		return $this->ci_score;
	}

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

		if ($this->ci_userid !== $v) {
			$this->ci_userid = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_USERID;
		}

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

		return $this;
	} 
	
	public function setCiBirthday($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->ci_birthday !== null || $dt !== null ) {
			
			$currNorm = ($this->ci_birthday !== null && $tmpDt = new DateTime($this->ci_birthday)) ? $tmpDt->format('Y-m-d') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->ci_birthday = ($dt ? $dt->format('Y-m-d') : null);
				$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_BIRTHDAY;
			}
		} 
		return $this;
	} 
	
	public function setCiPhone($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->ci_phone !== $v) {
			$this->ci_phone = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_PHONE;
		}

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

		if ($this->ci_pr !== $v) {
			$this->ci_pr = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_PR;
		}

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

		if ($this->ci_numberid !== $v) {
			$this->ci_numberid = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_NUMBERID;
		}

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

		if ($this->ci_position !== $v) {
			$this->ci_position = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_POSITION;
		}

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

		if ($this->ci_school !== $v) {
			$this->ci_school = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_SCHOOL;
		}

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

		if ($this->ci_district !== $v) {
			$this->ci_district = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_DISTRICT;
		}

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

		if ($this->ci_province !== $v) {
			$this->ci_province = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_PROVINCE;
		}

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

		if ($this->ci_badge !== $v) {
			$this->ci_badge = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_BADGE;
		}

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

		if ($this->ci_subject !== $v) {
			$this->ci_subject = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_SUBJECT;
		}

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

		if ($this->ci_score !== $v) {
			$this->ci_score = $v;
			$this->modifiedColumns[] = TblblogcheckinfoPeer::CI_SCORE;
		}

		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->ci_userid = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->ci_birthday = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
			$this->ci_phone = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
			$this->ci_pr = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->ci_numberid = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
			$this->ci_position = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null;
			$this->ci_school = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
			$this->ci_district = ($row[$startcol + 7] !== null) ? (int) $row[$startcol + 7] : null;
			$this->ci_province = ($row[$startcol + 8] !== null) ? (int) $row[$startcol + 8] : null;
			$this->ci_badge = ($row[$startcol + 9] !== null) ? (string) $row[$startcol + 9] : null;
			$this->ci_subject = ($row[$startcol + 10] !== null) ? (string) $row[$startcol + 10] : null;
			$this->ci_score = ($row[$startcol + 11] !== null) ? (int) $row[$startcol + 11] : null;
			$this->resetModified();

			$this->setNew(false);

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

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

	
	public function ensureConsistency()
	{

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

				
		$stmt = TblblogcheckinfoPeer::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(TblblogcheckinfoPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			TblblogcheckinfoPeer::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(TblblogcheckinfoPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			TblblogcheckinfoPeer::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->isModified()) {
				if ($this->isNew()) {
					$pk = TblblogcheckinfoPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += TblblogcheckinfoPeer::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 = TblblogcheckinfoPeer::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 = TblblogcheckinfoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getCiUserid();
				break;
			case 1:
				return $this->getCiBirthday();
				break;
			case 2:
				return $this->getCiPhone();
				break;
			case 3:
				return $this->getCiPr();
				break;
			case 4:
				return $this->getCiNumberid();
				break;
			case 5:
				return $this->getCiPosition();
				break;
			case 6:
				return $this->getCiSchool();
				break;
			case 7:
				return $this->getCiDistrict();
				break;
			case 8:
				return $this->getCiProvince();
				break;
			case 9:
				return $this->getCiBadge();
				break;
			case 10:
				return $this->getCiSubject();
				break;
			case 11:
				return $this->getCiScore();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = TblblogcheckinfoPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getCiUserid(),
			$keys[1] => $this->getCiBirthday(),
			$keys[2] => $this->getCiPhone(),
			$keys[3] => $this->getCiPr(),
			$keys[4] => $this->getCiNumberid(),
			$keys[5] => $this->getCiPosition(),
			$keys[6] => $this->getCiSchool(),
			$keys[7] => $this->getCiDistrict(),
			$keys[8] => $this->getCiProvince(),
			$keys[9] => $this->getCiBadge(),
			$keys[10] => $this->getCiSubject(),
			$keys[11] => $this->getCiScore(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setCiUserid($value);
				break;
			case 1:
				$this->setCiBirthday($value);
				break;
			case 2:
				$this->setCiPhone($value);
				break;
			case 3:
				$this->setCiPr($value);
				break;
			case 4:
				$this->setCiNumberid($value);
				break;
			case 5:
				$this->setCiPosition($value);
				break;
			case 6:
				$this->setCiSchool($value);
				break;
			case 7:
				$this->setCiDistrict($value);
				break;
			case 8:
				$this->setCiProvince($value);
				break;
			case 9:
				$this->setCiBadge($value);
				break;
			case 10:
				$this->setCiSubject($value);
				break;
			case 11:
				$this->setCiScore($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setCiUserid($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCiBirthday($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setCiPhone($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCiPr($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCiNumberid($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setCiPosition($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setCiSchool($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setCiDistrict($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setCiProvince($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setCiBadge($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setCiSubject($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setCiScore($arr[$keys[11]]);
	}

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

		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_USERID)) $criteria->add(TblblogcheckinfoPeer::CI_USERID, $this->ci_userid);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_BIRTHDAY)) $criteria->add(TblblogcheckinfoPeer::CI_BIRTHDAY, $this->ci_birthday);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_PHONE)) $criteria->add(TblblogcheckinfoPeer::CI_PHONE, $this->ci_phone);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_PR)) $criteria->add(TblblogcheckinfoPeer::CI_PR, $this->ci_pr);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_NUMBERID)) $criteria->add(TblblogcheckinfoPeer::CI_NUMBERID, $this->ci_numberid);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_POSITION)) $criteria->add(TblblogcheckinfoPeer::CI_POSITION, $this->ci_position);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_SCHOOL)) $criteria->add(TblblogcheckinfoPeer::CI_SCHOOL, $this->ci_school);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_DISTRICT)) $criteria->add(TblblogcheckinfoPeer::CI_DISTRICT, $this->ci_district);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_PROVINCE)) $criteria->add(TblblogcheckinfoPeer::CI_PROVINCE, $this->ci_province);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_BADGE)) $criteria->add(TblblogcheckinfoPeer::CI_BADGE, $this->ci_badge);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_SUBJECT)) $criteria->add(TblblogcheckinfoPeer::CI_SUBJECT, $this->ci_subject);
		if ($this->isColumnModified(TblblogcheckinfoPeer::CI_SCORE)) $criteria->add(TblblogcheckinfoPeer::CI_SCORE, $this->ci_score);

		return $criteria;
	}

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

		$criteria->add(TblblogcheckinfoPeer::CI_USERID, $this->ci_userid);

		return $criteria;
	}

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

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

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

		$copyObj->setCiUserid($this->ci_userid);

		$copyObj->setCiBirthday($this->ci_birthday);

		$copyObj->setCiPhone($this->ci_phone);

		$copyObj->setCiPr($this->ci_pr);

		$copyObj->setCiNumberid($this->ci_numberid);

		$copyObj->setCiPosition($this->ci_position);

		$copyObj->setCiSchool($this->ci_school);

		$copyObj->setCiDistrict($this->ci_district);

		$copyObj->setCiProvince($this->ci_province);

		$copyObj->setCiBadge($this->ci_badge);

		$copyObj->setCiSubject($this->ci_subject);

		$copyObj->setCiScore($this->ci_score);


		$copyObj->setNew(true);

	}

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

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

		$this->aTbluser = $v;

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

		return $this;
	}


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

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

} 