dolibarr 24.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-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
27// $action must be defined
28// $object must be defined (object is loaded in this file with fetch)
29// $cancel must be defined
30// $id or $ref must be defined (object is loaded in this file with fetch)
38'
39@phan-var-force string $action
40@phan-var-force string $cancel
41@phan-var-force string $ref
42@phan-var-force int $id
43';
44
45if (((!empty($id) && $id > 0) || (!empty($ref) && !in_array($action, array('create', 'createtask', 'add')))) && (empty($cancel) || $id > 0)) {
46 if (($id > 0 && is_numeric($id)) || !empty($ref)) { // To discard case when id is list of ids like '1,2,3...'
47 if ($object->element == 'usergroup') {
49 '@phan-var-force UserGroup $object';
50 $ret = $object->fetch($id, (empty($ref) ? '' : $ref), true); // to load $object->members
51 } else {
52 $ret = $object->fetch($id, (empty($ref) ? '' : $ref));
53 }
54 if ($ret > 0) {
55 $object->fetch_thirdparty();
56 $id = $object->id;
57 } else {
58 if (empty($object->error) && !count($object->errors)) {
59 if ($ret < 0) { // if $ret == 0, it means not found.
60 setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors');
61 }
62 } else {
63 setEventMessages($object->error, $object->errors, 'errors');
64 }
65 $action = '';
66 }
67 }
68}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.