18use Luracast\Restler\RestException;
79 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
80 throw new RestException(403);
83 $result = $this->jobposition->fetch($id);
85 throw new RestException(404,
'JobPosition not found');
89 throw new RestException(403,
'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(403);
114 $result = $this->candidature->fetch($id);
116 throw new RestException(404,
'Candidature not found');
120 throw new RestException(403,
'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 =
'')
149 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
150 throw new RestException(403);
153 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : 0;
155 $restrictonsocid = 0;
159 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
160 $search_sale = DolibarrApiAccess::$user->id;
163 $sql =
"SELECT t.rowid";
164 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
165 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
166 $sql .=
" WHERE 1 = 1";
167 if ($tmpobject->ismultientitymanaged) {
168 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
170 if ($restrictonsocid && $socid) {
171 $sql .=
" AND t.fk_soc = ".((int) $socid);
174 if ($search_sale && $search_sale !=
'-1') {
175 if ($search_sale == -2) {
176 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
177 } elseif ($search_sale > 0) {
178 $sql .=
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).
")";
185 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
189 $sql .= $this->db->order($sortfield, $sortorder);
194 $offset = $limit * $page;
196 $sql .= $this->db->plimit($limit + 1, $offset);
199 $result = $this->db->query($sql);
202 $num = $this->db->num_rows($result);
204 $obj = $this->db->fetch_object($result);
206 if ($tmp_object->fetch($obj->rowid)) {
212 throw new RestException(503,
'Error when retrieving jobposition list: '.$this->db->lasterror());
234 public function indexCandidature($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'')
241 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
242 throw new RestException(403);
245 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : 0;
247 $restrictonsocid = 0;
251 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
252 $search_sale = DolibarrApiAccess::$user->id;
255 $sql =
"SELECT t.rowid";
256 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
257 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
258 $sql .=
" WHERE 1 = 1";
259 if ($tmpobject->ismultientitymanaged) {
260 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
262 if ($restrictonsocid && $socid) {
263 $sql .=
" AND t.fk_soc = ".((int) $socid);
266 if ($search_sale && $search_sale !=
'-1') {
267 if ($search_sale == -2) {
268 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
269 } elseif ($search_sale > 0) {
270 $sql .=
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).
")";
277 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
281 $sql .= $this->db->order($sortfield, $sortorder);
286 $offset = $limit * $page;
288 $sql .= $this->db->plimit($limit + 1, $offset);
291 $result = $this->db->query($sql);
294 $num = $this->db->num_rows($result);
296 $obj = $this->db->fetch_object($result);
298 if ($tmp_object->fetch($obj->rowid)) {
304 throw new RestException(503,
'Error when retrieving candidature list: '.$this->db->lasterror());
322 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
323 throw new RestException(403);
327 $result = $this->
_validate($request_data);
329 foreach ($request_data as $field => $value) {
330 if ($field ===
'caller') {
332 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
336 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
342 if ($this->jobposition->create(DolibarrApiAccess::$user)<0) {
343 throw new RestException(500,
"Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
345 return $this->jobposition->id;
360 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
361 throw new RestException(403);
365 $result = $this->
_validate($request_data);
367 foreach ($request_data as $field => $value) {
368 if ($field ===
'caller') {
370 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
374 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
380 if ($this->candidature->create(DolibarrApiAccess::$user)<0) {
381 throw new RestException(500,
"Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
383 return $this->candidature->id;
399 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
400 throw new RestException(403);
403 $result = $this->jobposition->fetch($id);
405 throw new RestException(404,
'jobposition not found');
409 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
412 foreach ($request_data as $field => $value) {
413 if ($field ==
'id') {
416 if ($field ===
'caller') {
418 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
422 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
428 if ($this->jobposition->update(DolibarrApiAccess::$user,
false) > 0) {
431 throw new RestException(500, $this->jobposition->error);
448 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
449 throw new RestException(403);
452 $result = $this->candidature->fetch($id);
454 throw new RestException(404,
'candidature not found');
458 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
461 foreach ($request_data as $field => $value) {
462 if ($field ==
'id') {
465 if ($field ===
'caller') {
467 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
471 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
477 if ($this->candidature->update(DolibarrApiAccess::$user,
false) > 0) {
480 throw new RestException(500, $this->candidature->error);
497 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
498 throw new RestException(403);
500 $result = $this->jobposition->fetch($id);
502 throw new RestException(404,
'jobposition not found');
506 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
509 if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
510 throw new RestException(500,
'Error when deleting jobposition : '.$this->jobposition->error);
516 'message' =>
'jobposition deleted'
533 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
534 throw new RestException(403);
536 $result = $this->candidature->fetch($id);
538 throw new RestException(404,
'candidature not found');
542 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
545 if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
546 throw new RestException(500,
'Error when deleting candidature : '.$this->candidature->error);
552 'message' =>
'candidature deleted'
609 $nboflines = count(
$object->lines);
610 for ($i = 0; $i < $nboflines; $i++) {
613 unset(
$object->lines[$i]->lines);
614 unset(
$object->lines[$i]->note);
631 $jobposition = array();
632 foreach ($this->jobposition->fields as $field => $propfield) {
633 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat')) || $propfield[
'notnull'] != 1) {
636 if (!isset($data[$field])) {
637 throw new RestException(400,
"$field field missing");
639 $jobposition[$field] = $data[$field];
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
_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.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.