Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
a8ee123b
Commit
a8ee123b
authored
9 years ago
by
Jean-François Ferry
Browse files
Options
Downloads
Patches
Plain Diff
Add API methods to create, update and delete a thirdparty
parent
64d0a710
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
htdocs/societe/class/api_thirdparty.class.php
+57
-13
57 additions, 13 deletions
htdocs/societe/class/api_thirdparty.class.php
with
57 additions
and
13 deletions
htdocs/societe/class/api_thirdparty.class.php
+
57
−
13
View file @
a8ee123b
...
...
@@ -31,8 +31,7 @@
class
ThirdpartyApi
extends
DolibarrApi
{
static
$FIELDS
=
array
(
'name'
,
'email'
'name'
);
/**
...
...
@@ -48,9 +47,13 @@ class ThirdpartyApi extends DolibarrApi {
*/
function
__construct
()
{
global
$db
;
global
$db
,
$conf
;
$this
->
db
=
$db
;
$this
->
company
=
new
Societe
(
$this
->
db
);
if
(
!
empty
(
$conf
->
global
->
SOCIETE_MAIL_REQUIRED
))
{
static
::
$FIELDS
[]
=
'email'
;
}
}
/**
...
...
@@ -146,48 +149,89 @@ class ThirdpartyApi extends DolibarrApi {
throw
new
RestException
(
404
,
'Thirdparties not found'
);
}
return
$obj_ret
;
}
/**
* Create thirdparty object
*
* @url POST thirdparty/
* @param
type
$request_data
* @return ty
pe
* @param
array
$request_data
* @return
int ID of thirdpar
ty
*/
function
post
(
$request_data
=
NULL
)
{
return
$this
->
company
->
create
(
$this
->
_validate
(
$request_data
));
if
(
!
DolibarrApiAccess
::
$user
->
rights
->
societe
->
creer
)
{
throw
new
RestException
(
401
);
}
// Check mandatory fields
$result
=
$this
->
_validate
(
$request_data
);
foreach
(
$request_data
as
$field
=>
$value
)
{
$this
->
company
->
$field
=
$value
;
}
return
$this
->
company
->
create
(
DolibarrApiAccess
::
$user
);
}
/**
* Update thirdparty
*
* @url PUT thirdparty/{id}
* @param
type $id
* @param
type
$request_data
* @return
type$this->company
* @param
int $id Id of thirdparty to update
* @param
array
$request_data
Datas
* @return
int
*/
function
put
(
$id
,
$request_data
=
NULL
)
{
return
$this
->
company
->
update
(
$id
,
$this
->
_validate
(
$request_data
));
if
(
!
DolibarrApiAccess
::
$user
->
rights
->
societe
->
creer
)
{
throw
new
RestException
(
401
);
}
$result
=
$this
->
company
->
fetch
(
$id
);
if
(
!
$result
)
{
throw
new
RestException
(
404
,
'Thirdparty not found'
);
}
if
(
!
DolibarrApi
::
_checkAccessToResource
(
'societe'
,
$this
->
company
->
id
))
{
throw
new
RestException
(
401
,
'Access not allowed for login '
.
DolibarrApiAccess
::
$user
->
login
);
}
foreach
(
$request_data
as
$field
=>
$value
)
{
$this
->
company
->
$field
=
$value
;
}
if
(
$this
->
company
->
update
(
$id
,
DolibarrApiAccess
::
$user
,
1
,
''
,
''
,
'update'
))
return
$this
->
get
(
$id
);
return
false
;
}
/**
* Delete thirdparty
*
* @url DELETE thirdparty/{id}
* @param
type
$id
* @param
int
$id
* @return type
*/
function
delete
(
$id
)
{
if
(
!
DolibarrApiAccess
::
$user
->
rights
->
societe
->
supprimer
)
{
throw
new
RestException
(
401
);
}
$result
=
$this
->
company
->
fetch
(
$id
);
if
(
!
$result
)
{
throw
new
RestException
(
404
,
'Thirdparty not found'
);
}
if
(
!
DolibarrApi
::
_checkAccessToResource
(
'societe'
,
$this
->
company
->
id
))
{
throw
new
RestException
(
401
,
'Access not allowed for login '
.
DolibarrApiAccess
::
$user
->
login
);
}
return
$this
->
company
->
delete
(
$id
);
}
/**
* Validate fields before create or update object
* @param
type
$data
* @param
array
$data
* @return array
* @throws RestException
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment