✏️ 正在编辑: GrupoComissao.php
路径:
/srv/systems_dir/yuppiecred-bkp/application/models/GrupoComissao.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_GrupoComissao { private $_id; private $_descricao; public function getId() { return $this->_id; } public function setId($id) { $this->_id = $id; } public function getDescricao() { return $this->_descricao; } public function setDescricao($descricao) { $this->_descricao = $descricao; } public function __construct($options = null) { if( is_array($options) ){ $this->setOptions($options); } } public function setOptions(array $options) { $methods = get_class_methods($this); foreach ( $options as $key => $value ) { $explode = explode("_", $key); $methodName = ''; foreach ( $explode as $v ) { $methodName .= ucfirst($v); } $key = $methodName != '' ? $methodName : $key; $method = 'set' . ucfirst($key); if( in_array($method, $methods) ){ $this->$method($value); } } return $this; } public function _toArray() { $dbtable = new Model_DbTable_Tipos(); $info = $dbtable->info(); $methods = get_class_methods($this); $data = array( ); foreach ( $info['cols'] as $key ) { $col = $key; $explode = explode("_", $key); $methodName = ''; foreach ( $explode as $v ) { $methodName .= ucfirst($v); } $key = $methodName != '' ? $methodName : $key; $method = 'get' . ucfirst($key); if( in_array($method, $methods) ){ $data[$col] = $this->$method(); } } $data['tipo'] = "GRUPO_COMISSAO"; return $data; } /** * Insere ou altera o registro passado por parâmetro * @param Model_GrupoComissao $grupoComissao */ public function salvar(Model_GrupoComissao $grupoComissao) { $dbtable = new Model_DbTable_Tipos(); if( $grupoComissao->getId() > 0 ){ $dbtable->update($grupoComissao->_toArray(), "id = " . $grupoComissao->getId()); return $grupoComissao->getId(); } else { return $dbtable->insert($grupoComissao->_toArray()); } } /** * Exclui o registro passado por parâmetro * @param int $id * @return int The number of rows deleted */ public function excluir($id) { if( $id > 0 ){ $dbtable = new Model_DbTable_Tipos(); return $dbtable->delete("id = " . $id); } return null; } /** * Retorna uma lista * @param string $where * @param string $order * @param int $count * @param int $offset * @return array */ public function listar($where = null, $order = null, $count = null, $offset = null) { $where = $where != null ? "tipo = 'GRUPO_COMISSAO' AND " . $where : "tipo = 'GRUPO_COMISSAO'"; $dbtable = new Model_DbTable_Tipos(); return $dbtable->fetchAll($where, $order, $count, $offset); } /** * Retorna um fetchRow do item passado por parâmetro * @param int $id * @return Zend_Db_Table_Row_Abstract | null */ public function exibir($id) { $dbtable = new Model_DbTable_Tipos(); return $dbtable->fetchRow("id = " . $id); } public function getPaginatorAdapter($fields, $order = null) { $params = array( "tipo = 'GRUPO_COMISSAO'" ); if( isset($fields['nome']) && !empty($fields['nome']) ){ $params[] = "descricao LIKE '%" . $fields['nome'] . "%'"; } $where = null; if( count($params) > 0 ){ $where = implode(" AND ", $params); } $dbtable = new Model_DbTable_Tipos(); $select = $dbtable->select(); if( $where != null ) $select->where($where); if( $order != null ) $select->order($order); return new Zend_Paginator_Adapter_DbTableSelect($select); } public static function getIdGrupo($nome) { $dbtable = new Model_DbTable_Tipos(); $grupo = $dbtable->fetchRow("tipo = 'GRUPO_COMISSAO' AND descricao = '{$nome}'"); return $grupo ? $grupo->id : null; } public static function grupoComissaoPorNome($nome) { $dbtable = new Model_DbTable_Tipos(); $dados = $dbtable->selectGrupoComissaoPorNome($nome); if ( $dados != null ) { return (int)$dados['id']; } } }
💾 保存文件
← 返回文件管理器