--- db/prgsrc/drupal/modules/chgk_db/classes/DbQuestion.class.php 2010/02/28 20:17:34 1.1 +++ db/prgsrc/drupal/modules/chgk_db/classes/DbQuestion.class.php 2010/04/24 21:45:50 1.5 @@ -4,18 +4,52 @@ require_once(dirname(__FILE__)."/DbField class DbQuestion { private $question; private $fieldFactory; + protected $tour; + protected $searchString; public $fields; + private $typeMap = array( + 'Я' => 'Jeopardy' + ); - public function __construct($row) { + 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(); } - private function setFields() { - $this->setQuestionField(); + 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; + } + - $fields = array('Answer', 'PassCriteria', 'Comments', 'Sources'); + 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); } @@ -25,18 +59,38 @@ class DbQuestion { $this->fields['Question'] = $this->fieldFactory->getField( 'Question', $this->question->Question, - $this->question->Number); + $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} + $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(); + } }