20use Luracast\Restler\RestException;
24require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
81 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
82 throw new RestException(403);
85 $result = $this->jobposition->fetch(
$id);
87 throw new RestException(404,
'JobPosition not found');
91 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
112 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
113 throw new RestException(403);
116 $result = $this->candidature->fetch(
$id);
118 throw new RestException(404,
'Candidature not found');
122 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
148 public function indexJobPosition($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
153 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
154 throw new RestException(403);
157 $socid = DolibarrApiAccess::$user->socid ?: 0;
159 $restrictonsocid = 0;
163 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
164 $search_sale = DolibarrApiAccess::$user->id;
167 $sql =
"SELECT t.rowid";
168 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
169 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
170 $sql .=
" WHERE 1 = 1";
171 if ($tmpobject->ismultientitymanaged) {
172 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
174 if ($restrictonsocid && $socid) {
175 $sql .=
" AND t.fk_soc = ".((int) $socid);
178 if ($search_sale && $search_sale !=
'-1') {
179 if ($search_sale == -2) {
180 $sql .=
" AND ".getSalesRepresentativeSqlFilter(
't.fk_soc', 0, 1);
181 } elseif ($search_sale > 0) {
182 $sql .=
" AND ".getSalesRepresentativeSqlFilter(
't.fk_soc', (
int) $search_sale);
189 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
194 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
196 $sql .= $this->db->order($sortfield, $sortorder);
201 $offset = $limit * $page;
203 $sql .= $this->db->plimit($limit + 1, $offset);
206 $result = $this->db->query($sql);
209 $num = $this->db->num_rows($result);
210 $min = min($num, ($limit <= 0 ? $num : $limit));
212 $obj = $this->db->fetch_object($result);
214 if ($tmp_object->fetch($obj->rowid)) {
220 throw new RestException(503,
'Error when retrieving jobposition list: '.$this->db->lasterror());
224 if ($pagination_data) {
225 $totalsResult = $this->db->query($sqlTotals);
226 $total = $this->db->fetch_object($totalsResult)->total;
231 $obj_ret[
'data'] = $tmp;
232 $obj_ret[
'pagination'] = [
233 'total' => (int) $total,
235 'page_count' => ceil((
int) $total / $limit),
263 public function indexCandidature($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
270 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
271 throw new RestException(403);
274 $socid = DolibarrApiAccess::$user->socid ?: 0;
276 $restrictonsocid = 0;
280 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
281 $search_sale = DolibarrApiAccess::$user->id;
284 $sql =
"SELECT t.rowid";
285 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
286 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
287 $sql .=
" WHERE 1 = 1";
288 if ($tmpobject->ismultientitymanaged) {
289 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
291 if ($restrictonsocid && $socid) {
292 $sql .=
" AND t.fk_soc = ".((int) $socid);
295 if ($search_sale && $search_sale !=
'-1') {
296 if ($search_sale == -2) {
297 $sql .=
" AND ".getSalesRepresentativeSqlFilter(
't.fk_soc', 0, 1);
298 } elseif ($search_sale > 0) {
299 $sql .=
" AND ".getSalesRepresentativeSqlFilter(
't.fk_soc', (
int) $search_sale);
306 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
311 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
313 $sql .= $this->db->order($sortfield, $sortorder);
318 $offset = $limit * $page;
320 $sql .= $this->db->plimit($limit + 1, $offset);
323 $result = $this->db->query($sql);
326 $num = $this->db->num_rows($result);
327 $min = min($num, ($limit <= 0 ? $num : $limit));
329 $obj = $this->db->fetch_object($result);
331 if ($tmp_object->fetch($obj->rowid)) {
337 throw new RestException(503,
'Error when retrieving candidature list: '.$this->db->lasterror());
341 if ($pagination_data) {
342 $totalsResult = $this->db->query($sqlTotals);
343 $total = $this->db->fetch_object($totalsResult)->total;
348 $obj_ret[
'data'] = $tmp;
349 $obj_ret[
'pagination'] = [
350 'total' => (int) $total,
352 'page_count' => ceil((
int) $total / $limit),
374 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
375 throw new RestException(403);
379 $result = $this->
_validate($request_data, $this->jobposition);
381 foreach ($request_data as $field => $value) {
382 if ($field ===
'caller') {
384 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
388 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
394 if ($this->jobposition->create(DolibarrApiAccess::$user) < 0) {
395 throw new RestException(500,
"Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
397 return $this->jobposition->id;
414 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
415 throw new RestException(403);
421 $result = $this->
_validate($request_data, $this->candidature);
423 foreach ($request_data as $field => $value) {
424 if ($field ===
'caller') {
426 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
430 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
436 if ($this->candidature->create(DolibarrApiAccess::$user) < 0) {
437 throw new RestException(500,
"Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
439 return $this->candidature->id;
457 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
458 throw new RestException(403);
461 $result = $this->jobposition->fetch(
$id);
463 throw new RestException(404,
'jobposition not found');
467 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
470 foreach ($request_data as $field => $value) {
471 if ($field ==
'id') {
474 if ($field ===
'caller') {
476 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
480 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
486 if ($this->jobposition->update(DolibarrApiAccess::$user, 0) > 0) {
489 throw new RestException(500, $this->jobposition->error);
508 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
509 throw new RestException(403);
512 $result = $this->candidature->fetch(
$id);
514 throw new RestException(404,
'candidature not found');
518 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
521 foreach ($request_data as $field => $value) {
522 if ($field ==
'id') {
525 if ($field ===
'caller') {
527 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
531 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
537 if ($this->candidature->update(DolibarrApiAccess::$user, 0) > 0) {
540 throw new RestException(500, $this->candidature->error);
559 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
560 throw new RestException(403);
562 $result = $this->jobposition->fetch(
$id);
564 throw new RestException(404,
'jobposition not found');
568 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
571 if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
572 throw new RestException(500,
'Error when deleting jobposition : '.$this->jobposition->error);
578 'message' =>
'jobposition deleted'
597 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
598 throw new RestException(403);
600 $result = $this->candidature->fetch(
$id);
602 throw new RestException(404,
'candidature not found');
606 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
609 if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
610 throw new RestException(500,
'Error when deleting candidature : '.$this->candidature->error);
616 'message' =>
'candidature deleted'
676 $nboflines = count(
$object->lines);
677 for ($i = 0; $i < $nboflines; $i++) {
680 unset(
$object->lines[$i]->lines);
681 unset(
$object->lines[$i]->note);
699 if ($data ===
null) {
703 foreach (
$object->fields as $field => $propfield) {
704 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat',
'ref')) || empty($propfield[
'notnull']) || $propfield[
'notnull'] != 1 || !empty($propfield[
'noteditable']) || isset($propfield[
'default'])) {
707 if (!isset($data[$field])) {
708 throw new RestException(400,
"$field field missing");
710 $result[$field] = $data[$field];
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
Check access by user to a given resource.
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 @phpstan-template T.
putJobPosition($id, $request_data=null)
Update jobposition.
_validate($data, $object)
Validate fields before create or update object.
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.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.