Translated using Weblate (Portuguese)
[phpmyadmin.git] / src / Console.php
blobd4be6fcbaf08b4958a242892aed5360d032f371b
1 <?php
2 /**
3 * Used to render the console of PMA's pages
4 */
6 declare(strict_types=1);
8 namespace PhpMyAdmin;
10 use PhpMyAdmin\Bookmarks\BookmarkRepository;
11 use PhpMyAdmin\ConfigStorage\Relation;
13 use function __;
14 use function _ngettext;
15 use function count;
16 use function sprintf;
18 /**
19 * Class used to output the console
21 class Console
23 /**
24 * Whether to display anything
26 private bool $isEnabled = true;
28 /**
29 * Whether we are servicing an ajax request.
31 private bool $isAjax = false;
32 private readonly Config $config;
34 public function __construct(
35 private readonly Relation $relation,
36 private readonly Template $template,
37 private readonly BookmarkRepository $bookmarkRepository,
38 ) {
39 $this->config = Config::getInstance();
42 /**
43 * Set the ajax flag to indicate whether
44 * we are servicing an ajax request
46 * @param bool $isAjax Whether we are servicing an ajax request
48 public function setAjax(bool $isAjax): void
50 $this->isAjax = $isAjax;
53 /**
54 * Disables the rendering of the footer
56 public function disable(): void
58 $this->isEnabled = false;
61 /**
62 * Renders the bookmark content
64 public function getBookmarkContent(): string
66 $bookmarkFeature = $this->relation->getRelationParameters()->bookmarkFeature;
67 if ($bookmarkFeature === null) {
68 return '';
71 $bookmarks = $this->bookmarkRepository->getList($this->config->selectedServer['user']);
72 $countBookmarks = count($bookmarks);
73 if ($countBookmarks > 0) {
74 $welcomeMessage = sprintf(
75 _ngettext(
76 'Showing %1$d bookmark (both private and shared)',
77 'Showing %1$d bookmarks (both private and shared)',
78 $countBookmarks,
80 $countBookmarks,
82 } else {
83 $welcomeMessage = __('No bookmarks');
86 return $this->template->render('console/bookmark_content', [
87 'welcome_message' => $welcomeMessage,
88 'bookmarks' => $bookmarks,
89 ]);
92 /**
93 * Returns the list of JS scripts required by console
95 * @return string[] list of scripts
97 public function getScripts(): array
99 return ['console.js'];
103 * Renders the console
105 public function getDisplay(): string
107 if ($this->isAjax || ! $this->isEnabled) {
108 return '';
111 $bookmarkFeature = $this->relation->getRelationParameters()->bookmarkFeature;
112 $sqlHistory = $this->relation->getHistory($this->config->selectedServer['user']);
113 $bookmarkContent = $this->getBookmarkContent();
115 return $this->template->render('console/display', [
116 'settings' => $this->config->config->Console->asArray(),
117 'has_bookmark_feature' => $bookmarkFeature !== null,
118 'sql_history' => $sqlHistory,
119 'bookmark_content' => $bookmarkContent,
120 'debug' => $this->config->config->debug->sql,