20use Luracast\Restler\RestException;
80 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
81 throw new RestException(403);
84 $result = $this->jobposition->fetch(
$id);
86 throw new RestException(404,
'JobPosition not found');
90 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
111 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
112 throw new RestException(403);
115 $result = $this->candidature->fetch(
$id);
117 throw new RestException(404,
'Candidature not found');
121 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
147 public function indexJobPosition($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
152 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
153 throw new RestException(403);
156 $socid = DolibarrApiAccess::$user->socid ?: 0;
158 $restrictonsocid = 0;
162 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
163 $search_sale = DolibarrApiAccess::$user->id;
166 $sql =
"SELECT t.rowid";
167 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
168 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
169 $sql .=
" WHERE 1 = 1";
170 if ($tmpobject->ismultientitymanaged) {
171 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
173 if ($restrictonsocid && $socid) {
174 $sql .=
" AND t.fk_soc = ".((int) $socid);
177 if ($search_sale && $search_sale !=
'-1') {
178 if ($search_sale == -2) {
179 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
180 } elseif ($search_sale > 0) {
181 $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).
")";
186 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
188 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
193 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
195 $sql .= $this->db->order($sortfield, $sortorder);
200 $offset = $limit * $page;
202 $sql .= $this->db->plimit($limit + 1, $offset);
205 $result = $this->db->query($sql);
208 $num = $this->db->num_rows($result);
209 $min = min($num, ($limit <= 0 ? $num : $limit));
211 $obj = $this->db->fetch_object($result);
213 if ($tmp_object->fetch($obj->rowid)) {
219 throw new RestException(503,
'Error when retrieving jobposition list: '.$this->db->lasterror());
223 if ($pagination_data) {
224 $totalsResult = $this->db->query($sqlTotals);
225 $total = $this->db->fetch_object($totalsResult)->total;
230 $obj_ret[
'data'] = $tmp;
231 $obj_ret[
'pagination'] = [
232 'total' => (int) $total,
234 'page_count' => ceil((
int) $total / $limit),
262 public function indexCandidature($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
269 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
270 throw new RestException(403);
273 $socid = DolibarrApiAccess::$user->socid ?: 0;
275 $restrictonsocid = 0;
279 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
280 $search_sale = DolibarrApiAccess::$user->id;
283 $sql =
"SELECT t.rowid";
284 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
285 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
286 $sql .=
" WHERE 1 = 1";
287 if ($tmpobject->ismultientitymanaged) {
288 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
290 if ($restrictonsocid && $socid) {
291 $sql .=
" AND t.fk_soc = ".((int) $socid);
294 if ($search_sale && $search_sale !=
'-1') {
295 if ($search_sale == -2) {
296 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
297 } elseif ($search_sale > 0) {
298 $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).
")";
303 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
305 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
310 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
312 $sql .= $this->db->order($sortfield, $sortorder);
317 $offset = $limit * $page;
319 $sql .= $this->db->plimit($limit + 1, $offset);
322 $result = $this->db->query($sql);
325 $num = $this->db->num_rows($result);
326 $min = min($num, ($limit <= 0 ? $num : $limit));
328 $obj = $this->db->fetch_object($result);
330 if ($tmp_object->fetch($obj->rowid)) {
336 throw new RestException(503,
'Error when retrieving candidature list: '.$this->db->lasterror());
340 if ($pagination_data) {
341 $totalsResult = $this->db->query($sqlTotals);
342 $total = $this->db->fetch_object($totalsResult)->total;
347 $obj_ret[
'data'] = $tmp;
348 $obj_ret[
'pagination'] = [
349 'total' => (int) $total,
351 'page_count' => ceil((
int) $total / $limit),
373 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
374 throw new RestException(403);
378 $result = $this->
_validate($request_data, $this->jobposition);
380 foreach ($request_data as $field => $value) {
381 if ($field ===
'caller') {
383 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
387 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
393 if ($this->jobposition->create(DolibarrApiAccess::$user) < 0) {
394 throw new RestException(500,
"Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
396 return $this->jobposition->id;
413 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
414 throw new RestException(403);
420 $result = $this->
_validate($request_data, $this->candidature);
422 foreach ($request_data as $field => $value) {
423 if ($field ===
'caller') {
425 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
429 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
435 if ($this->candidature->create(DolibarrApiAccess::$user) < 0) {
436 throw new RestException(500,
"Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
438 return $this->candidature->id;
456 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
457 throw new RestException(403);
460 $result = $this->jobposition->fetch(
$id);
462 throw new RestException(404,
'jobposition not found');
466 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
469 foreach ($request_data as $field => $value) {
470 if ($field ==
'id') {
473 if ($field ===
'caller') {
475 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
479 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
485 if ($this->jobposition->update(DolibarrApiAccess::$user, 0) > 0) {
488 throw new RestException(500, $this->jobposition->error);
507 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
508 throw new RestException(403);
511 $result = $this->candidature->fetch(
$id);
513 throw new RestException(404,
'candidature not found');
517 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
520 foreach ($request_data as $field => $value) {
521 if ($field ==
'id') {
524 if ($field ===
'caller') {
526 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
530 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
536 if ($this->candidature->update(DolibarrApiAccess::$user, 0) > 0) {
539 throw new RestException(500, $this->candidature->error);
558 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
559 throw new RestException(403);
561 $result = $this->jobposition->fetch(
$id);
563 throw new RestException(404,
'jobposition not found');
567 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
570 if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
571 throw new RestException(500,
'Error when deleting jobposition : '.$this->jobposition->error);
577 'message' =>
'jobposition deleted'
596 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
597 throw new RestException(403);
599 $result = $this->candidature->fetch(
$id);
601 throw new RestException(404,
'candidature not found');
605 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
608 if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
609 throw new RestException(500,
'Error when deleting candidature : '.$this->candidature->error);
615 'message' =>
'candidature deleted'
675 $nboflines = count(
$object->lines);
676 for ($i = 0; $i < $nboflines; $i++) {
679 unset(
$object->lines[$i]->lines);
680 unset(
$object->lines[$i]->note);
698 if ($data ===
null) {
702 foreach (
$object->fields as $field => $propfield) {
703 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'])) {
706 if (!isset($data[$field])) {
707 throw new RestException(400,
"$field field missing");
709 $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.
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 @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.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.