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 = 1;
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) {
184 $sql .=
" AND (t.fk_soc IS NULL OR 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).
"))";
191 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
196 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
198 $sql .= $this->db->order($sortfield, $sortorder);
203 $offset = $limit * $page;
205 $sql .= $this->db->plimit($limit + 1, $offset);
208 $result = $this->db->query($sql);
211 $num = $this->db->num_rows($result);
212 $min = min($num, ($limit <= 0 ? $num : $limit));
214 $obj = $this->db->fetch_object($result);
216 if ($tmp_object->fetch($obj->rowid)) {
222 throw new RestException(503,
'Error when retrieving jobposition list: '.$this->db->lasterror());
226 if ($pagination_data) {
227 $totalsResult = $this->db->query($sqlTotals);
228 $total = $this->db->fetch_object($totalsResult)->total;
233 $obj_ret[
'data'] = $tmp;
234 $obj_ret[
'pagination'] = [
235 'total' => (int) $total,
237 'page_count' => ceil((
int) $total / $limit),
265 public function indexCandidature($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
272 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
273 throw new RestException(403);
276 $socid = DolibarrApiAccess::$user->socid ?: 0;
278 $restrictonsocid = 0;
282 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
283 $search_sale = DolibarrApiAccess::$user->id;
286 $sql =
"SELECT t.rowid";
287 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
288 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
289 $sql .=
" WHERE 1 = 1";
290 if ($tmpobject->ismultientitymanaged) {
291 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
293 if ($restrictonsocid && $socid) {
294 $sql .=
" AND t.fk_soc = ".((int) $socid);
297 if ($search_sale && $search_sale !=
'-1') {
298 if ($search_sale == -2) {
299 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
300 } elseif ($search_sale > 0) {
301 $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).
")";
308 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
313 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
315 $sql .= $this->db->order($sortfield, $sortorder);
320 $offset = $limit * $page;
322 $sql .= $this->db->plimit($limit + 1, $offset);
325 $result = $this->db->query($sql);
328 $num = $this->db->num_rows($result);
329 $min = min($num, ($limit <= 0 ? $num : $limit));
331 $obj = $this->db->fetch_object($result);
333 if ($tmp_object->fetch($obj->rowid)) {
339 throw new RestException(503,
'Error when retrieving candidature list: '.$this->db->lasterror());
343 if ($pagination_data) {
344 $totalsResult = $this->db->query($sqlTotals);
345 $total = $this->db->fetch_object($totalsResult)->total;
350 $obj_ret[
'data'] = $tmp;
351 $obj_ret[
'pagination'] = [
352 'total' => (int) $total,
354 'page_count' => ceil((
int) $total / $limit),
376 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
377 throw new RestException(403);
381 $result = $this->
_validate($request_data, $this->jobposition);
383 foreach ($request_data as $field => $value) {
384 if ($field ===
'caller') {
386 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
390 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
396 if ($this->jobposition->create(DolibarrApiAccess::$user) < 0) {
397 throw new RestException(500,
"Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
399 return $this->jobposition->id;
416 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
417 throw new RestException(403);
423 $result = $this->
_validate($request_data, $this->candidature);
425 foreach ($request_data as $field => $value) {
426 if ($field ===
'caller') {
428 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
432 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
438 if ($this->candidature->create(DolibarrApiAccess::$user) < 0) {
439 throw new RestException(500,
"Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
441 return $this->candidature->id;
459 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
460 throw new RestException(403);
463 $result = $this->jobposition->fetch(
$id);
465 throw new RestException(404,
'jobposition not found');
469 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
472 foreach ($request_data as $field => $value) {
473 if ($field ==
'id') {
476 if ($field ===
'caller') {
478 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
482 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
488 if ($this->jobposition->update(DolibarrApiAccess::$user, 0) > 0) {
491 throw new RestException(500, $this->jobposition->error);
510 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
511 throw new RestException(403);
514 $result = $this->candidature->fetch(
$id);
516 throw new RestException(404,
'candidature not found');
520 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
523 foreach ($request_data as $field => $value) {
524 if ($field ==
'id') {
527 if ($field ===
'caller') {
529 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
533 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
539 if ($this->candidature->update(DolibarrApiAccess::$user, 0) > 0) {
542 throw new RestException(500, $this->candidature->error);
561 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
562 throw new RestException(403);
564 $result = $this->jobposition->fetch(
$id);
566 throw new RestException(404,
'jobposition not found');
570 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
573 if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
574 throw new RestException(500,
'Error when deleting jobposition : '.$this->jobposition->error);
580 'message' =>
'jobposition deleted'
599 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
600 throw new RestException(403);
602 $result = $this->candidature->fetch(
$id);
604 throw new RestException(404,
'candidature not found');
608 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
611 if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
612 throw new RestException(500,
'Error when deleting candidature : '.$this->candidature->error);
618 'message' =>
'candidature deleted'
678 $nboflines = count(
$object->lines);
679 for ($i = 0; $i < $nboflines; $i++) {
682 unset(
$object->lines[$i]->lines);
683 unset(
$object->lines[$i]->note);
701 if ($data ===
null) {
705 foreach (
$object->fields as $field => $propfield) {
706 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'])) {
709 if (!isset($data[$field])) {
710 throw new RestException(400,
"$field field missing");
712 $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.