A-A+

inc_catalog_options dedecms 投稿栏目获取详解

2014年12月18日 17:12 学习笔记 暂无评论 共1532字 (阅读2,221 views次)

【注意:此文章为博主原创文章!转载需注意,请带原文链接,至少也要是txt格式!】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
 *  获取选项列表
 *
 * @param     string  $selid  当前选择ID
 * @param     string  $channeltype  频道类型
 * @return    string
 */
function GetOptionList($selid=0, $channeltype=0)
{
    global $OptionArrayList,$channels,$dsql;
    $dsql->SetQuery("SELECT id,typename FROM `#@__channeltype` ");	//将SQL查询语句格式化查询有多少个频道
    $dsql->Execute();				//执行SQL操作
    $channels = Array();			//定义$channels函数为数组格式。
    while($row = $dsql->GetObject())  	//一、此处为循环输出
    {
        $channels[$row->id] = $row->typename;	//把刚才查询的SQL结果(栏目名字)全部以ID,名字的格式放入$channels数组
    }
    $OptionArrayList = "";
    $query = "SELECT id,typename,ispart,channeltype,issend FROM `#@__arctype` WHERE ispart<2 AND reid=0 ORDER BY sortrank ASC "; 
    $dsql->SetQuery($query);
    $dsql->Execute();	//查询所有栏目
    $selected = '';			//定义$selected函数为空
    while($row=$dsql->GetObject())	//第二次循环输出
    {
        if($selid==$row->id) 
//$selid默认为0,判断$selid他的值与上面循环的栏目ID值一样,此处的主要目的可能用于修改文章
        {
            $selected = " selected='$selected'";	//输出$selected为0,意思为选择当前栏目。
        }
        if($row->channeltype==$channeltype && $row->issend==1)  //判断上面2次循环的频道是否与提交进来的频道ID对应,还有$row->issend代表可以发文章的
        {
            if($row->ispart==0)		//这里是判断栏目属性并循环输出(0最终、1封面、2外部频道等) 不同的栏目属性,显示不同的class
            {
                $OptionArrayList .= "<option value='".$row->id."' class='option3'{$selected}>".$row->typename."</option>\r\n"; //这里注意CSS样式3
            }
            else if($row->ispart==1)
            {
                $OptionArrayList .= "<option value='".$row->id."' class='option2'{$selected}>".$row->typename."</option>\r\n"; //这里注意CSS样式2
                //对于上面的\r\n解释:Unix系统里,每行结尾只有“<换行>”,即"\n";Windows系统里面,每行结尾是“<换行><回车>”,即“\n\r”;Mac系统里,每行结尾是“<回车>”,即"\n";。一个直接后果是,Unix/Mac系统下的文件在Windows里打开的话,所有文字会变成一行;而Windows里的文件在Unix/Mac下打开的话,在每行的结尾可能会多出一个^M符号。
            }
        }
        $selected = ''; //$OptionArrayList已经选择完主要显示的栏目了,剩下的是不需要选择的,就直接赋值为空。
        LogicGetOptionArray($row->id,"─",$channeltype,$selid);
    }
    return $OptionArrayList;
}
 
/**
 *  逻辑递归
 *			个人理解:主要用于列表显示  主栏目 然后主栏目下有多少子栏目。
 * @access    public
 * @param     int  $id				栏目ID
 * @param     string  $step			- 意思为下级栏目前面的符号
 * @param     string  $channeltype	频道
 * @param     int  $selid			当前选择ID
 * @return    string
 */
function LogicGetOptionArray($id,$step,$channeltype,$selid=0)
{
    global $OptionArrayList,$channels,$dsql;
    $selected = '';
    $dsql->SetQuery("Select id,typename,ispart,channeltype,issend From `#@__arctype` where reid='".$id."' And ispart<2 order by sortrank asc");
    $dsql->Execute($id);  
    while($row=$dsql->GetObject($id))
    {
        if($selid==$row->id)
        {
            $selected = " selected='$selected'";
        }
        if($row->channeltype==$channeltype && $row->issend==1)
        {
            if($row->ispart==0)
            {
                $OptionArrayList .= "<option value='".$row->id."' class='option3'{$selected}>$step".$row->typename."</option>\r\n";
            }
            else if($row->ispart==1)
            {
                $OptionArrayList .= "<option value='".$row->id."' class='option2'{$selected}>$step".$row->typename."</option>\r\n";
            }
        }
        $selected = '';
        LogicGetOptionArray($row->id,$step."─",$channeltype,$selid);
    }
}

布施恩德可便相知重

微信扫一扫打赏

支付宝扫一扫打赏

×
标签:

给我留言