Annotation of db/prgsrc/drupal/modules/chgk_db/classes/DbPackage.class.php, revision 1.4
1.1 roma7 1: <?php
2:
3: require_once(dirname(__FILE__)."/DbDatabase.class.php");
4: require_once(dirname(__FILE__)."/DbPackage/DbPackageGroup.class.php");
5: require_once(dirname(__FILE__)."/DbPackage/DbPackageTour.class.php");
6: require_once(dirname(__FILE__)."/DbPackage/DbPackageChamp.class.php");
1.2 roma7 7: require_once(dirname(__FILE__)."/DbPackage/DbPackageError.class.php");
1.1 roma7 8:
9: class DbPackage {
10:
11: protected $tour;
12: protected $db;
13:
14: public function __construct($row) {
1.2 roma7 15: $this->db = new DbDatabase();
16:
17: if (is_object($row)) {
18: $this->tour = $row;
19: $this->setId();
20: } else {
21: $this->id = $row;
22: $this->loadFromDatabase();
23: }
1.1 roma7 24: }
25:
26: protected function setId() {
27: $this->id = $this->tour->FileName;
28: }
29:
30: public static function newFromRow() {
31: $tour = new self;
32: $tour->tour = $row;
33: }
34:
35: public static function newFromDb($id) {
36: $db = new DbDatabase;
37: $row = $db->getTournament($id);
38: if (!$row) {
1.2 roma7 39: return new DbPackageError($id);
1.1 roma7 40: } elseif ($row->Type == 'Г' ) {
41: return new DbPackageGroup($row);
42: } elseif ($row->Type == 'Ч' ) {
43: return new DbPackageChamp($row);
44: } elseif ($row->Type == 'Т' ) {
45: return new DbPackageTour($row);
46: }
47: }
48:
1.2 roma7 49: public function loadFromDatabase() {
50: $this->tour = $this->db->getTournament($this->id);
51: }
1.1 roma7 52: public function getAll() {
53: return false;
54: }
55:
56: protected function getDbId() {
57: return $this->tour->Id;
58: }
59:
60: public function getTitle() {
61: return $this->tour->Title;
62: }
1.2 roma7 63:
64: public function getPrintVersion() {
65: return 'Please override this function';
66: }
67:
68: public function getLongTitle() {
69: return $this->getTitle();
70: }
1.3 roma7 71: public function getInfo() {
1.4 ! roma7 72: $info = $this->tour->Info;
! 73: $info = preg_replace('/(\s+)-+(\s+)/','\1—$2', $info);
! 74:
! 75: return $info;
1.3 roma7 76: }
1.4 ! roma7 77: public function hasEditor() {
1.3 roma7 78: return $this->tour->Editors?TRUE:FALSE;
79: }
1.4 ! roma7 80: public function hasInfo() {
! 81: return $this->tour->Info?TRUE:FALSE;
1.3 roma7 82: }
83:
84: public function getEditor() {
85: return $this->tour->Editors;
86: }
87:
88: public function getEditorHtml() {
89: $ed = $this->tour->Editors;
1.4 ! roma7 90: $ed = preg_replace('/(\s+)-+(\s+)/','\1—$2', $ed);
! 91:
1.3 roma7 92: if (preg_match('/\,/', $ed)) {
93: $ob = 'Редакторы: ';
94: } else {
95: $ob = 'Редактор: ';
96: }
97: return $ob.$ed;
98: }
1.1 roma7 99: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>