✏️ 正在编辑: Secretaria.php
路径:
/srv/systems_dir/yuppiecred/application/models/Secretaria.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_Secretaria { private $_id; private $_descricao; private $_orgaoId; /** * @return mixed */ public function getId() { return $this->_id; } /** * @param mixed $id */ public function setId($id): void { $this->_id = $id; } /** * @return mixed */ public function getDescricao() { return $this->_descricao; } /** * @param mixed $descricao */ public function setDescricao($descricao): void { $this->_descricao = $descricao; } /** * @return mixed */ public function getOrgaoId() { return $this->_orgaoId; } /** * @param mixed $orgaoId */ public function setOrgaoId($orgaoId): void { $this->_orgaoId = $orgaoId; } 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_Secretaria(); $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(); } } return $data; } /** * Insere ou altera o registro passado por parâmetro * @param Model_Secretaria $secretaria */ public function salvar(Model_Secretaria $secretaria) { $dbtable = new Model_DbTable_Secretaria(); if( $secretaria->getId() > 0 ){ $dbtable->update($secretaria->_toArray(), ["id = ?" => $secretaria->getId()]); return $secretaria->getId(); } else { return $dbtable->insert($secretaria->_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_Secretaria(); 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 = "descricao ASC", $count = null, $offset = null) { $dbtable = new Model_DbTable_Secretaria(); $select = $dbtable->getAdapter()->select()->from('tb_secretarias', ['id','descricao']) ->joinInner([ 'tb_orgaos' ], 'tb_secretarias.orgao_id = tb_orgaos.id', array( 'orgao' => 'descricao' )) ->where('tb_secretarias.excluido <> 1'); if(!empty($where)){ $select->where('tb_secretarias.descricao LIKE ?', "%".$where['descricao']."%"); } return $dbtable->getAdapter()->fetchAll($select); } public function getSecretariaIdByName($params = null, $order = "descricao ASC", $count = null, $offset = null) { $dbtable = new Model_DbTable_Secretaria(); $select = $dbtable->getAdapter()->select()->from('tb_secretarias', ['id','descricao']) ->joinInner([ 'tb_orgaos' ], 'tb_secretarias.orgao_id = tb_orgaos.id', array( 'orgao' => 'descricao' )); if(!empty($params['descricao'])){ $select->where("tb_secretarias.descricao = ?", $params['descricao']); } if(!empty($params['orgao_id'])){ $select->where("tb_secretarias.orgao_id = ?", $params['orgao_id']); } return $dbtable->getAdapter()->fetchRow($select); } /** * 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_Secretaria(); return $dbtable->fetchRow(["id = ?" => $id]); } }
💾 保存文件
← 返回文件管理器