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);
157 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
161 $sql .= $this->
db->order($sortfield, $sortorder);
166 $offset = $limit * $page;
168 $sql .= $this->
db->plimit($limit + 1, $offset);
172 $result = $this->
db->query($sql);
175 $num = $this->
db->num_rows($result);
176 $min = min($num, ($limit <= 0 ? $num : $limit));
179 $obj = $this->
db->fetch_object($result);
181 if ($fichinter_static->fetch($obj->rowid)) {
187 throw new RestException(503,
'Error when retrieve intervention list : '.$this->
db->lasterror());
189 if (!count($obj_ret)) {
190 throw new RestException(404,
'No intervention found');
201 public function post($request_data =
null)
203 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
204 throw new RestException(401,
"Insuffisant rights");
207 $result = $this->
_validate($request_data);
208 foreach ($request_data as $field => $value) {
209 $this->fichinter->$field = $value;
212 if ($this->fichinter->create(DolibarrApiAccess::$user) < 0) {
213 throw new RestException(500,
"Error creating intervention", array_merge(array($this->fichinter->error), $this->fichinter->errors));
216 return $this->fichinter->id;
263 public function postLine($id, $request_data =
null)
265 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
266 throw new RestException(401,
"Insuffisant rights");
271 foreach ($request_data as $field => $value) {
272 $this->fichinter->$field = $value;
276 throw new RestException(404,
'Intervention not found');
280 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
283 $updateRes = $this->fichinter->addLine(
284 DolibarrApiAccess::$user,
286 $this->fichinter->description,
287 $this->fichinter->date,
288 $this->fichinter->duree
291 if ($updateRes > 0) {
294 throw new RestException(400, $this->fichinter->error);
304 public function delete($id)
306 if (!DolibarrApiAccess::$user->rights->ficheinter->supprimer) {
307 throw new RestException(401);
309 $result = $this->fichinter->fetch($id);
311 throw new RestException(404,
'Intervention not found');
315 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
318 if (!$this->fichinter->delete(DolibarrApiAccess::$user)) {
319 throw new RestException(500,
'Error when delete intervention : '.$this->fichinter->error);
325 'message' =>
'Intervention deleted'
347 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
348 throw new RestException(401,
"Insuffisant rights");
350 $result = $this->fichinter->fetch($id);
352 throw new RestException(404,
'Intervention not found');
356 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
359 $result = $this->fichinter->setValid(DolibarrApiAccess::$user, $notrigger);
361 throw new RestException(304,
'Error nothing done. May be object is already validated');
364 throw new RestException(500,
'Error when validating Intervention: '.$this->commande->error);
367 $this->fichinter->fetchObjectLinked();
383 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
384 throw new RestException(401,
"Insuffisant rights");
386 $result = $this->fichinter->fetch($id);
388 throw new RestException(404,
'Intervention not found');
392 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
395 $result = $this->fichinter->setStatut(3);
398 throw new RestException(304,
'Error nothing done. May be object is already closed');
401 throw new RestException(500,
'Error when closing Intervention: '.$this->fichinter->error);
404 $this->fichinter->fetchObjectLinked();
419 $fichinter = array();
420 foreach (Interventions::$FIELDS as $field) {
421 if (!isset($data[$field])) {
422 throw new RestException(400,
"$field field missing");
424 $fichinter[$field] = $data[$field];
440 $object = parent::_cleanObjectDatas($object);
442 unset($object->statuts_short);
443 unset($object->statuts_logo);
444 unset($object->statuts);
459 $fichinter = array();
460 foreach (Interventions::$FIELDSLINE as $field) {
461 if (!isset($data[$field])) {
462 throw new RestException(400,
"$field field missing");
464 $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.
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.
forgeSQLFromUniversalSearchCriteria($filter, &$error='')
forgeSQLFromUniversalSearchCriteria
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.