105 lines
3.1 KiB
PHP
105 lines
3.1 KiB
PHP
<?php
|
|
|
|
class FooterModel extends BaseModel {
|
|
|
|
public function getFooter($params) {
|
|
$constructor_id = $params['constructor_id'];
|
|
$sql = "SELECT * FROM constructor_list WHERE id = $constructor_id";
|
|
$footerQuery = $this->db->query($sql);
|
|
$footerData = [];
|
|
|
|
while ($res = $this->db->fetch_assoc($footerQuery)) {
|
|
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);
|
|
}
|
|
$main_menu = $this->getFooterItems($constructor_id);
|
|
$bottom_menu = $this->getBottomItems($constructor_id);
|
|
$socials = $this->getSocials($constructor_id);
|
|
$contacts = $this->getContacts($constructor_id);
|
|
$res['mainMenu'] = $main_menu;
|
|
$res['bottomMenu'] = $bottom_menu;
|
|
$res['socials'] = $socials;
|
|
$res['contacts'] = $contacts;
|
|
|
|
$footerData[] = $res;
|
|
}
|
|
return $footerData;
|
|
}
|
|
public function getFooterItems($constructor_id) {
|
|
$sql = "SELECT * FROM constructor_items ci WHERE ci.constructor_id = $constructor_id AND type='footer'";
|
|
$navQuery = $this->db->query($sql);
|
|
|
|
$navItems = [];
|
|
|
|
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;
|
|
}
|
|
|
|
public function getBottomItems($constructor_id) {
|
|
$sql = "SELECT * FROM constructor_items ci WHERE ci.constructor_id = $constructor_id AND type='footer-bottom'";
|
|
$navQuery = $this->db->query($sql);
|
|
|
|
$navItems = [];
|
|
|
|
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;
|
|
}
|
|
|
|
public function getSocials($constructor_id) {
|
|
$sql = "SELECT * FROM constructor_socials cs WHERE cs.constructor_id = $constructor_id";
|
|
$query = $this->db->query($sql);
|
|
|
|
$socials = [];
|
|
|
|
while ($res = $this->db->fetch_assoc($query)) {
|
|
$socials[] = $res;
|
|
}
|
|
return $socials;
|
|
}
|
|
|
|
public function getContacts($constructor_id) {
|
|
$sql = "SELECT * FROM constructor_contacts cc WHERE cc.constructor_id = $constructor_id";
|
|
$query = $this->db->query($sql);
|
|
|
|
$contacts = [];
|
|
|
|
while ($row = $this->db->fetch_assoc($query)) {
|
|
$contacts[$row['id']] = $row;
|
|
$contacts[$row['id']]['items'] = [];
|
|
}
|
|
$tree = [];
|
|
foreach($contacts as $id => $item) {
|
|
if ($item['parent_id'] === null) {
|
|
$tree[] = &$contacts[$id];
|
|
} else {
|
|
$contacts[$item['parent_id']]['items'][] = &$contacts[$id];
|
|
}
|
|
}
|
|
return $tree;
|
|
}
|
|
} |