<?php namespace Tool\Lib;
use Dever;
class User
{
    # 获取后台展示需要的数据
    public function getData($where, $set)
    {
        $type = $set['type'];
        $extend = Dever::load('common', 'manage')->extend();
        $where['uid'] = $extend['data_id'];
        $info = Dever::db('user', 'tool')->select($where, $set);
        $data['head'] = $data['body'] = array();
        $page = Dever::load('common', 'manage')->page('user_tool_manage/user_tool_list');
        $data['field'] = $page->setting('field', $data['head']);
        if ($type == 1 && $info) {
            foreach ($info as $k => $v) {
                $tool_info = Dever::db('info', 'tool')->find($v['tool_id']);
                $body = $tool_info;
                $button = $page->button('data_button', $body);
                if ($button) {
                    $body['button'] = $button;
                }
                $data['body'][] = $body;
            }
        } elseif ($type == 2) {
            $not = array();
            if ($info) {
                foreach ($info as $k => $v) {
                    $not[] = $v['tool_id'];
                }
                if ($not) {
                    $where['id'] = array('not in', $not);
                }
            }
            $data['body'] = Dever::db('info', 'tool')->select($where, $set);
            if ($data['body']) {
                foreach ($data['body'] as $k => $v) {
                    $button = $page->button('data_button', $v);
                    if ($button) {
                        $data['body'][$k]['button'] = $button;
                    }
                }
            }
        }
        
        return $data;
    }

    # 获取类型
    public function getType()
    {
        $data = array();
        $data[] = array
        (
            'id' => '1',
            'name' => '已安装',
        );
        $data[] = array
        (
            'id' => '2',
            'name' => '未安装',
        );

        $result = array();
        $result[] = array
        (
            'id' => 'root',
            'name' => '类型',
            'children' => $data,
        );
        return $result;
    }
}