25use Luracast\Restler\RestException;
27require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
42 public static $FIELDS = array(
51 public static $FIELDSLINE = array(
69 $this->fichinter =
new Fichinter($this->db);
82 public function get($id)
84 if (!DolibarrApiAccess::$user->rights->ficheinter->lire) {
85 throw new RestException(401);
88 $result = $this->fichinter->fetch($id);
90 throw new RestException(404,
'Intervention not found');
94 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
97 $this->fichinter->fetchObjectLinked();
115 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'')
119 if (!DolibarrApiAccess::$user->rights->ficheinter->lire) {
120 throw new RestException(401);
126 $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
130 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
131 $search_sale = DolibarrApiAccess::$user->id;
134 $sql =
"SELECT t.rowid";
135 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
136 $sql .=
", sc.fk_soc, sc.fk_user";
138 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter AS t LEFT JOIN ".MAIN_DB_PREFIX.
"fichinter_extrafields AS ef ON (ef.fk_object = t.rowid)";
140 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
141 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
144 $sql .=
' WHERE t.entity IN ('.getEntity(
'intervention').
')';
145 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
146 $sql .=
" AND t.fk_soc = sc.fk_soc";
149 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
151 if ($search_sale > 0) {
152 $sql .=
" AND t.rowid = sc.fk_soc";
155 if ($search_sale > 0) {
156 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
163 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
167 $sql .= $this->db->order($sortfield, $sortorder);
172 $offset = $limit * $page;
174 $sql .= $this->db->plimit($limit + 1, $offset);
178 $result = $this->db->query($sql);
181 $num = $this->db->num_rows($result);
182 $min = min($num, ($limit <= 0 ? $num : $limit));
185 $obj = $this->db->fetch_object($result);
186 $fichinter_static =
new Fichinter($this->db);
187 if ($fichinter_static->fetch($obj->rowid)) {
193 throw new RestException(503,
'Error when retrieve intervention list : '.$this->db->lasterror());
195 if (!count($obj_ret)) {
196 throw new RestException(404,
'No intervention found');
207 public function post($request_data =
null)
209 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
210 throw new RestException(401,
"Insuffisant rights");
213 $result = $this->
_validate($request_data);
214 foreach ($request_data as $field => $value) {
215 $this->fichinter->$field = $value;
218 if ($this->fichinter->create(DolibarrApiAccess::$user) < 0) {
219 throw new RestException(500,
"Error creating intervention", array_merge(array($this->fichinter->error), $this->fichinter->errors));
222 return $this->fichinter->id;
269 public function postLine($id, $request_data =
null)
271 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
272 throw new RestException(401,
"Insuffisant rights");
277 foreach ($request_data as $field => $value) {
278 $this->fichinter->$field = $value;
282 throw new RestException(404,
'Intervention not found');
286 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
289 $updateRes = $this->fichinter->addLine(
290 DolibarrApiAccess::$user,
292 $this->fichinter->description,
293 $this->fichinter->date,
294 $this->fichinter->duree
297 if ($updateRes > 0) {
300 throw new RestException(400, $this->fichinter->error);
310 public function delete($id)
312 if (!DolibarrApiAccess::$user->rights->ficheinter->supprimer) {
313 throw new RestException(401);
315 $result = $this->fichinter->fetch($id);
317 throw new RestException(404,
'Intervention not found');
321 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
324 if (!$this->fichinter->delete(DolibarrApiAccess::$user)) {
325 throw new RestException(500,
'Error when delete intervention : '.$this->fichinter->error);
331 'message' =>
'Intervention deleted'
353 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
354 throw new RestException(401,
"Insuffisant rights");
356 $result = $this->fichinter->fetch($id);
358 throw new RestException(404,
'Intervention not found');
362 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
365 $result = $this->fichinter->setValid(DolibarrApiAccess::$user, $notrigger);
367 throw new RestException(304,
'Error nothing done. May be object is already validated');
370 throw new RestException(500,
'Error when validating Intervention: '.$this->commande->error);
373 $this->fichinter->fetchObjectLinked();
389 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
390 throw new RestException(401,
"Insuffisant rights");
392 $result = $this->fichinter->fetch($id);
394 throw new RestException(404,
'Intervention not found');
398 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
401 $result = $this->fichinter->setStatut(3);
404 throw new RestException(304,
'Error nothing done. May be object is already closed');
407 throw new RestException(500,
'Error when closing Intervention: '.$this->fichinter->error);
410 $this->fichinter->fetchObjectLinked();
425 $fichinter = array();
426 foreach (Interventions::$FIELDS as $field) {
427 if (!isset($data[$field])) {
428 throw new RestException(400,
"$field field missing");
430 $fichinter[$field] = $data[$field];
446 $object = parent::_cleanObjectDatas($object);
448 unset($object->statuts_short);
449 unset($object->statuts_logo);
450 unset($object->statuts);
465 $fichinter = array();
466 foreach (Interventions::$FIELDSLINE as $field) {
467 if (!isset($data[$field])) {
468 throw new RestException(400,
"$field field missing");
470 $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 Return a 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, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.