dolibarr  13.0.2
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 
57 
63  public function __construct($db)
64  {
65  $this->db = $db;
66  }
67 
68 
79  public function getNomUrl($parameters, &$object, &$action)
80  {
81  global $db, $langs, $conf, $user;
82  $this->resprints = '';
83  return 0;
84  }
85 
95  public function doActions($parameters, &$object, &$action, $hookmanager)
96  {
97  global $conf, $user, $langs;
98 
99  $error = 0; // Error counter
100 
101  /* print_r($parameters); print_r($object); echo "action: " . $action; */
102  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) // do something only for the context 'somecontext1' or 'somecontext2'
103  {
104  // Do what you want here...
105  // You can for example call global vars like $fieldstosearchall to overwrite them, or update database depending on $action and $_POST values.
106  }
107 
108  if (!$error) {
109  $this->results = array('myreturn' => 999);
110  $this->resprints = 'A text to show';
111  return 0; // or return 1 to replace standard code
112  } else {
113  $this->errors[] = 'Error message';
114  return -1;
115  }
116  }
117 
118 
128  public function doMassActions($parameters, &$object, &$action, $hookmanager)
129  {
130  global $conf, $user, $langs;
131 
132  $error = 0; // Error counter
133 
134  /* print_r($parameters); print_r($object); echo "action: " . $action; */
135  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) // do something only for the context 'somecontext1' or 'somecontext2'
136  {
137  foreach ($parameters['toselect'] as $objectid)
138  {
139  // Do action on each object id
140  }
141  }
142 
143  if (!$error) {
144  $this->results = array('myreturn' => 999);
145  $this->resprints = 'A text to show';
146  return 0; // or return 1 to replace standard code
147  } else {
148  $this->errors[] = 'Error message';
149  return -1;
150  }
151  }
152 
153 
163  public function addMoreMassActions($parameters, &$object, &$action, $hookmanager)
164  {
165  global $conf, $user, $langs;
166 
167  $error = 0; // Error counter
168  $disabled = 1;
169 
170  /* print_r($parameters); print_r($object); echo "action: " . $action; */
171  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) // do something only for the context 'somecontext1' or 'somecontext2'
172  {
173  $this->resprints = '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>'.$langs->trans("MyModuleMassAction").'</option>';
174  }
175 
176  if (!$error) {
177  return 0; // or return 1 to replace standard code
178  } else {
179  $this->errors[] = 'Error message';
180  return -1;
181  }
182  }
183 
184 
185 
196  public function beforePDFCreation($parameters, &$object, &$action)
197  {
198  global $conf, $user, $langs;
199  global $hookmanager;
200 
201  $outputlangs = $langs;
202 
203  $ret = 0; $deltemp = array();
204  dol_syslog(get_class($this).'::executeHooks action='.$action);
205 
206  /* print_r($parameters); print_r($object); echo "action: " . $action; */
207  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) // do something only for the context 'somecontext1' or 'somecontext2'
208  {
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 
311  /* Add here any other hooked methods... */
312 }
restrictedArea($parameters, &$action, $hookmanager)
Overloading the restrictedArea function : check permission on an object.
Class ActionsMyModule.
loadDataForCustomReports($parameters, &$action, $hookmanager)
Overloading the loadDataForCustomReports function : returns data to complete the customreport tool...
addMoreMassActions($parameters, &$object, &$action, $hookmanager)
Overloading the addMoreMassActions function : replacing the parent&#39;s function with the one below...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$conf db
API class for accounts.
Definition: inc.php:54
beforePDFCreation($parameters, &$object, &$action)
Execute action.
doMassActions($parameters, &$object, &$action, $hookmanager)
Overloading the doMassActions function : replacing the parent&#39;s function with the one below...
afterPDFCreation($parameters, &$pdfhandler, &$action)
Execute action.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getNomUrl($parameters, &$object, &$action)
Execute action.
__construct($db)
Constructor.
doActions($parameters, &$object, &$action, $hookmanager)
Overloading the doActions function : replacing the parent&#39;s function with the one below...