19use 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);
146 public function indexJobPosition($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
151 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
152 throw new RestException(403);
155 $socid = DolibarrApiAccess::$user->socid ?: 0;
157 $restrictonsocid = 0;
161 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
162 $search_sale = DolibarrApiAccess::$user->id;
165 $sql =
"SELECT t.rowid";
166 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
167 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
168 $sql .=
" WHERE 1 = 1";
169 if ($tmpobject->ismultientitymanaged) {
170 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
172 if ($restrictonsocid && $socid) {
173 $sql .=
" AND t.fk_soc = ".((int) $socid);
176 if ($search_sale && $search_sale !=
'-1') {
177 if ($search_sale == -2) {
178 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
179 } elseif ($search_sale > 0) {
180 $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).
")";
187 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
192 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
194 $sql .= $this->db->order($sortfield, $sortorder);
199 $offset = $limit * $page;
201 $sql .= $this->db->plimit($limit + 1, $offset);
204 $result = $this->db->query($sql);
207 $num = $this->db->num_rows($result);
209 $obj = $this->db->fetch_object($result);
211 if ($tmp_object->fetch($obj->rowid)) {
217 throw new RestException(503,
'Error when retrieving jobposition list: '.$this->db->lasterror());
221 if ($pagination_data) {
222 $totalsResult = $this->db->query($sqlTotals);
223 $total = $this->db->fetch_object($totalsResult)->total;
228 $obj_ret[
'data'] = $tmp;
229 $obj_ret[
'pagination'] = [
230 'total' => (int) $total,
232 'page_count' => ceil((
int) $total / $limit),
260 public function indexCandidature($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
267 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
268 throw new RestException(403);
271 $socid = DolibarrApiAccess::$user->socid ?: 0;
273 $restrictonsocid = 0;
277 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
278 $search_sale = DolibarrApiAccess::$user->id;
281 $sql =
"SELECT t.rowid";
282 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
283 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
284 $sql .=
" WHERE 1 = 1";
285 if ($tmpobject->ismultientitymanaged) {
286 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
288 if ($restrictonsocid && $socid) {
289 $sql .=
" AND t.fk_soc = ".((int) $socid);
292 if ($search_sale && $search_sale !=
'-1') {
293 if ($search_sale == -2) {
294 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
295 } elseif ($search_sale > 0) {
296 $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 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
308 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
310 $sql .= $this->db->order($sortfield, $sortorder);
315 $offset = $limit * $page;
317 $sql .= $this->db->plimit($limit + 1, $offset);
320 $result = $this->db->query($sql);
323 $num = $this->db->num_rows($result);
325 $obj = $this->db->fetch_object($result);
327 if ($tmp_object->fetch($obj->rowid)) {
333 throw new RestException(503,
'Error when retrieving candidature list: '.$this->db->lasterror());
337 if ($pagination_data) {
338 $totalsResult = $this->db->query($sqlTotals);
339 $total = $this->db->fetch_object($totalsResult)->total;
344 $obj_ret[
'data'] = $tmp;
345 $obj_ret[
'pagination'] = [
346 'total' => (int) $total,
348 'page_count' => ceil((
int) $total / $limit),
370 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
371 throw new RestException(403);
375 $result = $this->
_validate($request_data, $this->jobposition);
377 foreach ($request_data as $field => $value) {
378 if ($field ===
'caller') {
380 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
384 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
390 if ($this->jobposition->create(DolibarrApiAccess::$user) < 0) {
391 throw new RestException(500,
"Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
393 return $this->jobposition->id;
410 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
411 throw new RestException(403);
417 $result = $this->
_validate($request_data, $this->candidature);
419 foreach ($request_data as $field => $value) {
420 if ($field ===
'caller') {
422 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
426 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
432 if ($this->candidature->create(DolibarrApiAccess::$user) < 0) {
433 throw new RestException(500,
"Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
435 return $this->candidature->id;
453 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
454 throw new RestException(403);
457 $result = $this->jobposition->fetch(
$id);
459 throw new RestException(404,
'jobposition not found');
463 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
466 foreach ($request_data as $field => $value) {
467 if ($field ==
'id') {
470 if ($field ===
'caller') {
472 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
476 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
482 if ($this->jobposition->update(DolibarrApiAccess::$user, 0) > 0) {
485 throw new RestException(500, $this->jobposition->error);
504 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
505 throw new RestException(403);
508 $result = $this->candidature->fetch(
$id);
510 throw new RestException(404,
'candidature not found');
514 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
517 foreach ($request_data as $field => $value) {
518 if ($field ==
'id') {
521 if ($field ===
'caller') {
523 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
527 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
533 if ($this->candidature->update(DolibarrApiAccess::$user, 0) > 0) {
536 throw new RestException(500, $this->candidature->error);
555 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
556 throw new RestException(403);
558 $result = $this->jobposition->fetch(
$id);
560 throw new RestException(404,
'jobposition not found');
564 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
567 if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
568 throw new RestException(500,
'Error when deleting jobposition : '.$this->jobposition->error);
574 'message' =>
'jobposition deleted'
593 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
594 throw new RestException(403);
596 $result = $this->candidature->fetch(
$id);
598 throw new RestException(404,
'candidature not found');
602 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
605 if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
606 throw new RestException(500,
'Error when deleting candidature : '.$this->candidature->error);
612 'message' =>
'candidature deleted'
669 $nboflines = count(
$object->lines);
670 for ($i = 0; $i < $nboflines; $i++) {
673 unset(
$object->lines[$i]->lines);
674 unset(
$object->lines[$i]->note);
692 if ($data ===
null) {
696 foreach (
$object->fields as $field => $propfield) {
697 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat')) || empty($propfield[
'notnull']) || $propfield[
'notnull'] != 1) {
700 if (!isset($data[$field])) {
701 throw new RestException(400,
"$field field missing");
703 $result[$field] = $data[$field];
$id
Support class for third parties, contacts, members, users or resources.
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.
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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...