dolibarr 24.0.0-beta
documentlist.controller.class.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2025 Schaffhauser sébastien <sebastien@webmaster67.fr>
6 * Copyright (C) 2026 Ferran Marcet <fmarcet@2byte.es>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
22require_once __DIR__ . '/abstractdocument.controller.class.php';
23include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
24
38{
44 public function checkAccess()
45 {
46 $this->accessRight = getDolGlobalInt('WEBPORTAL_DOCUMENT_LIST_ACCESS');
47 return parent::checkAccess();
48 }
49
55 public function action(): int
56 {
57 global $langs;
59 if (!$context->controllerInstance->checkAccess()) {
60 return -1;
61 }
62
63 $langs->loadLangs(array('other', 'webportal@webportal'));
64 $context->title = $langs->trans('MyDocuments');
65 $context->desc = $langs->trans('ListOfMyDocuments');
66 $context->menu_active[] = 'document_list';
67
68 return 1;
69 }
70
76 public function display()
77 {
78 global $conf, $langs;
80 if (!$context->controllerInstance->checkAccess()) {
81 $this->display404();
82 return;
83 }
84
85 $this->loadTemplate('header');
86 $this->loadTemplate('menu');
87 $this->loadTemplate('hero-header-banner');
88
89 print '<main class="container">';
90
91 $thirdparty = $context->logged_thirdparty;
92
93 if (!empty($thirdparty) && $thirdparty->id) {
94 // 1. Prepare data
95 require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
96 $client_dir_name = $thirdparty->id;
97 $dir_ged_tiers = $conf->societe->multidir_output[$thirdparty->entity ?? $conf->entity]."/".$client_dir_name;
98 $fileList = dol_dir_list($dir_ged_tiers, 'files', 0, '', '', 'date', SORT_DESC, 1);
99
100 // 2. Define the link builder function
107 $linkBuilder = static function (array $file) use ($client_dir_name) {
108 return DOL_URL_ROOT . '/document.php?modulepart=societe&attachment=1&file=' . urlencode($client_dir_name . '/' . $file['name']);
109 };
110
111 // 3. Encapsulate the link builder in an array, as required by displayDocumentTable
112 $linkBuilderArray = [
113 'file' => $linkBuilder
114 ];
115
116 // 4. Call the correct parent method (displayDocumentTable) with the correct parameter type
118 $langs->trans('MyDocuments'),
119 $fileList,
120 $langs->trans('NoDocumentAvailable'),
121 $linkBuilderArray
122 );
123 }
124
125 print '</main>';
126
127 $this->loadTemplate('footer');
128 }
129}
displayDocumentTable($title, $itemList, $emptyMessage, array $linkBuilder)
Renders an HTML file browser table for a given list of files and directories.
static getInstance()
Singleton method to create one instance of this object.
display404()
Display error template.
loadTemplate($templateName, $vars=false)
Load a template .tpl file.
Class for DocumentListController.
action()
Action method is called before HTML output.
display()
Build and display the page.
checkAccess()
Check access rights for this page.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42