_ios of the example of Yii frame classification tree expansion

Source: Internet
Author: User
Tags set time yii

Provides two ways of classifying tree format, table and dropdown frame form tree structure
You can customize the style of the table and Drop-down boxes, customize which column parameters are formatted data, customize the hierarchy relationship parameters, customize the table column names, or set the formatting of the time.



Call mode

Table mode:

Copy Code code as follows:



<?php $this->widget (' Ext.tree.widgets.TreeWidget ', Array (


' Dataprovider ' => $dataProvider,//Pass data


' PID ' => ' pid ',//set level relationship ID


' Tableclass ' => ' items table table-striped table-bordered table-condensed ',//table style


' Formatparam ' => ' name ',//Set format field


' Formattime ' => Array (//Set time parameters for formatting)


' Created '


),


' Tablehead ' => Array (//Set table column header information


' Category ID ',


' Channel ',


' Chinese name ',


' English name ',


' First letter ',


' Sort ',


' Classification level ',


' Parent ID ',


' Creation time ',


),


));?>


Drop-down Box mode

Copy Code code as follows:



<?php $this->widget (' Ext.tree.widgets.TreeWidget ', Array (


' Dataprovider ' => $cate,//Pass data


' PID ' => ' pid ',//Set Parent ID


' Formatparam ' => ' name ',//Set format field


' Treetype ' => false,//output Tree format


' Selectclass ' => ' class= ' span11 ',//Set dropdown box style


' Defaultselectvalue ' => Array (//Set default values and options for drop-down boxes)


0, ' chess as a first-class column '


),


));?>


treewidget.php

Copy Code code as follows:



<?php

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**


* Description of tree


*


* @author Wang Jiacheng


* @email 819434425@qq.com


*


* Table Method call


<?php $this->widget (' Ext.tree.widgets.TreeWidget ', Array (


' Dataprovider ' => $dataProvider,//Pass data


' PID ' => ' pid ',//set level relationship ID


' Tableclass ' => ' items table table-striped table-bordered table-condensed ',//table style


' Formatparam ' => ' name ',//Set format field


' Formattime ' => Array (//Set time parameters for formatting)


' Created '


),


' Tablehead ' => Array (//Set table column header information


' Category ID ',


' Channel ',


' Chinese name ',


' English name ',


' First letter ',


' Sort ',


' Classification level ',


' Parent ID ',


' Creation time ',


),


));?>


*


* Drop-down Box Method call


* <?php $this->widget (' Ext.tree.widgets.TreeWidget ', Array (


' Dataprovider ' => $cate,//Pass data


' PID ' => ' pid ',//Set Parent ID


' Formatparam ' => ' name ',//Set format field


' Treetype ' => false,//output Tree format


' Selectclass ' => ' class= ' span11 ',//Set dropdown box style


' Defaultselectvalue ' => Array (//Set default values and options for drop-down boxes)


0, ' chess as a first-class column '


),


));?>


*/


Class Treewidget extends Widget {


/**


* Carraydataprovider data object or array data


* Component Data Receive parameters


* @var Object | | Array


*/


Public $dataProvider;





/**


* Assign value to receive data


* @var Type


*/


Public $arrAll = Array ();





/**


* The multidimensional relation of the key name by _id


* @var Type


*/


Public $arrIdRelation = Array ();





/**


* Simplify the multidimensional relationship of the _id as the key name to output the tree graph


* @var Type


*/


Public $arrIdRelationSimple = Array ();





/**


* An array that converts the original data into _id as the key name


* @var Type


*/


Public $arrIdAll = Array ();





/**


* All parent-child relationships


* @var Type


*/


Public $arrIdSon = Array ();





/**


* _id of leaf nodes


* @var Type


*/


Public $arrIdLeaf = Array ();





/**


* _id of the root node


* @var Type


*/


Public $arrIdRoot = Array ();





/**


* Posterity _id under each node


* @var Type


*/


Public $arrIdChildren = Array ();





/**


* Each node back to the root


* @var Type


*/


Public $arrIdBackPath = Array ();





/**


* Structure of the output tree


* @var Type


*/


Public $strItem = ' <br/>{$strSep} {$name} ';





/**


* Set Table Style


* @var Type


*/


Public $tableClass = ' Items table table-striped table-bordered table-condensed ';





/**


* Data Field parameter array


* @var Type


*/


Public $dataKey = Array ();





/**


* Specify the fields you want to format


* @var Type


*/


Public $formatParam = ' name ';





/**


* Table column Name


* @var Type


*/


Public $tableHead = Array ();





/**


* Parent ID


* @var Type


*/


Public $pid = ' pid ';





/**


* Specify the type of tree


* True Table type tree


* False dropdown box type tree


* @var Type


*/


Public $treeType = true;





/**


* Binding set the value of the dropdown box


* @var Type


*/


Public $optionValue = ' id ';





/**


* Format time


* @var Type


*/


Public $formatTime = Array ();





/**


* Dropdown box style


* @var Type


*/


Public $selectClass = ' class= ' span3 ';





/**


* Set the default values and options for the dropdown box


* @var Type


*/


Public $defaultSelectValue = Array (


0, ' chess as a first-class column ',


);





/**


* Set the dropdown box to select multiple


* True Multiple selection


* False Single selection


* @var Type


*/


Public $isMultiple = false;





/**


* The default value bound to the dropdown box


* @var Type


*/


Public $bindSelectValue = 0;


/**


* Run


*/


Public Function run () {


if (Is_array ($this->dataprovider) && count ($this->dataprovider) > 0)


$data = $this->_run ($this->dataprovider);


else if (Is_object ($this->dataprovider) && count ($this->dataprovider->rawdata) > 0)


$data = $this->_run ($this->dataprovider->rawdata);








$this->render (' Tree ', Array (' Data ' => $data));


}





/**


*


* @return Type


*/


Private Function _run ($datas) {


foreach ($datas as $data)


$this->arrall[] = $data;


$this->datakey = Array_keys ($data);

$this->processdata ();
if ($this->treetype = = True)
$data = $this->gettable ();
Else
$data = $this->getselect ($this->pid, $this->bindselectvalue, $this->ismultiple, $this->selectclass, $ This->defaultselectvalue);

return $data;
}

/**


* Get HTML


* @return Type


*/


Public Function gethtml () {


return $this->genhtml ();


}





/**


* Set up a hierarchical field


* Table Type


* @return String


*/


Public Function Getitemname () {


$html = ' <tr> ';


foreach ($this->datakey as $v) {


if ($this->formatparam = = $v)


$str = ' {$strSep} ';


Else


$str = ';





$html. = ' <td> '. $str. ' {$ '. $v. '}</td> ';


}


$html. = ' </tr> ';


return $html;


}





/**


* Get the table column name


* @return String


*/


Public Function Gettablehead () {


$html = ' <tr> ';


foreach ($this->tablehead as $v)


$html. = ' <th> '. $v. ' </th> ';





$html. = ' </tr> ';


return $html;


}

/**


* Get the form of a tree


* @return String


*/


Public Function gettable () {


$this->stritem = $this->getitemname ();


$strRe = ' <table class= '. $this->tableclass. ' " > ';


$strRe. = ' <thead> ' $this->gettablehead (). ' </thead><tbody> ';


$strRe. = $this->genhtml ();


$strRe. = ' </tbody></table> ';


return $strRe;


}

/**


* Gets the tree in the form of a dropdown box


* @param type $strName


* @param array $arrValue


* @param type $blmMulti


* @param type $strExt


* @param type $arrFirst


* @return String


*/


Public Function getselect ($strName = ' tree ', $arrValue = Array (), $blmMulti = false, $strExt = ', $arrFirst = null) {


!is_array ($arrValue) && $arrValue = Array ($arrValue);


foreach ($this->arridall as $strTemp => $arrTemp) {


$this->arridall[$strTemp] [' selected '] = ';





if (In_array ($arrTemp [' id '], $arrValue)) {


$this->arridall[$strTemp] [' selected '] = ' selected= ' selected ';


}


}


$this->stritem = ' <option value=\ ' {$ '. $this->optionvalue. '} \ ' {$selected} title=\ ' {$ '. $this->formatparam. '} \ >{$strSep}{$ '. $this->formatparam. '} </option> ';


$strRe = ' <select id= ' id_ '. $strName. ' "Name=". $strName. ($blmMulti? '[]' : '') . '"';


$strRe. = ($blmMulti? ' multiple= ' multiple "':". (Empty ($STREXT)? '' : ' ' . $STREXT). ' > ';





if (Is_array ($arrFirst) && count ($arrFirst) = = 2) {


$strRe. = ' <option value= '. $arrFirst [0]. ' > '. $arrFirst [1]. ' </option> ';


}





$strRe. = $this->gethtml (). ' </select> ';


return $strRe;


}





/**


* Data Processing


* @param type $arrData


* @return Type


*/


Private Function Helpforgetrelation ($arrData) {


$arrRe = Array ();


foreach ($arrData as $strTemp => $arrTemp) {


$arrRe [$strTemp] = $arrTemp;


if (Isset ($this->arridrelation[$strTemp])) {


$arrRe [$strTemp] = $this->arridrelation[$strTemp];


}


if (count ($arrRe [$strTemp]) > 0) {


$arrRe [$strTemp] = $this->helpforgetrelation ($arrRe [$strTemp]);


} else {


Array_push ($this->arridleaf, $strTemp);


}


}


return $arrRe;


}





/**


* Data Processing


* @param type $arrData


* @return Type


*/


Private Function Helpforgetchildren ($arrData) {


$arrRe = Array_keys ($arrData);


foreach ($arrData as $arrTemp) {


$arrRe = Array_merge ($arrRe, $this->helpforgetchildren ($arrTemp));


}


return $arrRe;


}

/**


* Data Processing


* @param type $str


* @return Type


*/


Private Function Helpforgetbackpath ($STR) {


$arrRe = Array ();


$intTemp = $this->arridall[$str] [$this->pid];


if ($intTemp > 0) {


$intTemp = ' _ '. $intTemp;


Array_push ($arrRe, $intTemp);


$arrRe = Array_merge ($arrRe, $this->helpforgetbackpath ($intTemp));


}


return $arrRe;


}





/**


* Data Processing


*/


Private Function ProcessData () {


$count = count ($this->arrall);


foreach ($this->arrall as $arrTemp) {


$strTemp = ' _ '. $arrTemp [' id '];


$this->arridall[$strTemp] = $arrTemp;


if ($arrTemp [$this->pid] > 0 && $count > 1) {


$strTemp _ = ' _ '. $arrTemp [$this->pid];


!isset ($this->arridrelation[$strTemp _]) && $this->arridrelation[$strTemp _] = Array ();


$this->arridrelation[$strTemp _][$strTemp] = array ();


!isset ($this->arridson[$strTemp _]) && $this->arridson[$strTemp _] = Array ();


Array_push ($this->arridson[$strTemp _], $strTemp);


} else {


!isset ($this->arridrelation[$strTemp]) && $this->arridrelation[$strTemp] = array ();


Array_push ($this->arridroot, $strTemp);


}


}





$this->arridrelation = $this->helpforgetrelation ($this->arridrelation);


$this->arridleaf = Array_unique ($this->arridleaf);


foreach ($this->arridrelation as $strTemp => $arrTemp) {


$this->arridchildren[$strTemp] = $this->helpforgetchildren ($arrTemp);


In_array ($strTemp, $this->arridroot) && $this->arridrelationsimple[$strTemp] = $arrTemp;


}


$arrTemp = Array_keys ($this->arridall);


foreach ($arrTemp as $strTemp) {


$this->arridbackpath[$strTemp] = $this->helpforgetbackpath ($strTemp);


}


}





/**


* Data Processing


* @param type $intLen


* @return String


*/


Private Function Genseparator ($intLen) {


$strRe = ';


$i = 0;


while ($i < $intLen) {


$strRe. = ". ($i + 1 = $intLen)? ' ├ ': ' │ ';


$i + +;


}





!empty ($strRe) && $strRe. = '-';


return $strRe;


}





/**


* Data Processing


* @param type $arrRelation


* @param type $intSep


* @return Type


*/


Private Function genhtml ($arrRelation = null, $INTSEP = 0) {


$strRe = ';


Null = = $arrRelation && $arrRelation = $this->arridrelationsimple;


foreach ($arrRelation as $strKey => $arrTemp) {


if (count ($this->arridall[$strKey]) > 0) {


if (!empty ($this->formattime) && count ($this->formattime) > 0) {


foreach ($this->formattime as $formatTime) {


if ($this->arridall[$strKey] [$formatTime] > 0) {


$this->arridall[$strKey] [$formatTime] = date (' y-m-d h:i:s ', $this->arridall[$strKey] [$formatTime]);


}


}


}





$strSep = $this->genseparator ($INTSEP);


Extract ($this->arridall[$strKey]);


Eval (' $strRe. = '. $this->stritem. '";');


Count ($arrTemp) > 0 && $strRe. = $this->genhtml ($arrTemp, ($intSep + 1));


}


}


return $strRe;


}


}


?>


tree.php

Copy Code code as follows:

<?php if (!empty ($data)):?>
<?php Echo $data; ?>
<?php Else:?>
<TR><TD colspan= "4" class= "Empty" ><span class= "Empty" > No data found. </span></td></tr >
<?php endif;?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.