<?php

/**
 * Subclass for representing a row from the 'tblblogschools' table.
 *
 *
 *
 * @package lib.model
 */
class Tblblogschools extends BaseTblblogschools
{
	/**
	 * Initializes internal state of Tblblogschools object.
	 * @see        parent::__construct()
	 */
	public function __construct()
	{
		// Make sure that parent constructor is always invoked, since that
		// is where any default values for this object are set.
		parent::__construct();
	}

	/**
	 * Enter description here...
	 *
	 * @param unknown_type $type
	 * @param unknown_type $parent
	 * @return unknown
	 */
	static function getItem($type, $parent, $maxParent = 0) {
	  $c = new Criteria();
	  //var_dump($type); exit();
	  if ($type == -1) {//dung cho chuc nang kich hoat violet
	    $c->add(TblblogschoolsPeer::SC_TYPE , 2, Criteria::GREATER_EQUAL);
	  } else {
      $c->add(TblblogschoolsPeer::SC_TYPE , $type, Criteria::IN);
	  }
    $criterion = $c->getNewCriterion(TblblogschoolsPeer::SC_PARENT, $parent);
    if (is_array($type)) {//list ra cac don vi con  va nhung don vi ko thuoc huyen nao
      if ($maxParent == 0) {//load id cua tinh/thanh
        $tblblogschool = TblblogschoolsPeer::retrieveByPK($parent);
        $maxParent = $tblblogschool->getScParent();//lay id cua (cha cua cha)
      }
      $criterion->addOr($c->getNewCriterion(TblblogschoolsPeer::SC_PARENT , $maxParent));
    }
    $c->add($criterion);
	  $c->addAscendingOrderByColumn(TblblogschoolsPeer::SC_NAME);
	  return TblblogschoolsPeer::doSelect($c);
	}

  static function getItemWithGuide($type, $parent, $guide = '') {
    $f = new Tblblogschools();
    $f->setScId(0);
    $f->setScName('&lt;'.$guide.'&gt;');
    return array_merge(array($f), self::getItem($type, $parent));
  }

	/**
	 * Enter description here...
	 *
	 * @param unknown_type $school_id
	 * @return unknown
	 */
	static function getCheckInfo ($school_id) {
	  $checkInfo = array();
	  $checkInfo['school'] = $checkInfo['district'] = $checkInfo['province'] = NULL;
	  //get school info
	  $checkInfo['school'] = TblblogschoolsPeer::retrieveByPK($school_id);
	  if ($checkInfo['school']) {
      //get thong tin phong giao duc
      $checkInfo['district'] = TblblogschoolsPeer::retrieveByPK($checkInfo['school']->getScParent());
      //get thong tin so giao duc
      if($checkInfo['district']) {
        $checkInfo['province'] = TblblogschoolsPeer::retrieveByPK($checkInfo['district']->getScParent());
      }
	  }

	  return $checkInfo;
	}

  public function getScHomepage() {
    $c = new Criteria();
    $c->add(TblblogPeer::BL_SCHOOL, $this->getScId());
    $tblblog = TblblogPeer::doSelectOne($c);
    return $tblblog? $tblblog->getRootUrl(): '';
  }

  public function getHtmlName($options = array('target'=>'_blank')) {
    $name = $this->getScName();
    $link = $this->getScHomepage();
    return ($link=='')? $name: link_to($name, $link, $options);
  }
}
