-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomHTMLPageModel.php
120 lines (88 loc) · 2.62 KB
/
CustomHTMLPageModel.php
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
class CustomHTMLPageModel extends ObjectModel
{
public $id;
public $name;
public $meta_title;
public $meta_description;
public $meta_keywords;
public $content;
public $active = 1;
public $related = [];
public $parent = null; // Reference
public $children = []; // Array of references
public $link_rewrite;
public $url;
public $link;
public $breadcrumb_parameters;
public $css;
private $raw;
public $_products = [];
public $_categories = [];
public function __construct($raw)
{
$this->id = $raw['id_page'];
$this->name = $raw['name'];
$this->meta_title = $raw['meta_title'];
$this->meta_description = $raw['meta_description'];
$this->meta_keywords = $raw['meta_keywords'];
$this->content = $raw['content'];
$this->active = $raw['active'];
$this->link_rewrite = $raw['url'];
$this->url = $raw['url'];
$this->link = $raw['url'];
$this->breadcrumb_parameters = $raw['breadcrumb_parameters'] ?: '';
$this->_products = (is_null($raw['id_products']) || empty($raw['id_products'])) ? [] : explode(',', $raw['id_products']);
$this->_categories = (is_null($raw['id_categories']) || empty($raw['id_categories'])) ? [] : explode(',', $raw['id_categories']);
$this->css = (array_key_exists('style', $raw)) ? $raw['style'] : null;
$this->raw = $raw;
}
/**
* Checks if the page has children
*/
public function hasChildren()
{
return count($this->children) > 0;
}
/**
* Checks if the page has a parent
*/
public function hasParent()
{
return !is_null($this->parent);
}
/**
* Adds a child to the page
*/
public function addChild($child)
{
array_push($this->children, $child);
$child->parent = $this;
$child->computeFullURL();
}
/**
* Adds a related page
*/
public function addRelated($page)
{
array_push($this->related, $page);
}
/**
* Returns/Recomputes the full URL to this page
*/
public function computeFullURL($computeChildren = true)
{
$prefix = "";
if (!is_null($this->parent))
$prefix = $this->parent->computeFullURL(false);
if (!empty($prefix))
$prefix .= '/';
$this->url = $prefix.$this->link_rewrite;
if ($computeChildren && count($this->children) > 0) {
foreach ($this->children as $child) {
$child->computeFullURL();
}
}
return $this->url;
}
}