|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Audiens\DoubleclickClient\entity; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class SegmentRevenue |
|
7
|
|
|
*/ |
|
8
|
|
|
class SegmentRevenue extends Segment |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
use HydratableTrait; |
|
12
|
|
|
|
|
13
|
|
|
/** @var string */ |
|
14
|
|
|
protected $clientName; |
|
15
|
|
|
|
|
16
|
|
|
/** @var int */ |
|
17
|
|
|
protected $segmentImpression; |
|
18
|
|
|
|
|
19
|
|
|
/** @var float */ |
|
20
|
|
|
protected $segmentRevenue; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* SegmentRevenue constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param $segmentId |
|
26
|
|
|
* @param $clientName |
|
27
|
|
|
* @param $segmentName |
|
28
|
|
|
* @param $segmentStatus |
|
29
|
|
|
* @param $segmentImpression |
|
30
|
|
|
* @param $segmentRevenue |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( |
|
33
|
|
|
$segmentId, |
|
34
|
|
|
$clientName, |
|
35
|
|
|
$segmentName, |
|
36
|
|
|
$segmentStatus, |
|
37
|
|
|
$segmentImpression, |
|
38
|
|
|
$segmentRevenue |
|
39
|
|
|
) { |
|
40
|
|
|
$this->clientName = $clientName; |
|
41
|
|
|
$this->segmentImpression = $segmentImpression; |
|
42
|
|
|
$this->segmentRevenue = $segmentRevenue; |
|
43
|
|
|
|
|
44
|
|
|
parent::__construct($segmentId, $segmentName, $segmentStatus); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return mixed |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getSegmentRevenue() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->segmentRevenue; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getClientName() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->clientName; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getSegmentImpression() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->segmentImpression; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param array $array |
|
73
|
|
|
* |
|
74
|
|
|
* @return SegmentRevenue |
|
75
|
|
|
* @throws \Exception |
|
76
|
|
|
*/ |
|
77
|
|
|
public static function fromArray(array $array) |
|
78
|
|
|
{ |
|
79
|
|
|
|
|
80
|
|
|
if (!isset($array['userlistid'])) { |
|
81
|
|
|
throw new \Exception('hydration: userlistid'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
if (!isset($array['clientcustomername'])) { |
|
85
|
|
|
throw new \Exception('hydration: clientcustomername'); |
|
86
|
|
|
} |
|
87
|
|
|
if (!isset($array['userlistname'])) { |
|
88
|
|
|
throw new \Exception('hydration: userlistname'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (!isset($array['status'])) { |
|
92
|
|
|
throw new \Exception('hydration: status'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if (!isset($array['stats']['clientimpressions'])) { |
|
96
|
|
|
throw new \Exception('hydration: stats->clientimpressions'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if (!isset($array['stats']['costusd']['microamount'])) { |
|
100
|
|
|
throw new \Exception('hydration: stats->costusd->microamount'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$clientName = $array['clientcustomername']; |
|
104
|
|
|
|
|
105
|
|
|
if (is_array($array['clientcustomername'])) { |
|
106
|
|
|
$clientName = $array['clientid']; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return new self( |
|
110
|
|
|
$array['userlistid'], |
|
111
|
|
|
$clientName, |
|
112
|
|
|
$array['userlistname'], |
|
113
|
|
|
$array['status'], |
|
114
|
|
|
$array['stats']['clientimpressions'], |
|
115
|
|
|
(round($array['stats']['costusd']['microamount'] / 1000000, 2)) |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|