dolibarr 21.0.0-beta
actions_fetchobject.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2015-2024 Frédéric France <frederic.france@free.fr>
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 * or see https://www.gnu.org/
18 */
19
26// $action must be defined
27// $object must be defined (object is loaded in this file with fetch)
28// $cancel must be defined
29// $id or $ref must be defined (object is loaded in this file with fetch)
30
31if (((!empty($id) && $id > 0) || (!empty($ref) && !in_array($action, array('create', 'createtask', 'add')))) && (empty($cancel) || $id > 0)) {
32 if (($id > 0 && is_numeric($id)) || !empty($ref)) { // To discard case when id is list of ids like '1,2,3...'
33 if ($object->element == 'usergroup') {
34 $ret = $object->fetch($id, (empty($ref) ? '' : $ref), true); // to load $object->members
35 } else {
36 $ret = $object->fetch($id, (empty($ref) ? '' : $ref));
37 }
38 if ($ret > 0) {
39 $object->fetch_thirdparty();
40 $id = $object->id;
41 } else {
42 if (empty($object->error) && !count($object->errors)) {
43 if ($ret < 0) { // if $ret == 0, it means not found.
44 setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors');
45 }
46 } else {
47 setEventMessages($object->error, $object->errors, 'errors');
48 }
49 $action = '';
50 }
51 }
52}
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.