19 use Luracast\Restler\RestException;
21 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
35 static $FIELDS = array(
44 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 =
'')
116 $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
120 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
122 $sql =
"SELECT t.rowid";
123 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .=
", sc.fk_soc, sc.fk_user";
124 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as t";
126 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
128 $sql .=
' WHERE t.entity IN ('.getEntity(
'intervention').
')';
129 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .=
" AND t.fk_soc = sc.fk_soc";
130 if ($socids) $sql .=
" AND t.fk_soc IN (".$socids.
")";
131 if ($search_sale > 0) $sql .=
" AND t.rowid = sc.fk_soc";
133 if ($search_sale > 0) {
134 $sql .=
" AND sc.fk_user = ".$search_sale;
141 throw new RestException(503,
'Error when validating parameter sqlfilters '.$sqlfilters);
143 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
144 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
147 $sql .= $this->
db->order($sortfield, $sortorder);
153 $offset = $limit * $page;
155 $sql .= $this->
db->plimit($limit + 1, $offset);
159 $result = $this->
db->query($sql);
163 $num = $this->
db->num_rows($result);
164 $min = min($num, ($limit <= 0 ? $num : $limit));
168 $obj = $this->
db->fetch_object($result);
170 if ($fichinter_static->fetch($obj->rowid)) {
176 throw new RestException(503,
'Error when retrieve intervention list : '.$this->
db->lasterror());
178 if (!count($obj_ret)) {
179 throw new RestException(404,
'No intervention found');
190 public function post($request_data = null)
192 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
193 throw new RestException(401,
"Insuffisant rights");
196 $result = $this->
_validate($request_data);
197 foreach ($request_data as $field => $value) {
198 $this->fichinter->$field = $value;
201 if ($this->fichinter->create(DolibarrApiAccess::$user) < 0) {
202 throw new RestException(500,
"Error creating intervention", array_merge(array($this->fichinter->error), $this->fichinter->errors));
205 return $this->fichinter->id;
252 public function postLine($id, $request_data = null)
254 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
255 throw new RestException(401,
"Insuffisant rights");
260 foreach ($request_data as $field => $value) {
261 $this->fichinter->$field = $value;
265 throw new RestException(404,
'Intervention not found');
269 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
272 $updateRes = $this->fichinter->addLine(
273 DolibarrApiAccess::$user,
275 $this->fichinter->description,
276 $this->fichinter->date,
277 $this->fichinter->duree
280 if ($updateRes > 0) {
283 throw new RestException(400, $this->fichinter->error);
293 public function delete($id)
295 if (!DolibarrApiAccess::$user->rights->ficheinter->supprimer) {
296 throw new RestException(401);
298 $result = $this->fichinter->fetch($id);
300 throw new RestException(404,
'Intervention not found');
304 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
307 if (!$this->fichinter->delete(DolibarrApiAccess::$user)) {
308 throw new RestException(500,
'Error when delete intervention : '.$this->fichinter->error);
314 'message' =>
'Intervention deleted'
336 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
337 throw new RestException(401,
"Insuffisant rights");
339 $result = $this->fichinter->fetch($id);
341 throw new RestException(404,
'Intervention not found');
345 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
348 $result = $this->fichinter->setValid(DolibarrApiAccess::$user, $notrigger);
350 throw new RestException(304,
'Error nothing done. May be object is already validated');
353 throw new RestException(500,
'Error when validating Intervention: '.$this->commande->error);
356 $this->fichinter->fetchObjectLinked();
372 if (!DolibarrApiAccess::$user->rights->ficheinter->creer)
374 throw new RestException(401,
"Insuffisant rights");
376 $result = $this->fichinter->fetch($id);
378 throw new RestException(404,
'Intervention not found');
382 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
385 $result = $this->fichinter->setStatut(3);
388 throw new RestException(304,
'Error nothing done. May be object is already closed');
391 throw new RestException(500,
'Error when closing Intervention: '.$this->fichinter->error);
394 $this->fichinter->fetchObjectLinked();
409 $fichinter = array();
410 foreach (Interventions::$FIELDS as $field) {
411 if (!isset($data[$field]))
412 throw new RestException(400,
"$field field missing");
413 $fichinter[$field] = $data[$field];
429 $object = parent::_cleanObjectDatas($object);
431 unset($object->statuts_short);
432 unset($object->statuts_logo);
433 unset($object->statuts);
448 $fichinter = array();
449 foreach (Interventions::$FIELDSLINE as $field) {
450 if (!isset($data[$field]))
451 throw new RestException(400,
"$field field missing");
452 $fichinter[$field] = $data[$field];
Class to manage interventions.
closeFichinter($id)
Close an intervention.
_validate($data)
Validate fields before create or update object.
$conf db
API class for accounts.
_checkFilters($sqlfilters)
Return if a $sqlfilters parameter is valid.
__construct()
Constructor.
validate($id, $notrigger=0)
Validate an intervention.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
postLine($id, $request_data=null)
Get lines of an intervention.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid')
Check user access to a resource.
post($request_data=null)
Create intervention object.
_validateLine($data)
Validate fields before create or update object.
index($sortfield="t.rowid", $sortorder= 'ASC', $limit=100, $page=0, $thirdparty_ids= '', $sqlfilters= '')
List of interventions.
_cleanObjectDatas($object)
Clean sensible object datas.