dolibarr 21.0.0-beta
documentation.class.php
1<?php
2/* Copyright (C) 2024 Anthony Damhet <a.damhet@progiseize.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
28{
34 public $view = array();
35
41 public $menu = array();
42
48 public $summary = array();
49
53 public $db;
54
55
61 public function __construct(DoliDB $db)
62 {
63 $this->db = $db;
64
65 // https://www.figma.com/community/file/1393171578760389765/dolibarr-ui-ux-kit
66
67 // Menu Constructor
68 $this->setMenu();
69 }
70
76 private function setMenu()
77 {
78
79 global $hookmanager;
80
81
82 $hookmanager->initHooks(array('uidocumentation'));
83
84 $baseUrl = 'admin/tools/ui';
85
86 // Go back to Dolibarr
87 $this->menu['BackToDolibarr'] = array(
88 'url' => DOL_URL_ROOT,
89 'icon' => 'fas fa-arrow-left pictofixedwidth',
90 'submenu' => array(),
91 );
92
93 // Home for Ui documentation
94 $this->menu['DocumentationHome'] = array(
95 'url' => dol_buildpath($baseUrl.'/index.php', 1),
96 'icon' => 'fas fa-book',
97 'submenu' => array(),
98 );
99
100 // Components
101 $this->menu['Components'] = array(
102 'url' => dol_buildpath($baseUrl.'/components/index.php', 1),
103 'icon' => 'fas fa-th-large',
104 'submenu' => array(
105 'Badges' => array(
106 'url' => dol_buildpath($baseUrl.'/components/badges.php', 1),
107 'icon' => 'fas fa-certificate pictofixedwidth',
108 'submenu' => array(),
109 'summary' => array(
110 'DocBasicUsage' => '#badgesection-basicusage',
111 'DocBadgeContextualVariations' => '#badgesection-contextvariations',
112 'DocBadgeDefaultStatus' => '#badgesection-defaultstatus',
113 'DocBadgePillBadges' => '#badgesection-pill',
114 'DocBadgeDotBadges' => '#badgesection-dot',
115 'DocBadgeLinks' => '#badgesection-links',
116 'DocBadgeHelper' => '#badgesection-dolgetbadge'
117 ),
118 ),
119 'Buttons' => array(
120 'url' => dol_buildpath($baseUrl.'/components/buttons.php', 1),
121 'icon' => 'fas fa-mouse pictofixedwidth',
122 'submenu' => array(),
123 'summary' => array(
124 'DocBasicUsage' => '#buttonsection-basicusage',
125 'DocButtonModal' => '#buttonsection-modals',
126 'DocButtonSubmenu' => '#buttonsection-submenu',
127 ),
128 ),
129 'Progress' => array(
130 'url' => dol_buildpath($baseUrl.'/components/progress-bars.php', 1),
131 'icon' => 'fas fa-battery-half pictofixedwidth',
132 'submenu' => array(),
133 'summary' => array(
134 'DocBasicUsage' => '#progresse-section-basic-usage',
135 'DocColorVariants' => '#progress-section-color',
136 'DocStripedVariants' => '#progresse-section-stripped',
137 ),
138 ),
139 'Event Message' => array(
140 'url' => dol_buildpath($baseUrl.'/components/event-message.php', 1),
141 'icon' => 'fas fa-comments pictofixedwidth',
142 'submenu' => array(),
143 'summary' => array(
144 'DocBasicUsage' => '#seteventmessagesection-basicusage',
145 'DocSetEventMessageContextualVariations' => '#seteventmessagesection-contextvariations',
146 )
147 ),
148 ),
149 'summary' => array(
150 'keySum' => '#keySum'
151 )
152 );
153
154 // Elements
155 $this->menu['Content'] = array(
156 'url' => dol_buildpath($baseUrl.'/content/index.php', 1),
157 'icon' => 'fas fa-th-large',
158 'submenu' => array(
159 'Tables' => array(
160 'url' => dol_buildpath('admin/tools/ui/content/tables.php', 1),
161 'icon' => 'fas fa-table pictofixedwidth',
162 'submenu' => array(),
163 'summary' => array(
164 'DocBasicUsage' => '#tablesection-basicusage',
165 'DocTableWithFilters' => '#tablesection-withfilters'
166 ),
167 ),
168 )
169 );
170
171 $parameters = array(
172 'baseUrl' => $baseUrl,
173 );
174 $action = '';
175
176 $reshook = $hookmanager->executeHooks('setMenu', $parameters, $this, $action);
177 if ($reshook < 0) {
178 return false;
179 }
180 }
181
190 public function docHeader($title = '', $arrayofjs = [], $arrayofcss = [])
191 {
192 global $langs;
193 $title = (!empty($title)) ? dol_escape_htmltag($title) : $langs->trans('Documentation');
194
195 $arrayofcss[] = 'admin/tools/ui/css/documentation.css';
196
197 top_htmlhead('', $title, 0, 0, $arrayofjs, $arrayofcss);
198
199 print '<body class="dolibarr-doc">';
200 }
201
206 public function docFooter()
207 {
208 global $langs;
209
210 // DIV FOR SCROLL ANIMATION
211 print '<div id="documentation-scrollwrapper">';
212 print '<div id="documentation-scroll"></div>';
213 print '</div>';
214
215 // JS
216 print '<script src="'.dol_buildpath('admin/tools/ui/js/documentation.js', 1).'"></script>';
217 print '<script src="'.DOL_URL_ROOT.'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.'"></script>';
218
219 print '</body>';
220 print '</html>';
221
223 }
224
229 public function showSidebar()
230 {
231 print '<div class="doc-sidebar">';
232
233 // LOGO
234 print '<div class="sidebar-logo">';
235 if (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
236 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
237 print '<img src="'.$urllogo.'" />';
238 }
239 print '</div>';
240
241 // NAVIGATION
242 print '<nav>';
243 if (!empty($this->menu)) {
244 $this->displayMenu($this->menu);
245 }
246 print '</nav>';
247
248 print '</div>';
249 }
250
258 private function displayMenu($menu, $level = 0)
259 {
260 global $langs;
261 $level++;
262
263 print '<ul>';
264 foreach ($menu as $key => $item) {
265 $levelclass = (!empty($item['submenu'])) ? 'li-withsubmenu' : '';
266 $levelclass .= (in_array($key, $this->view)) ? ' active' : '';
267
268 print '<li class="'.$levelclass.' level-'.$level.'">';
269 print '<a href="'.$item['url'].'" class="'.((!empty($item['submenu'])) ? 'link-withsubmenu' : '').'">';
270 print ((!empty($item['icon'])) ? '<i class="menu-icon '.$item['icon'].'" aria-hidden="true"></i>' : '');
271 print '<span class="label">'.$langs->transnoentities($key).'</span>';
272 print ((!empty($item['submenu'])) ? '<i class="submenu-toggle fas fa-chevron-right" aria-hidden="true"></i>' : '');
273 print '</a>';
274 if (!empty($item['submenu'])) {
275 $this->displayMenu($item['submenu'], $level); // Appel récursif pour afficher les sous-menus
276 }
277 echo '</li>';
278 }
279 print '</ul>';
280 }
281
286 public function showBreadcrumb()
287 {
288 global $langs;
289
290 print '<nav class="doc-breadcrumbs">';
291 print '<ul>';
292 print '<li class="breadcrumb-item"><a href="'.$this->menu['DocumentationHome']['url'].'"><i class="'.$this->menu['DocumentationHome']['icon'].'" aria-hidden="true"></i></a></li>';
293 if (!empty($this->view)) {
294 $nb_entries = count($this->view);
295 $i = 0;
296
297 $menu_entry = $this->menu;
298 foreach ($this->view as $page) {
299 $i++;
300 if ($i < $nb_entries && isset($menu_entry[$page])) {
301 print '<li class="breadcrumb-item"><a href="'.$menu_entry[$page]['url'].'">'.$langs->transnoentities($page).'</a></li>';
302 $menu_entry = $menu_entry[$page]['submenu'];
303 } else {
304 print '<li class="breadcrumb-item">'.$langs->transnoentities($page).'</li>';
305 }
306 }
307 } else {
308 print '<li class="breadcrumb-item">'.$langs->trans('Documentation').'</li>';
309 }
310 print '</ul>';
311 print '</nav>';
312 }
313
320 public function showSummary($showsubmenu = 1, $showsubmenu_summary = 1)
321 {
322 $i = 0;
323 if (!empty($this->view)) :
324 // On se place au bon niveau
325 foreach ($this->view as $view) {
326 $i++;
327 if ($i == 1) {
328 $menu_entry = $this->menu[$view];
329 } else {
330 $menu_entry = $menu_entry['submenu'][$view];
331 }
332 }
333 endif;
334
335 if (!empty($menu_entry['summary']) || !empty($menu_entry['submenu'] && $showsubmenu)) {
336 print '<div class="summary-wrapper">';
337 $this->displaySummary($menu_entry);
338 print '</div>';
339 }
340 }
341
342
352 public function displaySummary($menu, $level = 0, $showsubmenu = 1, $showsubmenu_summary = 1)
353 {
354
355 global $langs;
356
357 $level++;
358 print '<ul class="documentation-summary level-'.$level.'"">';
359
360 if (!empty($menu['summary'])) :
361 foreach ($menu['summary'] as $summary_label => $summary_link) {
362 if ($summary_link[0] == '#') {
363 $summary_link = $menu['url'].$summary_link;
364 }
365
366 print '<li><a href="'.$summary_link.'">'.$langs->trans($summary_label).'</a></li>';
367 }
368 endif;
369
370 if ($showsubmenu && !empty($menu['submenu'])) {
371 foreach ($menu['submenu'] as $key => $item) {
372 print '<li class="summary-title ">';
373 print '<h3 class="level-'.$level.'">'.$key.'</h3>';
374 if ($showsubmenu_summary) {
375 $this->displaySummary($item, $level);
376 }
377 print '</li>';
378 }
379 }
380 print '</ul>';
381 }
382
389 public function showCode($lines = array())
390 {
391 print '<div class="documentation-code"><pre>';
392 if (!empty($lines)) {
393 foreach ($lines as $lineofcode) {
394 print dol_htmlentities($lineofcode).'<br/>';
395 }
396 }
397 print '</pre></div>';
398 }
399}
Class to manage UI documentation.
showBreadcrumb()
Output breadcrumb.
displayMenu($menu, $level=0)
Recursive function to set Menu.
docHeader($title='', $arrayofjs=[], $arrayofcss=[])
Output header + body.
showSummary($showsubmenu=1, $showsubmenu_summary=1)
Output summary.
docFooter()
Output close body + html.
showSidebar()
Output sidebar.
__construct(DoliDB $db)
Constructor.
setMenu()
Set Documentation Menu.
displaySummary($menu, $level=0, $showsubmenu=1, $showsubmenu_summary=1)
Recursive function for Automatic Summary.
showCode($lines=array())
Output a View Code area.
Class to manage Dolibarr database access.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.