18use Luracast\Restler\RestException;
69 public function get(
$id)
71 if (!DolibarrApiAccess::$user->hasRight(
'partnership',
'read')) {
72 throw new RestException(403);
75 $result = $this->partnership->fetch(
$id);
77 throw new RestException(404,
'Partnership not found');
81 throw new RestException(403,
'Access to instance id='.$this->partnership->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
105 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
110 if (!DolibarrApiAccess::$user->hasRight(
'partnership',
'read')) {
111 throw new RestException(403);
114 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : 0;
116 $restrictonsocid = 0;
120 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
121 $search_sale = DolibarrApiAccess::$user->id;
124 $sql =
"SELECT t.rowid";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
126 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
127 $sql .=
" WHERE 1 = 1";
128 if ($tmpobject->ismultientitymanaged) {
129 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
131 if ($restrictonsocid && $socid) {
132 $sql .=
" AND t.fk_soc = ".((int) $socid);
135 if ($search_sale && $search_sale !=
'-1') {
136 if ($search_sale == -2) {
137 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
138 } elseif ($search_sale > 0) {
139 $sql .=
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).
")";
146 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
150 $sql .= $this->db->order($sortfield, $sortorder);
155 $offset = $limit * $page;
157 $sql .= $this->db->plimit($limit + 1, $offset);
160 $result = $this->db->query($sql);
163 $num = $this->db->num_rows($result);
165 $obj = $this->db->fetch_object($result);
167 if ($tmp_object->fetch($obj->rowid)) {
173 throw new RestException(503,
'Error when retrieving partnership list: '.$this->db->lasterror());
189 public function post($request_data =
null)
191 if (!DolibarrApiAccess::$user->hasRight(
'partnership',
'write')) {
192 throw new RestException(403);
196 $result = $this->
_validate($request_data);
198 foreach ($request_data as $field => $value) {
199 if ($field ===
'caller') {
201 $this->partnership->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
205 $this->partnership->$field = $this->
_checkValForAPI($field, $value, $this->partnership);
211 if ($this->partnership->create(DolibarrApiAccess::$user)<0) {
212 throw new RestException(500,
"Error creating Partnership", array_merge(array($this->partnership->error), $this->partnership->errors));
214 return $this->partnership->id;
228 public function put(
$id, $request_data =
null)
230 if (!DolibarrApiAccess::$user->hasRight(
'partnership',
'write')) {
231 throw new RestException(403);
234 $result = $this->partnership->fetch(
$id);
236 throw new RestException(404,
'Partnership not found');
240 throw new RestException(403,
'Access to instance id='.$this->partnership->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
243 foreach ($request_data as $field => $value) {
244 if ($field ==
'id') {
247 if ($field ===
'caller') {
249 $this->partnership->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
253 $this->partnership->$field = $this->
_checkValForAPI($field, $value, $this->partnership);
259 if ($this->partnership->update(DolibarrApiAccess::$user,
false) > 0) {
260 return $this->
get(
$id);
262 throw new RestException(500, $this->partnership->error);
276 public function delete(
$id)
278 if (!DolibarrApiAccess::$user->hasRight(
'partnership',
'delete')) {
279 throw new RestException(403);
281 $result = $this->partnership->fetch(
$id);
283 throw new RestException(404,
'Partnership not found');
287 throw new RestException(403,
'Access to instance id='.$this->partnership->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
290 if (!$this->partnership->delete(DolibarrApiAccess::$user)) {
291 throw new RestException(500,
'Error when deleting Partnership : '.$this->partnership->error);
297 'message' =>
'Partnership deleted'
354 $nboflines = count(
$object->lines);
355 for ($i = 0; $i < $nboflines; $i++) {
358 unset(
$object->lines[$i]->lines);
359 unset(
$object->lines[$i]->note);
376 $partnership = array();
377 foreach ($this->partnership->fields as $field => $propfield) {
378 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat')) || $propfield[
'notnull'] != 1) {
381 if (!isset($data[$field])) {
382 throw new RestException(400,
"$field field missing");
384 $partnership[$field] = $data[$field];
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
List partnerships.
__construct()
Constructor.
post($request_data=null)
Create partnership object.
_validate($data)
Validate fields before create or update object.
put($id, $request_data=null)
Update partnership.
_cleanObjectDatas($object)
Clean sensible object datas.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.