dolibarr 19.0.3
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 *
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
26require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php';
27
32{
36 public $db;
37
41 public $error = '';
42
46 public $errors = array();
47
48
52 public $results = array();
53
57 public $resprints;
58
62 public $priority;
63
64
70 public function __construct($db)
71 {
72 $this->db = $db;
73 }
74
75
86 public function getNomUrl($parameters, &$object, &$action)
87 {
88 global $db, $langs, $conf, $user;
89 $this->resprints = '';
90 return 0;
91 }
92
102 public function doActions($parameters, &$object, &$action, $hookmanager)
103 {
104 global $conf, $user, $langs;
105
106 $error = 0; // Error counter
107
108 /* print_r($parameters); print_r($object); echo "action: " . $action; */
109 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
110 // Do what you want here...
111 // You can for example call global vars like $fieldstosearchall to overwrite them, or update database depending on $action and $_POST values.
112 }
113
114 if (!$error) {
115 $this->results = array('myreturn' => 999);
116 $this->resprints = 'A text to show';
117 return 0; // or return 1 to replace standard code
118 } else {
119 $this->errors[] = 'Error message';
120 return -1;
121 }
122 }
123
124
134 public function doMassActions($parameters, &$object, &$action, $hookmanager)
135 {
136 global $conf, $user, $langs;
137
138 $error = 0; // Error counter
139
140 /* print_r($parameters); print_r($object); echo "action: " . $action; */
141 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
142 foreach ($parameters['toselect'] as $objectid) {
143 // Do action on each object id
144 }
145 }
146
147 if (!$error) {
148 $this->results = array('myreturn' => 999);
149 $this->resprints = 'A text to show';
150 return 0; // or return 1 to replace standard code
151 } else {
152 $this->errors[] = 'Error message';
153 return -1;
154 }
155 }
156
157
167 public function addMoreMassActions($parameters, &$object, &$action, $hookmanager)
168 {
169 global $conf, $user, $langs;
170
171 $error = 0; // Error counter
172 $disabled = 1;
173
174 /* print_r($parameters); print_r($object); echo "action: " . $action; */
175 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
176 $this->resprints = '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>'.$langs->trans("MyModuleMassAction").'</option>';
177 }
178
179 if (!$error) {
180 return 0; // or return 1 to replace standard code
181 } else {
182 $this->errors[] = 'Error message';
183 return -1;
184 }
185 }
186
187
188
199 public function beforePDFCreation($parameters, &$object, &$action)
200 {
201 global $conf, $user, $langs;
202 global $hookmanager;
203
204 $outputlangs = $langs;
205
206 $ret = 0;
207 $deltemp = array();
208 dol_syslog(get_class($this).'::executeHooks action='.$action);
209
210 /* print_r($parameters); print_r($object); echo "action: " . $action; */
211 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
212 }
213
214 return $ret;
215 }
216
227 public function afterPDFCreation($parameters, &$pdfhandler, &$action)
228 {
229 global $conf, $user, $langs;
230 global $hookmanager;
231
232 $outputlangs = $langs;
233
234 $ret = 0;
235 $deltemp = array();
236 dol_syslog(get_class($this).'::executeHooks action='.$action);
237
238 /* print_r($parameters); print_r($object); echo "action: " . $action; */
239 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) {
240 // do something only for the context 'somecontext1' or 'somecontext2'
241 }
242
243 return $ret;
244 }
245
246
247
256 public function loadDataForCustomReports($parameters, &$action, $hookmanager)
257 {
258 global $conf, $user, $langs;
259
260 $langs->load("mymodule@mymodule");
261
262 $this->results = array();
263
264 $head = array();
265 $h = 0;
266
267 if ($parameters['tabfamily'] == 'mymodule') {
268 $head[$h][0] = dol_buildpath('/module/index.php', 1);
269 $head[$h][1] = $langs->trans("Home");
270 $head[$h][2] = 'home';
271 $h++;
272
273 $this->results['title'] = $langs->trans("MyModule");
274 $this->results['picto'] = 'mymodule@mymodule';
275 }
276
277 $head[$h][0] = 'customreports.php?objecttype='.$parameters['objecttype'].(empty($parameters['tabfamily']) ? '' : '&tabfamily='.$parameters['tabfamily']);
278 $head[$h][1] = $langs->trans("CustomReports");
279 $head[$h][2] = 'customreports';
280
281 $this->results['head'] = $head;
282
283 return 1;
284 }
285
286
287
298 public function restrictedArea($parameters, &$action, $hookmanager)
299 {
300 global $user;
301
302 if ($parameters['features'] == 'myobject') {
303 if ($user->hasRight('mymodule', 'myobject', 'read')) {
304 $this->results['result'] = 1;
305 return 1;
306 } else {
307 $this->results['result'] = 0;
308 return 1;
309 }
310 }
311
312 return 0;
313 }
314
326 public function completeTabsHead(&$parameters, &$object, &$action, $hookmanager)
327 {
328 global $langs, $conf, $user;
329
330 if (!isset($parameters['object']->element)) {
331 return 0;
332 }
333 if ($parameters['mode'] == 'remove') {
334 // used to make some tabs removed
335 return 0;
336 } elseif ($parameters['mode'] == 'add') {
337 $langs->load('mymodule@mymodule');
338 // used when we want to add some tabs
339 $counter = count($parameters['head']);
340 $element = $parameters['object']->element;
341 $id = $parameters['object']->id;
342 // verifier le type d'onglet comme member_stats où ça ne doit pas apparaitre
343 // if (in_array($element, ['societe', 'member', 'contrat', 'fichinter', 'project', 'propal', 'commande', 'facture', 'order_supplier', 'invoice_supplier'])) {
344 if (in_array($element, ['context1', 'context2'])) {
345 $datacount = 0;
346
347 $parameters['head'][$counter][0] = dol_buildpath('/mymodule/mymodule_tab.php', 1) . '?id=' . $id . '&amp;module='.$element;
348 $parameters['head'][$counter][1] = $langs->trans('MyModuleTab');
349 if ($datacount > 0) {
350 $parameters['head'][$counter][1] .= '<span class="badge marginleftonlyshort">' . $datacount . '</span>';
351 }
352 $parameters['head'][$counter][2] = 'mymoduleemails';
353 $counter++;
354 }
355 if ($counter > 0 && (int) DOL_VERSION < 14) {
356 $this->results = $parameters['head'];
357 // return 1 to replace standard code
358 return 1;
359 } else {
360 // en V14 et + $parameters['head'] est modifiable par référence
361 return 0;
362 }
363 } else {
364 // Bad value for $parameters['mode']
365 return -1;
366 }
367 }
368
369 /* Add here any other hooked methods... */
370}
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.