<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

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

/**
 * Description of upload_log
 *
 * @author Administrator
 */
class upload_log extends MY_Model {
    
    /**
     * 图片删除
     */
    const STATUS_DELPIC = 2;
    /**
     * 冻结房源
     */
    const STATUS_FROZENHOUSE = 3;

    /**
     * 表名
     * @var type 表名
     */
    private $table;

    public function __construct() {
        parent::__construct(0,1,0);
        $this->table = 'upload_log';
    }

    /**
     * 按用户id，时间等查上传记录
     * @param type $uid
     * @param type $startTime
     * @param type $endTime
     * @param type $start
     * @param type $number
     * @return type
     */
    public function findByUidTime($uid, $startTime, $endTime, $start, $number) {
        $this->dbback->select("filename,sort,tbl,rowid, optime, op AS esta")
                ->from($this->table)
                ->where("uid = $uid and sort != 99 and optime >= '$startTime' and optime <= '$endTime'")
                ->order_by("id desc")->limit($number, $start);
        $query = $this->dbback->get();
        return $query->result_array();
    }

    /**
     * 按用户id，时间等查上传记录总数
     * @param type $uid
     * @param type $startTime
     * @param type $endTime
     * @return type
     */
    public function findCountByUidTime($uid, $startTime, $endTime) {
        $startTime = strtotime($startTime);
        $endTime = strtotime($endTime);
        $this->dbback->select("rowid")
                ->from($this->table)
        ->where("uid = $uid and sort != 99 and optime >= '$startTime' and optime <= '$endTime'")
        ;
        return $this->dbback->count_all_results();
    }

    /**
     * 根据状态码返回对应的文字说明
     * @param type $status
     * @return string|boolean
     */
    public static function getStatusText($status) {
        $deal_arr = array(
            upload_log::STATUS_DELPIC => '图片删除',
            upload_log::STATUS_FROZENHOUSE => '冻结房源'
        );
        if (array_key_exists($status, $deal_arr)) {
            return $deal_arr[$status];
        } else {
            return false;
        }
    }

    public static function getTblText($tbl) {
        $array = array('sell' => '出售', 'rent' => '出租');
        if (array_key_exists($tbl, $array)) {
            return $array[$tbl];
        } else {
            return '';
        }
    }

}

?>
