1
|
|
|
<?php namespace FlatPlan\Components; |
2
|
|
|
|
3
|
|
|
class Ad extends AbstractComponent { |
4
|
|
|
|
5
|
|
|
private $role; |
6
|
|
|
private $bannerType; |
7
|
|
|
|
8
|
|
|
protected $roles = ['banner_advertisement', 'medium_rectangle_advertisement']; |
9
|
|
|
protected $bannerTypes = ['any', 'standard', 'double_height', 'large']; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @param string $role |
13
|
|
|
* @param string $bannerType |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public function __construct($role, $bannerType = null) |
17
|
|
|
{ |
18
|
|
|
$this->setRole($role); |
19
|
|
|
if ($role === 'banner_advertisement') { |
20
|
|
|
$this->setBannerType($bannerType); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function setRole($role) |
25
|
|
|
{ |
26
|
|
|
if (!in_array($role, $this->roles)) { |
27
|
|
|
throw new \ErrorException('Invalid role supplied.'); |
28
|
|
|
} |
29
|
|
|
$this->role = $role; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getRole() |
33
|
|
|
{ |
34
|
|
|
return $this->role; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function setBannerType($bannerType = null) |
38
|
|
|
{ |
39
|
|
|
if (!in_array($bannerType, $this->bannerTypes)) { |
40
|
|
|
throw new \ErrorException('Invalid banner type supplied.'); |
41
|
|
|
} |
42
|
|
|
$this->bannerTypes = $bannerType; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getBannerType() |
46
|
|
|
{ |
47
|
|
|
return $this->bannerType; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getComponent() |
51
|
|
|
{ |
52
|
|
|
$component = new \stdClass(); |
53
|
|
|
$component->role = $this->getRole(); |
54
|
|
|
$component->bannerType = $this->getBannerType(); |
55
|
|
|
return $component; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function __toString() |
59
|
|
|
{ |
60
|
|
|
return json_encode($this->getComponent()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|