19 use Luracast\Restler\RestException;
21 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
35 public static $FIELDS = array(
44 public static $FIELDSLINE = array(
75 public function get($id)
77 if (!DolibarrApiAccess::$user->rights->ficheinter->lire) {
78 throw new RestException(401);
81 $result = $this->fichinter->fetch($id);
83 throw new RestException(404,
'Intervention not found');
87 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
90 $this->fichinter->fetchObjectLinked();
109 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'')
113 if (!DolibarrApiAccess::$user->rights->ficheinter->lire) {
114 throw new RestException(401);
120 $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
124 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
125 $search_sale = DolibarrApiAccess::$user->id;
128 $sql =
"SELECT t.rowid";
129 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
130 $sql .=
", sc.fk_soc, sc.fk_user";
132 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as t";
134 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
135 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
138 $sql .=
' WHERE t.entity IN ('.getEntity(
'intervention').
')';
139 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
140 $sql .=
" AND t.fk_soc = sc.fk_soc";
143 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
145 if ($search_sale > 0) {
146 $sql .=
" AND t.rowid = sc.fk_soc";
149 if ($search_sale > 0) {
150 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
156 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
158 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
159 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
162 $sql .= $this->
db->order($sortfield, $sortorder);
167 $offset = $limit * $page;
169 $sql .= $this->
db->plimit($limit + 1, $offset);
173 $result = $this->
db->query($sql);
176 $num = $this->
db->num_rows($result);
177 $min = min($num, ($limit <= 0 ? $num : $limit));
180 $obj = $this->
db->fetch_object($result);
182 if ($fichinter_static->fetch($obj->rowid)) {
188 throw new RestException(503,
'Error when retrieve intervention list : '.$this->
db->lasterror());
190 if (!count($obj_ret)) {
191 throw new RestException(404,
'No intervention found');
202 public function post($request_data =
null)
204 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
205 throw new RestException(401,
"Insuffisant rights");
208 $result = $this->
_validate($request_data);
209 foreach ($request_data as $field => $value) {
210 $this->fichinter->$field = $value;
213 if ($this->fichinter->create(DolibarrApiAccess::$user) < 0) {
214 throw new RestException(500,
"Error creating intervention", array_merge(array($this->fichinter->error), $this->fichinter->errors));
217 return $this->fichinter->id;
264 public function postLine($id, $request_data =
null)
266 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
267 throw new RestException(401,
"Insuffisant rights");
272 foreach ($request_data as $field => $value) {
273 $this->fichinter->$field = $value;
277 throw new RestException(404,
'Intervention not found');
281 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
284 $updateRes = $this->fichinter->addLine(
285 DolibarrApiAccess::$user,
287 $this->fichinter->description,
288 $this->fichinter->date,
289 $this->fichinter->duree
292 if ($updateRes > 0) {
295 throw new RestException(400, $this->fichinter->error);
305 public function delete($id)
307 if (!DolibarrApiAccess::$user->rights->ficheinter->supprimer) {
308 throw new RestException(401);
310 $result = $this->fichinter->fetch($id);
312 throw new RestException(404,
'Intervention not found');
316 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
319 if (!$this->fichinter->delete(DolibarrApiAccess::$user)) {
320 throw new RestException(500,
'Error when delete intervention : '.$this->fichinter->error);
326 'message' =>
'Intervention deleted'
348 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
349 throw new RestException(401,
"Insuffisant rights");
351 $result = $this->fichinter->fetch($id);
353 throw new RestException(404,
'Intervention not found');
357 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
360 $result = $this->fichinter->setValid(DolibarrApiAccess::$user, $notrigger);
362 throw new RestException(304,
'Error nothing done. May be object is already validated');
365 throw new RestException(500,
'Error when validating Intervention: '.$this->commande->error);
368 $this->fichinter->fetchObjectLinked();
384 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
385 throw new RestException(401,
"Insuffisant rights");
387 $result = $this->fichinter->fetch($id);
389 throw new RestException(404,
'Intervention not found');
393 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
396 $result = $this->fichinter->setStatut(3);
399 throw new RestException(304,
'Error nothing done. May be object is already closed');
402 throw new RestException(500,
'Error when closing Intervention: '.$this->fichinter->error);
405 $this->fichinter->fetchObjectLinked();
420 $fichinter = array();
421 foreach (Interventions::$FIELDS as $field) {
422 if (!isset($data[$field])) {
423 throw new RestException(400,
"$field field missing");
425 $fichinter[$field] = $data[$field];
441 $object = parent::_cleanObjectDatas($object);
443 unset($object->statuts_short);
444 unset($object->statuts_logo);
445 unset($object->statuts);
460 $fichinter = array();
461 foreach (Interventions::$FIELDSLINE as $field) {
462 if (!isset($data[$field])) {
463 throw new RestException(400,
"$field field missing");
465 $fichinter[$field] = $data[$field];
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid.
Class to manage interventions.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $sqlfilters='')
List of interventions.
_cleanObjectDatas($object)
Clean sensible object datas.
validate($id, $notrigger=0)
Validate an intervention.
_validateLine($data)
Validate fields before create or update object.
post($request_data=null)
Create intervention object.
closeFichinter($id)
Close an intervention.
_validate($data)
Validate fields before create or update object.
__construct()
Constructor.
postLine($id, $request_data=null)
Get lines of an intervention.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.