✏️ 正在编辑: Prospecto.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/models/DbTable/Prospecto.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_DbTable_Prospecto extends Zend_Db_Table_Abstract { protected $_primary = 'id'; protected $_name = 'tb_clientes'; protected static $_viewName = 'vw_clientes'; protected $_dependentTables = array( 'Model_DbTable_Proposta' ); protected $_referenceMap = array( 'Empresa' => array( 'columns' => array( 'empresa_id' ), 'refTableClass' => 'Model_DbTable_Empresa', 'refColumns' => array( 'id' ) ) ); public static function getViewName() { return self::$_viewName; } /** * Verifica se o cpf já está cadastrado * @param string $cpf * @return boolean */ public function existeCpf($cpf) { if( ($dados = parent::fetchRow("excluido<>1 AND cpf = '" . String_Refatorar::formatarCpf($cpf) . "'")) != null ) return $dados; return null; } public function insert(array $data) { $data['tipo_registro'] = 0; //seta o tipo como prospecto //verifica se o cpf está sendo passado if( isset($data['cpf']) && !empty($data['cpf']) ){ //verifica se o cpf já está cadastrado if( $this->existeCpf($data['cpf']) ) return null; } $id = parent::insert($data); //grava inserção no log if( $id > 0 ){ $log = new Model_DbTable_Log(); $log->save($this, $data, 'insert', $id); } return $id; } public function update(array $data, $where) { if( isset($data['cpf']) && !empty($data['cpf']) ){ //verifica se o cpf já existe if( ($dadosCpf = $this->existeCpf($data['cpf'])) != null ){ $dados = $this->fetchRow($where); //se o registro que está tentando alterar é diferente do registro do cpf existente, //não permite a alteração if( $dadosCpf['id'] != $dados['id'] ) return null; } } $result = parent::update($data, $where); //grava alteracao no log if( $result > 0 ){ $log = new Model_DbTable_Log(); $log->save($this, $data, $where, $this->_primary[1]); } return $result; } public function delete($where) { $data = array( 'excluido' => 1 ); $result = parent::update($data, $where); //grava alteracao no log if( $result > 0 ){ $log = new Model_DbTable_Log(); $log->save($this, $data, $where); } return $result; } public function fetchAll($where = null, $order = null, $count = null, $offset = null) { //verifica as permissoes $ns = new Zend_Session_Namespace(); $and = ""; if( !$ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, 'visualizar-clientes-filiais') ){ $and = " AND empresa_id = " . Yuppie_Auth::getIdentity()->empresa_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); } public function fetchRow($where = null, $order = null, $offset = null) { if( ($where instanceof Zend_Db_Table_Select ) ){ $strWhere = "excluido<>1"; foreach ( $where->getPart(Zend_Db_Table_Select::WHERE) as $w ) { $strWhere .= " AND " . $w; } $where->where($strWhere); } elseif( $where != null ){ $where = $where . " AND excluido<>1"; } else { $where = "excluido<>1"; } return parent::fetchRow($where, $order, $offset); } }
💾 保存文件
← 返回文件管理器