1: <?php
2: require_once(dirname(__FILE__)."/DbFieldFactory.class.php");
3:
4: class DbQuestion {
5: private $question;
6: private $fieldFactory;
7: protected $tour;
8: protected $searchString;
9: public $fields;
10: private $typeMap = array(
11: 'Я' => 'Jeopardy'
12: );
13:
14: public function __construct($row, $tour = null) {
15: $this->question = $row;
16: $this->tour = $tour;
17: if (!$tour && $row->tourId) {
18: $this->tour = DbPackage::newFromQuestionRow($row,'tour');
19: $this->tournament = DbPackage::newFromQuestionRow($row,'tournament');
20: $this->tour->setParent($this->tournament);
21: }
22: $this->fieldFactory = new DbFieldFactory();
23: $this->setFields();
24: }
25:
26: public function getHtml() {
27: return theme('chgk_db_question', $this);
28: }
29:
30: public function getFb2() {
31: return theme('chgk_db_question_fb2', $this);
32: }
33:
34: public function getImages() {
35: $this->images = array();
36: foreach ($this->fields as $f) {
37: $this->images = array_merge($this->images, $f->getImages());
38: }
39: return $this->images;
40: }
41:
42:
43: public function getField($name) {
44: return $this->fields[$name];
45: }
46:
47: public function getNumber() {
48: return $this->question->Number;
49: }
50: protected function setFields() {
51: $this->setQuestionField();
52: $fields = array('Answer', 'PassCriteria', 'Comments', 'Sources', 'Authors');
53: foreach ($fields as $field) {
54: $this->setField($field);
55: }
56: }
57:
58: private function setQuestionField() {
59: $this->fields['Question'] = $this->fieldFactory->getField(
60: 'Question',
61: $this->question->Question,
62: $this->question->Number,
63: $this
64: );
65: }
66: public function setSearchString($string) {
67: $this->searchString =$string;
68: }
69:
70: public function getSearchString() {
71: return $this->searchString;
72: }
73: private function setField($field) {
74: $f = $this->fieldFactory->getField(
75: $field,
76: $this->question->{$field},
77: false,
78: $this
79: );
80: if ($f->isEmpty()) {
81: return;
82: }
83: if ($this->searchString) {
84: $f->setSearchString( $this->searchString );
85: }
86: $this->fields[$field] = $f;
87: }
88:
89: public function getUrl() {
90: return url($this->tour->getLink());
91: }
92:
93: public function getSearchTitle() {
94: return $this->tour->getFullTitle();
95: }
96: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>