24use Luracast\Restler\RestException;
26require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
41 public static $FIELDS = array(
50 public static $FIELDSLINE = array(
68 $this->fichinter =
new Fichinter($this->db);
80 public function get($id)
82 if (!DolibarrApiAccess::$user->rights->ficheinter->lire) {
83 throw new RestException(401);
86 $result = $this->fichinter->fetch($id);
88 throw new RestException(404,
'Intervention not found');
92 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
95 $this->fichinter->fetchObjectLinked();
113 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'')
117 if (!DolibarrApiAccess::$user->rights->ficheinter->lire) {
118 throw new RestException(401);
124 $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
128 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
129 $search_sale = DolibarrApiAccess::$user->id;
132 $sql =
"SELECT t.rowid";
133 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
134 $sql .=
", sc.fk_soc, sc.fk_user";
136 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter AS t LEFT JOIN ".MAIN_DB_PREFIX.
"fichinter_extrafields AS ef ON (ef.fk_object = t.rowid)";
138 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
139 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
142 $sql .=
' WHERE t.entity IN ('.getEntity(
'intervention').
')';
143 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
144 $sql .=
" AND t.fk_soc = sc.fk_soc";
147 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
149 if ($search_sale > 0) {
150 $sql .=
" AND t.rowid = sc.fk_soc";
153 if ($search_sale > 0) {
154 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
161 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
165 $sql .= $this->db->order($sortfield, $sortorder);
170 $offset = $limit * $page;
172 $sql .= $this->db->plimit($limit + 1, $offset);
176 $result = $this->db->query($sql);
179 $num = $this->db->num_rows($result);
180 $min = min($num, ($limit <= 0 ? $num : $limit));
183 $obj = $this->db->fetch_object($result);
184 $fichinter_static =
new Fichinter($this->db);
185 if ($fichinter_static->fetch($obj->rowid)) {
191 throw new RestException(503,
'Error when retrieve intervention list : '.$this->db->lasterror());
193 if (!count($obj_ret)) {
194 throw new RestException(404,
'No intervention found');
205 public function post($request_data =
null)
207 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
208 throw new RestException(401,
"Insuffisant rights");
211 $result = $this->
_validate($request_data);
212 foreach ($request_data as $field => $value) {
213 $this->fichinter->$field = $value;
216 if ($this->fichinter->create(DolibarrApiAccess::$user) < 0) {
217 throw new RestException(500,
"Error creating intervention", array_merge(array($this->fichinter->error), $this->fichinter->errors));
220 return $this->fichinter->id;
267 public function postLine($id, $request_data =
null)
269 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
270 throw new RestException(401,
"Insuffisant rights");
275 foreach ($request_data as $field => $value) {
276 $this->fichinter->$field = $value;
280 throw new RestException(404,
'Intervention not found');
284 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
287 $updateRes = $this->fichinter->addLine(
288 DolibarrApiAccess::$user,
290 $this->fichinter->description,
291 $this->fichinter->date,
292 $this->fichinter->duree
295 if ($updateRes > 0) {
298 throw new RestException(400, $this->fichinter->error);
308 public function delete($id)
310 if (!DolibarrApiAccess::$user->rights->ficheinter->supprimer) {
311 throw new RestException(401);
313 $result = $this->fichinter->fetch($id);
315 throw new RestException(404,
'Intervention not found');
319 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
322 if (!$this->fichinter->delete(DolibarrApiAccess::$user)) {
323 throw new RestException(500,
'Error when delete intervention : '.$this->fichinter->error);
329 'message' =>
'Intervention deleted'
351 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
352 throw new RestException(401,
"Insuffisant rights");
354 $result = $this->fichinter->fetch($id);
356 throw new RestException(404,
'Intervention not found');
360 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
363 $result = $this->fichinter->setValid(DolibarrApiAccess::$user, $notrigger);
365 throw new RestException(304,
'Error nothing done. May be object is already validated');
368 throw new RestException(500,
'Error when validating Intervention: '.$this->commande->error);
371 $this->fichinter->fetchObjectLinked();
387 if (!DolibarrApiAccess::$user->rights->ficheinter->creer) {
388 throw new RestException(401,
"Insuffisant rights");
390 $result = $this->fichinter->fetch($id);
392 throw new RestException(404,
'Intervention not found');
396 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
399 $result = $this->fichinter->setStatut(3);
402 throw new RestException(304,
'Error nothing done. May be object is already closed');
405 throw new RestException(500,
'Error when closing Intervention: '.$this->fichinter->error);
408 $this->fichinter->fetchObjectLinked();
423 $fichinter = array();
424 foreach (Interventions::$FIELDS as $field) {
425 if (!isset($data[$field])) {
426 throw new RestException(400,
"$field field missing");
428 $fichinter[$field] = $data[$field];
444 $object = parent::_cleanObjectDatas($object);
446 unset($object->statuts_short);
447 unset($object->statuts_logo);
448 unset($object->statuts);
463 $fichinter = array();
464 foreach (Interventions::$FIELDSLINE as $field) {
465 if (!isset($data[$field])) {
466 throw new RestException(400,
"$field field missing");
468 $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.