<?php


abstract class BaseTblblogschools extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $sc_id;

	
	protected $sc_name;

	
	protected $sc_type;

	
	protected $sc_parent;

	
	protected $sc_approve;

	
	protected $sc_phone;

	
	protected $sc_email;

	
	protected $sc_headmaster;

	
	protected $sc_taxcode;

	
	protected $sc_user;

	
	protected $collVioletactives;

	
	private $lastVioletactiveCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

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

	
	public function applyDefaultValues()
	{
		$this->sc_type = 2;
		$this->sc_approve = 0;
		$this->sc_user = 0;
	}

	
	public function getScId()
	{
		return $this->sc_id;
	}

	
	public function getScName()
	{
		return $this->sc_name;
	}

	
	public function getScType()
	{
		return $this->sc_type;
	}

	
	public function getScParent()
	{
		return $this->sc_parent;
	}

	
	public function getScApprove()
	{
		return $this->sc_approve;
	}

	
	public function getScPhone()
	{
		return $this->sc_phone;
	}

	
	public function getScEmail()
	{
		return $this->sc_email;
	}

	
	public function getScHeadmaster()
	{
		return $this->sc_headmaster;
	}

	
	public function getScTaxcode()
	{
		return $this->sc_taxcode;
	}

	
	public function getScUser()
	{
		return $this->sc_user;
	}

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

		if ($this->sc_id !== $v) {
			$this->sc_id = $v;
			$this->modifiedColumns[] = TblblogschoolsPeer::SC_ID;
		}

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

		if ($this->sc_name !== $v) {
			$this->sc_name = $v;
			$this->modifiedColumns[] = TblblogschoolsPeer::SC_NAME;
		}

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

		if ($this->sc_type !== $v || $v === 2) {
			$this->sc_type = $v;
			$this->modifiedColumns[] = TblblogschoolsPeer::SC_TYPE;
		}

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

		if ($this->sc_parent !== $v) {
			$this->sc_parent = $v;
			$this->modifiedColumns[] = TblblogschoolsPeer::SC_PARENT;
		}

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

		if ($this->sc_approve !== $v || $v === 0) {
			$this->sc_approve = $v;
			$this->modifiedColumns[] = TblblogschoolsPeer::SC_APPROVE;
		}

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

		if ($this->sc_phone !== $v) {
			$this->sc_phone = $v;
			$this->modifiedColumns[] = TblblogschoolsPeer::SC_PHONE;
		}

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

		if ($this->sc_email !== $v) {
			$this->sc_email = $v;
			$this->modifiedColumns[] = TblblogschoolsPeer::SC_EMAIL;
		}

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

		if ($this->sc_headmaster !== $v) {
			$this->sc_headmaster = $v;
			$this->modifiedColumns[] = TblblogschoolsPeer::SC_HEADMASTER;
		}

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

		if ($this->sc_taxcode !== $v) {
			$this->sc_taxcode = $v;
			$this->modifiedColumns[] = TblblogschoolsPeer::SC_TAXCODE;
		}

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

		if ($this->sc_user !== $v || $v === 0) {
			$this->sc_user = $v;
			$this->modifiedColumns[] = TblblogschoolsPeer::SC_USER;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array(TblblogschoolsPeer::SC_TYPE,TblblogschoolsPeer::SC_APPROVE,TblblogschoolsPeer::SC_USER))) {
				return false;
			}

			if ($this->sc_type !== 2) {
				return false;
			}

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

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

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

			$this->sc_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->sc_name = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
			$this->sc_type = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
			$this->sc_parent = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null;
			$this->sc_approve = ($row[$startcol + 4] !== null) ? (int) $row[$startcol + 4] : null;
			$this->sc_phone = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->sc_email = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
			$this->sc_headmaster = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
			$this->sc_taxcode = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
			$this->sc_user = ($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 Tblblogschools 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(TblblogschoolsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = TblblogschoolsPeer::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->collVioletactives = null;
			$this->lastVioletactiveCriteria = 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(TblblogschoolsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			TblblogschoolsPeer::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(TblblogschoolsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			TblblogschoolsPeer::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[] = TblblogschoolsPeer::SC_ID;
			}

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

				$this->resetModified(); 			}

			if ($this->collVioletactives !== null) {
				foreach ($this->collVioletactives as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$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 = TblblogschoolsPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collVioletactives !== null) {
					foreach ($this->collVioletactives as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

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

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

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getScId();
				break;
			case 1:
				return $this->getScName();
				break;
			case 2:
				return $this->getScType();
				break;
			case 3:
				return $this->getScParent();
				break;
			case 4:
				return $this->getScApprove();
				break;
			case 5:
				return $this->getScPhone();
				break;
			case 6:
				return $this->getScEmail();
				break;
			case 7:
				return $this->getScHeadmaster();
				break;
			case 8:
				return $this->getScTaxcode();
				break;
			case 9:
				return $this->getScUser();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = TblblogschoolsPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getScId(),
			$keys[1] => $this->getScName(),
			$keys[2] => $this->getScType(),
			$keys[3] => $this->getScParent(),
			$keys[4] => $this->getScApprove(),
			$keys[5] => $this->getScPhone(),
			$keys[6] => $this->getScEmail(),
			$keys[7] => $this->getScHeadmaster(),
			$keys[8] => $this->getScTaxcode(),
			$keys[9] => $this->getScUser(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setScId($value);
				break;
			case 1:
				$this->setScName($value);
				break;
			case 2:
				$this->setScType($value);
				break;
			case 3:
				$this->setScParent($value);
				break;
			case 4:
				$this->setScApprove($value);
				break;
			case 5:
				$this->setScPhone($value);
				break;
			case 6:
				$this->setScEmail($value);
				break;
			case 7:
				$this->setScHeadmaster($value);
				break;
			case 8:
				$this->setScTaxcode($value);
				break;
			case 9:
				$this->setScUser($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setScId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setScName($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setScType($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setScParent($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setScApprove($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setScPhone($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setScEmail($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setScHeadmaster($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setScTaxcode($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setScUser($arr[$keys[9]]);
	}

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

		if ($this->isColumnModified(TblblogschoolsPeer::SC_ID)) $criteria->add(TblblogschoolsPeer::SC_ID, $this->sc_id);
		if ($this->isColumnModified(TblblogschoolsPeer::SC_NAME)) $criteria->add(TblblogschoolsPeer::SC_NAME, $this->sc_name);
		if ($this->isColumnModified(TblblogschoolsPeer::SC_TYPE)) $criteria->add(TblblogschoolsPeer::SC_TYPE, $this->sc_type);
		if ($this->isColumnModified(TblblogschoolsPeer::SC_PARENT)) $criteria->add(TblblogschoolsPeer::SC_PARENT, $this->sc_parent);
		if ($this->isColumnModified(TblblogschoolsPeer::SC_APPROVE)) $criteria->add(TblblogschoolsPeer::SC_APPROVE, $this->sc_approve);
		if ($this->isColumnModified(TblblogschoolsPeer::SC_PHONE)) $criteria->add(TblblogschoolsPeer::SC_PHONE, $this->sc_phone);
		if ($this->isColumnModified(TblblogschoolsPeer::SC_EMAIL)) $criteria->add(TblblogschoolsPeer::SC_EMAIL, $this->sc_email);
		if ($this->isColumnModified(TblblogschoolsPeer::SC_HEADMASTER)) $criteria->add(TblblogschoolsPeer::SC_HEADMASTER, $this->sc_headmaster);
		if ($this->isColumnModified(TblblogschoolsPeer::SC_TAXCODE)) $criteria->add(TblblogschoolsPeer::SC_TAXCODE, $this->sc_taxcode);
		if ($this->isColumnModified(TblblogschoolsPeer::SC_USER)) $criteria->add(TblblogschoolsPeer::SC_USER, $this->sc_user);

		return $criteria;
	}

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

		$criteria->add(TblblogschoolsPeer::SC_ID, $this->sc_id);

		return $criteria;
	}

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

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

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

		$copyObj->setScName($this->sc_name);

		$copyObj->setScType($this->sc_type);

		$copyObj->setScParent($this->sc_parent);

		$copyObj->setScApprove($this->sc_approve);

		$copyObj->setScPhone($this->sc_phone);

		$copyObj->setScEmail($this->sc_email);

		$copyObj->setScHeadmaster($this->sc_headmaster);

		$copyObj->setScTaxcode($this->sc_taxcode);

		$copyObj->setScUser($this->sc_user);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach ($this->getVioletactives() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addVioletactive($relObj->copy($deepCopy));
				}
			}

		} 

		$copyObj->setNew(true);

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

	
	public function clearVioletactives()
	{
		$this->collVioletactives = null; 	}

	
	public function initVioletactives()
	{
		$this->collVioletactives = array();
	}

	
	public function getVioletactives($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(TblblogschoolsPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collVioletactives === null) {
			if ($this->isNew()) {
			   $this->collVioletactives = array();
			} else {

				$criteria->add(VioletactivePeer::VA_CUSTOMERID, $this->sc_id);

				VioletactivePeer::addSelectColumns($criteria);
				$this->collVioletactives = VioletactivePeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(VioletactivePeer::VA_CUSTOMERID, $this->sc_id);

				VioletactivePeer::addSelectColumns($criteria);
				if (!isset($this->lastVioletactiveCriteria) || !$this->lastVioletactiveCriteria->equals($criteria)) {
					$this->collVioletactives = VioletactivePeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastVioletactiveCriteria = $criteria;
		return $this->collVioletactives;
	}

	
	public function countVioletactives(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(TblblogschoolsPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collVioletactives === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(VioletactivePeer::VA_CUSTOMERID, $this->sc_id);

				$count = VioletactivePeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(VioletactivePeer::VA_CUSTOMERID, $this->sc_id);

				if (!isset($this->lastVioletactiveCriteria) || !$this->lastVioletactiveCriteria->equals($criteria)) {
					$count = VioletactivePeer::doCount($criteria, $con);
				} else {
					$count = count($this->collVioletactives);
				}
			} else {
				$count = count($this->collVioletactives);
			}
		}
		$this->lastVioletactiveCriteria = $criteria;
		return $count;
	}

	
	public function addVioletactive(Violetactive $l)
	{
		if ($this->collVioletactives === null) {
			$this->initVioletactives();
		}
		if (!in_array($l, $this->collVioletactives, true)) { 			array_push($this->collVioletactives, $l);
			$l->setTblblogschools($this);
		}
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			if ($this->collVioletactives) {
				foreach ((array) $this->collVioletactives as $o) {
					$o->clearAllReferences($deep);
				}
			}
		} 
		$this->collVioletactives = null;
	}

} 