Total Complexity | 6 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | trait WriteTrait |
||
11 | { |
||
12 | use ModelMapperTrait; |
||
13 | |||
14 | /** @var Model */ |
||
15 | protected $model; |
||
16 | |||
17 | /** |
||
18 | * @param Model $model |
||
19 | * @return bool |
||
20 | */ |
||
21 | public function save(Model $model) |
||
22 | { |
||
23 | $this->model = $model; |
||
24 | |||
25 | return $this->insertOrUpdate(); |
||
26 | } |
||
27 | |||
28 | /** @return bool */ |
||
29 | private function insertOrUpdate() |
||
38 | } |
||
39 | |||
40 | /** @return bool */ |
||
41 | private function insert() |
||
42 | { |
||
43 | $query = new Insert($this); |
||
44 | $success = $query->execute(); |
||
45 | $this->model->setId((int) static::$db->getLastInsertId()); |
||
46 | |||
47 | return $success; |
||
48 | } |
||
49 | |||
50 | /** @return bool */ |
||
51 | public function update() |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Remove o registro do banco |
||
60 | * @param Model $model |
||
61 | * @return bool |
||
62 | */ |
||
63 | public function delete(Model $model) |
||
69 | } |
||
70 | } |
||
71 |