<?php
/**
 * 成长值相关控制类
 *
 * @author sun
 */
class GrowthExpControll {
    /**
     * 主数据库
     */
    private $db;

    /**
     * 从数据库
     */
    private $dbback;

    /**
     * 缓存
     */
    private $mc;
    
    /**
     * 表名
     * @var string
     */
    private $table;
    
    /**
     * 表名字段数据
     * @var array
     */
    private static $fields = array('id','type','alias','name','is_display');
    
    public function __construct() {
        $container = Container::getInstance();
        $this->db = $container->get('db');
        $this->dbback = $container->get('dbback');
        $this->table = 'growth_exp_controll_way';
    }
    
    /**
     * 初始化数据
     * @param array $arrFields
     * @return boolean
     */
    public function initData($arrFields) {
        $sql = SqlCombinHelper::insert_sql($this->table, $arrFields);
        return $this->db->execute($sql);
    }
    
    /**
     * 获取是否显示的所有数据
     * @param int $isDisplay 是否显示
     * @return array
     */
    public function findAllByDisplay($isDisplay = 1) {
        $sql = SqlCombinHelper::select_sql($this->table, self::$fields, 
                "is_display = $isDisplay");
        return $this->dbback->getAll($sql);
    }
    
    /**
     * 获取某个类型的数据
     * @param int $type   类型
     * @param int $isDisplay 是否显示
     * @return array
     */
    public function findOneControllByTypeId($type, $isDisplay = 1) {
        $sql = SqlCombinHelper::select_sql($this->table, self::$fields, 
                "type = {$type} AND is_display = {$isDisplay}");
        return $this->dbback->getRow($sql);
    }
    
    /**
     * 清空
     */
    public function emptyTable() {
        $sql = "TRUNCATE TABLE $this->table";
        $this->db->execute($sql);
    }
}
