<?php

/**
 * luffy丶大叔 
 * <><><><><><><><><><><><><>有妹子加微信不哦！~<><><><><><><><><><><><><><><><>
 * $Author: luffy丶大叔 
 * $Z 2015-4-8 9:34:24
 * $email luffy00789@126.com
 * $encoding UTF-8
 * $ Copyright (c) 2014-2015, http://www.globex.cn. All Rights Reserved.
 */
class Table_ExceptionLog {
    ######name is not a number, it is freemarker.template.SimpleScalar#######
    protected $_table = null;

    public function __construct()
    {
        $this->_table = new DbTable_ExceptionLog();
    }

    public function getAdapter()
    {
        return $this->_table->getAdapter();
    }

    public static function getInstance()
    {
        return new Table_ExceptionLog();
    }

    /**
     * @param $row
     * @return mixed
     */
    public function add($row)
    {
        return $this->_table->insert($row);
    }
    
    /**
     * @param $value
     * @param string $field
     * @return mixed
     */
    public function delete($value, $field = "el_id")
    {
        $where = $this->_table->getAdapter()->quoteInto("{$field}= ?", $value);
        return $this->_table->delete($where);
    }
    /**
     * @param $row
     * @param $value
     * @param string $field
     * @return mixed
     */
    public function update($row, $value, $field = "el_id")
    {
        $where = $this->_table->getAdapter()->quoteInto("{$field}= ?", $value);
        return $this->_table->update($row, $where);
    }

    /**
     * @param $value
     * @param string $field
     * @param string $colums
     * @return mixed
     */
    public function getByField($value, $field = 'el_id', $colums = "*")
    {
        $select = $this->_table->getAdapter()->select();
        $table = $this->_table->info('name');
        $select->from($table, $colums);
        $select->where("{$field} = ?", $value);
        return $this->_table->getAdapter()->fetchRow($select);
    }
    
    /**
     * @param $value
     * @param string $field
     * @param string $colums
     * @return mixed
     */
    public function getLogByEid($e_id)
    {
        $select = $this->_table->getAdapter()->select();
        $table = $this->_table->info('name');
        $select->from($table, '*');
        $select->where("e_id = ?", $e_id);   
        $select->joinLeft('user as u', 'u.user_id='.$table.".user_id",array('user_name'));        
        return $this->_table->getAdapter()->fetchAll($select);
    }
    
    
}
