private function init() { if ($this->debug) { echo "GCThreadNode:init初始化参数<br/>"; } $db = GCDB::getInstance(); $sql = "\n\t\t\t\tSELECT t.author,\n\t\t\t\t\t\tt.subject,\n \t\t\t\t\tt.dateline,\n \t\t\t\t\tt.lastpost,\n \t\t\t\t\tt.lastposter,\n \t\t\t\t\tt.views,\n \t\t\t\t\tt.replies,\n \t\t\t\t\tt.attachment as 'isattach'\n\t\t\t\tFROM `{$db->tablepre}forum_thread` t\n\t\t\t\tWHERE t.tid={$this->tid};\n\t\t\t\t"; $sqldata = $db->query($sql); $row = $sqldata->fetch_assoc(); if (empty($row)) { echo "指tid未搜索到数据<br/>"; return false; } $this->author = $row['author']; $this->subject = $row['subject']; $this->dateline = $row['dateline']; $this->lastpost = $row['lastpost']; $this->lastposter = $row['lastposter']; $this->views = $row['views']; //查看次数 $this->replies = $row['replies']; //回复次数 $this->isattach = $row['isattach']; //是否有附件 if ($this->isattach) { //如果有附件,则取附件 $data = GCAttachment::getAidTableidByTid($this->tid); foreach ($data as $key => $value) { //以aid作为数组的key值,生成附件数组 $this->attachment[$key] = new GCAttachment($key, $this->tid, $value); } } else { $this->attachment = array(); //附件数组 } return true; }
private function init() { if ($this->debug) { echo "GCThreadNode:init初始化参数<br/>"; } $db = GCDB::getInstance(); $sql = "\n\t\t\t\tSELECT t.author,\n\t\t\t\t\t\tt.subject,\n \t\t\t\t\tt.dateline,\n \t\t\t\t\tt.lastpost,\n \t\t\t\t\tt.lastposter,\n \t\t\t\t\tt.views,\n \t\t\t\t\tt.replies,\n \t\t\t\t\tt.attachment as 'isattach'\n\t\t\t\tFROM `{$db->tablepre}forum_thread` t\n\t\t\t\tWHERE t.tid={$this->tid};\n\t\t\t\t"; $sqldata = $db->query($sql); $row = $sqldata->fetch_assoc(); if (empty($row)) { echo "指tid未搜索到数据<br/>"; return false; } $this->author = $row['author']; $this->subject = $row['subject']; $this->dateline = intval($row['dateline']); $this->lastpost = intval($row['lastpost']); $this->lastposter = $row['lastposter']; $this->views = intval($row['views']); //查看次数 $this->replies = intval($row['replies']); //回复次数 $this->isattach = $row['isattach']; //是否有附件 if ($this->isattach) { //如果有附件,则取附件 $data = GCAttachment::getAidTableidByTid($this->tid); foreach ($data as $key => $value) { //以aid作为数组的key值,生成附件数组 $this->attachment[$key] = new GCAttachment($key, $this->tid, $value); } } else { $this->attachment = array(); //附件数组 } //获取附件的类型 $result = ThreadWithType::beCategoried($this->tid); if ($this->debug) { echo "帖子类别<br/>"; print_r($result); echo "<br/>"; } if ($result[0] == true) { //找到分类id数组 //对数组排序 //type_id的第一层祖先节点id最小的那个为主分类 //即与root的id相差为1的类型id为主分类 $tree = DataTree::getInstance(); $dataarray = $result[1]; $total = count($dataarray); $tmpValue = $dataarray[0]; $tmp = $tree->getANodeByOtherNode($tmpValue[type_id], 1); //获取第一个值的祖先节点 if ($tmp[0]) { $tmpid = $tmp[1]->type_id; } else { if ($this->debug) { echo "查找祖先节点失败<br/>"; print_r($tmp); echo "<br/>"; } return false; } //从1开始 //获取次分类 for ($i = 1; $i < $total; $i++) { $value = $dataarray[$i]; //$value的结构为[type_id]、[rate]、[type_name] $tmp = $tree->getANodeByOtherNode($value[type_id], 1); if ($tmp[0]) { $valueid = $tmp[1]->type_id; } else { if ($this->debug) { echo "查找祖先节点失败<br/>"; print_r($tmp); echo "<br/>"; } return false; } //id较小的是主分类,id较大的是次分类 //只能有一个主分类,因此大于等于的都是次分类 if ($tmpid <= $valueid) { //存到次分类 $this->type[subordinate][] = $value; } else { $this->type[subordinate][] = $tmpValue; //替换最小值 $tmpValue = $value; $tmpid = $valueid; } } //获取主分类 $this->type[maintype][] = $tmpValue; } else { //未找到分类id数组 $this->type[maintype][][typename] = "未分类"; $this->type[subordinate][][typename] = "未分类"; } return true; }