setParent($parent);
$this->db = new DbDatabase();
if (is_object($row)) {
$this->tour = $row;
$this->setId();
} else {
$this->id = $row;
$this->loadFromDatabase();
}
}
protected function setId() {
$this->id = $this->tour->FileName;
}
public static function newRoot() {
return new DbPackageRoot($row);
}
public static function newFromRow($row) {
if (!$row) {
return new DbPackageError($id);
} elseif ($row->Type == 'Г' ) {
return new DbPackageGroup($row);
} elseif ($row->Type == 'Ч' ) {
return new DbPackageChamp($row);
} elseif ($row->Type == 'Т' ) {
return new DbPackageTour($row);
}
}
public static function newFromQuestionRow($row, $prefix) {
$tour = new stdClass();
$tour->Id = $row->{"{$prefix}Id"};
$tour->Title = $row->{"{$prefix}Title"};
$tour->FileName = $row->{"{$prefix}FileName"};
$tour->Type = $row->{"{$prefix}Type"};
return self::newFromRow($tour);
}
public static function newFromDb($id) {
if (self::$tourCache[$id]) return self::$tourCache[$id];
$db = new DbDatabase;
$row = $db->getTournament($id);
$result = self::newFromRow($row);
self::$tourCache[$id] = $result;
return $result;
}
public function loadFromDatabase() {
$this->tour = $this->db->getTournament($this->id);
}
public function getAll() {
return false;
}
protected function getDbId() {
return $this->tour->Id;
}
public function getTitle() {
return $this->tour->Title;
}
public function getFullTitle() {
return $this->getTitle();
}
public function getLongTitle() {
return $this->getTitle();
}
public function getInfo() {
$info = $this->tour->Info;
$info = preg_replace('/(\s+)-+(\s+)/','\1—$2', $info);
return $info;
}
public function hasEditor() {
return $this->tour->Editors?TRUE:FALSE;
}
public function hasInfo() {
return $this->tour->Info?TRUE:FALSE;
}
public function getEditor() {
return $this->tour->Editors;
}
public function getEditorHtml() {
$ed = $this->tour->Editors;
$ed = preg_replace('/(\s+)-+(\s+)/','\1—$2', $ed);
if (preg_match('/\,/', $ed)) {
$ob = 'Редакторы: ';
} else {
$ob = 'Редактор: ';
}
return $ob.$ed;
}
public function getFb2() {
$this->getAll();
return theme('chgk_db_fb2', $this);
}
public function loadTree() {
foreach ($this->getChildren() as $child) {
$child->loadTree();
}
}
public function getChildren() {
if ($this->children === FALSE ) {
$this->loadChildren();
}
return $this->children;
}
public function loadChildren() {
$this->children = array();
$res = $this->db->getChildrenRes($this->getDbId());
while ($row = $this->db->fetch_row($res)) {
$this->children[] = DbPackage::newFromRow($row, $this);
}
}
public function getImagesBinaries() {
$images=$this->getImages();
$result = '';
foreach ($images as $i) {
$name = "/home/znatoki/chgk-db/public_html/images/db/$i";
................
$result.="