20use Luracast\Restler\RestException;
22require_once DOL_DOCUMENT_ROOT.
'/api/class/api.class.php';
23require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
24require_once DOL_DOCUMENT_ROOT.
'/core/class/objectlink.class.php';
38 public static $FIELDS = array(
97 $clean_field = $this->
_checkValForAPI($field, $value, $this->objectlink);
107 if (in_array($field, $intFields)) {
108 $this->objectlink->$field = (int) $clean_field;
110 $this->objectlink->$field = (
string) $clean_field;
136 public function create($request_data =
null)
139 $result = $this->
_validate($request_data);
141 foreach ($request_data as $field => $value) {
142 if ($field ==
'notrigger') {
143 $this->notrigger = (int) $value;
150 $srctype = $this->objectlink->sourcetype;
151 if ($this->objectlink->sourcetype ==
'subscription') {
152 $srctype =
'adherent';
154 if ($this->objectlink->sourcetype ==
'conferenceorboothattendee') {
157 $tgttype = $this->objectlink->targettype;
158 if ($this->objectlink->targettype ==
'subscription') {
159 $tgttype =
'adherent';
161 if ($this->objectlink->targettype ==
'conferenceorboothattendee') {
164 if (!DolibarrApiAccess::$user->hasRight((
string) $srctype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $srctype,
'write')) {
165 throw new RestException(403,
'denied access to create the objectlinks sourcetype='.$this->objectlink->sourcetype);
167 if (!DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'write')) {
168 throw new RestException(403,
'denied access to create the objectlinks targettype='.$this->objectlink->targettype);
171 throw new RestException(403,
'denied access to create the objectlinks sourcetype='.$this->objectlink->sourcetype);
174 throw new RestException(403,
'denied access to create the objectlinks targettype='.$this->objectlink->targettype);
178 $result = $this->objectlink->create(DolibarrApiAccess::$user, $this->objectlink->fk_source, $this->objectlink->sourcetype, $this->objectlink->fk_target, $this->objectlink->targettype, $this->objectlink->relationtype, $this->notrigger);
181 throw new RestException(500,
'when create objectlink : '.$this->objectlink->error);
185 throw new RestException(304,
'Object link already exists');
191 'message' =>
'object link created'
213 $result = $this->objectlink->fetch(
$id);
215 $srctype = $this->objectlink->sourcetype;
216 if ($this->objectlink->sourcetype ==
'subscription') {
217 $srctype =
'adherent';
219 if ($this->objectlink->sourcetype ==
'conferenceorboothattendee') {
222 $tgttype = $this->objectlink->targettype;
223 if ($this->objectlink->targettype ==
'subscription') {
224 $tgttype =
'adherent';
226 if ($this->objectlink->targettype ==
'conferenceorboothattendee') {
229 if (!DolibarrApiAccess::$user->hasRight(((
string) $srctype),
'creer') && !DolibarrApiAccess::$user->hasRight(((
string) $srctype),
'write')) {
230 throw new RestException(403,
'denied access to the objectlinks sourcetype');
232 if (!DolibarrApiAccess::$user->hasRight(((
string) $tgttype),
'creer') && !DolibarrApiAccess::$user->hasRight(((
string) $tgttype),
'write')) {
233 throw new RestException(403,
'denied access to the objectlinks targettype');
236 throw new RestException(403,
'denied access to the objectlinks sourcetype');
239 throw new RestException(403,
'denied access to the objectlinks targettype');
242 throw new RestException(404,
'Object Link not found');
245 if (!$this->objectlink->delete(DolibarrApiAccess::$user)) {
246 throw new RestException(500,
'Error when delete objectlink : '.$this->objectlink->error);
252 'message' =>
'object link deleted'
275 public function getByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype =
null)
277 $request_data = array(
278 'fk_source' => ((
int) $fk_source),
279 'sourcetype' => (
string) $sourcetype,
280 'fk_target' => ((
int) $fk_target),
281 'targettype' => (
string) $targettype,
282 'relationtype' => $relationtype,
286 $result = $this->
_validate($request_data);
288 foreach ($request_data as $field => $value) {
293 $srctype = $this->objectlink->sourcetype;
294 if ($this->objectlink->sourcetype ==
'subscription') {
295 $srctype =
'adherent';
297 if ($this->objectlink->sourcetype ==
'conferenceorboothattendee') {
300 $tgttype = $this->objectlink->targettype;
301 if ($this->objectlink->targettype ==
'subscription') {
302 $tgttype =
'adherent';
304 if ($this->objectlink->targettype ==
'conferenceorboothattendee') {
307 if (!DolibarrApiAccess::$user->hasRight((
string) $srctype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $srctype,
'write')) {
308 throw new RestException(403,
'denied access to get the objectlinks sourcetype='.$this->objectlink->sourcetype);
310 if (!DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'write')) {
311 throw new RestException(403,
'denied access to get the objectlinks targettype='.$this->objectlink->targettype);
314 throw new RestException(403,
'denied access to the objectlinks sourcetype');
317 throw new RestException(403,
'denied access to the objectlinks targettype');
320 $findresult = $this->objectlink->fetchByValues($this->objectlink->fk_source, $this->objectlink->sourcetype, $this->objectlink->fk_target, $this->objectlink->targettype, $this->objectlink->relationtype);
322 if ($findresult < 0) {
323 throw new RestException(500,
'Error when finding objectlink : '.$this->objectlink->error);
324 } elseif ($findresult > 0) {
327 throw new RestException(404,
'Object Link not found');
351 public function deleteByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype =
null, $notrigger = 0)
353 $request_data = array(
354 'fk_source' => ((
int) $fk_source),
355 'sourcetype' => (
string) $sourcetype,
356 'fk_target' => ((
int) $fk_target),
357 'targettype' => (
string) $targettype,
358 'relationtype' => $relationtype,
362 $result = $this->
_validate($request_data);
364 foreach ($request_data as $field => $value) {
369 $srctype = $this->objectlink->sourcetype;
370 if ($this->objectlink->sourcetype ==
'subscription') {
371 $srctype =
'adherent';
373 if ($this->objectlink->sourcetype ==
'conferenceorboothattendee') {
376 $tgttype = $this->objectlink->targettype;
377 if ($this->objectlink->targettype ==
'subscription') {
378 $tgttype =
'adherent';
380 if ($this->objectlink->targettype ==
'conferenceorboothattendee') {
383 if (!DolibarrApiAccess::$user->hasRight((
string) $srctype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $srctype,
'write')) {
384 throw new RestException(403,
'denied access to delete the objectlinks sourcetype='.$this->objectlink->sourcetype);
386 if (!DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'write')) {
387 throw new RestException(403,
'denied access to delete the objectlinks targettype='.$this->objectlink->targettype);
390 throw new RestException(403,
'denied access to the objectlinks sourcetype');
393 throw new RestException(403,
'denied access to the objectlinks targettype');
396 $findresult = $this->objectlink->fetchByValues($this->objectlink->fk_source, $this->objectlink->sourcetype, $this->objectlink->fk_target, $this->objectlink->targettype, $this->objectlink->relationtype);
398 if ($findresult < 0) {
399 throw new RestException(500,
'Error when finding objectlink : '.$this->objectlink->error);
400 } elseif ($findresult > 0) {
401 $result = $this->objectlink->delete(DolibarrApiAccess::$user, $notrigger);
404 throw new RestException(500,
'Error when delete objectlink : '.$this->objectlink->error);
410 'message' =>
'object link deleted'
414 throw new RestException(404,
'Object Link not found');
433 $result = $this->objectlink->fetch(
$id);
435 $srctype = $this->objectlink->sourcetype;
436 if ($this->objectlink->sourcetype ==
'subscription') {
437 $srctype =
'adherent';
439 if ($this->objectlink->sourcetype ==
'conferenceorboothattendee') {
442 $tgttype = $this->objectlink->targettype;
443 if ($this->objectlink->targettype ==
'subscription') {
444 $tgttype =
'adherent';
446 if ($this->objectlink->targettype ==
'conferenceorboothattendee') {
449 if (!DolibarrApiAccess::$user->hasRight(((
string) $srctype),
'lire') && !DolibarrApiAccess::$user->hasRight(((
string) $srctype),
'read')) {
450 throw new RestException(403,
'denied access to the objectlinks sourcetype');
452 if (!DolibarrApiAccess::$user->hasRight(((
string) $tgttype),
'lire') && !DolibarrApiAccess::$user->hasRight(((
string) $tgttype),
'read')) {
453 throw new RestException(403,
'denied access to the objectlinks targettype');
456 throw new RestException(403,
'denied access to the objectlinks sourcetype');
459 throw new RestException(403,
'denied access to the objectlinks targettype');
462 throw new RestException(404,
'Object Link not found');
489 unset(
$object->array_languages);
491 unset(
$object->linkedObjectsIds);
507 unset(
$object->barcode_type_coder);
508 unset(
$object->mode_reglement_id);
509 unset(
$object->cond_reglement_id);
510 unset(
$object->demand_reason_id);
511 unset(
$object->transport_mode_id);
512 unset(
$object->shipping_method_id);
513 unset(
$object->shipping_method);
514 unset(
$object->fk_multicurrency);
515 unset(
$object->multicurrency_code);
516 unset(
$object->multicurrency_tx);
517 unset(
$object->multicurrency_total_ht);
518 unset(
$object->multicurrency_total_tva);
519 unset(
$object->multicurrency_total_ttc);
520 unset(
$object->multicurrency_total_localtax1);
521 unset(
$object->multicurrency_total_localtax2);
528 unset(
$object->total_localtax1);
529 unset(
$object->total_localtax2);
532 unset(
$object->actiontypecode);
538 unset(
$object->date_validation);
539 unset(
$object->date_modification);
542 unset(
$object->user_creation_id);
543 unset(
$object->user_validation_id);
544 unset(
$object->user_closing_id);
545 unset(
$object->user_modification_id);
549 unset(
$object->totalcreditnotes);
551 unset(
$object->totalpaid_multicurrency);
552 unset(
$object->totalcreditnotes_multicurrency);
553 unset(
$object->totaldeposits_multicurrency);
555 unset(
$object->cond_reglement_supplier_id);
556 unset(
$object->deposit_percent);
557 unset(
$object->retained_warranty_fk_cond_reglement);
579 $objectlink = array();
580 foreach (ObjectLinks::$FIELDS as $field) {
581 if (!isset($data[$field])) {
582 throw new RestException(400, $field.
" field missing");
584 $objectlink[$field] = $data[$field];
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
_validate($data)
Validate fields before create or update object.
create($request_data=null)
Create object link.
deleteById($id)
Delete an object link.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
__construct()
Constructor of the class.
getByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype=null)
GET object link(s) By Values, not id.
_setObjectLinkField($field, $value)
Set a field of $this->objectlink, with proper type.
getById($id)
Get properties of a ObjectLink object.
_fetch($id)
Get properties of an object link.
deleteByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype=null, $notrigger=0)
Delete object link By Values, not id.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
checkUserAccessToObject($user, array $featuresarray, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='', $dbt_select='rowid', $parenttableforentity='')
Check that access by a given user to an object is ok.