Skip to content

Commit

Permalink
🐛 #118 correção validação PK Existe ou não
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Sep 28, 2022
1 parent c0f1080 commit 4015bd7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion controllers/CreateControllers.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,29 @@ private function addSelectAll()
$this->addLine(ESP.'}');
}
//--------------------------------------------------------------------------------------
private function addSave()
private function addValidatePkNotExist()
{
$columunPK = strtoupper($this->listColumnsName[0]);
$this->addLine();
$this->addLine(ESP.'private function validatePkNotExist( $id )');
$this->addLine(ESP.'{');
$this->addLine(ESP.ESP.'$where=array(\''.$columunPK.'\'=>$id);');
$this->addLine(ESP.ESP.'$qtd = $this->selectCount($where);');
$this->addLine(ESP.ESP.'if($qtd >= 1){');
$this->addLine(ESP.ESP.ESP.'throw new DomainException(Message::GENERIC_ID_NOT_EXIST);');
$this->addLine(ESP.ESP.'}');
$this->addLine(ESP.'}');
}
//--------------------------------------------------------------------------------------
private function addSave()
{
$columunPK = ucfirst(strtolower($this->listColumnsName[0]));
$this->addLine();
$this->addLine(ESP.'public function save( '.$this->tableRefVO.' $objVo )');
$this->addLine(ESP.'{');
$this->addLine(ESP.ESP.'$result = null;');
$this->addLine(ESP.ESP.'if( $objVo->get'.$columunPK.'() ) {');
$this->addLine(ESP.ESP.'$this->validatePkNotExist( $id );');
$this->addLine(ESP.ESP.ESP.'$result = $this->dao->update( $objVo );');
$this->addLine(ESP.ESP.'} else {');
$this->addLine(ESP.ESP.ESP.'$result = $this->dao->insert( $objVo );');
Expand All @@ -155,6 +170,7 @@ private function addDelete()
$this->addLine();
$this->addLine(ESP.'public function delete( $id )');
$this->addLine(ESP.'{');
$this->addLine(ESP.ESP.'$this->validatePkNotExist( $id );');
$this->addLine(ESP.ESP.'$result = $this->dao->delete( $id );');
$this->addLine(ESP.ESP.'return $result;');
$this->addLine(ESP.'}');
Expand Down Expand Up @@ -199,6 +215,7 @@ public function show($print = false)
$this->addSelectAll();

if( $this->getTableType()==TableInfo::TB_TYPE_TABLE){
$this->addValidatePkNotExist();
$this->addSave();
$this->addDelete();
}
Expand Down

0 comments on commit 4015bd7

Please sign in to comment.