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

namespace Application\Service\DB\Item;

use Interop\Container\ContainerInterface;

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

    /**
     * Notes: 获取所有文档分类
     * User: yinai
     * DateTime: 2022/5/24 16:40
     *
     * @return int
     */
    public function getDocumentList(){
        $whereitemDocument['where'] = 'is_del=0 ';
        $whereitemDocument['columns'] = ['value'=>'id', 'label'=>'document_name', 'document_pid'];
        $whereitemDocument['order'] = ['document_pid', 'itemdocument_order'];
        $itemdocumentData = $this->LocalService()->itemItemdocument->fetchAll($whereitemDocument);
        if (!empty($itemdocumentData)) $itemdocumentDatas = $this->getTreeall($itemdocumentData);
        return $itemdocumentDatas;
    }

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

}