|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hiqdev\billing\hiapi\plan; |
|
4
|
|
|
|
|
5
|
|
|
use hiapi\components\ConnectionInterface; |
|
6
|
|
|
use hiapi\query\Specification; |
|
7
|
|
|
use hiapi\repositories\BaseRepository; |
|
8
|
|
|
use hiqdev\php\billing\customer\Customer; |
|
9
|
|
|
use hiqdev\php\billing\plan\PlanFactoryInterface; |
|
10
|
|
|
use hiqdev\php\billing\plan\PlanRepositoryInterface; |
|
11
|
|
|
use hiqdev\php\billing\action\ActionInterface; |
|
12
|
|
|
use hiqdev\php\billing\order\OrderInterface; |
|
13
|
|
|
use Yii; |
|
14
|
|
|
use yii\db\Query; |
|
15
|
|
|
|
|
16
|
|
|
class PlanRepository extends BaseRepository implements PlanRepositoryInterface |
|
17
|
|
|
{ |
|
18
|
|
|
public $queryClass = PlanQuery::class; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var PlanFactory |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $factory; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct( |
|
26
|
|
|
ConnectionInterface $db, |
|
27
|
|
|
PlanFactoryInterface $factory, |
|
28
|
|
|
array $config = [] |
|
29
|
|
|
) { |
|
30
|
|
|
parent::__construct($config); |
|
31
|
|
|
|
|
32
|
|
|
$this->db = $db; |
|
33
|
|
|
$this->factory = $factory; |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function create(array $row) |
|
37
|
|
|
{ |
|
38
|
|
|
$row['seller'] = $this->createEntity(Customer::class, $row['seller']); |
|
39
|
|
|
|
|
40
|
|
|
return parent::create($row); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function findByAction(ActionInterface $action) |
|
44
|
|
|
{ |
|
45
|
|
|
$client_id = $action->getCustomer()->getId(); |
|
46
|
|
|
$seller = $action->getCustomer()->getSeller()->getLogin(); |
|
47
|
|
|
$type = $action->getTarget()->getType(); |
|
48
|
|
|
|
|
49
|
|
|
$spec = Yii::createObject(Specification::class) |
|
50
|
|
|
->with(Price::class) |
|
51
|
|
|
->where([ |
|
52
|
|
|
'type-name' => $type, |
|
53
|
|
|
'available_for' => [ |
|
54
|
|
|
'client_id' => $client_id, |
|
55
|
|
|
'seller' => $seller, |
|
56
|
|
|
], |
|
57
|
|
|
]) |
|
58
|
|
|
; |
|
59
|
|
|
|
|
60
|
|
|
return $this->findOne($spec); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function findByOrder(OrderInterface $order) |
|
64
|
|
|
{ |
|
65
|
|
|
return array_map([$this, 'findByAction'], $order->getActions()); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..