19use 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);
107 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
112 if (!DolibarrApiAccess::$user->hasRight(
'partnership',
'read')) {
113 throw new RestException(403);
116 $socid = DolibarrApiAccess::$user->socid ?: 0;
118 $restrictonsocid = 0;
122 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
123 $search_sale = DolibarrApiAccess::$user->id;
126 $sql =
"SELECT t.rowid";
127 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
128 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
129 $sql .=
" WHERE 1 = 1";
130 if ($tmpobject->ismultientitymanaged) {
131 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
133 if ($restrictonsocid && $socid) {
134 $sql .=
" AND t.fk_soc = ".((int) $socid);
137 if ($search_sale && $search_sale !=
'-1') {
138 if ($search_sale == -2) {
139 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
140 } elseif ($search_sale > 0) {
141 $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).
")";
148 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
152 $sql .= $this->db->order($sortfield, $sortorder);
157 $offset = $limit * $page;
159 $sql .= $this->db->plimit($limit + 1, $offset);
162 $result = $this->db->query($sql);
165 $num = $this->db->num_rows($result);
167 $obj = $this->db->fetch_object($result);
169 if ($tmp_object->fetch($obj->rowid)) {
175 throw new RestException(503,
'Error when retrieving partnership list: '.$this->db->lasterror());
193 public function post($request_data =
null)
195 if (!DolibarrApiAccess::$user->hasRight(
'partnership',
'write')) {
196 throw new RestException(403);
200 $result = $this->
_validate($request_data);
202 foreach ($request_data as $field => $value) {
203 if ($field ===
'caller') {
205 $this->partnership->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
209 $this->partnership->$field = $this->
_checkValForAPI($field, $value, $this->partnership);
215 if ($this->partnership->create(DolibarrApiAccess::$user) < 0) {
216 throw new RestException(500,
"Error creating Partnership", array_merge(array($this->partnership->error), $this->partnership->errors));
218 return $this->partnership->id;
234 public function put(
$id, $request_data =
null)
236 if (!DolibarrApiAccess::$user->hasRight(
'partnership',
'write')) {
237 throw new RestException(403);
240 $result = $this->partnership->fetch(
$id);
242 throw new RestException(404,
'Partnership not found');
246 throw new RestException(403,
'Access to instance id='.$this->partnership->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
249 foreach ($request_data as $field => $value) {
250 if ($field ==
'id') {
253 if ($field ===
'caller') {
255 $this->partnership->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
258 if ($field ==
'array_options' && is_array($value)) {
259 foreach ($value as $index => $val) {
260 $this->partnership->array_options[$index] = $this->
_checkValForAPI($field, $val, $this->partnership);
265 $this->partnership->$field = $this->
_checkValForAPI($field, $value, $this->partnership);
271 if ($this->partnership->update(DolibarrApiAccess::$user, 0) > 0) {
272 return $this->
get(
$id);
274 throw new RestException(500, $this->partnership->error);
290 public function delete(
$id)
292 if (!DolibarrApiAccess::$user->hasRight(
'partnership',
'delete')) {
293 throw new RestException(403);
295 $result = $this->partnership->fetch(
$id);
297 throw new RestException(404,
'Partnership not found');
301 throw new RestException(403,
'Access to instance id='.$this->partnership->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
304 if (!$this->partnership->delete(DolibarrApiAccess::$user)) {
305 throw new RestException(500,
'Error when deleting Partnership : '.$this->partnership->error);
311 'message' =>
'Partnership deleted'
368 $nboflines = count(
$object->lines);
369 for ($i = 0; $i < $nboflines; $i++) {
372 unset(
$object->lines[$i]->lines);
373 unset(
$object->lines[$i]->note);
390 if ($data ===
null) {
393 $partnership = array();
394 foreach ($this->partnership->fields as $field => $propfield) {
395 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat')) || empty($propfield[
'notnull']) || $propfield[
'notnull'] != 1) {
398 if (!isset($data[$field])) {
399 throw new RestException(400,
"$field field missing");
401 $partnership[$field] = $data[$field];
$id
Support class for third parties, contacts, members, users or resources.
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.