|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Radowoj\Yaah; |
|
4
|
|
|
|
|
5
|
|
|
use Radowoj\Yaah\Constants\SellFormOpts; |
|
6
|
|
|
|
|
7
|
|
|
class Helper |
|
8
|
|
|
{ |
|
9
|
|
|
protected $client = null; |
|
10
|
|
|
|
|
11
|
|
|
public function __construct(Client $client) |
|
12
|
|
|
{ |
|
13
|
|
|
$this->client = $client; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get simplified fields list for given category |
|
18
|
|
|
* @param integer $idCategory id of category in question |
|
19
|
|
|
* @return array of fields metadata |
|
20
|
|
|
*/ |
|
21
|
|
|
public function getFieldsByCategory($idCategory) |
|
22
|
|
|
{ |
|
23
|
|
|
$data = $this->client->getSellFormFieldsForCategory(['categoryId' => $idCategory]); |
|
|
|
|
|
|
24
|
|
|
$items = $data->sellFormFieldsForCategory->sellFormFieldsList->item; |
|
25
|
|
|
|
|
26
|
|
|
return array_map(function ($item) { |
|
27
|
|
|
return [ |
|
28
|
|
|
'fid' => $item->sellFormId, |
|
29
|
|
|
'title' => $item->sellFormTitle, |
|
30
|
|
|
'required' => ($item->sellFormOpt == SellFormOpts::SELL_FORM_OPT_REQUIRED), |
|
31
|
|
|
'options' => $item->sellFormOptsValues, |
|
32
|
|
|
'optionsDesc' => $item->sellFormDesc, |
|
33
|
|
|
]; |
|
34
|
|
|
}, $items); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Create new auction |
|
39
|
|
|
* |
|
40
|
|
|
* @throws Exception on failure |
|
41
|
|
|
* |
|
42
|
|
|
* @param Auction $auction Auction to create |
|
43
|
|
|
* @param integer $localId - local item id, required by WebAPI |
|
44
|
|
|
* @return integer id of created auction |
|
45
|
|
|
*/ |
|
46
|
|
|
public function newAuction(AuctionInterface $auction, $localId) |
|
47
|
|
|
{ |
|
48
|
|
|
$auctionArray = $auction->toApiRepresentation(); |
|
49
|
|
|
$auctionArray['localId'] = $localId; |
|
50
|
|
|
|
|
51
|
|
|
$resultNewAuction = $this->client->newAuctionExt($auctionArray); |
|
|
|
|
|
|
52
|
|
|
$resultVerify = $this->client->verifyItem(['localId' => $localId]); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
if (!is_object($resultVerify) || !isset($resultVerify->itemId)) { |
|
55
|
|
|
throw new Exception("Auction has not been created: " . print_r($resultVerify, 1)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $resultVerify->itemId; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Finish a single auction |
|
64
|
|
|
* @param integer $auctionId itemId of auction to finish |
|
65
|
|
|
* @param integer $cancelAllBids whether to cancel all bids |
|
66
|
|
|
* @param string $finishCancelReason reason |
|
67
|
|
|
* @return array |
|
68
|
|
|
*/ |
|
69
|
|
|
public function finishAuction($auctionId, $cancelAllBids = 0, $finishCancelReason = '') |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->finishAuctions((array)($auctionId), $cancelAllBids, $finishCancelReason); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Finish a single auction |
|
77
|
|
|
* @param array $auctionIds itemIds of auctions to finish |
|
78
|
|
|
* @param integer $cancelAllBids whether to cancel all bids |
|
79
|
|
|
* @param string $finishCancelReason reason |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
|
|
public function finishAuctions(array $auctionIds, $cancelAllBids = 0, $finishCancelReason = '') |
|
83
|
|
|
{ |
|
84
|
|
|
$finishItemsList = array_map(function ($auctionId) use ($cancelAllBids, $finishCancelReason) { |
|
85
|
|
|
return [ |
|
86
|
|
|
'finishItemId' => $auctionId, |
|
87
|
|
|
'finishCancelAllBids' => $cancelAllBids, |
|
88
|
|
|
'finishCancelReason' => $finishCancelReason, |
|
89
|
|
|
]; |
|
90
|
|
|
}, $auctionIds); |
|
91
|
|
|
|
|
92
|
|
|
return $this->client->finishItems(['finishItemsList' => $finishItemsList]); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Change quantity of items available in auction |
|
97
|
|
|
* @param integer $auctionId itemId of auction to change quantity |
|
98
|
|
|
* @param integer $newQuantity new quantity to set |
|
99
|
|
|
* @return array |
|
100
|
|
|
*/ |
|
101
|
|
|
public function changeQuantity($auctionId, $newQuantity) |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->client->changeQuantityItem([ |
|
|
|
|
|
|
104
|
|
|
'itemId' => $auctionId, |
|
105
|
|
|
'newItemQuantity' => $newQuantity |
|
106
|
|
|
]); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Return site journal deals |
|
112
|
|
|
* @param integer $journalStart start point (dealEventId) |
|
113
|
|
|
* @return array |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getSiteJournalDeals($journalStart) |
|
116
|
|
|
{ |
|
117
|
|
|
$response = $this->client->getSiteJournalDeals(['journalStart' => $journalStart]); |
|
|
|
|
|
|
118
|
|
|
if (isset($response->siteJournalDeals->item)) { |
|
119
|
|
|
return $response->siteJournalDeals->item; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
throw new Exception("Unable to get site journal deals: " . print_r($response, 1)); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param integer $itemId id of auction to get |
|
128
|
|
|
* @return Auction | null |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getAuctionByItemId($itemId) |
|
131
|
|
|
{ |
|
132
|
|
|
$response = $this->client->getItemFields(['itemId' => $itemId]); |
|
|
|
|
|
|
133
|
|
|
if (isset($response->itemFields->item)) { |
|
134
|
|
|
$auction = new Auction(); |
|
135
|
|
|
$auction->fromApiRepresentation($response->itemFields->item); |
|
136
|
|
|
return $auction; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return null; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: