18use Luracast\Restler\RestException;
79 if (!DolibarrApiAccess::$user->hasRight(
'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->hasRight(
'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->hasRight(
'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 LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
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);
199 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
203 $sql .= $this->db->order($sortfield, $sortorder);
208 $offset = $limit * $page;
210 $sql .= $this->db->plimit($limit + 1, $offset);
213 $result = $this->db->query($sql);
216 $num = $this->db->num_rows($result);
218 $obj = $this->db->fetch_object($result);
220 if ($tmp_object->fetch($obj->rowid)) {
226 throw new RestException(503,
'Error when retrieving jobposition list: '.$this->db->lasterror());
228 if (!count($obj_ret)) {
229 throw new RestException(404,
'No jobposition found');
250 public function indexCandidature($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'')
257 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
258 throw new RestException(401);
261 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
263 $restrictonsocid = 0;
267 if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
268 $search_sale = DolibarrApiAccess::$user->id;
271 $sql =
"SELECT t.rowid";
272 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
273 $sql .=
", sc.fk_soc, sc.fk_user";
275 $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)";
277 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
278 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
280 $sql .=
" WHERE 1 = 1";
286 if ($tmpobject->ismultientitymanaged) {
287 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
289 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
290 $sql .=
" AND t.fk_soc = sc.fk_soc";
292 if ($restrictonsocid && $socid) {
293 $sql .=
" AND t.fk_soc = ".((int) $socid);
295 if ($restrictonsocid && $search_sale > 0) {
296 $sql .=
" AND t.rowid = sc.fk_soc";
299 if ($restrictonsocid && $search_sale > 0) {
300 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
306 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
310 $sql .= $this->db->order($sortfield, $sortorder);
315 $offset = $limit * $page;
317 $sql .= $this->db->plimit($limit + 1, $offset);
320 $result = $this->db->query($sql);
323 $num = $this->db->num_rows($result);
325 $obj = $this->db->fetch_object($result);
327 if ($tmp_object->fetch($obj->rowid)) {
333 throw new RestException(503,
'Error when retrieving candidature list: '.$this->db->lasterror());
335 if (!count($obj_ret)) {
336 throw new RestException(404,
'No candidature found');
353 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
354 throw new RestException(401);
358 $result = $this->
_validate($request_data);
360 foreach ($request_data as $field => $value) {
361 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
367 if ($this->jobposition->create(DolibarrApiAccess::$user)<0) {
368 throw new RestException(500,
"Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
370 return $this->jobposition->id;
385 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
386 throw new RestException(401);
390 $result = $this->
_validate($request_data);
392 foreach ($request_data as $field => $value) {
393 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
399 if ($this->candidature->create(DolibarrApiAccess::$user)<0) {
400 throw new RestException(500,
"Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
402 return $this->candidature->id;
418 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
419 throw new RestException(401);
422 $result = $this->jobposition->fetch($id);
424 throw new RestException(404,
'jobposition not found');
428 throw new RestException(401,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
431 foreach ($request_data as $field => $value) {
432 if ($field ==
'id') {
435 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
441 if ($this->jobposition->update(DolibarrApiAccess::$user,
false) > 0) {
444 throw new RestException(500, $this->jobposition->error);
461 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
462 throw new RestException(401);
465 $result = $this->candidature->fetch($id);
467 throw new RestException(404,
'candidature not found');
471 throw new RestException(401,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
474 foreach ($request_data as $field => $value) {
475 if ($field ==
'id') {
478 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
484 if ($this->candidature->update(DolibarrApiAccess::$user,
false) > 0) {
487 throw new RestException(500, $this->candidature->error);
504 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
505 throw new RestException(401);
507 $result = $this->jobposition->fetch($id);
509 throw new RestException(404,
'jobposition not found');
513 throw new RestException(401,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
516 if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
517 throw new RestException(500,
'Error when deleting jobposition : '.$this->jobposition->error);
523 'message' =>
'jobposition deleted'
540 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
541 throw new RestException(401);
543 $result = $this->candidature->fetch($id);
545 throw new RestException(404,
'candidature not found');
549 throw new RestException(401,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
552 if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
553 throw new RestException(500,
'Error when deleting candidature : '.$this->candidature->error);
559 'message' =>
'candidature deleted'
575 $object = parent::_cleanObjectDatas($object);
577 unset($object->rowid);
578 unset($object->canvas);
615 if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
616 $nboflines = count($object->lines);
617 for ($i = 0; $i < $nboflines; $i++) {
620 unset($object->lines[$i]->lines);
621 unset($object->lines[$i]->note);
638 $jobposition = array();
639 foreach ($this->jobposition->fields as $field => $propfield) {
640 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat')) || $propfield[
'notnull'] != 1) {
643 if (!isset($data[$field])) {
644 throw new RestException(400,
"$field field missing");
646 $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.
_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.
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.