dolibarr 20.0.0
actions_mymodule.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) ---Put here your own copyright and developer email---
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php';
28
33{
37 public $db;
38
42 public $error = '';
43
47 public $errors = array();
48
49
53 public $results = array();
54
58 public $resprints;
59
63 public $priority;
64
65
71 public function __construct($db)
72 {
73 $this->db = $db;
74 }
75
76
87 public function getNomUrl($parameters, &$object, &$action)
88 {
89 global $db, $langs, $conf, $user;
90 $this->resprints = '';
91 return 0;
92 }
93
103 public function doActions($parameters, &$object, &$action, $hookmanager)
104 {
105 global $conf, $user, $langs;
106
107 $error = 0; // Error counter
108
109 /* print_r($parameters); print_r($object); echo "action: " . $action; */
110 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
111 // Do what you want here...
112 // You can for example load and use call global vars like $fieldstosearchall to overwrite them, or update database depending on $action and GETPOST values.
113 }
114
115 if (!$error) {
116 $this->results = array('myreturn' => 999);
117 $this->resprints = 'A text to show';
118 return 0; // or return 1 to replace standard code
119 } else {
120 $this->errors[] = 'Error message';
121 return -1;
122 }
123 }
124
125
135 public function doMassActions($parameters, &$object, &$action, $hookmanager)
136 {
137 global $conf, $user, $langs;
138
139 $error = 0; // Error counter
140
141 /* print_r($parameters); print_r($object); echo "action: " . $action; */
142 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
143 foreach ($parameters['toselect'] as $objectid) {
144 // Do action on each object id
145 }
146 }
147
148 if (!$error) {
149 $this->results = array('myreturn' => 999);
150 $this->resprints = 'A text to show';
151 return 0; // or return 1 to replace standard code
152 } else {
153 $this->errors[] = 'Error message';
154 return -1;
155 }
156 }
157
158
168 public function addMoreMassActions($parameters, &$object, &$action, $hookmanager)
169 {
170 global $conf, $user, $langs;
171
172 $error = 0; // Error counter
173 $disabled = 1;
174
175 /* print_r($parameters); print_r($object); echo "action: " . $action; */
176 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
177 $this->resprints = '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>'.$langs->trans("MyModuleMassAction").'</option>';
178 }
179
180 if (!$error) {
181 return 0; // or return 1 to replace standard code
182 } else {
183 $this->errors[] = 'Error message';
184 return -1;
185 }
186 }
187
188
189
200 public function beforePDFCreation($parameters, &$object, &$action)
201 {
202 global $conf, $user, $langs;
203 global $hookmanager;
204
205 $outputlangs = $langs;
206
207 $ret = 0;
208 $deltemp = array();
209 dol_syslog(get_class($this).'::executeHooks action='.$action);
210
211 /* print_r($parameters); print_r($object); echo "action: " . $action; */
212 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
213 }
214
215 return $ret;
216 }
217
228 public function afterPDFCreation($parameters, &$pdfhandler, &$action)
229 {
230 global $conf, $user, $langs;
231 global $hookmanager;
232
233 $outputlangs = $langs;
234
235 $ret = 0;
236 $deltemp = array();
237 dol_syslog(get_class($this).'::executeHooks action='.$action);
238
239 /* print_r($parameters); print_r($object); echo "action: " . $action; */
240 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) {
241 // do something only for the context 'somecontext1' or 'somecontext2'
242 }
243
244 return $ret;
245 }
246
247
248
257 public function loadDataForCustomReports($parameters, &$action, $hookmanager)
258 {
259 global $langs;
260
261 $langs->load("mymodule@mymodule");
262
263 $this->results = array();
264
265 $head = array();
266 $h = 0;
267
268 if ($parameters['tabfamily'] == 'mymodule') {
269 $head[$h][0] = dol_buildpath('/module/index.php', 1);
270 $head[$h][1] = $langs->trans("Home");
271 $head[$h][2] = 'home';
272 $h++;
273
274 $this->results['title'] = $langs->trans("MyModule");
275 $this->results['picto'] = 'mymodule@mymodule';
276 }
277
278 $head[$h][0] = 'customreports.php?objecttype='.$parameters['objecttype'].(empty($parameters['tabfamily']) ? '' : '&tabfamily='.$parameters['tabfamily']);
279 $head[$h][1] = $langs->trans("CustomReports");
280 $head[$h][2] = 'customreports';
281
282 $this->results['head'] = $head;
283
284 $arrayoftypes = array();
285 //$arrayoftypes['mymodule_myobject'] = array('label' => 'MyObject', 'picto'=>'myobject@mymodule', 'ObjectClassName' => 'MyObject', 'enabled' => isModEnabled('mymodule'), 'ClassPath' => "/mymodule/class/myobject.class.php", 'langs'=>'mymodule@mymodule')
286
287 $this->results['arrayoftype'] = $arrayoftypes;
288
289 return 0;
290 }
291
292
293
304 public function restrictedArea($parameters, &$action, $hookmanager)
305 {
306 global $user;
307
308 if ($parameters['features'] == 'myobject') {
309 if ($user->hasRight('mymodule', 'myobject', 'read')) {
310 $this->results['result'] = 1;
311 return 1;
312 } else {
313 $this->results['result'] = 0;
314 return 1;
315 }
316 }
317
318 return 0;
319 }
320
332 public function completeTabsHead(&$parameters, &$object, &$action, $hookmanager)
333 {
334 global $langs, $conf, $user;
335
336 if (!isset($parameters['object']->element)) {
337 return 0;
338 }
339 if ($parameters['mode'] == 'remove') {
340 // used to make some tabs removed
341 return 0;
342 } elseif ($parameters['mode'] == 'add') {
343 $langs->load('mymodule@mymodule');
344 // used when we want to add some tabs
345 $counter = count($parameters['head']);
346 $element = $parameters['object']->element;
347 $id = $parameters['object']->id;
348 // verifier le type d'onglet comme member_stats où ça ne doit pas apparaitre
349 // if (in_array($element, ['societe', 'member', 'contrat', 'fichinter', 'project', 'propal', 'commande', 'facture', 'order_supplier', 'invoice_supplier'])) {
350 if (in_array($element, ['context1', 'context2'])) {
351 $datacount = 0;
352
353 $parameters['head'][$counter][0] = dol_buildpath('/mymodule/mymodule_tab.php', 1) . '?id=' . $id . '&amp;module='.$element;
354 $parameters['head'][$counter][1] = $langs->trans('MyModuleTab');
355 if ($datacount > 0) {
356 $parameters['head'][$counter][1] .= '<span class="badge marginleftonlyshort">' . $datacount . '</span>';
357 }
358 $parameters['head'][$counter][2] = 'mymoduleemails';
359 $counter++;
360 }
361 if ($counter > 0 && (int) DOL_VERSION < 14) {
362 $this->results = $parameters['head'];
363 // return 1 to replace standard code
364 return 1;
365 } else {
366 // en V14 et + $parameters['head'] est modifiable par référence
367 return 0;
368 }
369 } else {
370 // Bad value for $parameters['mode']
371 return -1;
372 }
373 }
374
375 /* Add here any other hooked methods... */
376}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class ActionsMyModule.
__construct($db)
Constructor.
doActions($parameters, &$object, &$action, $hookmanager)
Overloading the doActions function : replacing the parent's function with the one below.
loadDataForCustomReports($parameters, &$action, $hookmanager)
Overloading the loadDataForCustomReports function : returns data to complete the customreport tool.
doMassActions($parameters, &$object, &$action, $hookmanager)
Overloading the doMassActions function : replacing the parent's function with the one below.
restrictedArea($parameters, &$action, $hookmanager)
Overloading the restrictedArea function : check permission on an object.
afterPDFCreation($parameters, &$pdfhandler, &$action)
Execute action.
completeTabsHead(&$parameters, &$object, &$action, $hookmanager)
Execute action completeTabsHead.
beforePDFCreation($parameters, &$object, &$action)
Execute action.
addMoreMassActions($parameters, &$object, &$action, $hookmanager)
Overloading the addMoreMassActions function : replacing the parent's function with the one below.
getNomUrl($parameters, &$object, &$action)
Execute action.
Parent class of all other hook actions classes.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.