1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WSW\SiftScience\Transformers; |
4
|
|
|
|
5
|
|
|
use WSW\SiftScience\Entities\CreditPoint; |
6
|
|
|
use WSW\SiftScience\Entities\Discount; |
7
|
|
|
use WSW\SiftScience\Entities\Promotion; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class PromotionTransformer |
11
|
|
|
* |
12
|
|
|
* @package WSW\SiftScience\Transformers |
13
|
|
|
* @author Ronaldo Matos Rodrigues <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class PromotionTransformer extends AbstractTransformer |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param Promotion $promotion |
19
|
|
|
* |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
|
|
public function transform(Promotion $promotion) |
23
|
|
|
{ |
24
|
|
|
return array_filter([ |
25
|
|
|
'$promotion_id' => $promotion->getId(), |
26
|
|
|
'$status' => $promotion->getStatus(), |
27
|
|
|
'$failure_reason' => $promotion->getFailureReason(), |
28
|
|
|
'$description' => $promotion->getDescription(), |
29
|
|
|
'$referrer_user_id' => $promotion->getReferrerUserId(), |
30
|
|
|
'$discount' => $this->discount($promotion->getDiscount()), |
31
|
|
|
'$credit_point' => $this->creditPoint($promotion->getCreditPoint()) |
32
|
|
|
]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param Discount $discount |
37
|
|
|
* |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
protected function discount($discount) |
41
|
|
|
{ |
42
|
|
|
if (!$discount instanceof Discount) { |
43
|
|
|
return null; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $this->loadItem($discount, new DiscountTransformer); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param CreditPoint $creditPoint |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
protected function creditPoint($creditPoint) |
55
|
|
|
{ |
56
|
|
|
if (!$creditPoint instanceof CreditPoint) { |
57
|
|
|
return null; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $this->loadItem($creditPoint, new CreditPointTransformer); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|