Conditions | 8 |
Paths | 11 |
Total Lines | 39 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
45 | public function save(): bool |
||
46 | { |
||
47 | if (!$this->required()) { |
||
48 | $this->error = "Faltam campos obrigatórios!"; |
||
49 | return false; |
||
50 | } |
||
51 | |||
52 | /** Gender Update */ |
||
53 | if (!empty($this->id)) { |
||
54 | $genderId = $this->id; |
||
55 | |||
56 | if ($this->find("name = :e AND id != :i", "e={$this->name}&i={$genderId}", "id")->fetch()) { |
||
57 | $this->error = "O sexo informado já está cadastrado"; |
||
58 | return false; |
||
59 | } |
||
60 | |||
61 | $this->update($this->safe(), "id = :id", "id={$genderId}"); |
||
62 | if ($this->fail()) { |
||
63 | $this->error = "Erro ao atualizar, verifique os dados"; |
||
64 | return false; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | /** Gender Create */ |
||
69 | if (empty($this->id)) { |
||
70 | if ($this->findByName($this->name, 'id')) { |
||
71 | $this->error = "O sexo informado já está cadastrado"; |
||
72 | return false; |
||
73 | } |
||
74 | |||
75 | $genderId = $this->create($this->safe()); |
||
76 | if ($this->fail()) { |
||
77 | $this->error = "Erro ao cadastrar, verifique os dados"; |
||
78 | return false; |
||
79 | } |
||
80 | } |
||
81 | |||
82 | $this->data = ($this->findById($genderId))->data(); |
||
83 | return true; |
||
84 | } |
||
86 |