public function getComments($menuId) { $rows = $this->db->query("SELECT * FROM comment WHERE menu_id=%i", $menuId)->fetchAll(); foreach ($rows as &$row) { $row['comment_id'] = (int) $row['comment_id']; } array_unshift($rows, new \Dibi\Row(array('id' => 0, 'comment_id' => null))); $tree = $this->library->convertToTree($rows, 'id', 'comment_id', 'comments'); $tree[0]['comments'] = $this->library->removeKeys($tree[0]['comments'], 'comments'); return $tree[0]['comments']; }
public function getMenu($languageId = null) { if (empty($languageId)) { $languageId = $this->languageId; } if (!isset($this->menu[$languageId])) { $sql = "SELECT m.id,m.menu_id,m.type_id,t.text,t.url,visibility,IF(url IS NULL AND sort = 0, 255, sort) AS sort\n \t\t\tFROM [menu] m\n\t\t\tLEFT JOIN [name_has_text] nht ON m.name_id=nht.name_id AND language_id=%i\n\t\t\tLEFT JOIN [text] t ON t.id=nht.text_id\n\t\t\tWHERE site_id=%i\n\t\t\tORDER BY m.visibility,[sort],[id]"; $rows = $this->db->query($sql, $languageId, $this->siteId)->fetchAll(); foreach ($rows as &$row) { $row['menu_id'] = (int) $row['menu_id']; } array_unshift($rows, new \Dibi\Row(array('id' => 0, 'menu_id' => null))); $tree = $this->library->convertToTree($rows, 'id', 'menu_id', 'items'); $tree[0]['items'] = $this->library->removeKeys($tree[0]['items'], 'items'); $this->menu[$languageId] = $tree; } return $this->menu[$languageId]; }
public function getMenu($type = 'visible') { if (!isset($this->menu[$type])) { $sql = "SELECT m.id,m.menu_id,m.type_id AS type,t.text,t.url,m.visibility FROM [menu] m\n\t\t\tJOIN [name_has_text] nht ON m.name_id=nht.name_id AND language_id=%i\n\t\t\tJOIN [text] t ON t.id=nht.text_id\n\t\t\tWHERE site_id=%i AND m.visibility = %s\n\t\t\tORDER BY [sort],[id]"; $rows = $this->db->query($sql, $this->getLanguageId(), $this->siteId, $type)->fetchAll(); foreach ($rows as &$row) { $row['menu_id'] = (int) $row['menu_id']; } if ($type == 'visible') { array_unshift($rows, new DibiRow(array('id' => 0, 'menu_id' => null))); $tree = $this->library->convertToTree($rows, 'id', 'menu_id', 'items'); $tree[0]['items'] = $this->library->removeKeys($tree[0]['items'], 'items'); $this->menu[$type] = $tree; } else { $this->menu[$type] = $rows; } } return $this->menu[$type]; }