1 | <?php |
||
16 | class helper |
||
17 | { |
||
18 | /** @var \phpbb\user */ |
||
19 | protected $user; |
||
20 | |||
21 | /** @var \phpbb\user_loader */ |
||
22 | protected $user_loader; |
||
23 | |||
24 | /** @var \phpbb\language\language */ |
||
25 | protected $language; |
||
26 | |||
27 | /** @var \phpbb\template\template */ |
||
28 | protected $template; |
||
29 | |||
30 | /** @var \phpbb\log\log */ |
||
31 | protected $log; |
||
32 | |||
33 | /** @var \phpbb\ads\location\manager */ |
||
34 | protected $location_manager; |
||
35 | |||
36 | /** @var string root_path */ |
||
37 | protected $root_path; |
||
38 | |||
39 | /** @var string php_ext */ |
||
40 | protected $php_ext; |
||
41 | |||
42 | /** |
||
43 | * Constructor |
||
44 | * |
||
45 | * @param \phpbb\user $user User object |
||
46 | * @param \phpbb\user_loader $user_loader User loader object |
||
47 | * @param \phpbb\language\language $language Language object |
||
48 | * @param \phpbb\template\template $template Template object |
||
49 | * @param \phpbb\log\log $log The phpBB log system |
||
50 | * @param \phpbb\ads\location\manager $location_manager Template location manager object |
||
51 | * @param string $root_path phpBB root path |
||
52 | * @param string $php_ext PHP extension |
||
53 | */ |
||
54 | 16 | public function __construct(\phpbb\user $user, \phpbb\user_loader $user_loader, \phpbb\language\language $language, \phpbb\template\template $template, \phpbb\log\log $log, \phpbb\ads\location\manager $location_manager, $root_path, $php_ext) |
|
55 | { |
||
56 | 16 | $this->user = $user; |
|
57 | 16 | $this->user_loader = $user_loader; |
|
58 | 16 | $this->language = $language; |
|
59 | 16 | $this->template = $template; |
|
60 | 16 | $this->log = $log; |
|
61 | 16 | $this->location_manager = $location_manager; |
|
62 | 16 | $this->root_path = $root_path; |
|
63 | 16 | $this->php_ext = $php_ext; |
|
64 | 16 | } |
|
65 | |||
66 | /** |
||
67 | * Assign ad data for ACP form template. |
||
68 | * |
||
69 | * @param array $data Ad data |
||
70 | * @param array $errors Validation errors |
||
71 | */ |
||
72 | 5 | public function assign_data($data, $errors) |
|
93 | |||
94 | /** |
||
95 | * Assign template locations data to the template. |
||
96 | * |
||
97 | * @param mixed $ad_locations The form data or nothing. |
||
98 | * @return void |
||
99 | */ |
||
100 | 7 | public function assign_locations($ad_locations = false) |
|
101 | { |
||
102 | 7 | foreach ($this->location_manager->get_all_locations() as $location_category_id => $location_category) |
|
103 | { |
||
104 | 2 | $this->template->assign_block_vars('ad_locations', array( |
|
105 | 2 | 'CATEGORY_NAME' => $this->language->lang($location_category_id), |
|
106 | 2 | )); |
|
107 | |||
108 | 2 | foreach ($location_category as $location_id => $location_data) |
|
109 | { |
||
110 | 2 | $this->template->assign_block_vars('ad_locations', array( |
|
111 | 2 | 'LOCATION_ID' => $location_id, |
|
112 | 2 | 'LOCATION_DESC' => $location_data['desc'], |
|
113 | 2 | 'LOCATION_NAME' => $location_data['name'], |
|
114 | 2 | 'S_SELECTED' => $ad_locations ? in_array($location_id, $ad_locations) : false, |
|
115 | 2 | )); |
|
116 | 2 | } |
|
117 | 7 | } |
|
118 | 7 | } |
|
119 | |||
120 | /** |
||
121 | * Log action |
||
122 | * |
||
123 | * @param string $action Performed action in uppercase |
||
124 | * @param string $ad_name Advertisement name |
||
125 | * @return void |
||
126 | */ |
||
127 | 1 | public function log($action, $ad_name) |
|
131 | |||
132 | /** |
||
133 | * Get "Find username" URL to easily look for ad owner. |
||
134 | * |
||
135 | * @return string Find username URL |
||
136 | */ |
||
137 | 1 | public function get_find_username_link() |
|
141 | |||
142 | /** |
||
143 | * Generate URL to enable visual demo of ad locations. |
||
144 | * |
||
145 | * @return string Enable visual demo URL |
||
146 | */ |
||
147 | public function get_enable_visual_demo_link() |
||
151 | |||
152 | /** |
||
153 | * Is an ad expired? |
||
154 | * |
||
155 | * @param array $row Advertisement data |
||
156 | * @return bool True if expired, false otherwise |
||
157 | */ |
||
158 | 7 | public function is_expired($row) |
|
177 | |||
178 | /** |
||
179 | * Prepare ad owner for display. Method takes user_id |
||
180 | * of the ad owner and returns username. |
||
181 | * |
||
182 | * @param int $user_id User ID |
||
183 | * @return string Username belonging to $user_id. |
||
184 | */ |
||
185 | 5 | protected function get_username($user_id) |
|
195 | } |
||
196 |