dolibarr 24.0.0-beta
ticketlist.controller.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Pierre Ardoin <developpeur@lesmetiersdubatiment.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
24require_once DOL_DOCUMENT_ROOT . '/webportal/class/html.formlistwebportal.class.php';
25require_once DOL_DOCUMENT_ROOT . '/webportal/controllers/abstractlist.controller.class.php';
26require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
27
32{
36 public $userStaticCache = array();
37
43 public function checkAccess()
44 {
45 $this->accessRight = isModEnabled('ticket') && getDolGlobalInt('WEBPORTAL_TICKET_LIST_ACCESS');
46
47 return parent::checkAccess();
48 }
49
56 public function action()
57 {
58 global $langs;
59
61 if (!$context->controllerInstance->checkAccess()) {
62 return -1;
63 }
64
65 $langs->loadLangs(array('ticket', 'companies', 'products'));
66
67 $context->title = $langs->trans('WebPortalTicketListTitle');
68 $context->desc = $langs->trans('WebPortalTicketListDesc');
69 $context->menu_active[] = 'ticket_list';
70
71 $this->formList = new FormListWebPortal($this->db);
72 $this->formList->init($this, 'ticket');
73
74 $hookRes = $this->hookDoAction();
75 if (empty($hookRes)) {
76 $this->formList->doActions();
77 }
78
79 $sqlBody = " AND t.fk_soc = ".((int) $context->logged_thirdparty->id);
80 $sqlBody .= " AND t.fk_statut <> 9";
81 $this->formList->setSqlRequest('', $sqlBody);
82
83 $this->formList->loadRecords();
84 $this->formList->setParams();
85 $this->formList->setColumnsVisibility();
86
87 return 1;
88 }
89
90
96 public function listSetArrayFields()
97 {
98 $this->formList->arrayfields['consultation_link'] = array(
99 'type' => '',
100 'label' => 'WebPortalTicketConsultation',
101 'checked' => 1,
102 'enabled' => isModEnabled('ticket'),
103 'visible' => 1,
104 'position' => 10003,
105 'help' => '',
106 );
107 }
108
117 public function listPrintValueBefore($field_key, $field_spec, &$record)
118 {
119 global $langs;
120
121 if ($field_key === 'fk_statut') {
122 $this->formList->object->status = (int) ($record->fk_statut ?? 0);
123 $this->formList->object->fk_statut = (int) ($record->fk_statut ?? 0);
124 return $this->formList->object->getLibStatut(5);
125 }
126
127 if ($field_key === 'fk_user_assign') {
128 $idUserAssign = (int) ($record->fk_user_assign ?? 0);
129 if ($idUserAssign <= 0) {
130 return $langs->trans('WebPortalTicketNotAssigned');
131 }
132
133 if (!isset($this->userStaticCache[$idUserAssign])) {
134 $userStatic = new User($this->db);
135 $userStatic->fetch($idUserAssign);
136 $this->userStaticCache[$idUserAssign] = $userStatic;
137 }
138
139 if (!empty($this->userStaticCache[$idUserAssign]->id)) {
140 return $this->userStaticCache[$idUserAssign]->getFullName($langs);
141 }
142
143 return $langs->trans('Unknown');
144 }
145
146 if ($field_key === 'consultation_link') {
147 $baseurl = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.'/public/ticket/');
148 $baseurl = rtrim($baseurl, '/').'/';
149 if ((int) ($record->fk_user_create ?? 0) <= 0 && !empty($record->track_id)) {
150 $url = $baseurl.'view.php?track_id='.urlencode((string) $record->track_id);
151 if (!empty($record->origin_email)) {
152 $url .= '&email='.urlencode((string) $record->origin_email);
153 }
154 return '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$langs->trans('WebPortalTicketConsultationLink').'</a>';
155 }
156
157 return img_object($langs->trans('WebPortalTicketConsultationTooltipNotPublic'), 'info', 'class="classfortooltip"');
158 }
159
160 return '';
161 }
162
168 public function display()
169 {
171 if (!$context->controllerInstance->checkAccess()) {
172 $this->display404();
173 return;
174 }
175
176 $this->loadTemplate('header');
177 $this->loadTemplate('menu');
178 $this->loadTemplate('hero-header-banner');
179
180 $hookRes = $this->hookPrintPageView();
181 if (empty($hookRes)) {
182 print '<main class="container">';
183 $this->loadTemplate('list');
184 print '</main>';
185 }
186
187 $this->loadTemplate('footer');
188 }
189}
Class for AbstractListController.
static getInstance()
Singleton method to create one instance of this object.
hookPrintPageView($parameters=array())
Execute hook PrintPageView.
display404()
Display error template.
hookDoAction($parameters=array())
Execute hook doActions.
loadTemplate($templateName, $vars=false)
Load a template .tpl file.
Class to manage generation of HTML components Only common components for WebPortal must be here.
Class for TicketListController.
action()
Action method is called before html output can be used to manage security and change context.
listPrintValueBefore($field_key, $field_spec, &$record)
Called before print value for list.
checkAccess()
Check current access to controller.
listSetArrayFields()
Set array fields for ticket list.
Class to manage Dolibarr users.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42