1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rudolf\Modules\Appearance\Menu\Item; |
4
|
|
|
|
5
|
|
|
use Rudolf\Component\Html\Text; |
6
|
|
|
use Rudolf\Framework\Model\AdminModel; |
7
|
|
|
|
8
|
|
|
class ItemEditModel extends AdminModel |
9
|
|
|
{ |
10
|
|
|
public function getInfo($id) |
11
|
|
|
{ |
12
|
|
|
$stmt = $this->pdo->prepare("SELECT * FROM {$this->prefix}menu WHERE id=?"); |
13
|
|
|
$stmt->execute([$id]); |
14
|
|
|
$value = $stmt->fetch(\PDO::FETCH_ASSOC); |
15
|
|
|
|
16
|
|
|
return new MenuItem([ |
17
|
|
|
'id' => $value['id'], |
18
|
|
|
'parent_id' => $value['parent_id'], |
19
|
|
|
'title' => $value['title'], |
20
|
|
|
'slug' => $value['slug'], |
21
|
|
|
'caption' => $value['caption'], |
22
|
|
|
'menu_type' => $value['menu_type'], |
23
|
|
|
'item_type' => $value['item_type'], |
24
|
|
|
'position' => $value['position'], |
25
|
|
|
]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function edit($id, $p) |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$stmt = $this->pdo->prepare("UPDATE {$this->prefix}menu SET |
31
|
|
|
parent_id = :parent_id, title = :title, slug = :slug, caption = :caption, menu_type = :menu_type, |
32
|
|
|
item_type = :item_type, position = :position WHERE id = :id"); |
33
|
|
|
$stmt->bindValue(':parent_id', $p['parent_id'], \PDO::PARAM_INT); |
34
|
|
|
$stmt->bindValue(':title', $p['title']); |
35
|
|
|
$stmt->bindValue(':slug', !empty($p['slug']) ? $p['slug'] : Text::sluger($p['title'])); |
36
|
|
|
$stmt->bindValue(':caption', $p['caption']); |
37
|
|
|
$stmt->bindValue(':menu_type', $p['menu_type']); |
38
|
|
|
$stmt->bindValue(':item_type', $p['item_type']); |
39
|
|
|
$stmt->bindValue(':position', (int) $p['position'], \PDO::PARAM_INT); |
40
|
|
|
$stmt->bindValue(':id', $id, \PDO::PARAM_INT); |
41
|
|
|
|
42
|
|
|
return $stmt->execute(); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.