oct_locations.php
2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* @copyright OCTemplates
* @support https://octemplates.net/
* @license LICENSE.txt
*/
class ModelOCTemplatesWidgetsOctLocations extends Model {
public function getOCTLocations() {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "oct_location` ORDER BY `sort`");
$oct_locations = [];
foreach ($query->rows as $location) {
$thumb = $this->getLocationThumb($location);
$description = json_decode($location['description'], true);
$phone = $this->getLocationPhones($location);
$open = $this->getLocationOpens($description);
$oct_locations[] = [
'title' => $this->getDescriptionValue($description, 'title'),
'address' => $this->getDescriptionValue($description, 'address'),
'open' => $open,
'phone' => $phone,
'map' => html_entity_decode($location['map'], ENT_QUOTES, 'UTF-8'),
'thumb' => $thumb,
'link' => html_entity_decode($location['link'], ENT_QUOTES, 'UTF-8')
];
}
return $oct_locations;
}
private function getLocationThumb($location) {
if (isset($location['image']) && !empty($location['image']) && file_exists(DIR_IMAGE.$location['image'])) {
$this->load->model('tool/image');
return $this->model_tool_image->resize($location['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_location_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_location_height'));
} else {
return false;
}
}
private function getDescriptionValue($description, $key) {
if (isset($description[(int)$this->config->get('config_language_id')][$key])) {
return html_entity_decode($description[(int)$this->config->get('config_language_id')][$key], ENT_QUOTES, 'UTF-8');
} else {
return '';
}
}
private function getLocationPhones($location) {
$phones = !empty($location['phone']) ? explode(PHP_EOL, $location['phone']) : [];
return array_map(function($phone) {
return html_entity_decode(trim($phone), ENT_QUOTES, 'UTF-8');
}, $phones);
}
private function getLocationOpens($description) {
$opens = (isset($description[(int)$this->config->get('config_language_id')]['open']) && !empty($description[(int)$this->config->get('config_language_id')]['open']))
? explode(PHP_EOL, isset($description[(int)$this->config->get('config_language_id')]['open']) ? $description[(int)$this->config->get('config_language_id')]['open'] : '')
: [];
return array_map(function($open) {
return html_entity_decode(trim($open), ENT_QUOTES, 'UTF-8');
}, $opens);
}
}