<?php
/**
 * Copy Right IJH.CC
 * Each engineer has a duty to keep the code elegant
 * Author @shzhrui<Anhuike@gmail.com>
 * $Id: widget.php 9343 2015-03-24 07:07:00Z youyi $
 */

class Widget_Data extends Model
{

    public function index(&$params)
    {
        
    }




    public function attr(&$params)
    {
        $params['tpl'] = $params['tpl'] ? $params['tpl'] : ($params['type']=='filter' ? 'attr-filter.html' : 'attr-form.html');
        $data['value'] = array();
        if($params['value']){
            if(!is_array($params['value'])){
                $data['value'] = explode(',', $params['value']);
            }
            $data['value'] = $params['value'];
        }
        $data['attrs'] = K::M('data/attr')->attrs_by_from($params['from']);
        return $data;           
    }

    public function ttl(&$params)
    {
        $params['tpl'] = 'widget:default/option.html';
        $data['options'] = K::M('data/data')->ttl();
        $data['value'] = $params['value'] ? $params['value'] : '86400';
        return $data;    
        
    }

    
    public function mapmarker(&$params)
    {
        $params['tpl'] = 'mapmarker.html';
        //117.332856,31.898782
        $data['lng'] = $params['lng'];
        $data['lat'] = $params['lat'];
		$data['city_name'] = K::$system->request['city']['city_name'];
        return $data;
    }

    public function staff(&$params)
    {
        if(!$params['tpl']){
            if(!in_array($params['type'], array('label', 'checkbox', 'radio', 'option'))){
                $params['type'] = 'option';
            }
            $params['tpl'] = 'widget:default/'.$params['type'].'.html';
        }

        $data['options'] = K::M('data/data')->staff_from();
        $data['value'] = $params['value'] ? $params['value'] : '';
        return $data;            
    }

    public function bank(&$params)
    {
        if(!$params['tpl']){
            if(!in_array($params['type'], array('label', 'checkbox', 'radio', 'option'))){
                $params['type'] = 'option';
            }
            $params['tpl'] = 'widget:default/'.$params['type'].'.html';
        }
        $bank_list = K::M('data/data')->bank_list();
        $data['options'] = array_combine($bank_list, $bank_list);
        $data['value'] = $params['value'] ? $params['value'] : '';
        return $data;   
    }

}