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(
98 $clean_field = $this->
_checkValForAPI($field, $value, $this->objectlink);
108 if (in_array($field, $intFields)) {
109 $this->objectlink->$field = (int) $clean_field;
111 $this->objectlink->$field = (string) $clean_field;
137 public function create($request_data =
null)
140 $result = $this->
_validate($request_data);
142 foreach ($request_data as $field => $value) {
143 if ($field ==
'notrigger') {
144 $this->notrigger = (int) $value;
151 $srctype = $this->objectlink->sourcetype;
152 if ($this->objectlink->sourcetype ==
'subscription') {
153 $srctype =
'adherent';
155 $tgttype = $this->objectlink->targettype;
156 if ($this->objectlink->targettype ==
'subscription') {
157 $tgttype =
'adherent';
159 if (!DolibarrApiAccess::$user->hasRight((
string) $srctype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $srctype,
'write')) {
160 throw new RestException(403,
'denied access to create the objectlinks sourcetype='.$this->objectlink->sourcetype);
162 if (!DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'write')) {
163 throw new RestException(403,
'denied access to create the objectlinks targettype='.$this->objectlink->targettype);
166 $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);
169 throw new RestException(500,
'when create objectlink : '.$this->objectlink->error);
173 throw new RestException(304,
'Object link already exists');
179 'message' =>
'object link created'
201 $result = $this->objectlink->fetch(
$id);
203 $srctype = $this->objectlink->sourcetype;
204 if ($this->objectlink->sourcetype ==
'subscription') {
205 $srctype =
'adherent';
207 $tgttype = $this->objectlink->targettype;
208 if ($this->objectlink->targettype ==
'subscription') {
209 $tgttype =
'adherent';
211 if (!DolibarrApiAccess::$user->hasRight(((
string) $srctype),
'lire') && !DolibarrApiAccess::$user->hasRight(((
string) $srctype),
'read')) {
212 throw new RestException(403,
'denied access to the objectlinks sourcetype');
214 if (!DolibarrApiAccess::$user->hasRight(((
string) $tgttype),
'lire') && !DolibarrApiAccess::$user->hasRight(((
string) $tgttype),
'read')) {
215 throw new RestException(403,
'denied access to the objectlinks targettype');
218 throw new RestException(404,
'Object Link not found');
221 if (!$this->objectlink->delete(DolibarrApiAccess::$user)) {
222 throw new RestException(500,
'Error when delete objectlink : '.$this->objectlink->error);
228 'message' =>
'object link deleted'
251 public function getByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype =
null)
253 $request_data = array(
254 'fk_source' => ((
int) $fk_source),
255 'sourcetype' => (
string) $sourcetype,
256 'fk_target' => ((
int) $fk_target),
257 'targettype' => (
string) $targettype,
258 'relationtype' => $relationtype,
262 $result = $this->
_validate($request_data);
264 foreach ($request_data as $field => $value) {
269 $srctype = $this->objectlink->sourcetype;
270 if ($this->objectlink->sourcetype ==
'subscription') {
271 $srctype =
'adherent';
273 $tgttype = $this->objectlink->targettype;
274 if ($this->objectlink->targettype ==
'subscription') {
275 $tgttype =
'adherent';
277 if (!DolibarrApiAccess::$user->hasRight((
string) $srctype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $srctype,
'write')) {
278 throw new RestException(403,
'denied access to get the objectlinks sourcetype='.$this->objectlink->sourcetype);
280 if (!DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'write')) {
281 throw new RestException(403,
'denied access to get the objectlinks targettype='.$this->objectlink->targettype);
284 $findresult = $this->objectlink->fetchByValues($this->objectlink->fk_source, $this->objectlink->sourcetype, $this->objectlink->fk_target, $this->objectlink->targettype, $this->objectlink->relationtype);
286 if ($findresult < 0) {
287 throw new RestException(500,
'Error when finding objectlink : '.$this->objectlink->error);
288 } elseif ($findresult > 0) {
291 throw new RestException(404,
'Object Link not found');
315 public function deleteByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype =
null, $notrigger = 0)
317 $request_data = array(
318 'fk_source' => ((
int) $fk_source),
319 'sourcetype' => (
string) $sourcetype,
320 'fk_target' => ((
int) $fk_target),
321 'targettype' => (
string) $targettype,
322 'relationtype' => $relationtype,
326 $result = $this->
_validate($request_data);
328 foreach ($request_data as $field => $value) {
333 $srctype = $this->objectlink->sourcetype;
334 if ($this->objectlink->sourcetype ==
'subscription') {
335 $srctype =
'adherent';
337 $tgttype = $this->objectlink->targettype;
338 if ($this->objectlink->targettype ==
'subscription') {
339 $tgttype =
'adherent';
341 if (!DolibarrApiAccess::$user->hasRight((
string) $srctype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $srctype,
'write')) {
342 throw new RestException(403,
'denied access to delete the objectlinks sourcetype='.$this->objectlink->sourcetype);
344 if (!DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'creer') && !DolibarrApiAccess::$user->hasRight((
string) $tgttype,
'write')) {
345 throw new RestException(403,
'denied access to delete the objectlinks targettype='.$this->objectlink->targettype);
348 $findresult = $this->objectlink->fetchByValues($this->objectlink->fk_source, $this->objectlink->sourcetype, $this->objectlink->fk_target, $this->objectlink->targettype, $this->objectlink->relationtype);
350 if ($findresult < 0) {
351 throw new RestException(500,
'Error when finding objectlink : '.$this->objectlink->error);
352 } elseif ($findresult > 0) {
353 $result = $this->objectlink->delete(DolibarrApiAccess::$user, $notrigger);
356 throw new RestException(500,
'Error when delete objectlink : '.$this->objectlink->error);
362 'message' =>
'object link deleted'
366 throw new RestException(404,
'Object Link not found');
385 $result = $this->objectlink->fetch(
$id);
387 $srctype = $this->objectlink->sourcetype;
388 if ($this->objectlink->sourcetype ==
'subscription') {
389 $srctype =
'adherent';
391 $tgttype = $this->objectlink->targettype;
392 if ($this->objectlink->targettype ==
'subscription') {
393 $tgttype =
'adherent';
395 if (!DolibarrApiAccess::$user->hasRight(((
string) $srctype),
'lire') && !DolibarrApiAccess::$user->hasRight(((
string) $srctype),
'read')) {
396 throw new RestException(403,
'denied access to the objectlinks sourcetype');
398 if (!DolibarrApiAccess::$user->hasRight(((
string) $tgttype),
'lire') && !DolibarrApiAccess::$user->hasRight(((
string) $tgttype),
'read')) {
399 throw new RestException(403,
'denied access to the objectlinks targettype');
402 throw new RestException(404,
'Object Link not found');
428 unset(
$object->array_languages);
430 unset(
$object->linkedObjectsIds);
446 unset(
$object->barcode_type_coder);
447 unset(
$object->mode_reglement_id);
448 unset(
$object->cond_reglement_id);
449 unset(
$object->demand_reason_id);
450 unset(
$object->transport_mode_id);
451 unset(
$object->shipping_method_id);
452 unset(
$object->shipping_method);
453 unset(
$object->fk_multicurrency);
454 unset(
$object->multicurrency_code);
455 unset(
$object->multicurrency_tx);
456 unset(
$object->multicurrency_total_ht);
457 unset(
$object->multicurrency_total_tva);
458 unset(
$object->multicurrency_total_ttc);
459 unset(
$object->multicurrency_total_localtax1);
460 unset(
$object->multicurrency_total_localtax2);
467 unset(
$object->total_localtax1);
468 unset(
$object->total_localtax2);
471 unset(
$object->actiontypecode);
477 unset(
$object->date_validation);
478 unset(
$object->date_modification);
483 unset(
$object->user_creation_id);
485 unset(
$object->user_validation);
486 unset(
$object->user_validation_id);
487 unset(
$object->user_closing_id);
488 unset(
$object->user_modification);
489 unset(
$object->user_modification_id);
494 unset(
$object->cond_reglement_supplier_id);
495 unset(
$object->deposit_percent);
496 unset(
$object->retained_warranty_fk_cond_reglement);
518 $objectlink = array();
519 foreach (ObjectLinks::$FIELDS as $field) {
520 if (!isset($data[$field])) {
521 throw new RestException(400, $field.
" field missing");
523 $objectlink[$field] = $data[$field];
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
__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.