File:  [Local Repository] / db / prgsrc / drupal / modules / chgk_db / classes / DbQuestion.class.php
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Sat Apr 24 21:45:50 2010 UTC (14 years ago) by roma7
Branches: MAIN
CVS tags: HEAD
Version 2 big update

<?php 
require_once(dirname(__FILE__)."/DbFieldFactory.class.php");

class DbQuestion {
  private $question;
  private $fieldFactory;
  protected $tour;
  protected $searchString;
  public $fields;
  private $typeMap = array(
    'Я' => 'Jeopardy'
  );
  
  public function __construct($row, $tour = null) {
    $this->question = $row;
    $this->tour = $tour;
    if (!$tour && $row->tourId) {
        $this->tour = DbPackage::newFromQuestionRow($row,'tour');
        $this->tournament = DbPackage::newFromQuestionRow($row,'tournament');
        $this->tour->setParent($this->tournament);
    }
    $this->fieldFactory = new DbFieldFactory();
    $this->setFields();
  }
  
  public function getHtml() {
    return theme('chgk_db_question', $this);  
  }

  public function getFb2() {
      return theme('chgk_db_question_fb2', $this);
  }

  public function getImages() {
      $this->images = array();
      foreach ($this->fields as $f) {
          $this->images = array_merge($this->images, $f->getImages());
      }
      return $this->images;
  }


  public function getField($name) {
    return $this->fields[$name];
  }
  
  public function getNumber() {
    return $this->question->Number;
  }
  protected function setFields() {
    $this->setQuestionField();
    $fields = array('Answer', 'PassCriteria', 'Comments', 'Sources', 'Authors');
    foreach ($fields as $field) {
      $this->setField($field);
    }
  }
  
  private function setQuestionField() {
    $this->fields['Question'] = $this->fieldFactory->getField(
      'Question', 
      $this->question->Question, 
      $this->question->Number,
      $this
    );
  }
  public function setSearchString($string) {
      $this->searchString =$string;
  }

  public function getSearchString() {
      return $this->searchString;
  }
  private function setField($field) {  
    $f = $this->fieldFactory->getField(
      $field, 
      $this->question->{$field},
      false,
      $this
    );
    if ($f->isEmpty()) {
      return;
    }
    if ($this->searchString) {
        $f->setSearchString( $this->searchString );
    }
    $this->fields[$field] = $f;
  }

  public function getUrl() {
      return url($this->tour->getLink());
  }

  public function getSearchTitle() {
      return $this->tour->getFullTitle();
  }
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>