dolibarr  17.0.4
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 
30 {
34  public $db;
35 
39  public $error = '';
40 
44  public $errors = array();
45 
46 
50  public $results = array();
51 
55  public $resprints;
56 
60  public $priority;
61 
62 
68  public function __construct($db)
69  {
70  $this->db = $db;
71  }
72 
73 
84  public function getNomUrl($parameters, &$object, &$action)
85  {
86  global $db, $langs, $conf, $user;
87  $this->resprints = '';
88  return 0;
89  }
90 
100  public function doActions($parameters, &$object, &$action, $hookmanager)
101  {
102  global $conf, $user, $langs;
103 
104  $error = 0; // Error counter
105 
106  /* print_r($parameters); print_r($object); echo "action: " . $action; */
107  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
108  // Do what you want here...
109  // You can for example call global vars like $fieldstosearchall to overwrite them, or update database depending on $action and $_POST values.
110  }
111 
112  if (!$error) {
113  $this->results = array('myreturn' => 999);
114  $this->resprints = 'A text to show';
115  return 0; // or return 1 to replace standard code
116  } else {
117  $this->errors[] = 'Error message';
118  return -1;
119  }
120  }
121 
122 
132  public function doMassActions($parameters, &$object, &$action, $hookmanager)
133  {
134  global $conf, $user, $langs;
135 
136  $error = 0; // Error counter
137 
138  /* print_r($parameters); print_r($object); echo "action: " . $action; */
139  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
140  foreach ($parameters['toselect'] as $objectid) {
141  // Do action on each object id
142  }
143  }
144 
145  if (!$error) {
146  $this->results = array('myreturn' => 999);
147  $this->resprints = 'A text to show';
148  return 0; // or return 1 to replace standard code
149  } else {
150  $this->errors[] = 'Error message';
151  return -1;
152  }
153  }
154 
155 
165  public function addMoreMassActions($parameters, &$object, &$action, $hookmanager)
166  {
167  global $conf, $user, $langs;
168 
169  $error = 0; // Error counter
170  $disabled = 1;
171 
172  /* print_r($parameters); print_r($object); echo "action: " . $action; */
173  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
174  $this->resprints = '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>'.$langs->trans("MyModuleMassAction").'</option>';
175  }
176 
177  if (!$error) {
178  return 0; // or return 1 to replace standard code
179  } else {
180  $this->errors[] = 'Error message';
181  return -1;
182  }
183  }
184 
185 
186 
197  public function beforePDFCreation($parameters, &$object, &$action)
198  {
199  global $conf, $user, $langs;
200  global $hookmanager;
201 
202  $outputlangs = $langs;
203 
204  $ret = 0; $deltemp = array();
205  dol_syslog(get_class($this).'::executeHooks action='.$action);
206 
207  /* print_r($parameters); print_r($object); echo "action: " . $action; */
208  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
209  }
210 
211  return $ret;
212  }
213 
224  public function afterPDFCreation($parameters, &$pdfhandler, &$action)
225  {
226  global $conf, $user, $langs;
227  global $hookmanager;
228 
229  $outputlangs = $langs;
230 
231  $ret = 0; $deltemp = array();
232  dol_syslog(get_class($this).'::executeHooks action='.$action);
233 
234  /* print_r($parameters); print_r($object); echo "action: " . $action; */
235  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) {
236  // do something only for the context 'somecontext1' or 'somecontext2'
237  }
238 
239  return $ret;
240  }
241 
242 
243 
252  public function loadDataForCustomReports($parameters, &$action, $hookmanager)
253  {
254  global $conf, $user, $langs;
255 
256  $langs->load("mymodule@mymodule");
257 
258  $this->results = array();
259 
260  $head = array();
261  $h = 0;
262 
263  if ($parameters['tabfamily'] == 'mymodule') {
264  $head[$h][0] = dol_buildpath('/module/index.php', 1);
265  $head[$h][1] = $langs->trans("Home");
266  $head[$h][2] = 'home';
267  $h++;
268 
269  $this->results['title'] = $langs->trans("MyModule");
270  $this->results['picto'] = 'mymodule@mymodule';
271  }
272 
273  $head[$h][0] = 'customreports.php?objecttype='.$parameters['objecttype'].(empty($parameters['tabfamily']) ? '' : '&tabfamily='.$parameters['tabfamily']);
274  $head[$h][1] = $langs->trans("CustomReports");
275  $head[$h][2] = 'customreports';
276 
277  $this->results['head'] = $head;
278 
279  return 1;
280  }
281 
282 
283 
294  public function restrictedArea($parameters, &$action, $hookmanager)
295  {
296  global $user;
297 
298  if ($parameters['features'] == 'myobject') {
299  if ($user->rights->mymodule->myobject->read) {
300  $this->results['result'] = 1;
301  return 1;
302  } else {
303  $this->results['result'] = 0;
304  return 1;
305  }
306  }
307 
308  return 0;
309  }
310 
322  public function completeTabsHead(&$parameters, &$object, &$action, $hookmanager)
323  {
324  global $langs, $conf, $user;
325 
326  if (!isset($parameters['object']->element)) {
327  return 0;
328  }
329  if ($parameters['mode'] == 'remove') {
330  // utilisé si on veut faire disparaitre des onglets.
331  return 0;
332  } elseif ($parameters['mode'] == 'add') {
333  $langs->load('mymodule@mymodule');
334  // utilisé si on veut ajouter des onglets.
335  $counter = count($parameters['head']);
336  $element = $parameters['object']->element;
337  $id = $parameters['object']->id;
338  // verifier le type d'onglet comme member_stats où ça ne doit pas apparaitre
339  // if (in_array($element, ['societe', 'member', 'contrat', 'fichinter', 'project', 'propal', 'commande', 'facture', 'order_supplier', 'invoice_supplier'])) {
340  if (in_array($element, ['context1', 'context2'])) {
341  $datacount = 0;
342 
343  $parameters['head'][$counter][0] = dol_buildpath('/mymodule/mymodule_tab.php', 1) . '?id=' . $id . '&amp;module='.$element;
344  $parameters['head'][$counter][1] = $langs->trans('MyModuleTab');
345  if ($datacount > 0) {
346  $parameters['head'][$counter][1] .= '<span class="badge marginleftonlyshort">' . $datacount . '</span>';
347  }
348  $parameters['head'][$counter][2] = 'mymoduleemails';
349  $counter++;
350  }
351  if ($counter > 0 && (int) DOL_VERSION < 14) {
352  $this->results = $parameters['head'];
353  // return 1 to replace standard code
354  return 1;
355  } else {
356  // en V14 et + $parameters['head'] est modifiable par référence
357  return 0;
358  }
359  }
360  }
361 
362  /* Add here any other hooked methods... */
363 }
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.
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.
$conf db
API class for accounts.
Definition: inc.php:41