<?php
/**
 *
 * @author：llbjj
 * @DateTime：2022/5/6 10:57
 * @Description：
 *
 */

namespace Application\Service\DB\Dictionary;

use Interop\Container\ContainerInterface;

class Document extends \Application\Service\DB\AbstractDb
{
    public function __construct($dbAdapter, ContainerInterface $container)
    {
        $this->tableName = 'yikeen_dictionary_document';
        parent::__construct($dbAdapter, $container);
    }

    /**
     * Notes: 获取所有文档分类
     * User: yinai
     * DateTime: 2022/5/24 16:40
     *
     * @return int
     */
    public function getDocumentList(){
        $whereDocument['where'] = ['is_del' => 0];
        $whereDocument['columns'] = ['value'=>'id', 'label'=>'name', 'pid'];
        $whereDocument['order'] = ['pid', 'document_order'];
        $documentData = $this->LocalService()->dictionaryDocument->fetchAll($whereDocument);
        if (!empty($documentData)) $documentDatas = $this->getTreeall($documentData);
        return $documentDatas;
    }

    /**
     * 无限分类
     * **/
    public function getTreeall($arr,$pid=0,$step=0){
        global $tree;
        foreach($arr as $key=>$val) {
            if($val['pid'] == $pid) {
                $flg = str_repeat("&nbsp;",$step);
                $val['label'] = $flg.$val['label'];
                $tree[] = $val;
                $this->getTreeall($arr , $val['value'] ,$step+1);
            }
        }
        return $tree;
    }
    
}