1
|
|
|
<?php |
2
|
|
|
namespace xbanners\src\Managers; |
3
|
|
|
|
4
|
|
|
class BannerPageTypesManager |
|
|
|
|
5
|
|
|
{ |
|
|
|
|
6
|
|
|
|
7
|
|
|
const PAGE_TYPE_MAIN = 'main'; |
8
|
|
|
const PAGE_TYPE_SHOP_CATEGORY = 'shop_category'; |
9
|
|
|
const PAGE_TYPE_PRODUCT = 'product'; |
10
|
|
|
const PAGE_TYPE_CATEGORY = 'category'; |
11
|
|
|
const PAGE_TYPE_PAGE = 'page'; |
12
|
|
|
const PAGE_TYPE_BRAND = 'brand'; |
13
|
|
|
const PAGE_TYPE_SEARCH = 'search'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var BannerPageTypesManager instance |
17
|
|
|
*/ |
18
|
|
|
private static $instance = NULL; |
19
|
|
|
|
20
|
|
|
private function __construct() { |
21
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get BannerPageTypesManager instance |
26
|
|
|
* @return BannerPageTypesManager instance |
27
|
|
|
*/ |
28
|
|
|
public static function getInstance() { |
29
|
|
|
if (null === self::$instance) { |
30
|
|
|
self::$instance = new self(); |
31
|
|
|
} |
32
|
|
|
return self::$instance; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get banner pages type|types: ['main', 'shop_category', 'product',...] on nothing to get all types array |
37
|
|
|
* @param string $type - banner type |
|
|
|
|
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public function getPagesTypes($type = NULL) { |
41
|
|
|
$pageTypes = [ |
42
|
|
|
'main' => [ |
43
|
|
|
'name' => lang('Main', 'xbanners'), |
44
|
|
|
'class' => NULL |
45
|
|
|
], |
46
|
|
|
'shop_category' => [ |
47
|
|
|
'name' => lang('Product category', 'xbanners'), |
48
|
|
|
'class' => '\xbanners\src\BannerPagesTypes\ShopCategory' |
49
|
|
|
], |
50
|
|
|
'product' => [ |
51
|
|
|
'name' => lang('Product', 'xbanners'), |
52
|
|
|
'class' => '\xbanners\src\BannerPagesTypes\Product' |
53
|
|
|
], |
54
|
|
|
'category' => [ |
55
|
|
|
'name' => lang('Page category', 'xbanners'), |
56
|
|
|
'class' => '\xbanners\src\BannerPagesTypes\Category' |
57
|
|
|
], |
58
|
|
|
'page' => [ |
59
|
|
|
'name' => lang('Page', 'xbanners'), |
60
|
|
|
'class' => '\xbanners\src\BannerPagesTypes\Page' |
61
|
|
|
], |
62
|
|
|
'brand' => [ |
63
|
|
|
'name' => lang('Product brand', 'xbanners'), |
64
|
|
|
'class' => '\xbanners\src\BannerPagesTypes\Brand' |
65
|
|
|
], |
66
|
|
|
'search' => [ |
67
|
|
|
'name' => lang('Search page', 'xbanners'), |
68
|
|
|
'class' => NULL |
69
|
|
|
], |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
return $type ? $pageTypes[$type] : $pageTypes; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get banner type view |
77
|
|
|
* @param string $type - banner page type name type: ['main', 'shop_category', 'product',...] |
78
|
|
|
* @param string $locale - locale name |
|
|
|
|
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
View Code Duplication |
public function getView($type, $locale = NULL) { |
82
|
|
|
$locale = $locale ? $locale : \MY_Controller::defaultLocale(); |
83
|
|
|
$type = $this->getPagesTypes($type); |
84
|
|
|
|
85
|
|
|
if (!$type OR !$type['class'] OR !class_exists($type['class'])) { |
86
|
|
|
return NULL; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$typeObj = new $type['class']($locale); |
90
|
|
|
|
91
|
|
|
return $typeObj->getView(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get banner page type allowed pages list |
96
|
|
|
* @param string $type - banner page type name type: ['main', 'shop_category', 'product',...] |
97
|
|
|
* @param string $locale - locale name |
|
|
|
|
98
|
|
|
* @return array |
99
|
|
|
*/ |
100
|
|
View Code Duplication |
public function getPages($type, $locale = NULL) { |
101
|
|
|
$locale = $locale ? $locale : \MY_Controller::defaultLocale(); |
102
|
|
|
$type = $this->getPagesTypes($type); |
103
|
|
|
|
104
|
|
|
if (!$type OR !$type['class'] OR !class_exists($type['class'])) { |
105
|
|
|
return NULL; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$typeObj = new $type['class']($locale); |
109
|
|
|
|
110
|
|
|
return $typeObj->getPages(); |
111
|
|
|
} |
112
|
|
|
} |