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
6cae631a
Commit
6cae631a
authored
8 years ago
by
Laurent Destailleur
Browse files
Options
Downloads
Patches
Plain Diff
NEW Add REST API to read users
parent
77e20371
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/user/class/api_users.class.php
+73
-0
73 additions, 0 deletions
htdocs/user/class/api_users.class.php
with
73 additions
and
0 deletions
htdocs/user/class/api_users.class.php
+
73
−
0
View file @
6cae631a
...
...
@@ -49,6 +49,79 @@ class Users extends DolibarrApi
$this
->
useraccount
=
new
User
(
$this
->
db
);
}
/**
* List Users
*
* Get a list of Users
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param string $user_ids User ids filter field. Example: '1' or '1,2,3' {@pattern /^[0-9,]*$/i}
*
* @return array Array of User objects
*/
function
index
(
$sortfield
=
"t.rowid"
,
$sortorder
=
'ASC'
,
$limit
=
0
,
$page
=
0
,
$user_ids
=
0
)
{
global
$db
,
$conf
;
$obj_ret
=
array
();
if
(
!
DolibarrApiAccess
::
$user
->
rights
->
user
->
user
->
lire
)
{
throw
new
RestException
(
401
,
"You are not allowed to read list of users"
);
}
// case of external user, $societe param is ignored and replaced by user's socid
//$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe;
$sql
=
"SELECT t.rowid"
;
$sql
.
=
" FROM "
.
MAIN_DB_PREFIX
.
"user as t"
;
$sql
.
=
' WHERE t.entity IN ('
.
getEntity
(
'user'
,
1
)
.
')'
;
if
(
$user_ids
)
$sql
.
=
" AND t.rowid IN ("
.
$user_ids
.
")"
;
$nbtotalofrecords
=
0
;
if
(
empty
(
$conf
->
global
->
MAIN_DISABLE_FULL_SCANLIST
))
{
$result
=
$db
->
query
(
$sql
);
$nbtotalofrecords
=
$db
->
num_rows
(
$result
);
}
$sql
.
=
$db
->
order
(
$sortfield
,
$sortorder
);
if
(
$limit
)
{
if
(
$page
<
0
)
{
$page
=
0
;
}
$offset
=
$limit
*
$page
;
$sql
.
=
$db
->
plimit
(
$limit
+
1
,
$offset
);
}
$result
=
$db
->
query
(
$sql
);
if
(
$result
)
{
$num
=
$db
->
num_rows
(
$result
);
while
(
$i
<
$num
)
{
$obj
=
$db
->
fetch_object
(
$result
);
$user_static
=
new
User
(
$db
);
if
(
$user_static
->
fetch
(
$obj
->
rowid
))
{
$obj_ret
[]
=
parent
::
_cleanObjectDatas
(
$user_static
);
}
$i
++
;
}
}
else
{
throw
new
RestException
(
503
,
'Error when retrieve User list'
);
}
if
(
!
count
(
$obj_ret
))
{
throw
new
RestException
(
404
,
'No User found'
);
}
return
$obj_ret
;
}
/**
* Get properties of an user object
*
...
...
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