EditModel::edit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Modules\Users\One\Admin\Profile;
4
5
use Rudolf\Component\Auth\Auth;
6
use Rudolf\Framework\Model\AdminModel;
7
8
class EditModel extends AdminModel
9
{
10
    public function edit($id, $f)
11
    {
12
        $stmt = $this->pdo->prepare("
13
            UPDATE
14
                {$this->prefix}users
15
            SET
16
                nick = :nick,
17
                first_name = :first_name,
18
                surname = :surname,
19
                email = :email,
20
                active = :active
21
            WHERE
22
                id = :id
23
        ");
24
        $stmt->bindValue(':nick', $f['nick']);
25
        $stmt->bindValue(':first_name', $f['first_name']);
26
        $stmt->bindValue(':surname', $f['surname']);
27
        $stmt->bindValue(':email', $f['email']);
28
        $stmt->bindValue(':active', $f['active'], \PDO::PARAM_STR);
29
        $stmt->bindValue(':id', $id, \PDO::PARAM_INT);
30
31
        return $stmt->execute();
32
    }
33
34
    public function updatePassword($id, $password)
35
    {
36
        $auth = new Auth($this->pdo, $this->prefix);
37
        $hash = $auth->getPasswordHash($password);
38
39
        $stmt = $this->pdo->prepare("UPDATE {$this->prefix}users SET password = :password WHERE id = :id");
40
        $stmt->bindValue(':password', $hash);
41
        $stmt->bindValue('id', $id, \PDO::PARAM_INT);
42
43
        return $stmt->execute();
44
45
    }
46
47
    public function getUserInfoById($id)
48
    {
49
        $stmt = $this->pdo->prepare("SELECT * FROM {$this->prefix}users WHERE id =?");
50
        $stmt->execute([$id]);
51
        return $stmt->fetch(\PDO::FETCH_ASSOC);
52
    }
53
}
54