--- db/prgsrc/drupal/modules/chgk_db/classes/DbPackage.class.php 2010/03/20 17:23:42 1.4
+++ db/prgsrc/drupal/modules/chgk_db/classes/DbPackage.class.php 2010/04/24 21:45:50 1.5
@@ -4,16 +4,23 @@ require_once(dirname(__FILE__)."/DbDatab
require_once(dirname(__FILE__)."/DbPackage/DbPackageGroup.class.php");
require_once(dirname(__FILE__)."/DbPackage/DbPackageTour.class.php");
require_once(dirname(__FILE__)."/DbPackage/DbPackageChamp.class.php");
+require_once(dirname(__FILE__)."/DbPackage/DbPackageRoot.class.php");
+
require_once(dirname(__FILE__)."/DbPackage/DbPackageError.class.php");
class DbPackage {
protected $tour;
protected $db;
+ protected $id;
+ protected $children = FALSE;
+ protected $parent = FALSE;
+ const NOSPACES = TRUE;
+ private static $tourCache = array();
- public function __construct($row) {
+ public function __construct($row, $parent = FALSE) {
+ $this->setParent($parent);
$this->db = new DbDatabase();
-
if (is_object($row)) {
$this->tour = $row;
$this->setId();
@@ -27,14 +34,11 @@ class DbPackage {
$this->id = $this->tour->FileName;
}
- public static function newFromRow() {
- $tour = new self;
- $tour->tour = $row;
- }
-
- public static function newFromDb($id) {
- $db = new DbDatabase;
- $row = $db->getTournament($id);
+ public static function newRoot() {
+ return new DbPackageRoot($row);
+ }
+
+ public static function newFromRow($row) {
if (!$row) {
return new DbPackageError($id);
} elseif ($row->Type == 'Г' ) {
@@ -43,7 +47,25 @@ class DbPackage {
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() {
@@ -58,12 +80,13 @@ class DbPackage {
}
public function getTitle() {
- return $this->tour->Title;
+ return $this->tour->Title;
}
-
- public function getPrintVersion() {
- return 'Please override this function';
+
+ public function getFullTitle() {
+ return $this->getTitle();
}
+
public function getLongTitle() {
return $this->getTitle();
@@ -96,4 +119,153 @@ class DbPackage {
}
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 = file_directory_path()."/$i";
+ $result.="