<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Operate
 *
 * @author yzxh24
 */
class Operate
{
    public static $_operations =
        array(
            //'0' => array('label' => '',       'operate' => ''),
            '1' => array('label' => '等于',    'operate' => '='),
            '2' => array('label' => '大于',    'operate' => '>'),
            '3' => array('label' => '小于',    'operate' => '<'),
            '4' => array('label' => '大于等于', 'operate' => '>='),
            '5' => array('label' => '小于等于', 'operate' => '<='),
            '6' => array('label' => '包含',    'operate'  => 'LIKE'),
        );

    public static function int($field, $htmlOptions = array())
    {
        $operates = self::$_operations;
        unset($operates[6]);

        foreach ($operates as $id => $operate)
        {
            $data[$id] = $operate['label'];
        }

        echo CHtml::dropDownList($field.'[operate]', $_GET[$field]['operate'], $data) . CHtml::textField($field.'[value]', $_GET[$field]['value'],$htmlOptions);
    }

    public static function string($field, $htmlOptions = array())
    {
        //$operates[0] = self::$_operations[0];
        $operates[1] = self::$_operations[1];
        $operates[6] = self::$_operations[6];

        foreach ($operates as $id => $operate)
        {
            $data[$id] = $operate['label'];
        }

        echo CHtml::dropDownList($field.'[operate]', $_GET[$field]['operate'], $data) . CHtml::textField($field.'[value]', $_GET[$field]['value'],$htmlOptions);
    }

    public static function in($field, $data)
    {
        echo CHtml::dropDownList($field.'[value][]', $_GET[$field]['value'], $data, array('multiple'=>'multiple','style'=>"height: 60px;"));
    }

    public static function options($filed, $data)
    {
        // 比较猥琐的实现-_-，array_merge()函数会重设数字的键值，所以只能这样实现
        $data = array('' => '') + $data;
        echo CHtml::dropDownList($filed.'[value]', $_GET[$filed]['value'], $data);
        echo CHtml::hiddenField($filed.'[operate]','1');
    }

    public static function date($field)
    {
        $widget = CBaseController::createWidget('zii.widgets.jui.CJuiDatePicker',array(
            'name' => $field.'[value]',
            'language' => 'zh_cn',
            'value' => $_GET[$field]['value'],
            'options' => array(
                'dateFormat' => 'yy-mm-dd',
            ),
        ));
        $widget->run();
    }
}