✏️ 正在编辑: Cidade.php
路径:
/srv/systems_dir/yuppiecred/application/models/Cidade.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_Cidade { private $_id; private $_nome; private $_uf; private $_parentId; public function getId() { return $this->_id; } public function setId($id) { $this->_id = $id; } public function getNome() { return $this->_nome; } public function setNome($nome) { $this->_nome = $nome; } public function getUf() { return $this->_uf; } public function setUf($uf) { $this->_uf = $uf; } public function getParentId() { return $this->_parentId; } public function setParentId($parentId) { $this->_parentId = $parentId; } public function __construct($options = null) { if(!$options['parent_id']){ unset($options['parent_id']); } 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_Cidade(); $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; } public function excluir($id) { if( $id > 0 ){ $dbtable = new Model_DbTable_Cidade(); return $dbtable->delete("id = " . $id); } return null; } public function salvar(Model_Cidade $cidade) { $dbtable = new Model_DbTable_Cidade(); if( $cidade->getId() > 0 ){ $dbtable->update($cidade->_toArray(), "id = " . $cidade->getId()); return $cidade->getId(); } else { return $dbtable->insert($cidade->_toArray()); } } public function exibir($id) { $dbtable = new Model_DbTable_Cidade(); return $dbtable->fetchRow("id = " . $id); } public function listar($where = null, $order = null, $count = null, $offset = null) { $dbtable = new Model_DbTable_Cidade(); return $dbtable->fetchAll($where, $order, $count, $offset); } public function getPaginatorAdapter(array $fields, $page = null, $limit = null, $order = null, $range = null) { $dbtable = new Model_DbTable_Cidade(); $params = array(); if( !empty($fields['nome']) ){ $params["nome LIKE ?"] = "%" . $fields['nome'] . "%"; } if( !empty($fields['uf']) ){ $params['uf = ? '] = $fields['uf']; } $result = $dbtable->fetchAll($params, $order); if( $page ){ $paginator = Zend_Paginator::factory($result); $paginator->setCurrentPageNumber($page); if( $limit && is_numeric($limit) ){ $paginator->setItemCountPerPage($limit); } if( $range && is_numeric($range) ){ $paginator->setPageRange($range); } return $paginator; } return $result; } public function atualizarCidadesCallcenterBase(Model_Cidade $cidade) { if( $cidade->getParentId()&& $cidade->getParentId() > 0){ $cidadePai = $this->exibir($cidade->getParentId()); $dbtable = new Model_DbTable_CallcenterBase(); if($cidadePai){ $dataUpdate = array( 'cidade' => $cidadePai['nome'], 'uf' => $cidadePai['uf'] ); $update = $dbtable->update($dataUpdate, "cidade ='{$cidade->getNome()}' and uf ='{$cidade->getUf()}'"); return $update; } } } public function hgienizarCidades($nome, $uf) { $nome = trim($nome); $uf = trim($uf); if($nome){ $dbtable = new Model_DbTable_Cidade(); $select = $dbtable->getAdapter()->select()->from('tb_cidades') ->where('nome = ?', $nome) ->where('uf = ?', $uf) ->where('excluido = 0'); $cidade = $dbtable->getAdapter()->fetchRow($select); if(!$cidade){ $data = array( 'nome' => $nome, 'uf' => $uf ); $dbtable->insert($data); }elseif($cidade['parent_id']){ $select = $dbtable->getAdapter()->select()->from('tb_cidades') ->where('id = ?', $cidade['parent_id']) ->where('excluido = 0'); $cidadePai = $dbtable->getAdapter()->fetchRow($select); return $cidadePai; } return array('nome' => $nome, 'uf'=> $uf); } return null; } }
💾 保存文件
← 返回文件管理器