print_r(ThreadWithType::insertThreadTypeSFun(2, array("56", "58"), "心情舒畅")); echo "<br/>"; $data = array("37"); $type_thread = new ThreadWithType($data); //$result=ThreadWithType::getThreadSFun($data); $result = ThreadWithType::getOneTypeThreadSFun(array(55, 54)); if ($result[0]) { echo "获取该类型帖子成功<br/>"; $type_thread->showThread($result[1]); } //$type_thread->deleteThreadType(2); //测试静态函数 //ThreadWithType::insertThreadTypeSFun(2,array("56","60"),"心情舒畅"); //ThreadWithType::deleteThreadTypeSFun(2); $threadwithtype = $type_thread->getThreadArray(); $test = ThreadWithType::beCategoried(1); //echo "{$test[0]}<br/>"; if (intval($test[0]) == -1) { echo "出错{$test[0]}<br/>"; //print_r($test); echo "<br/>"; } if ($test[0] == 0) { echo "该帖子未分类<br/>"; } else { print_r($test); } //print_r($threadwithtype); echo "帖子分类操作部分完成<br/>"; require_once "function/function_showThreadWithTable.php"; require_once "function/function_showAttachmentDownload.php";
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; }