zoukankan      html  css  js  c++  java
  • 无限极分类算法 thinkphp

    <?php
    /*
    * 本类实现的是无限级递归分类的管理
    */
    class InfiniteLevel{

    public $id_str="";
    public function add_top($modelName,$data,$id=0){//添加顶级分类
    $model = D($modelName);
    $data['parent_id_str'] = ',0,';
    $data['depth'] = '0';
    $data['create_time'] = time();
    if ($id>0) {
    $model->where('id="'.$id.'"')->save($data);
    }else{
    $id = $model->add($data);
    }
    return $id;
    }
    public function add_child($modelName,$data,$parentId=0){
    $model = D($modelName);
    if ($parentId>0) {
    $tempModel = $model->where(array('id'=>$parentId))->find();
    $depth = $tempModel['depth']+1;
    $parent_id_str = $tempModel['parent_id_str'].$parentId.',';
    $data['parent_id_str'] = $parent_id_str;
    $data['depth'] = $depth;
    $data['create_time'] = time();
    $id = $model->add($data);
    return $id;
    }
    }
    public function move(){}  //项目暂时用不上,以后再写把
    public function delete(){} //项目暂时用不上,以后再写把

    //1
    public function list_model($modelName){
    $model = D($modelName);
    $list = $this->_all_child($modelName);
    return urldecode(urldecode(json_encode($list)));
    }
    //2
    private function _all_child($modelName,$parentId=0,$depth=0,$data=NULL){
    $model = D($modelName);
    $data['parent_id'] = $parentId;
    $data['depth'] = $depth;
    $data['is_deleted'] =0;
    $childArr = $model->field('id,name,parent_id,parent_id_str,depth')->where($data)->select();

    $maxNum = count($childArr);
    if ($maxNum>0) {
    foreach ($childArr as $key => $value) {
    $value['name'] = urlencode($value['name']);
    $item = $this->_all_child($modelName,$value['id'],($value['depth']+1),$childArr);
    if ($item) {
    foreach ($item as $k => $v) {
    $v['name'] = urlencode($v['name']);
    $item[$k] = $v;
    }
    $value['child'] = $item;
    $childArr[$key] = $value;
    }
    }

    return $childArr;
    }else{
    return;
    }
    }

    //
    public function _self_child($modelName,$parentId=0,$num=0){

    $model = D($modelName);
    $data['parent_id'] = $parentId;
    $data['is_deleted'] =0;
    $childArr = $model->field('id,name,parent_id,parent_id_str,depth')->where($data)->select();
    if($num==0){
    $id_str=$parentId.",";
    }else{
    $id_str="";
    }

    $maxNum = count($childArr);
    if ($maxNum>0) {

    foreach ($childArr as $key => $value) {
    $id_str.=$value['id'].",";
    $item = $this->_self_child($modelName,$value['id'],$num=1);
    $id_str.=$item;

    }
    return $id_str;
    }else{
    return;
    }
    }
    }

  • 相关阅读:
    代码注入——c++代码注入
    Windows 用来定位 DLL 的搜索路径
    LoadLibraryA与GetProcAddress介绍
    DLL 函数导出的规则和方法
    C++ dll的隐式与显式调用
    C++ main函数的参数
    DLL注入之修改PE静态注入
    用户权限设置和进程权限提升
    DLL注入之windows消息钩取
    c++回调函数
  • 原文地址:https://www.cnblogs.com/liuwenbohhh/p/4860370.html
Copyright © 2011-2022 走看看