49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
<?php
 | 
						|
 | 
						|
namespace app\repository;
 | 
						|
 | 
						|
use app\traits\cms\ArticleTrait;
 | 
						|
use app\traits\cms\MenuTrait;
 | 
						|
use app\traits\CmsCategoryTrait;
 | 
						|
use think\db\exception\DataNotFoundException;
 | 
						|
use think\db\exception\DbException;
 | 
						|
use think\db\exception\ModelNotFoundException;
 | 
						|
use think\Model;
 | 
						|
use app\service\Repository;
 | 
						|
 | 
						|
/**
 | 
						|
 * CMS 基础功能仓储
 | 
						|
 *
 | 
						|
 * Class CmsRepository
 | 
						|
 * @package app\repository
 | 
						|
 * @method self getInstance(Model $model = null) static
 | 
						|
 */
 | 
						|
class CmsRepository extends Repository
 | 
						|
{
 | 
						|
    use CmsCategoryTrait;
 | 
						|
    use MenuTrait;
 | 
						|
    use ArticleTrait;
 | 
						|
 | 
						|
    /**
 | 
						|
     * xmSelect下拉列表格式处理
 | 
						|
     * 如 [['title' => 'aa', 'value' => 1, 'selected' => true, 'prefix' => '    ']]
 | 
						|
     *
 | 
						|
     * @param  array  $data  待处理的数据
 | 
						|
     * @param  string  $symbol  分隔符号 默认  
 | 
						|
     * @param  int  $repeatNum  重复次数 默认4
 | 
						|
     * @return array
 | 
						|
     */
 | 
						|
    public function handleSelectedList(array $data, string $symbol = ' ', int $repeatNum = 4): array
 | 
						|
    {
 | 
						|
        $list = [];
 | 
						|
        foreach ($data as $item) {
 | 
						|
            $level    = $item['level'] ?? 0;
 | 
						|
            $arr = $item;
 | 
						|
            $arr['children'] = $arr['children'] ?? [];
 | 
						|
            $arr['prefix'] = str_repeat($symbol, $level * $repeatNum);
 | 
						|
            $list[] = $arr;
 | 
						|
        }
 | 
						|
 | 
						|
        return $list;
 | 
						|
    }
 | 
						|
} |