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
0978ebc7
Commit
0978ebc7
authored
8 years ago
by
nka11
Browse files
Options
Downloads
Patches
Plain Diff
Improve categories API to retreive categories of a given Item
parent
f3ae67a4
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/categories/class/api_category.class.php
+95
-0
95 additions, 0 deletions
htdocs/categories/class/api_category.class.php
with
95 additions
and
0 deletions
htdocs/categories/class/api_category.class.php
+
95
−
0
View file @
0978ebc7
...
...
@@ -162,6 +162,86 @@ class CategoryApi extends DolibarrApi
}
return
$obj_ret
;
}
/**
* List categories of an entity
*
* Get a list of categories
*
* @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact')
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param int $item Id of the item to get categories for
* @return array Array of category objects
*
* @url GET /product/{item}/categories
*/
function
getListForItem
(
$type
=
'product'
,
$sortfield
=
"s.rowid"
,
$sortorder
=
'ASC'
,
$limit
=
0
,
$page
=
0
,
$item
=
0
)
{
global
$db
,
$conf
;
$obj_ret
=
array
();
if
(
!
DolibarrApiAccess
::
$user
->
rights
->
categorie
->
lire
)
{
throw
new
RestException
(
401
);
}
//if ($type == "") {
//$type="product";
//}
$sub_type
=
$type
;
$subcol_name
=
"fk_"
.
$type
;
if
(
$type
==
"customer"
||
$type
==
"supplier"
)
{
$sub_type
=
"societe"
;
$subcol_name
=
"fk_soc"
;
}
$sql
=
"SELECT s.rowid"
;
$sql
.
=
" FROM "
.
MAIN_DB_PREFIX
.
"categorie as s"
;
$sql
.
=
" , "
.
MAIN_DB_PREFIX
.
"categorie_"
.
$sub_type
.
" as sub "
;
$sql
.
=
' WHERE s.entity IN ('
.
getEntity
(
'categorie'
,
1
)
.
')'
;
$sql
.
=
' AND s.type='
.
array_search
(
$type
,
CategoryApi
::
$TYPES
);
$sql
.
=
' AND s.rowid = sub.fk_categorie'
;
$sql
.
=
' AND sub.'
.
$subcol_name
.
' = '
.
$item
;
$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
);
$category_static
=
new
Categorie
(
$db
);
if
(
$category_static
->
fetch
(
$obj
->
rowid
))
{
$obj_ret
[]
=
parent
::
_cleanObjectDatas
(
$category_static
);
}
$i
++
;
}
}
else
{
throw
new
RestException
(
503
,
'Error when retrieve category list : '
.
$category_static
->
error
);
}
if
(
!
count
(
$obj_ret
))
{
throw
new
RestException
(
404
,
'No category found'
);
}
return
$obj_ret
;
}
/**
* Get member categories list
...
...
@@ -193,6 +273,21 @@ class CategoryApi extends DolibarrApi
function
getListCategoryCustomer
(
$sortfield
=
"s.rowid"
,
$sortorder
=
'ASC'
,
$limit
=
0
,
$page
=
0
)
{
return
$this
->
getList
(
'customer'
,
$sortfield
,
$sortorder
,
$limit
,
$page
);
}
/**
* Get categories for a customer
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
*
* @return mixed
*
* @url GET /customer/{cusid}/categories
*/
function
getListCustomerCategories
(
$sortfield
=
"s.rowid"
,
$sortorder
=
'ASC'
,
$limit
=
0
,
$page
=
0
,
$cusid
)
{
return
$this
->
getListForItem
(
'customer'
,
$sortfield
,
$sortorder
,
$limit
,
$page
,
$cusid
);
}
/**
* Get supplier categories list
...
...
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