✏️ 正在编辑: GerenteRota.php
路径:
/srv/systems_dir/yuppiecred/application/models/DbTable/GerenteRota.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Modules\Core\Exception\CPFJaCadastradoException; class Model_DbTable_GerenteRota extends Core_DbTable { protected $_primary = 'id'; protected $_name = 'tb_gerente_rota'; protected static $_viewName = 'vw_gerente_rota'; protected $_dependentTables = array( 'Model_DbTable_Corretor' ); protected $_referenceMap = array( 'Gerente' => array( 'columns' => array( 'gerente_id' ), 'refTableClass' => 'Model_DbTable_Gerente', 'refColumns' => array( 'id' ) ), 'BancoFebraban' => array( 'columns' => array( 'banco' ), 'refTableClass' => 'Model_DbTable_BancoFebraban', 'refColumns' => array( 'codigo' ) ) ); public static function getViewName() { return self::$_viewName; } public function insert(array $data) { //verifica se o cpf está sendo passado if (!empty($data['cpf']) && $this->existeCpf($data['cpf'])) { throw new CPFJaCadastradoException(); } if (isset($data['senha'])) { if ((empty($data['senha']) || $data['senha'] == null )) { unset($data['senha']); } else { $data['senha'] = md5($data['senha']); } } $id = parent::insert($data); //grava inserção no log if ($id > 0) { $data['id'] = $id; (new Model_DbTable_Log())->save($this, [], $data); } return $id; } public function existeCpf($cpf): bool { if ($this->fetchRow("cpf = '" . String_Refatorar::formatarCpf($cpf) . "'") != null) { return true; } return false; } public function update(array $data, $where, $registerLog = true) { if (!empty($data['cpf']) && $this->existeCpf($data['cpf'])) { $dados = $this->fetchRow($where); $dadosCpf = $this->fetchRow("cpf = '" . String_Refatorar::formatarCpf($data['cpf']) . "'"); //se o registro que está tentando alterar é diferente do registro do cpf existente, //não permite a alteração if ($dadosCpf['id'] != $dados['id']) { throw new Core_Exception('CPF/CNPJ já está sendo utilizado'); } } if (isset($data['senha'])) { if ((empty($data['senha']) || $data['senha'] == null )) { unset($data['senha']); } else { $data['senha'] = md5($data['senha']); } } return parent::update($data, $where); } public function fetchAll($where = null, $order = null, $count = null, $offset = null) { $and = ""; if (Yuppie_Auth::getIdentity()->grupo == "Gerente Regional") { $and .= " AND gerente_id = " . Yuppie_Auth::getIdentity()->id; } if (($where instanceof Zend_Db_Table_Select )) { $strWhere = "excluido<>1 " . $and; foreach ($where->getPart(Zend_Db_Table_Select::WHERE) as $w) { $strWhere .= " AND " . $w; } $where->where($strWhere . $and); } elseif ($where != null) { $where = $where . " AND excluido<>1 " . $and; } else { $where = "excluido<>1 " . $and; } return parent::fetchAll($where, $order, $count, $offset); } }
💾 保存文件
← 返回文件管理器