|
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, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hiqdev\billing\hiapi\sale; |
|
12
|
|
|
|
|
13
|
|
|
use hiapi\db\CallExpression; |
|
14
|
|
|
use hiapi\db\HstoreExpression; |
|
15
|
|
|
use hiapi\components\EntityManagerInterface; |
|
16
|
|
|
use hiapi\repositories\BaseRepository; |
|
17
|
|
|
use hiqdev\php\billing\sale\SaleInterface; |
|
18
|
|
|
use hiqdev\php\billing\sale\SaleFactoryInterface; |
|
19
|
|
|
use hiqdev\php\billing\sale\SaleQuery; |
|
20
|
|
|
use hiqdev\php\billing\sale\Sale; |
|
21
|
|
|
|
|
22
|
|
|
class SaleRepository extends BaseRepository |
|
23
|
|
|
{ |
|
24
|
|
|
public $queryClass = SaleQuery::class; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var SaleFactory |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $factory; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct( |
|
32
|
|
|
EntityManagerInterface $em, |
|
33
|
|
|
SaleFactoryInterface $factory, |
|
34
|
|
|
array $config = [] |
|
35
|
|
|
) { |
|
36
|
|
|
parent::__construct($config); |
|
37
|
|
|
|
|
38
|
|
|
$this->em = $em; |
|
|
|
|
|
|
39
|
|
|
$this->factory = $factory; |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function findId(SaleInterface $sale) |
|
43
|
|
|
{ |
|
44
|
|
|
$hstore = new HstoreExpression(array_filter([ |
|
45
|
|
|
'buyer' => $sale->getCustomer()->getLogin(), |
|
46
|
|
|
'buyer_id' => $sale->getCustomer()->getId(), |
|
47
|
|
|
'object_id' => $sale->getTarget()->getId(), |
|
48
|
|
|
'tariff_id' => $sale->getPlan()->getId(), |
|
49
|
|
|
])); |
|
50
|
|
|
$call = new CallExpression('sale_id', [$hstore]); |
|
51
|
|
|
$command = $this->em->getConnection()->createSelect($call); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
return $command->scalar(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.