|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* HIAM module for MRDP database compatibility |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/hiam-mrdp |
|
7
|
|
|
* @package hiam-mrdp |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hiam\mrdp\storage; |
|
13
|
|
|
|
|
14
|
|
|
class ClientQuery extends \yii\db\ActiveQuery |
|
15
|
|
|
{ |
|
16
|
|
|
public function init() |
|
17
|
|
|
{ |
|
18
|
|
|
parent::init(); |
|
19
|
|
|
$this |
|
20
|
|
|
->select([ |
|
21
|
|
|
'c.obj_id AS id', |
|
22
|
|
|
'c.login AS username', |
|
23
|
|
|
'r.login AS seller', |
|
24
|
|
|
'c.seller_id AS seller_id', |
|
25
|
|
|
'y.name AS type', |
|
26
|
|
|
'z.name AS state', |
|
27
|
|
|
'k.first_name AS first_name', |
|
28
|
|
|
'k.last_name AS last_name', |
|
29
|
|
|
'i.value AS allowed_ips', |
|
30
|
|
|
'coalesce(c.email,k.email) AS email', |
|
31
|
|
|
]) |
|
32
|
|
|
->from('client c') |
|
33
|
|
|
->innerJoin('client r', 'r.obj_id=c.seller_id') |
|
34
|
|
|
->innerJoin('ref y', 'y.obj_id=c.type_id') |
|
35
|
|
|
->innerJoin('ref z', "z.obj_id=c.state_id AND z.name IN ('ok')") |
|
36
|
|
|
->leftJoin('contact k', 'k.obj_id=c.obj_id') |
|
37
|
|
|
->leftJoin('value i', "i.obj_id=c.obj_id AND i.prop_id=prop_id('client,access:allowed_ips')") |
|
38
|
|
|
; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function andWhere($condition) |
|
42
|
|
|
{ |
|
43
|
|
|
if (!is_array($condition) || $condition[0]) { |
|
44
|
|
|
return parent::andWhere($condition); |
|
45
|
|
|
} |
|
46
|
|
|
foreach (['id', 'username', 'password', 'email'] as $key) { |
|
47
|
|
|
if (isset($condition[$key])) { |
|
48
|
|
|
$this->{"where$key"}($condition[$key]); |
|
49
|
|
|
unset($condition[$key]); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
if (!empty($condition)) { |
|
53
|
|
|
$this->andWhere($condition); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function whereId($id) |
|
60
|
|
|
{ |
|
61
|
|
|
return parent::andWhere(['c.obj_id' => $id]); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function whereEmail($username) |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->whereUsername($username); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function whereUsername($username) |
|
70
|
|
|
{ |
|
71
|
|
|
$userId = (int) $username; |
|
72
|
|
|
if ($userId > 0) { |
|
73
|
|
|
return $this->whereId($userId); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return parent::andWhere(['or', 'c.login=:username', 'c.email=:username'], [':username' => $username]); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function wherePassword($password) |
|
80
|
|
|
{ |
|
81
|
|
|
return parent::andWhere( |
|
|
|
|
|
|
82
|
|
|
'check_password(:password,c.password) OR check_password(:password,t.value)', |
|
83
|
|
|
[':password' => $password] |
|
84
|
|
|
)->leftJoin('value t', "t.obj_id=c.obj_id AND t.prop_id=prop_id('client,access:tmp_pwd')"); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.