version 1.3, 2010/03/09 21:08:33
|
version 1.5, 2010/04/24 21:45:50
|
Line 4 require_once(dirname(__FILE__)."/DbDatab
|
Line 4 require_once(dirname(__FILE__)."/DbDatab
|
require_once(dirname(__FILE__)."/DbPackage/DbPackageGroup.class.php"); |
require_once(dirname(__FILE__)."/DbPackage/DbPackageGroup.class.php"); |
require_once(dirname(__FILE__)."/DbPackage/DbPackageTour.class.php"); |
require_once(dirname(__FILE__)."/DbPackage/DbPackageTour.class.php"); |
require_once(dirname(__FILE__)."/DbPackage/DbPackageChamp.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"); |
require_once(dirname(__FILE__)."/DbPackage/DbPackageError.class.php"); |
|
|
class DbPackage { |
class DbPackage { |
|
|
protected $tour; |
protected $tour; |
protected $db; |
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(); |
$this->db = new DbDatabase(); |
|
|
if (is_object($row)) { |
if (is_object($row)) { |
$this->tour = $row; |
$this->tour = $row; |
$this->setId(); |
$this->setId(); |
Line 27 class DbPackage {
|
Line 34 class DbPackage {
|
$this->id = $this->tour->FileName; |
$this->id = $this->tour->FileName; |
} |
} |
|
|
public static function newFromRow() { |
public static function newRoot() { |
$tour = new self; |
return new DbPackageRoot($row); |
$tour->tour = $row; |
} |
} |
|
|
public static function newFromRow($row) { |
public static function newFromDb($id) { |
|
$db = new DbDatabase; |
|
$row = $db->getTournament($id); |
|
if (!$row) { |
if (!$row) { |
return new DbPackageError($id); |
return new DbPackageError($id); |
} elseif ($row->Type == 'Г' ) { |
} elseif ($row->Type == 'Г' ) { |
Line 43 class DbPackage {
|
Line 47 class DbPackage {
|
return new DbPackageChamp($row); |
return new DbPackageChamp($row); |
} elseif ($row->Type == 'Т' ) { |
} elseif ($row->Type == 'Т' ) { |
return new DbPackageTour($row); |
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() { |
public function loadFromDatabase() { |
Line 58 class DbPackage {
|
Line 80 class DbPackage {
|
} |
} |
|
|
public function getTitle() { |
public function getTitle() { |
return $this->tour->Title; |
return $this->tour->Title; |
} |
} |
|
|
public function getPrintVersion() { |
public function getFullTitle() { |
return 'Please override this function'; |
return $this->getTitle(); |
} |
} |
|
|
|
|
public function getLongTitle() { |
public function getLongTitle() { |
return $this->getTitle(); |
return $this->getTitle(); |
} |
} |
public function getInfo() { |
public function getInfo() { |
return $this->tour->Info; |
$info = $this->tour->Info; |
|
$info = preg_replace('/(\s+)-+(\s+)/','\1—$2', $info); |
|
|
|
return $info; |
} |
} |
public function hasEditor() { |
public function hasEditor() { |
return $this->tour->Editors?TRUE:FALSE; |
return $this->tour->Editors?TRUE:FALSE; |
} |
} |
public function hasInfo() { |
public function hasInfo() { |
return $this->tour->Editors?TRUE:FALSE; |
return $this->tour->Info?TRUE:FALSE; |
} |
} |
|
|
public function getEditor() { |
public function getEditor() { |
Line 84 public function hasInfo() {
|
Line 110 public function hasInfo() {
|
|
|
public function getEditorHtml() { |
public function getEditorHtml() { |
$ed = $this->tour->Editors; |
$ed = $this->tour->Editors; |
|
$ed = preg_replace('/(\s+)-+(\s+)/','\1—$2', $ed); |
|
|
if (preg_match('/\,/', $ed)) { |
if (preg_match('/\,/', $ed)) { |
$ob = 'Редакторы: '; |
$ob = 'Редакторы: '; |
} else { |
} else { |
Line 91 public function hasInfo() {
|
Line 119 public function hasInfo() {
|
} |
} |
return $ob.$ed; |
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.="<binary content-type='image/jpeg' id='$i'>"; |
|
$file = fopen($name,'rb'); |
|
$str_file=fread($file,filesize($name)); |
|
$result.=base64_encode($str_file); |
|
$result.="</binary>"; |
|
fclose($file); |
|
} |
|
return $result; |
|
} |
|
|
|
protected function getEditorsForList() { |
|
$ed = $this->db->getEditors($this->tour->Id); |
|
if ($ed) { |
|
$result = array(); |
|
foreach ($ed as $editor) { |
|
$result[] = $editor->Name." ".$editor->Surname; |
|
} |
|
return implode(', ',$result); |
|
} else { |
|
return ''; |
|
} |
|
} |
|
|
|
public function getHtmlLinkForList() { |
|
$result = l($this->getTitle(), $this->getLink()); |
|
return $result; |
|
} |
|
|
|
public function getHtmlLinkForBreadrumb() { |
|
return l($this->getTitle(), $this->getLink()); |
|
} |
|
|
|
public function getLink() { |
|
return "tour/".$this->id; |
|
} |
|
|
|
public function htmlTree($level = 0) { |
|
$result = $this->getHtmlLinkForList(); |
|
$children_html = ''; |
|
foreach ($this->getChildren() as $child) { |
|
if (!self::NOSPACES) { |
|
$children_html.=str_repeat(' ',$level*4+4); |
|
} |
|
$children_html.= "<li>".$child->htmlTree($level+1)."</li>"; |
|
if (!self::NOSPACES) { |
|
$children_html .= "\n"; |
|
} |
|
} |
|
if ($children_html) { |
|
if (!self::NOSPACES) { |
|
$result.="\n".str_repeat(' ',$level*4+2); |
|
} |
|
$result.="<ul>"; |
|
if (!self::NOSPACES) { |
|
$result.="\n"; |
|
} |
|
$result.=$children_html; |
|
if (!self::NOSPACES) { |
|
$result .= str_repeat(' ',$level*4+2); |
|
} |
|
$result.="</ul>"; |
|
if (!self::NOSPACES) { |
|
$result.="\n".str_repeat(' ',$level*4); |
|
} |
|
} |
|
return $result; |
|
} |
|
|
|
public function setParent($parent = FALSE) { |
|
if ($parent) { |
|
$this->parent = $parent; |
|
} elseif($this->tour->ParentId) { |
|
$this->parent = DbPackage::newFromDb($this->tour->ParentId); |
|
} elseif ($this->tour->ParentId === '0') { |
|
$this->parent = DbPackage::newRoot(); |
|
} |
|
} |
|
public function getParent() { |
|
if ($this->parent === FALSE) { |
|
$this->setParent(); |
|
} |
|
return $this->parent; |
|
} |
|
|
|
public function getPrintVersion() { |
|
$content = $this->getHtmlContent(); |
|
return theme('chgk_db_print', $this->getLongTitle(), |
|
$content, |
|
url($this->getLink(), array('absolute'=>TRUE))); |
|
} |
|
|
|
public function getHtmlContent() { |
|
return ''; |
|
} |
|
|
|
public function getBreadcrumb() { |
|
$this->loadBranch(); |
|
$result = array(); |
|
for ($current=$this->getParent(); $current; $current=$current->getParent()) { |
|
array_unshift($result,$current->getHtmlLinkForBreadrumb()); |
|
} |
|
return $result; |
|
} |
|
|
|
public function hasPrintVersion() { |
|
return FALSE; |
|
} |
|
|
|
public function hasFb2() { |
|
return FALSE; |
|
} |
|
|
|
|
|
private function loadBranch() { |
|
$parent = $this->getParent(); |
|
if ($parent) $parent->loadBranch(); |
|
} |
} |
} |