<?php

/**
 * Subclass for representing a row from the 'tbltestexam' table.
 *
 * 
 *
 * @package lib.model
 */ 
class Tbltestexam extends BaseTbltestexam
{
  private $cr_info = null;

	/**
	 * Initializes internal state of Tbltestexam 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();
	}

  public function getQuestionList() {
    $tests = array();
    $questions = explode(',', $this->getExQuestions());
    foreach ($questions as $id) $tests[] = TbltestquestionPeer::retrieveByPk($id);
    return $tests;
  }

  public function setQuestionList($tests) {
    $questions = array();
    foreach ($tests as $test) $questions[] = $test->getTeId();
    $this->setExQuestions(implode(',', $questions));
  }

  public function setCreateInfo($blogs, $categories, $counts, $levels) {
    $catinfo = array();
    for ($i = 0; $i < count($blogs); $i ++) {
      $catinfo[] = implode(',', array($blogs[$i], $categories[$i], $counts[$i], $levels[$i]));
    }
    $this->setExInfo(implode('|', $catinfo));
  }

  public function getCreateInfo($index) {
    if ($this->cr_info == null) {
      $this->cr_info = array();
      foreach (explode('|', $this->getExInfo()) as $info) $this->cr_info[] = explode(',', $info);
    }
    foreach ($this->cr_info as $info) {
      $index -= $info[2];
      if ($index < 0) return $info;
    }
  }

  public function getCategoryName() {
    return TblblogcategoryPeer::retrieveByPk($this->getExCategory())->getCatName();
  }
}
