<?php

namespace app\extra\service\blue;

use app\extra\basic\Service;
use app\model\blue\BlueArticle;
use app\model\blue\BlueCategory;

class ArticleService extends Service
{



    /**
     * 列表
     * @param array $param
     */
    public function getList(array $param = [])
    {
        $this->mode = new BlueArticle();
        return $this->searchVal($param,$this->searchFilter($param))->with(['categoryJoin' => function($query){
            $query->field("id,name");
        }])->paginate([
            "list_rows" => $param['pageSize'],
            "page"      => $param['page']
        ]);
    }



    /**
     * 列表
     * @param array $param
     */
    public function getSchoolList(array $param = [])
    {
        $this->mode = new BlueArticle();
        return $this->searchVal($param,$this->searchFilter($param))->with(['categoryJoin' => function($query){
            $query->field("id,name");
        }])->field("id,title,category,view,zan,author,source,comment,cover")->paginate([
            "list_rows" => $param['pageSize'],
            "page"      => $param['page']
        ]);
    }


    /**
     *
     * @param array $param
     * @return array
     */
    public function searchFilter(array $param = []): array
    {
        $filter = [];
        !empty($param['type']) && $filter[] = ["type", '=', $param['type']];
        !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
        !empty($param['name']) && $filter[] = ["name", 'like', "%{$param['name']}%"];
        return $filter;
    }

}