Fix: missing include api_categories class
This commit is contained in:
parent
db8d27f0fe
commit
f8f4ff6d21
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2016 Xebax Christy <xebax@wanadoo.fr>
|
||||
/* Copyright (C) 2016 Xebax Christy <xebax@wanadoo.fr>
|
||||
* Copyright (C) 2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -357,4 +358,26 @@ class Members extends DolibarrApi
|
||||
return $member->subscription($start_date, $amount, 0, '', $label, '', '', '', $end_date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories for a member
|
||||
*
|
||||
* @param int $id ID of member
|
||||
* @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 {id}/categories
|
||||
*/
|
||||
function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php';
|
||||
|
||||
$categories = new Categories();
|
||||
|
||||
return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'member', $id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,13 +23,13 @@
|
||||
/**
|
||||
* API class for categories
|
||||
*
|
||||
* @access protected
|
||||
* @access protected
|
||||
* @class DolibarrApiAccess {@requires user,external}
|
||||
*/
|
||||
class Categories extends DolibarrApi
|
||||
{
|
||||
/**
|
||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||
*/
|
||||
static $FIELDS = array(
|
||||
'label',
|
||||
@ -44,7 +44,7 @@ class Categories extends DolibarrApi
|
||||
4 => 'contact',
|
||||
5 => 'account',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* @var Categorie $category {@type Categorie}
|
||||
*/
|
||||
@ -67,20 +67,20 @@ class Categories extends DolibarrApi
|
||||
*
|
||||
* @param int $id ID of category
|
||||
* @return array|mixed data without useless information
|
||||
*
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
function get($id)
|
||||
{
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->categorie->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
|
||||
$result = $this->category->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'category not found');
|
||||
}
|
||||
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
@ -90,7 +90,7 @@ class Categories extends DolibarrApi
|
||||
|
||||
/**
|
||||
* List categories
|
||||
*
|
||||
*
|
||||
* Get a list of categories
|
||||
*
|
||||
* @param string $sortfield Sort field
|
||||
@ -105,13 +105,13 @@ class Categories extends DolibarrApi
|
||||
*/
|
||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $type = '', $sqlfilters = '') {
|
||||
global $db, $conf;
|
||||
|
||||
|
||||
$obj_ret = array();
|
||||
|
||||
|
||||
if(! DolibarrApiAccess::$user->rights->categorie->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT t.rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as t";
|
||||
$sql.= ' WHERE t.entity IN ('.getEntity('category').')';
|
||||
@ -120,7 +120,7 @@ class Categories extends DolibarrApi
|
||||
$sql.= ' AND t.type='.array_search($type,Categories::$TYPES);
|
||||
}
|
||||
// Add sql filters
|
||||
if ($sqlfilters)
|
||||
if ($sqlfilters)
|
||||
{
|
||||
if (! DolibarrApi::_checkFilters($sqlfilters))
|
||||
{
|
||||
@ -129,7 +129,7 @@ class Categories extends DolibarrApi
|
||||
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
||||
}
|
||||
|
||||
|
||||
$sql.= $db->order($sortfield, $sortorder);
|
||||
if ($limit) {
|
||||
if ($page < 0)
|
||||
@ -168,7 +168,7 @@ class Categories extends DolibarrApi
|
||||
|
||||
/**
|
||||
* List categories of an entity
|
||||
*
|
||||
*
|
||||
* Note: This method is not directly exposed in the API, it is used
|
||||
* in the GET /xxx/{id}/categories requests.
|
||||
*
|
||||
@ -184,9 +184,9 @@ class Categories extends DolibarrApi
|
||||
*/
|
||||
function getListForItem($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $type='customer', $item = 0) {
|
||||
global $db, $conf;
|
||||
|
||||
|
||||
$obj_ret = array();
|
||||
|
||||
|
||||
if(! DolibarrApiAccess::$user->rights->categorie->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
@ -250,13 +250,13 @@ class Categories extends DolibarrApi
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No category found');
|
||||
}
|
||||
|
||||
|
||||
return $obj_ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create category object
|
||||
*
|
||||
*
|
||||
* @param array $request_data Request data
|
||||
* @return int ID of category
|
||||
*/
|
||||
@ -268,7 +268,7 @@ class Categories extends DolibarrApi
|
||||
|
||||
// Check mandatory fields
|
||||
$result = $this->_validate($request_data);
|
||||
|
||||
|
||||
foreach($request_data as $field => $value) {
|
||||
$this->category->$field = $value;
|
||||
}
|
||||
@ -280,22 +280,22 @@ class Categories extends DolibarrApi
|
||||
|
||||
/**
|
||||
* Update category
|
||||
*
|
||||
*
|
||||
* @param int $id Id of category to update
|
||||
* @param array $request_data Datas
|
||||
* @return int
|
||||
* @param array $request_data Datas
|
||||
* @return int
|
||||
*/
|
||||
function put($id, $request_data = NULL)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->categorie->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
|
||||
$result = $this->category->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'category not found');
|
||||
}
|
||||
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
@ -304,13 +304,13 @@ class Categories extends DolibarrApi
|
||||
if ($field == 'id') continue;
|
||||
$this->category->$field = $value;
|
||||
}
|
||||
|
||||
|
||||
if($this->category->update(DolibarrApiAccess::$user))
|
||||
return $this->get ($id);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete category
|
||||
*
|
||||
@ -326,15 +326,15 @@ class Categories extends DolibarrApi
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'category not found');
|
||||
}
|
||||
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
|
||||
if (! $this->category->delete(DolibarrApiAccess::$user)) {
|
||||
throw new RestException(401,'error when delete category');
|
||||
}
|
||||
|
||||
|
||||
return array(
|
||||
'success' => array(
|
||||
'code' => 200,
|
||||
@ -342,8 +342,8 @@ class Categories extends DolibarrApi
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Clean sensible object datas
|
||||
*
|
||||
@ -351,9 +351,9 @@ class Categories extends DolibarrApi
|
||||
* @return array Array of cleaned object properties
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
|
||||
$object = parent::_cleanObjectDatas($object);
|
||||
|
||||
|
||||
// Remove fields not relevent to categories
|
||||
unset($object->country);
|
||||
unset($object->country_id);
|
||||
@ -394,16 +394,16 @@ class Categories extends DolibarrApi
|
||||
unset($object->fk_project);
|
||||
unset($object->note);
|
||||
unset($object->statut);
|
||||
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate fields before create or update object
|
||||
*
|
||||
*
|
||||
* @param array|null $data Data to validate
|
||||
* @return array
|
||||
*
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
function _validate($data)
|
||||
|
||||
@ -16,24 +16,24 @@
|
||||
*/
|
||||
|
||||
use Luracast\Restler\RestException;
|
||||
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
|
||||
/**
|
||||
* API class for products
|
||||
*
|
||||
* @access protected
|
||||
* @access protected
|
||||
* @class DolibarrApiAccess {@requires user,external}
|
||||
*/
|
||||
class Products extends DolibarrApi
|
||||
{
|
||||
/**
|
||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||
*/
|
||||
static $FIELDS = array(
|
||||
'ref',
|
||||
'label'
|
||||
'label'
|
||||
);
|
||||
|
||||
/**
|
||||
@ -53,30 +53,30 @@ class Products extends DolibarrApi
|
||||
|
||||
/**
|
||||
* Get properties of a product object
|
||||
*
|
||||
*
|
||||
* Return an array with product informations
|
||||
*
|
||||
* @param int $id ID of product
|
||||
* @return array|mixed data without useless information
|
||||
*
|
||||
*
|
||||
* @throws RestException
|
||||
* TODO implement getting a product by ref or by $ref_ext
|
||||
*/
|
||||
function get($id)
|
||||
{
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->produit->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
|
||||
$result = $this->product->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Product not found');
|
||||
}
|
||||
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('product',$this->product->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
|
||||
$this->product->load_stock();
|
||||
|
||||
return $this->_cleanObjectDatas($this->product);
|
||||
@ -84,9 +84,9 @@ class Products extends DolibarrApi
|
||||
|
||||
/**
|
||||
* List products
|
||||
*
|
||||
*
|
||||
* Get a list of products
|
||||
*
|
||||
*
|
||||
* @param string $sortfield Sort field
|
||||
* @param string $sortorder Sort order
|
||||
* @param int $limit Limit for list
|
||||
@ -98,9 +98,9 @@ class Products extends DolibarrApi
|
||||
*/
|
||||
function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $category=0, $sqlfilters = '') {
|
||||
global $db, $conf;
|
||||
|
||||
|
||||
$obj_ret = array();
|
||||
|
||||
|
||||
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
|
||||
|
||||
$sql = "SELECT t.rowid, t.ref, t.ref_ext";
|
||||
@ -121,7 +121,7 @@ class Products extends DolibarrApi
|
||||
// Show services
|
||||
if ($mode == 2) $sql.= " AND t.fk_product_type = 1";
|
||||
// Add sql filters
|
||||
if ($sqlfilters)
|
||||
if ($sqlfilters)
|
||||
{
|
||||
if (! DolibarrApi::_checkFilters($sqlfilters))
|
||||
{
|
||||
@ -130,7 +130,7 @@ class Products extends DolibarrApi
|
||||
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
||||
}
|
||||
|
||||
|
||||
$sql.= $db->order($sortfield, $sortorder);
|
||||
if ($limit) {
|
||||
if ($page < 0)
|
||||
@ -165,10 +165,10 @@ class Products extends DolibarrApi
|
||||
}
|
||||
return $obj_ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create product object
|
||||
*
|
||||
*
|
||||
* @param array $request_data Request data
|
||||
* @return int ID of product
|
||||
*/
|
||||
@ -179,35 +179,35 @@ class Products extends DolibarrApi
|
||||
}
|
||||
// Check mandatory fields
|
||||
$result = $this->_validate($request_data);
|
||||
|
||||
|
||||
foreach($request_data as $field => $value) {
|
||||
$this->product->$field = $value;
|
||||
}
|
||||
if ($this->product->create(DolibarrApiAccess::$user) < 0) {
|
||||
throw new RestException(500, "Error creating product", array_merge(array($this->product->error), $this->product->errors));
|
||||
}
|
||||
|
||||
|
||||
return $this->product->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update product
|
||||
*
|
||||
*
|
||||
* @param int $id Id of product to update
|
||||
* @param array $request_data Datas
|
||||
* @return int
|
||||
* @param array $request_data Datas
|
||||
* @return int
|
||||
*/
|
||||
function put($id, $request_data = NULL)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->produit->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
|
||||
$result = $this->product->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Product not found');
|
||||
}
|
||||
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('product',$this->product->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
@ -216,16 +216,16 @@ class Products extends DolibarrApi
|
||||
if ($field == 'id') continue;
|
||||
$this->product->$field = $value;
|
||||
}
|
||||
|
||||
|
||||
if($this->product->update($id, DolibarrApiAccess::$user,1,'update'))
|
||||
return $this->get ($id);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete product
|
||||
*
|
||||
*
|
||||
* @param int $id Product ID
|
||||
* @return array
|
||||
*/
|
||||
@ -238,18 +238,18 @@ class Products extends DolibarrApi
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Product not found');
|
||||
}
|
||||
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('product',$this->product->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
|
||||
// The Product::delete() method uses the global variable $user.
|
||||
global $user;
|
||||
$user = DolibarrApiAccess::$user;
|
||||
|
||||
return $this->product->delete(DolibarrApiAccess::$user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get categories for a product
|
||||
*
|
||||
@ -263,9 +263,13 @@ class Products extends DolibarrApi
|
||||
*
|
||||
* @url GET {id}/categories
|
||||
*/
|
||||
function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
|
||||
$categories = new Categories();
|
||||
return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'product', $id);
|
||||
function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php';
|
||||
|
||||
$categories = new Categories();
|
||||
|
||||
return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'product', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -275,17 +279,17 @@ class Products extends DolibarrApi
|
||||
* @return array Array of cleaned object properties
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
|
||||
$object = parent::_cleanObjectDatas($object);
|
||||
|
||||
|
||||
unset($object->regeximgext);
|
||||
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate fields before create or update object
|
||||
*
|
||||
*
|
||||
* @param array $data Datas to validate
|
||||
* @return array
|
||||
* @throws RestException
|
||||
|
||||
@ -333,8 +333,12 @@ class Contacts extends DolibarrApi
|
||||
*
|
||||
* @url GET {id}/categories
|
||||
*/
|
||||
function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
|
||||
function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php';
|
||||
|
||||
$categories = new Categories();
|
||||
|
||||
return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'contact', $id);
|
||||
}
|
||||
|
||||
|
||||
@ -21,15 +21,15 @@
|
||||
/**
|
||||
* API class for thirdparties
|
||||
*
|
||||
* @access protected
|
||||
* @access protected
|
||||
* @class DolibarrApiAccess {@requires user,external}
|
||||
*
|
||||
*
|
||||
*/
|
||||
class Thirdparties extends DolibarrApi
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||
*/
|
||||
static $FIELDS = array(
|
||||
'name'
|
||||
@ -48,7 +48,7 @@ class Thirdparties extends DolibarrApi
|
||||
global $db, $conf;
|
||||
$this->db = $db;
|
||||
$this->company = new Societe($this->db);
|
||||
|
||||
|
||||
if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
|
||||
static::$FIELDS[] = 'email';
|
||||
}
|
||||
@ -61,20 +61,20 @@ class Thirdparties extends DolibarrApi
|
||||
*
|
||||
* @param int $id ID of thirdparty
|
||||
* @return array|mixed data without useless information
|
||||
*
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
function get($id)
|
||||
{
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->societe->lire) {
|
||||
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);
|
||||
}
|
||||
@ -84,14 +84,14 @@ class Thirdparties extends DolibarrApi
|
||||
|
||||
/**
|
||||
* List thirdparties
|
||||
*
|
||||
*
|
||||
* Get a list of thirdparties
|
||||
*
|
||||
*
|
||||
* @param string $sortfield Sort field
|
||||
* @param string $sortorder Sort order
|
||||
* @param int $limit Limit for list
|
||||
* @param int $page Page number
|
||||
* @param int $mode Set to 1 to show only customers
|
||||
* @param int $mode Set to 1 to show only customers
|
||||
* Set to 2 to show only prospects
|
||||
* Set to 3 to show only those are not customer neither prospect
|
||||
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
|
||||
@ -99,12 +99,12 @@ class Thirdparties extends DolibarrApi
|
||||
*/
|
||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $sqlfilters = '') {
|
||||
global $db, $conf;
|
||||
|
||||
|
||||
$obj_ret = array();
|
||||
|
||||
|
||||
// case of external user, we force socids
|
||||
$socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
|
||||
|
||||
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
$search_sale = 0;
|
||||
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
|
||||
@ -112,7 +112,7 @@ class Thirdparties extends DolibarrApi
|
||||
$sql = "SELECT t.rowid";
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
|
||||
|
||||
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
|
||||
$sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
|
||||
$sql.= " WHERE t.fk_stcomm = st.id";
|
||||
@ -130,7 +130,7 @@ class Thirdparties extends DolibarrApi
|
||||
$sql .= " AND sc.fk_user = ".$search_sale;
|
||||
}
|
||||
// Add sql filters
|
||||
if ($sqlfilters)
|
||||
if ($sqlfilters)
|
||||
{
|
||||
if (! DolibarrApi::_checkFilters($sqlfilters))
|
||||
{
|
||||
@ -139,7 +139,7 @@ class Thirdparties extends DolibarrApi
|
||||
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
||||
}
|
||||
|
||||
|
||||
$sql.= $db->order($sortfield, $sortorder);
|
||||
|
||||
if ($limit) {
|
||||
@ -175,7 +175,7 @@ class Thirdparties extends DolibarrApi
|
||||
}
|
||||
return $obj_ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create thirdparty object
|
||||
*
|
||||
@ -189,13 +189,13 @@ class Thirdparties extends DolibarrApi
|
||||
}
|
||||
// Check mandatory fields
|
||||
$result = $this->_validate($request_data);
|
||||
|
||||
|
||||
foreach($request_data as $field => $value) {
|
||||
$this->company->$field = $value;
|
||||
}
|
||||
if ($this->company->create(DolibarrApiAccess::$user) < 0)
|
||||
throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
|
||||
|
||||
|
||||
return $this->company->id;
|
||||
}
|
||||
|
||||
@ -203,20 +203,20 @@ class Thirdparties extends DolibarrApi
|
||||
* Update thirdparty
|
||||
*
|
||||
* @param int $id Id of thirdparty to update
|
||||
* @param array $request_data Datas
|
||||
* @return int
|
||||
* @param array $request_data Datas
|
||||
* @return int
|
||||
*/
|
||||
function put($id, $request_data = NULL)
|
||||
{
|
||||
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);
|
||||
}
|
||||
@ -225,13 +225,13 @@ class Thirdparties extends DolibarrApi
|
||||
if ($field == 'id') continue;
|
||||
$this->company->$field = $value;
|
||||
}
|
||||
|
||||
|
||||
if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update'))
|
||||
return $this->get ($id);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete thirdparty
|
||||
*
|
||||
@ -252,7 +252,7 @@ class Thirdparties extends DolibarrApi
|
||||
}
|
||||
return $this->company->delete($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get categories for a thirdparty
|
||||
*
|
||||
@ -266,8 +266,12 @@ class Thirdparties extends DolibarrApi
|
||||
*
|
||||
* @url GET {id}/categories
|
||||
*/
|
||||
function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
|
||||
function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php';
|
||||
|
||||
$categories = new Categories();
|
||||
|
||||
return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'customer', $id);
|
||||
}
|
||||
|
||||
@ -318,24 +322,24 @@ class Thirdparties extends DolibarrApi
|
||||
* @return array Array of cleaned object properties
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
|
||||
$object = parent::_cleanObjectDatas($object);
|
||||
|
||||
|
||||
unset($object->total_ht);
|
||||
unset($object->total_tva);
|
||||
unset($object->total_localtax1);
|
||||
unset($object->total_localtax2);
|
||||
unset($object->total_ttc);
|
||||
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate fields before create or update object
|
||||
*
|
||||
*
|
||||
* @param array $data Datas to validate
|
||||
* @return array
|
||||
*
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
function _validate($data)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user