公共機関の改革を促進するための分類に関する意見 先日書いた無限分類

WBOY
リリース: 2016-07-29 08:36:17
オリジナル
845 人が閲覧しました

これは 1 週間前に書きましたが、実際に使ってみると非常にうまく機能しています。
主なアイデアは http://www.phpobject.net/b...[url=http://www.phpobject.net/blog/read.php?49][/url] から来ています
あまり説明はありません原則は明らかです。コードを送信するだけです。
PS: このコードは直接使用できないため、他のライブラリ クラスのいくつかと組み合わせる必要があります。ここでは主に分類のアイデアを提供します。

コードをコピーします コードは次のとおりです:


/** 
--
-- 表の结构 `daxue8_category`
--
CREATE TABLE `daxue8_category` (
`cid` smallint(6) NOT NULL auto_increment,
`pid` smallint(6) NOT NULL default '0'、
`level` smallint(6) NOT NULL default '0',
`cname` char(64) NOT NULL default '',
`lft` smallint(6) NOT NULL default '0',
`rgt` smallint(6 ) NOT NULL デフォルト '0',
`uid` mediumint(8) NOT NULL デフォルト '0',
`username` char(32) NOT NULL デフォルト '',
`ctime` int(10) NOT NULL デフォルト '0 ',
`cstate` tinyint(1) NOT NULL default '0',
`gnum` mediumint(8) NOT NULL default '0',
`orderstyle` smallint(3) NOT NULL default '0',
PRIMARY KEY (`cid`)
) TYPE=MyISAM AUTO_INCREMENT=2 ; 
--
-- 导出表中のデータ `daxue8_category`
--
INSERT INTO `daxue8_category` VALUES (1, 0, 1, 'root', 1, 2, 0, '管理员', 1163608814, 1, 0, 0); 
*/
クラスカテゴリ
{
var $tbname;
function category()
$this-& gt;tbname=TB_PREX.'_category' ;
$this->module=new module($this->tbname); if($node_exist=$this->module ->detail('where pid='.$pid.' and cname= ''.$node['cname'].'')){ $this->error(__FUNCTION__.'(): ノード '.$node['cname'].' はすでに存在します!');
`'。$ this-> tbname.'` lft = lft+2を設定します。$ pnode [' rgt ']); $ pnode ['rgt']; & gt; module-& gt; add
}
/**
*ノードを削除する
*@Param $ delete_childern 子ノードがある場合、強制的に削除するかどうか。設定が true ではなく、子ノードがある場合、削除は失敗し、 false を返します
> ;get_by_cid($cid);
If(($this->child_num($node)>0)&&(! $delete_childern))$this->error(__FUNCTION__.'(): このノードには子ノードがあります。'); // ノードとそのすべてのサブノードを削除します
$ this-> module->
// 対応する左クリック値と右クリック値を変更します
; Plus = $ ノード ['rgt']-$ ノード ['lft']+1; $ This- & gt; クエリ ('update `' ' .$this->tbname.'` set lft=lft-'.$plus.' where lft>'.$node['rgt']);
$this->module->query('update ` '.$this->tbname.'` set rgt=rgt-'.$plus.' where rgt>'.$node['rgt']); /
Function Update ($ set, $ cid) {
Return $ this- & gt; -& gt; update ($ set, 'where cid ='. $ Cid);
/**
*ノードを更新します*/
function select($cid,$deep=0)
{ ].' ['rgt'];
if(!empty($deep))$where.=' および level<'.$node['level']+$deep;
if($deep ==1){戻る) ;
}
/**
を使用して*/
function get_parent($cid)
{
gt;select( 'where lft<='.$node['lft'].' and rgt>='.$node ['rgt'].' lft asc') で注文します。 
/**
‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐*/
function get_children($pid,$deep=0){
//获取节点情報
$pnode=$this->get_by_cid($pid); 
$where='where lft>'.$pnode['lft'].' そしてrgt if(!empty($deep))$where.=' and level<='.($pnode['level']+$deep); 
if($deep==1){
$where.=' order by orderstyle desc'; 
}else{
$where.='order by lft asc';             
}
return $this->module->select($where); 
}
/**
を使用して*/
function get_level_children($pid,$deep){
//获取节点情報
$pnode=$this->get_by_cid($pid); 
$where='where lft>'.$pnode['lft'].' そしてrgt $where.=' and level='.($pnode['level']+$deep); 
$where.=' orderstyle desc で注文'; 
return $this->module->select($where); 
}
/**
使用する 使用するオフ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐*/
function get_by_cid($cid){
$node=$this->module->detail('where cid='.$cid); 
if(!$node)$this->error(__FUNCTION__.'():获取节点'.$cid.'失败!'); T リターン $ ノード
}
/**
*子ノードの数を取得します*/
関数 Child_num ($ ノード) {
リターン ($ ノード [' rgt ']-$ ノード [' lft ']/2 ;
}
/ **&#&*/
関数ディスプレイ($ cid){
$ nodes = $ this-&gt; select($ cid);ノード['レベル']-1).$node['cname']."n"; --------------------------* /
function error($msg){
die('ERROR : ファイル '.__FILE__.' 関数 ' .$msg);
}
}

;
以上、先日書いた無限分類カテゴリーに公的機関の分類と改革推進に関する意見を紹介しましたので、興味のある友人の参考になれば幸いです。 PHPのチュートリアル。


ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!