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 =
'', $pagination_data =
false)
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);
190 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
192 $sql .= $this->db->order($sortfield, $sortorder);
197 $offset = $limit * $page;
199 $sql .= $this->db->plimit($limit + 1, $offset);
202 $result = $this->db->query($sql);
205 $num = $this->db->num_rows($result);
207 $obj = $this->db->fetch_object($result);
209 if ($tmp_object->fetch($obj->rowid)) {
215 throw new RestException(503,
'Error when retrieving jobposition list: '.$this->db->lasterror());
219 if ($pagination_data) {
220 $totalsResult = $this->db->query($sqlTotals);
221 $total = $this->db->fetch_object($totalsResult)->total;
226 $obj_ret[
'data'] = $tmp;
227 $obj_ret[
'pagination'] = [
228 'total' => (int) $total,
230 'page_count' => ceil((
int) $total / $limit),
256 public function indexCandidature($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
263 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
264 throw new RestException(403);
267 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : 0;
269 $restrictonsocid = 0;
273 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
274 $search_sale = DolibarrApiAccess::$user->id;
277 $sql =
"SELECT t.rowid";
278 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
279 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
280 $sql .=
" WHERE 1 = 1";
281 if ($tmpobject->ismultientitymanaged) {
282 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
284 if ($restrictonsocid && $socid) {
285 $sql .=
" AND t.fk_soc = ".((int) $socid);
288 if ($search_sale && $search_sale !=
'-1') {
289 if ($search_sale == -2) {
290 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
291 } elseif ($search_sale > 0) {
292 $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).
")";
299 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
304 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
306 $sql .= $this->db->order($sortfield, $sortorder);
311 $offset = $limit * $page;
313 $sql .= $this->db->plimit($limit + 1, $offset);
316 $result = $this->db->query($sql);
319 $num = $this->db->num_rows($result);
321 $obj = $this->db->fetch_object($result);
323 if ($tmp_object->fetch($obj->rowid)) {
329 throw new RestException(503,
'Error when retrieving candidature list: '.$this->db->lasterror());
333 if ($pagination_data) {
334 $totalsResult = $this->db->query($sqlTotals);
335 $total = $this->db->fetch_object($totalsResult)->total;
340 $obj_ret[
'data'] = $tmp;
341 $obj_ret[
'pagination'] = [
342 'total' => (int) $total,
344 'page_count' => ceil((
int) $total / $limit),
364 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
365 throw new RestException(403);
369 $result = $this->
_validate($request_data);
371 foreach ($request_data as $field => $value) {
372 if ($field ===
'caller') {
374 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
378 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
384 if ($this->jobposition->create(DolibarrApiAccess::$user)<0) {
385 throw new RestException(500,
"Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
387 return $this->jobposition->id;
402 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
403 throw new RestException(403);
407 $result = $this->
_validate($request_data);
409 foreach ($request_data as $field => $value) {
410 if ($field ===
'caller') {
412 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
416 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
422 if ($this->candidature->create(DolibarrApiAccess::$user)<0) {
423 throw new RestException(500,
"Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
425 return $this->candidature->id;
441 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
442 throw new RestException(403);
445 $result = $this->jobposition->fetch(
$id);
447 throw new RestException(404,
'jobposition not found');
451 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
454 foreach ($request_data as $field => $value) {
455 if ($field ==
'id') {
458 if ($field ===
'caller') {
460 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
464 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
470 if ($this->jobposition->update(DolibarrApiAccess::$user,
false) > 0) {
473 throw new RestException(500, $this->jobposition->error);
490 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
491 throw new RestException(403);
494 $result = $this->candidature->fetch(
$id);
496 throw new RestException(404,
'candidature not found');
500 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
503 foreach ($request_data as $field => $value) {
504 if ($field ==
'id') {
507 if ($field ===
'caller') {
509 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
513 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
519 if ($this->candidature->update(DolibarrApiAccess::$user,
false) > 0) {
522 throw new RestException(500, $this->candidature->error);
539 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
540 throw new RestException(403);
542 $result = $this->jobposition->fetch(
$id);
544 throw new RestException(404,
'jobposition not found');
548 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
551 if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
552 throw new RestException(500,
'Error when deleting jobposition : '.$this->jobposition->error);
558 'message' =>
'jobposition deleted'
575 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
576 throw new RestException(403);
578 $result = $this->candidature->fetch(
$id);
580 throw new RestException(404,
'candidature not found');
584 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
587 if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
588 throw new RestException(500,
'Error when deleting candidature : '.$this->candidature->error);
594 'message' =>
'candidature deleted'
651 $nboflines = count(
$object->lines);
652 for ($i = 0; $i < $nboflines; $i++) {
655 unset(
$object->lines[$i]->lines);
656 unset(
$object->lines[$i]->note);
673 $jobposition = array();
674 foreach ($this->jobposition->fields as $field => $propfield) {
675 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat')) || $propfield[
'notnull'] != 1) {
678 if (!isset($data[$field])) {
679 throw new RestException(400,
"$field field missing");
681 $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.
indexJobPosition($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='', $pagination_data=false)
List jobpositions.
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.
_validate($data)
Validate fields before create or update object.
putJobPosition($id, $request_data=null)
Update jobposition.
getCandidature($id)
Get properties of a candidature object.
indexCandidature($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='', $pagination_data=false)
List candatures.
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.