105 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
112 if (!DolibarrApiAccess::$user->rights->partnership->read) {
113 throw new RestException(401);
116 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
118 $restrictonsocid = 0;
122 if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
123 $search_sale = DolibarrApiAccess::$user->id;
126 $sql =
"SELECT t.rowid";
127 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
128 $sql .=
", sc.fk_soc, sc.fk_user";
130 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
132 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
133 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
135 $sql .=
" WHERE 1 = 1";
141 if ($tmpobject->ismultientitymanaged) {
142 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
144 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
145 $sql .=
" AND t.fk_soc = sc.fk_soc";
147 if ($restrictonsocid && $socid) {
148 $sql .=
" AND t.fk_soc = ".((int) $socid);
150 if ($restrictonsocid && $search_sale > 0) {
151 $sql .=
" AND t.rowid = sc.fk_soc";
154 if ($restrictonsocid && $search_sale > 0) {
155 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
161 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
165 $sql .= $this->db->order($sortfield, $sortorder);
170 $offset = $limit * $page;
172 $sql .= $this->db->plimit($limit + 1, $offset);
175 $result = $this->db->query($sql);
178 $num = $this->db->num_rows($result);
180 $obj = $this->db->fetch_object($result);
182 if ($tmp_object->fetch($obj->rowid)) {
188 throw new RestException(503,
'Error when retrieving partnership list: '.$this->db->lasterror());
204 public function post($request_data =
null)
206 if (!DolibarrApiAccess::$user->rights->partnership->write) {
207 throw new RestException(401);
211 $result = $this->
_validate($request_data);
213 foreach ($request_data as $field => $value) {
214 if ($field ===
'caller') {
216 $this->partnership->context[
'caller'] = $request_data[
'caller'];
220 $this->partnership->$field = $this->
_checkValForAPI($field, $value, $this->partnership);
226 if ($this->partnership->create(DolibarrApiAccess::$user)<0) {
227 throw new RestException(500,
"Error creating Partnership", array_merge(array($this->partnership->error), $this->partnership->errors));
229 return $this->partnership->id;
243 public function put($id, $request_data =
null)
245 if (!DolibarrApiAccess::$user->rights->partnership->write) {
246 throw new RestException(401);
249 $result = $this->partnership->fetch($id);
251 throw new RestException(404,
'Partnership not found');
255 throw new RestException(401,
'Access to instance id='.$this->partnership->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
258 foreach ($request_data as $field => $value) {
259 if ($field ==
'id') {
262 if ($field ===
'caller') {
264 $this->partnership->context[
'caller'] = $request_data[
'caller'];
268 $this->partnership->$field = $this->
_checkValForAPI($field, $value, $this->partnership);
274 if ($this->partnership->update(DolibarrApiAccess::$user,
false) > 0) {
275 return $this->
get($id);
277 throw new RestException(500, $this->partnership->error);
291 public function delete($id)
293 if (!DolibarrApiAccess::$user->rights->partnership->delete) {
294 throw new RestException(401);
296 $result = $this->partnership->fetch($id);
298 throw new RestException(404,
'Partnership not found');
302 throw new RestException(401,
'Access to instance id='.$this->partnership->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
305 if (!$this->partnership->delete(DolibarrApiAccess::$user)) {
306 throw new RestException(500,
'Error when deleting Partnership : '.$this->partnership->error);
312 'message' =>
'Partnership deleted'
328 $object = parent::_cleanObjectDatas($object);
330 unset($object->rowid);
331 unset($object->canvas);
368 if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
369 $nboflines = count($object->lines);
370 for ($i = 0; $i < $nboflines; $i++) {
373 unset($object->lines[$i]->lines);
374 unset($object->lines[$i]->note);