18 use Luracast\Restler\RestException;
79 if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->read) {
80 throw new RestException(401);
83 $result = $this->jobposition->fetch($id);
85 throw new RestException(404,
'JobPosition not found');
89 throw new RestException(401,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
110 if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->read) {
111 throw new RestException(401);
114 $result = $this->candidature->fetch($id);
116 throw new RestException(404,
'Candidature not found');
120 throw new RestException(401,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
143 public function indexJobPosition($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'')
150 if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->read) {
151 throw new RestException(401);
154 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
156 $restrictonsocid = 0;
160 if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
161 $search_sale = DolibarrApiAccess::$user->id;
164 $sql =
"SELECT t.rowid";
165 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
166 $sql .=
", sc.fk_soc, sc.fk_user";
168 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" as t";
170 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
171 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
173 $sql .=
" WHERE 1 = 1";
179 if ($tmpobject->ismultientitymanaged) {
180 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
182 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
183 $sql .=
" AND t.fk_soc = sc.fk_soc";
185 if ($restrictonsocid && $socid) {
186 $sql .=
" AND t.fk_soc = ".((int) $socid);
188 if ($restrictonsocid && $search_sale > 0) {
189 $sql .=
" AND t.rowid = sc.fk_soc";
192 if ($restrictonsocid && $search_sale > 0) {
193 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
198 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
200 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
201 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
204 $sql .= $this->
db->order($sortfield, $sortorder);
209 $offset = $limit * $page;
211 $sql .= $this->
db->plimit($limit + 1, $offset);
214 $result = $this->
db->query($sql);
217 $num = $this->
db->num_rows($result);
219 $obj = $this->
db->fetch_object($result);
221 if ($tmp_object->fetch($obj->rowid)) {
227 throw new RestException(503,
'Error when retrieving jobposition list: '.$this->
db->lasterror());
229 if (!count($obj_ret)) {
230 throw new RestException(404,
'No jobposition found');
251 public function indexCandidature($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'')
258 if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->read) {
259 throw new RestException(401);
262 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
264 $restrictonsocid = 0;
268 if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
269 $search_sale = DolibarrApiAccess::$user->id;
272 $sql =
"SELECT t.rowid";
273 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
274 $sql .=
", sc.fk_soc, sc.fk_user";
276 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" as t";
278 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
279 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
281 $sql .=
" WHERE 1 = 1";
287 if ($tmpobject->ismultientitymanaged) {
288 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
290 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
291 $sql .=
" AND t.fk_soc = sc.fk_soc";
293 if ($restrictonsocid && $socid) {
294 $sql .=
" AND t.fk_soc = ".((int) $socid);
296 if ($restrictonsocid && $search_sale > 0) {
297 $sql .=
" AND t.rowid = sc.fk_soc";
300 if ($restrictonsocid && $search_sale > 0) {
301 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
306 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
308 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
309 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
312 $sql .= $this->
db->order($sortfield, $sortorder);
317 $offset = $limit * $page;
319 $sql .= $this->
db->plimit($limit + 1, $offset);
322 $result = $this->
db->query($sql);
325 $num = $this->
db->num_rows($result);
327 $obj = $this->
db->fetch_object($result);
329 if ($tmp_object->fetch($obj->rowid)) {
335 throw new RestException(503,
'Error when retrieving candidature list: '.$this->
db->lasterror());
337 if (!count($obj_ret)) {
338 throw new RestException(404,
'No candidature found');
355 if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->write) {
356 throw new RestException(401);
360 $result = $this->
_validate($request_data);
362 foreach ($request_data as $field => $value) {
363 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
369 if ($this->jobposition->create(DolibarrApiAccess::$user)<0) {
370 throw new RestException(500,
"Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
372 return $this->jobposition->id;
387 if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->write) {
388 throw new RestException(401);
392 $result = $this->
_validate($request_data);
394 foreach ($request_data as $field => $value) {
395 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
401 if ($this->candidature->create(DolibarrApiAccess::$user)<0) {
402 throw new RestException(500,
"Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
404 return $this->candidature->id;
420 if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->write) {
421 throw new RestException(401);
424 $result = $this->jobposition->fetch($id);
426 throw new RestException(404,
'jobposition not found');
430 throw new RestException(401,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
433 foreach ($request_data as $field => $value) {
434 if ($field ==
'id') {
437 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
443 if ($this->jobposition->update(DolibarrApiAccess::$user,
false) > 0) {
446 throw new RestException(500, $this->jobposition->error);
463 if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->write) {
464 throw new RestException(401);
467 $result = $this->candidature->fetch($id);
469 throw new RestException(404,
'candidature not found');
473 throw new RestException(401,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
476 foreach ($request_data as $field => $value) {
477 if ($field ==
'id') {
480 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
486 if ($this->candidature->update(DolibarrApiAccess::$user,
false) > 0) {
489 throw new RestException(500, $this->candidature->error);
506 if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->delete) {
507 throw new RestException(401);
509 $result = $this->jobposition->fetch($id);
511 throw new RestException(404,
'jobposition not found');
515 throw new RestException(401,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
518 if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
519 throw new RestException(500,
'Error when deleting jobposition : '.$this->jobposition->error);
525 'message' =>
'jobposition deleted'
542 if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->delete) {
543 throw new RestException(401);
545 $result = $this->candidature->fetch($id);
547 throw new RestException(404,
'candidature not found');
551 throw new RestException(401,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
554 if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
555 throw new RestException(500,
'Error when deleting candidature : '.$this->candidature->error);
561 'message' =>
'candidature deleted'
577 $object = parent::_cleanObjectDatas($object);
579 unset($object->rowid);
580 unset($object->canvas);
617 if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
618 $nboflines = count($object->lines);
619 for ($i = 0; $i < $nboflines; $i++) {
622 unset($object->lines[$i]->lines);
623 unset($object->lines[$i]->note);
640 $jobposition = array();
641 foreach ($this->jobposition->fields as $field => $propfield) {
642 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat')) || $propfield[
'notnull'] != 1) {
645 if (!isset($data[$field])) {
646 throw new RestException(400,
"$field field missing");
648 $jobposition[$field] = $data[$field];
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Class for RecruitmentCandidature.
indexJobPosition($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='')
List jobpositions.
_validate($data)
Validate fields before create or update object.
getJobPosition($id)
Get properties of a jobposition object.
deleteCandidature($id)
Delete candidature.
__construct()
Constructor.
indexCandidature($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='')
List candatures.
putCandidature($id, $request_data=null)
Update candidature.
deleteJobPosition($id)
Delete jobposition.
getCandidature($id)
Get properties of a candidature object.
postJobPosition($request_data=null)
Create jobposition object.
postCandidature($request_data=null)
Create candidature object.
putJobPosition($id, $request_data=null)
Update jobposition.
_cleanObjectDatas($object)
Clean sensible object datas.
Class for RecruitmentJobPosition.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
$conf db
API class for accounts.