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);
144 public function indexJobPosition($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
151 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
152 throw new RestException(401);
155 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
157 $restrictonsocid = 0;
161 if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
162 $search_sale = DolibarrApiAccess::$user->id;
165 $sql =
"SELECT t.rowid";
166 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
167 $sql .=
", sc.fk_soc, sc.fk_user";
169 $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)";
171 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
172 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
174 $sql .=
" WHERE 1 = 1";
180 if ($tmpobject->ismultientitymanaged) {
181 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
183 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
184 $sql .=
" AND t.fk_soc = sc.fk_soc";
186 if ($restrictonsocid && $socid) {
187 $sql .=
" AND t.fk_soc = ".((int) $socid);
189 if ($restrictonsocid && $search_sale > 0) {
190 $sql .=
" AND t.rowid = sc.fk_soc";
193 if ($restrictonsocid && $search_sale > 0) {
194 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
200 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
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());
249 public function indexCandidature($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'')
256 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
257 throw new RestException(401);
260 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
262 $restrictonsocid = 0;
266 if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
267 $search_sale = DolibarrApiAccess::$user->id;
270 $sql =
"SELECT t.rowid";
271 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
272 $sql .=
", sc.fk_soc, sc.fk_user";
274 $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)";
276 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
277 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
279 $sql .=
" WHERE 1 = 1";
285 if ($tmpobject->ismultientitymanaged) {
286 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
288 if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
289 $sql .=
" AND t.fk_soc = sc.fk_soc";
291 if ($restrictonsocid && $socid) {
292 $sql .=
" AND t.fk_soc = ".((int) $socid);
294 if ($restrictonsocid && $search_sale > 0) {
295 $sql .=
" AND t.rowid = sc.fk_soc";
298 if ($restrictonsocid && $search_sale > 0) {
299 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
305 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
309 $sql .= $this->db->order($sortfield, $sortorder);
314 $offset = $limit * $page;
316 $sql .= $this->db->plimit($limit + 1, $offset);
319 $result = $this->db->query($sql);
322 $num = $this->db->num_rows($result);
324 $obj = $this->db->fetch_object($result);
326 if ($tmp_object->fetch($obj->rowid)) {
332 throw new RestException(503,
'Error when retrieving candidature list: '.$this->db->lasterror());
350 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
351 throw new RestException(401);
355 $result = $this->
_validate($request_data);
357 foreach ($request_data as $field => $value) {
358 if ($field ===
'caller') {
360 $this->jobposition->context[
'caller'] = $request_data[
'caller'];
364 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
370 if ($this->jobposition->create(DolibarrApiAccess::$user)<0) {
371 throw new RestException(500,
"Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
373 return $this->jobposition->id;
388 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
389 throw new RestException(401);
393 $result = $this->
_validate($request_data);
395 foreach ($request_data as $field => $value) {
396 if ($field ===
'caller') {
398 $this->jobposition->context[
'caller'] = $request_data[
'caller'];
402 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
408 if ($this->candidature->create(DolibarrApiAccess::$user)<0) {
409 throw new RestException(500,
"Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
411 return $this->candidature->id;
427 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
428 throw new RestException(401);
431 $result = $this->jobposition->fetch($id);
433 throw new RestException(404,
'jobposition not found');
437 throw new RestException(401,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
440 foreach ($request_data as $field => $value) {
441 if ($field ==
'id') {
444 if ($field ===
'caller') {
446 $this->jobposition->context[
'caller'] = $request_data[
'caller'];
450 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
456 if ($this->jobposition->update(DolibarrApiAccess::$user,
false) > 0) {
459 throw new RestException(500, $this->jobposition->error);
476 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
477 throw new RestException(401);
480 $result = $this->candidature->fetch($id);
482 throw new RestException(404,
'candidature not found');
486 throw new RestException(401,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
489 foreach ($request_data as $field => $value) {
490 if ($field ==
'id') {
493 if ($field ===
'caller') {
495 $this->candidature->context[
'caller'] = $request_data[
'caller'];
499 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
505 if ($this->candidature->update(DolibarrApiAccess::$user,
false) > 0) {
508 throw new RestException(500, $this->candidature->error);
525 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
526 throw new RestException(401);
528 $result = $this->jobposition->fetch($id);
530 throw new RestException(404,
'jobposition not found');
534 throw new RestException(401,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
537 if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
538 throw new RestException(500,
'Error when deleting jobposition : '.$this->jobposition->error);
544 'message' =>
'jobposition deleted'
561 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
562 throw new RestException(401);
564 $result = $this->candidature->fetch($id);
566 throw new RestException(404,
'candidature not found');
570 throw new RestException(401,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
573 if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
574 throw new RestException(500,
'Error when deleting candidature : '.$this->candidature->error);
580 'message' =>
'candidature deleted'
596 $object = parent::_cleanObjectDatas($object);
598 unset($object->rowid);
599 unset($object->canvas);
636 if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
637 $nboflines = count($object->lines);
638 for ($i = 0; $i < $nboflines; $i++) {
641 unset($object->lines[$i]->lines);
642 unset($object->lines[$i]->note);
659 $jobposition = array();
660 foreach ($this->jobposition->fields as $field => $propfield) {
661 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat')) || $propfield[
'notnull'] != 1) {
664 if (!isset($data[$field])) {
665 throw new RestException(400,
"$field field missing");
667 $jobposition[$field] = $data[$field];
_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.
Class for RecruitmentCandidature.
Class for RecruitmentJobPosition.
getJobPosition($id)
Get properties of a jobposition object.
deleteJobPosition($id)
Delete jobposition.
__construct()
Constructor.
putCandidature($id, $request_data=null)
Update candidature.
deleteCandidature($id)
Delete candidature.
postJobPosition($request_data=null)
Create jobposition object.
_cleanObjectDatas($object)
Clean sensible object datas.
indexCandidature($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='')
List candatures.
_validate($data)
Validate fields before create or update object.
putJobPosition($id, $request_data=null)
Update jobposition.
indexJobPosition($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
List jobpositions.
getCandidature($id)
Get properties of a candidature object.
postCandidature($request_data=null)
Create candidature object.
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.