Completed
Push — master ( d015d4...c50906 )
by Mikołaj
02:42
created

EditModel   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 37
rs 10
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInfo() 0 17 1
A edit() 0 16 1
1
<?php
2
3
namespace Rudolf\Modules\Appearance\Menu;
4
5
use Rudolf\Framework\Model\AdminModel;
6
7
class EditModel extends AdminModel
8
{
9
    public function getInfo($id)
10
    {
11
        $stmt = $this->pdo->prepare("SELECT * FROM {$this->prefix}menu WHERE id=?");
12
        $stmt->execute([$id]);
13
        $value = $stmt->fetch(\PDO::FETCH_ASSOC);
14
15
        return new MenuItem([
16
            'id' => $value['id'],
17
            'parent_id' => $value['parent_id'],
18
            'title' => $value['title'],
19
            'slug' => $value['slug'],
20
            'caption' => $value['caption'],
21
            'menu_type' => $value['menu_type'],
22
            'item_type' => $value['item_type'],
23
            'position' => $value['position'],
24
        ]);
25
    }
26
27
    public function edit($id, $p)
28
    {
29
        $stmt = $this->pdo->prepare("UPDATE {$this->prefix}menu SET
30
            parent_id = :parent_id, title = :title, slug = :slug, caption = :caption, menu_type = :menu_type,
31
            item_type = :item_type, position = :position WHERE id = :id");
32
        $stmt->bindValue(':parent_id', $p['parent_id'], \PDO::PARAM_INT);
33
        $stmt->bindValue(':title', $p['title']);
34
        $stmt->bindValue(':slug', $p['slug']);
35
        $stmt->bindValue(':caption', $p['caption']);
36
        $stmt->bindValue(':menu_type', $p['menu_type']);
37
        $stmt->bindValue(':item_type', $p['item_type']);
38
        $stmt->bindValue(':position', (int) $p['position'], \PDO::PARAM_INT);
39
        $stmt->bindValue(':id', $id, \PDO::PARAM_INT);
40
41
        return $stmt->execute();
42
    }
43
}
44