105 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'')
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());
190 if (!count($obj_ret)) {
191 throw new RestException(404,
'No partnership found');
206 public function post($request_data =
null)
208 if (!DolibarrApiAccess::$user->rights->partnership->write) {
209 throw new RestException(401);
213 $result = $this->
_validate($request_data);
215 foreach ($request_data as $field => $value) {
216 $this->partnership->$field = $this->
_checkValForAPI($field, $value, $this->partnership);
222 if ($this->partnership->create(DolibarrApiAccess::$user)<0) {
223 throw new RestException(500,
"Error creating Partnership", array_merge(array($this->partnership->error), $this->partnership->errors));
225 return $this->partnership->id;
239 public function put($id, $request_data =
null)
241 if (!DolibarrApiAccess::$user->rights->partnership->write) {
242 throw new RestException(401);
245 $result = $this->partnership->fetch($id);
247 throw new RestException(404,
'Partnership not found');
251 throw new RestException(401,
'Access to instance id='.$this->partnership->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
254 foreach ($request_data as $field => $value) {
255 if ($field ==
'id') {
258 $this->partnership->$field = $this->
_checkValForAPI($field, $value, $this->partnership);
264 if ($this->partnership->update(DolibarrApiAccess::$user,
false) > 0) {
265 return $this->
get($id);
267 throw new RestException(500, $this->partnership->error);
281 public function delete($id)
283 if (!DolibarrApiAccess::$user->rights->partnership->delete) {
284 throw new RestException(401);
286 $result = $this->partnership->fetch($id);
288 throw new RestException(404,
'Partnership not found');
292 throw new RestException(401,
'Access to instance id='.$this->partnership->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
295 if (!$this->partnership->delete(DolibarrApiAccess::$user)) {
296 throw new RestException(500,
'Error when deleting Partnership : '.$this->partnership->error);
302 'message' =>
'Partnership deleted'
318 $object = parent::_cleanObjectDatas($object);
320 unset($object->rowid);
321 unset($object->canvas);
358 if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
359 $nboflines = count($object->lines);
360 for ($i = 0; $i < $nboflines; $i++) {
363 unset($object->lines[$i]->lines);
364 unset($object->lines[$i]->note);