1 | <?php |
||
2 | /** |
||
3 | * API for Billing |
||
4 | * |
||
5 | * @link https://github.com/hiqdev/billing-hiapi |
||
6 | * @package billing-hiapi |
||
7 | * @license BSD-3-Clause |
||
8 | * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/) |
||
9 | */ |
||
10 | |||
11 | namespace hiqdev\billing\hiapi\plan; |
||
12 | |||
13 | use hiqdev\yii\DataMapper\query\FieldInterface; |
||
14 | use yii\db\Expression; |
||
15 | |||
16 | class AvailableForField implements FieldInterface |
||
17 | { |
||
18 | public $name = 'available_for'; |
||
19 | |||
20 | public function canBeSelected() |
||
21 | { |
||
22 | return false; |
||
23 | } |
||
24 | |||
25 | public function isApplicable($key) |
||
26 | { |
||
27 | return strcasecmp($this->name, $key) === 0; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @return string |
||
32 | */ |
||
33 | public function getName() |
||
34 | { |
||
35 | return $this->name; |
||
36 | } |
||
37 | |||
38 | public function buildCondition($key, $value) |
||
39 | { |
||
40 | $params = []; |
||
41 | if ($value['client_id']) { |
||
42 | $params[':available_for_client_id'] = $value['client_id']; |
||
43 | $ids_sql = ' |
||
44 | SELECT tariff_id |
||
45 | FROM client2tariff |
||
46 | WHERE client_id=:available_for_client_id |
||
47 | '; |
||
48 | } else { |
||
49 | $params[':available_for_seller'] = $value['seller']; |
||
50 | $ids_sql = " |
||
51 | SELECT dst_id |
||
52 | FROM tie |
||
53 | WHERE src_id=client_id(:available_for_seller) |
||
54 | AND tag_id=type_id('tariff') |
||
55 | "; |
||
56 | } |
||
57 | |||
58 | return new Expression("zt.obj_id IN ($ids_sql)", $params); |
||
0 ignored issues
–
show
|
|||
59 | } |
||
60 | } |
||
61 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: