Passed
Branch master (293701)
by refat
04:14
created

UserModel::insert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 1
rs 10
1
<?php
2
3
namespace App\Models;
4
5
use System\Model;
6
7
class UserModel extends Model
8
{
9
  protected $table = 'users';
10
11
  public function getTable()
12
  {
13
    return $this->table;
14
  }
15
16
  public function users()
17
  {
18
    return $this->join('
19
    users.id,
20
    users.username,
21
    users.fname,
22
    users.lname,
23
    users.gender,
24
    users.registration,
25
    users.status,
26
    users.img,
27
    address.country,
28
    address.zip,
29
    activity.is_login,
30
    activity.last_login
31
    ', $this->table, [['address', 'id', 'user_id'], ['activity', 'id', 'user_id']])->orderBy('users.registration', 'DESC')->fetchAll();
32
  }
33
34
  public function user($id)
35
  {
36
    $exists = $this->exists($id);
37
38
    if (!$exists) {
39
      return $this->url->notfound();
40
    }
41
42
    return $this->hasOne('
43
    users.id,
44
    users.username,
45
    users.fname,
46
    users.lname,
47
    users.gender,
48
    users.birthday,
49
    users.email,
50
    users.password,
51
    users.img,
52
    users.registration,
53
    users.status,
54
    address.country,
55
    address.state,
56
    address.zip,
57
    address.city,
58
    address.street,
59
    address.house_number,
60
    address.additional,
61
    activity.is_login,
62
    activity.last_login,
63
    activity.last_logout
64
    ', $this->table, [['address', 'id', 'user_id'], ['activity', 'id', 'user_id']], $id)->fetch();
65
  }
66
67
  public function filter($sql, $wheres)
68
  {
69
    return $this->join('
70
    users.id,
71
    users.username,
72
    users.fname,
73
    users.lname,
74
    users.gender,
75
    users.registration,
76
    users.status,
77
    users.img,
78
    address.country,
79
    address.zip,
80
    activity.is_login,
81
    activity.last_login
82
    ', $this->table, [['address', 'id', 'user_id'], ['activity', 'id', 'user_id']])->where($sql, $wheres)->orderBy('users.registration', 'DESC')->fetchAll();
83
  }
84
}
85