42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
class HeaderModel extends BaseModel {
|
|
public function getHeader($params) {
|
|
$constructor_id = $params['constructor_id'];
|
|
$sql = "SELECT * FROM constructor_list WHERE id = $constructor_id";
|
|
$headerQuery = $this->db->query($sql);
|
|
$headerData = [];
|
|
|
|
while ($res = $this->db->fetch_assoc($headerQuery)) {
|
|
if (isset($res['logo']) && !empty($res['logo'])) {
|
|
$res['logo'] = json_decode($res['logo'], true);
|
|
}
|
|
if (isset($res['subscribe']) && !empty($res['subscribe'])) {
|
|
$res['subscribe'] = json_decode($res['subscribe'], true);
|
|
}
|
|
$navigation = $this->getNavItems($constructor_id);
|
|
$res['navigation'] = $navigation;
|
|
|
|
$headerData[] = $res;
|
|
}
|
|
return $headerData;
|
|
}
|
|
public function getNavItems($constructor_id) {
|
|
$sql = "SELECT * FROM constructor_items cni WHERE cni.constructor_id = $constructor_id AND type='nav'";
|
|
$navQuery = $this->db->query($sql);
|
|
|
|
while ($row = $this->db->fetch_assoc($navQuery)) {
|
|
$navItems[$row['id']] = $row;
|
|
$navItems[$row['id']]['items'] = [];
|
|
}
|
|
$tree = [];
|
|
foreach($navItems as $id => $item) {
|
|
if ($item['parent_id'] === null) {
|
|
$tree[] = &$navItems[$id];
|
|
} else {
|
|
$navItems[$item['parent_id']]['items'][] = &$navItems[$id];
|
|
}
|
|
}
|
|
return $tree;
|
|
}
|
|
} |