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