19use 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 ? 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).
")";
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);
210 $obj = $this->db->fetch_object($result);
212 if ($tmp_object->fetch($obj->rowid)) {
218 throw new RestException(503,
'Error when retrieving jobposition list: '.$this->db->lasterror());
222 if ($pagination_data) {
223 $totalsResult = $this->db->query($sqlTotals);
224 $total = $this->db->fetch_object($totalsResult)->total;
229 $obj_ret[
'data'] = $tmp;
230 $obj_ret[
'pagination'] = [
231 'total' => (int) $total,
233 'page_count' => ceil((
int) $total / $limit),
261 public function indexCandidature($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
268 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
269 throw new RestException(403);
272 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : 0;
274 $restrictonsocid = 0;
278 if ($restrictonsocid && !DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
279 $search_sale = DolibarrApiAccess::$user->id;
282 $sql =
"SELECT t.rowid";
283 $sql .=
" FROM ".MAIN_DB_PREFIX.$tmpobject->table_element.
" AS t";
284 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element.
"_extrafields AS ef ON (ef.fk_object = t.rowid)";
285 $sql .=
" WHERE 1 = 1";
286 if ($tmpobject->ismultientitymanaged) {
287 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
289 if ($restrictonsocid && $socid) {
290 $sql .=
" AND t.fk_soc = ".((int) $socid);
293 if ($search_sale && $search_sale !=
'-1') {
294 if ($search_sale == -2) {
295 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
296 } elseif ($search_sale > 0) {
297 $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).
")";
304 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
309 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
311 $sql .= $this->db->order($sortfield, $sortorder);
316 $offset = $limit * $page;
318 $sql .= $this->db->plimit($limit + 1, $offset);
321 $result = $this->db->query($sql);
324 $num = $this->db->num_rows($result);
326 $obj = $this->db->fetch_object($result);
328 if ($tmp_object->fetch($obj->rowid)) {
334 throw new RestException(503,
'Error when retrieving candidature list: '.$this->db->lasterror());
338 if ($pagination_data) {
339 $totalsResult = $this->db->query($sqlTotals);
340 $total = $this->db->fetch_object($totalsResult)->total;
345 $obj_ret[
'data'] = $tmp;
346 $obj_ret[
'pagination'] = [
347 'total' => (int) $total,
349 'page_count' => ceil((
int) $total / $limit),
371 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
372 throw new RestException(403);
376 $result = $this->
_validate($request_data);
378 foreach ($request_data as $field => $value) {
379 if ($field ===
'caller') {
381 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
385 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
391 if ($this->jobposition->create(DolibarrApiAccess::$user) < 0) {
392 throw new RestException(500,
"Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
394 return $this->jobposition->id;
411 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
412 throw new RestException(403);
416 $result = $this->
_validate($request_data);
418 foreach ($request_data as $field => $value) {
419 if ($field ===
'caller') {
421 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
425 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
431 if ($this->candidature->create(DolibarrApiAccess::$user) < 0) {
432 throw new RestException(500,
"Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
434 return $this->candidature->id;
452 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
453 throw new RestException(403);
456 $result = $this->jobposition->fetch(
$id);
458 throw new RestException(404,
'jobposition not found');
462 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
465 foreach ($request_data as $field => $value) {
466 if ($field ==
'id') {
469 if ($field ===
'caller') {
471 $this->jobposition->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
475 $this->jobposition->$field = $this->
_checkValForAPI($field, $value, $this->jobposition);
481 if ($this->jobposition->update(DolibarrApiAccess::$user,
false) > 0) {
484 throw new RestException(500, $this->jobposition->error);
503 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'write')) {
504 throw new RestException(403);
507 $result = $this->candidature->fetch(
$id);
509 throw new RestException(404,
'candidature not found');
513 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
516 foreach ($request_data as $field => $value) {
517 if ($field ==
'id') {
520 if ($field ===
'caller') {
522 $this->candidature->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
526 $this->candidature->$field = $this->
_checkValForAPI($field, $value, $this->candidature);
532 if ($this->candidature->update(DolibarrApiAccess::$user,
false) > 0) {
535 throw new RestException(500, $this->candidature->error);
554 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
555 throw new RestException(403);
557 $result = $this->jobposition->fetch(
$id);
559 throw new RestException(404,
'jobposition not found');
563 throw new RestException(403,
'Access to instance id='.$this->jobposition->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
566 if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
567 throw new RestException(500,
'Error when deleting jobposition : '.$this->jobposition->error);
573 'message' =>
'jobposition deleted'
592 if (!DolibarrApiAccess::$user->hasRight(
'recruitment',
'recruitmentjobposition',
'delete')) {
593 throw new RestException(403);
595 $result = $this->candidature->fetch(
$id);
597 throw new RestException(404,
'candidature not found');
601 throw new RestException(403,
'Access to instance id='.$this->candidature->id.
' of object not allowed for login '.DolibarrApiAccess::$user->login);
604 if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
605 throw new RestException(500,
'Error when deleting candidature : '.$this->candidature->error);
611 'message' =>
'candidature deleted'
668 $nboflines = count(
$object->lines);
669 for ($i = 0; $i < $nboflines; $i++) {
672 unset(
$object->lines[$i]->lines);
673 unset(
$object->lines[$i]->note);
690 $jobposition = array();
691 foreach ($this->jobposition->fields as $field => $propfield) {
692 if (in_array($field, array(
'rowid',
'entity',
'date_creation',
'tms',
'fk_user_creat')) || $propfield[
'notnull'] != 1) {
695 if (!isset($data[$field])) {
696 throw new RestException(400,
"$field field missing");
698 $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.