dolibarr 22.0.5
api_tasks.class.php
1<?php
2/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21use Luracast\Restler\RestException;
22
23require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
24require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
25require_once DOL_DOCUMENT_ROOT.'/core/class/timespent.class.php';
26
33class Tasks extends DolibarrApi
34{
38 public static $FIELDS = array(
39 'ref',
40 'label',
41 'fk_project'
42 );
43
47 public $task;
48
52 public function __construct()
53 {
54 global $db, $conf;
55 $this->db = $db;
56 $this->task = new Task($this->db);
57 }
58
70 public function get($id, $includetimespent = 0)
71 {
72 if (!DolibarrApiAccess::$user->hasRight('projet', 'lire')) {
73 throw new RestException(403);
74 }
75
76 $result = $this->task->fetch($id);
77 if (!$result) {
78 throw new RestException(404, 'Task not found');
79 }
80
81 if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
82 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
83 }
84
85 if ($includetimespent == 1) {
86 $timespent = $this->task->getSummaryOfTimeSpent(0);
87 }
88 if ($includetimespent == 2) {
89 $timespent = $this->task->fetchTimeSpentOnTask();
90 }
91
92 return $this->_cleanObjectDatas($this->task);
93 }
94
95
96
112 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '')
113 {
114 global $db, $conf;
115
116 if (!DolibarrApiAccess::$user->hasRight('projet', 'lire')) {
117 throw new RestException(403);
118 }
119
120 $obj_ret = array();
121
122 // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
123 $socids = DolibarrApiAccess::$user->socid ?: 0;
124
125 // If the internal user must only see his customers, force searching by him
126 $search_sale = 0;
127 if (!DolibarrApiAccess::$user->hasRight('societe', 'client', 'voir') && !$socids) {
128 $search_sale = DolibarrApiAccess::$user->id;
129 }
130
131 $sql = "SELECT t.rowid";
132 $sql .= " FROM ".MAIN_DB_PREFIX."projet_task AS t";
133 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
134 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet AS p ON p.rowid = t.fk_projet";
135 $sql .= ' WHERE t.entity IN ('.getEntity('project').')';
136 if ($socids) {
137 $sql .= " AND t.fk_soc IN (".$this->db->sanitize((string) $socids).")";
138 }
139 // Search on sale representative
140 if ($search_sale && $search_sale != '-1') {
141 if ($search_sale == -2) {
142 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
143 } elseif ($search_sale > 0) {
144 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
145 }
146 }
147 // Add sql filters
148 if ($sqlfilters) {
149 $errormessage = '';
150 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
151 if ($errormessage) {
152 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
153 }
154 }
155
156 $sql .= $this->db->order($sortfield, $sortorder);
157 if ($limit) {
158 if ($page < 0) {
159 $page = 0;
160 }
161 $offset = $limit * $page;
162
163 $sql .= $this->db->plimit($limit + 1, $offset);
164 }
165
166 dol_syslog("API Rest request");
167 $result = $this->db->query($sql);
168
169 if ($result) {
170 $num = $this->db->num_rows($result);
171 $min = min($num, ($limit <= 0 ? $num : $limit));
172 $i = 0;
173 while ($i < $min) {
174 $obj = $this->db->fetch_object($result);
175 $task_static = new Task($this->db);
176 if ($task_static->fetch($obj->rowid)) {
177 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($task_static), $properties);
178 }
179 $i++;
180 }
181 } else {
182 throw new RestException(503, 'Error when retrieve task list : '.$this->db->lasterror());
183 }
184
185 return $obj_ret;
186 }
187
196 public function post($request_data = null)
197 {
198 if (!DolibarrApiAccess::$user->hasRight('projet', 'creer')) {
199 throw new RestException(403, "Insuffisant rights");
200 }
201 // Check mandatory fields
202 $result = $this->_validate($request_data);
203
204 foreach ($request_data as $field => $value) {
205 if ($field === 'caller') {
206 // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
207 $this->task->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
208 continue;
209 }
210
211 $this->task->$field = $this->_checkValForAPI($field, $value, $this->task);
212 }
213 /*if (isset($request_data["lines"])) {
214 $lines = array();
215 foreach ($request_data["lines"] as $line) {
216 array_push($lines, (object) $line);
217 }
218 $this->project->lines = $lines;
219 }*/
220 if ($this->task->create(DolibarrApiAccess::$user) < 0) {
221 throw new RestException(500, "Error creating task", array_merge(array($this->task->error), $this->task->errors));
222 }
223
224 return $this->task->id;
225 }
226
227 // /**
228 // * Get time spent of a task
229 // *
230 // * @param int $id Id of task
231 // * @return int
232 // *
233 // * @url GET {id}/tasks
234 // */
235 /*
236 public function getLines($id, $includetimespent=0)
237 {
238 if(! DolibarrApiAccess::$user->hasRight('projet', 'lire')) {
239 throw new RestException(403);
240 }
241
242 $result = $this->project->fetch($id);
243 if( ! $result ) {
244 throw new RestException(404, 'Project not found');
245 }
246
247 if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
248 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
249 }
250 $this->project->getLinesArray(DolibarrApiAccess::$user);
251 $result = array();
252 foreach ($this->project->lines as $line) // $line is a task
253 {
254 if ($includetimespent == 1)
255 {
256 $timespent = $line->getSummaryOfTimeSpent(0);
257 }
258 if ($includetimespent == 1)
259 {
260 // TODO
261 // Add class for timespent records and loop and fill $line->lines with records of timespent
262 }
263 array_push($result,$this->_cleanObjectDatas($line));
264 }
265 return $result;
266 }
267 */
268
280 public function getRoles($id, $userid = 0)
281 {
282 global $db;
283
284 if (!DolibarrApiAccess::$user->hasRight('projet', 'lire')) {
285 throw new RestException(403);
286 }
287
288 $result = $this->task->fetch($id);
289 if (!$result) {
290 throw new RestException(404, 'Task not found');
291 }
292
293 if (!DolibarrApi::_checkAccessToResource('tasks', $this->task->id)) {
294 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
295 }
296
297 $usert = DolibarrApiAccess::$user;
298 if ($userid > 0) {
299 $usert = new User($this->db);
300 $usert->fetch($userid);
301 }
302 $this->task->roles = $this->task->getUserRolesForProjectsOrTasks(null, $usert, '0', $id);
303 $result = array();
304 foreach ($this->task->roles as $line) {
305 array_push($result, $this->_cleanObjectDatas($line));
306 }
307
308 return $result;
309 }
310
311
312 // /**
313 // * Add a task to given project
314 // *
315 // * @param int $id Id of project to update
316 // * @param array $request_data Projectline data
317 // * @phan-param ?array<string,string> $request_data
318 // * @phpstan-param ?array<string,string> $request_data
319 // *
320 // * @url POST {id}/tasks
321 // *
322 // * @return int
323 // */
324 /*
325 public function postLine($id, $request_data = null)
326 {
327 if(! DolibarrApiAccess::$user->hasRight('projet', 'creer')) {
328 throw new RestException(403);
329 }
330
331 $result = $this->project->fetch($id);
332 if( ! $result ) {
333 throw new RestException(404, 'Project not found');
334 }
335
336 if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
337 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
338 }
339
340 $request_data = (object) $request_data;
341
342 $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml');
343
344 $updateRes = $this->project->addline(
345 $request_data->desc,
346 $request_data->subprice,
347 $request_data->qty,
348 $request_data->tva_tx,
349 $request_data->localtax1_tx,
350 $request_data->localtax2_tx,
351 $request_data->fk_product,
352 $request_data->remise_percent,
353 $request_data->info_bits,
354 $request_data->fk_remise_except,
355 'HT',
356 0,
357 $request_data->date_start,
358 $request_data->date_end,
359 $request_data->product_type,
360 $request_data->rang,
361 $request_data->special_code,
362 $fk_parent_line,
363 $request_data->fk_fournprice,
364 $request_data->pa_ht,
365 $request_data->label,
366 $request_data->array_options,
367 $request_data->fk_unit,
368 $this->element,
369 $request_data->id
370 );
371
372 if ($updateRes > 0) {
373 return $updateRes;
374
375 }
376 return false;
377 }
378 */
379
380 // /**
381 // * Update a task of a given project
382 // *
383 // * @param int $id Id of project to update
384 // * @param int $taskid Id of task to update
385 // * @param array $request_data Projectline data
386 // * @phan-param ?array<string,string> $request_data
387 // * @phpstan-param ?array<string,string> $request_data
388 // *
389 // * @url PUT {id}/tasks/{taskid}
390 // *
391 // * @return object
392 // */
393 /*
394 public function putLine($id, $lineid, $request_data = null)
395 {
396 if(! DolibarrApiAccess::$user->hasRight('projet', 'creer')) {
397 throw new RestException(403);
398 }
399
400 $result = $this->project->fetch($id);
401 if( ! $result ) {
402 throw new RestException(404, 'Project not found');
403 }
404
405 if( ! DolibarrApi::_checkAccessToResource('project',$this->project->id)) {
406 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
407 }
408
409 $request_data = (object) $request_data;
410
411 $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml');
412
413 $updateRes = $this->project->updateline(
414 $lineid,
415 $request_data->desc,
416 $request_data->subprice,
417 $request_data->qty,
418 $request_data->remise_percent,
419 $request_data->tva_tx,
420 $request_data->localtax1_tx,
421 $request_data->localtax2_tx,
422 'HT',
423 $request_data->info_bits,
424 $request_data->date_start,
425 $request_data->date_end,
426 $request_data->product_type,
427 $request_data->fk_parent_line,
428 0,
429 $request_data->fk_fournprice,
430 $request_data->pa_ht,
431 $request_data->label,
432 $request_data->special_code,
433 $request_data->array_options,
434 $request_data->fk_unit
435 );
436
437 if ($updateRes > 0) {
438 $result = $this->get($id);
439 unset($result->line);
440 return $this->_cleanObjectDatas($result);
441 }
442 return false;
443 }*/
444
445
455 public function put($id, $request_data = null)
456 {
457 if (!DolibarrApiAccess::$user->hasRight('projet', 'creer')) {
458 throw new RestException(403);
459 }
460
461 $result = $this->task->fetch($id);
462 if (!$result) {
463 throw new RestException(404, 'Task not found');
464 }
465
466 if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
467 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
468 }
469 foreach ($request_data as $field => $value) {
470 if ($field == 'id') {
471 continue;
472 }
473 if ($field === 'caller') {
474 // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
475 $this->task->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
476 continue;
477 }
478 if ($field == 'array_options' && is_array($value)) {
479 foreach ($value as $index => $val) {
480 $this->task->array_options[$index] = $this->_checkValForAPI($field, $val, $this->task);
481 }
482 continue;
483 }
484
485 $this->task->$field = $this->_checkValForAPI($field, $value, $this->task);
486 }
487
488 if ($this->task->update(DolibarrApiAccess::$user) > 0) {
489 return $this->get($id);
490 } else {
491 throw new RestException(500, $this->task->error);
492 }
493 }
494
505 public function delete($id)
506 {
507 if (!DolibarrApiAccess::$user->hasRight('projet', 'supprimer')) {
508 throw new RestException(403);
509 }
510 $result = $this->task->fetch($id);
511 if (!$result) {
512 throw new RestException(404, 'Task not found');
513 }
514
515 if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
516 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
517 }
518
519 if ($this->task->delete(DolibarrApiAccess::$user) <= 0) {
520 throw new RestException(500, 'Error when delete task : '.$this->task->error);
521 }
522
523 return array(
524 'success' => array(
525 'code' => 200,
526 'message' => 'Task deleted'
527 )
528 );
529 }
530
543 public function getTimeSpent($id, $timespent_id)
544 {
545 dol_syslog("API Rest request::getTimeSpent", LOG_DEBUG);
546 if (! DolibarrApiAccess::$user->hasRight('projet', 'lire')) {
547 throw new RestException(403);
548 }
549
550 $taskresult = $this->task->fetch($id);
551 if (!$taskresult ) {
552 throw new RestException(404, 'Task with id='.$id.' not found');
553 }
554 if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
555 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
556 }
557
558 $timespent = new TimeSpent($this->db);
559 $timeresult = $timespent->fetch($timespent_id);
560 if (!$timeresult ) {
561 throw new RestException(404, 'Timespent with id='.$timespent_id.' not found');
562 }
563 if (!DolibarrApi::_checkAccessToResource('time', $timespent->id)) {
564 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
565 }
566
567 return $this->_cleanTimeSpentObjectDatas($timespent);
568 }
569
590 public function addTimeSpent($id, $date, $duration, $product_id = null, $user_id = 0, $note = '')
591 {
592 if (!DolibarrApiAccess::$user->hasRight('projet', 'creer')) {
593 throw new RestException(403);
594 }
595 $result = $this->task->fetch($id);
596 if ($result <= 0) {
597 throw new RestException(404, 'Task not found');
598 }
599
600 if (!DolibarrApi::_checkAccessToResource('project', $this->task->fk_project)) {
601 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
602 }
603
604 $uid = $user_id;
605 if (empty($uid)) {
606 $uid = DolibarrApiAccess::$user->id;
607 }
608
609 $newdate = dol_stringtotime($date, 1);
610 $this->task->timespent_date = $newdate;
611 $this->task->timespent_datehour = $newdate;
612 $this->task->timespent_withhour = 1;
613 $this->task->timespent_duration = $duration;
614 $this->task->timespent_fk_product = $product_id;
615 $this->task->timespent_fk_user = $uid;
616 $this->task->timespent_note = $note;
617
618 $result = $this->task->addTimeSpent(DolibarrApiAccess::$user, 0);
619 if ($result == 0) {
620 throw new RestException(304, 'Error nothing done. May be object is already validated');
621 }
622 if ($result < 0) {
623 throw new RestException(500, 'Error when adding time: '.$this->task->error);
624 }
625
626 return array(
627 'success' => array(
628 'code' => 200,
629 'message' => 'Time spent added'
630 )
631 );
632 }
633
654 public function putTimeSpent($id, $timespent_id, $date, $duration, $product_id = null, $user_id = 0, $note = '')
655 {
656 if (!DolibarrApiAccess::$user->hasRight('projet', 'creer')) {
657 throw new RestException(403);
658 }
659 $this->timespentRecordChecks($id, $timespent_id);
660
661 if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
662 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
663 }
664
665 $newdate = dol_stringtotime($date, 1);
666 $this->task->timespent_date = $newdate;
667 $this->task->timespent_datehour = $newdate;
668 $this->task->timespent_withhour = 1;
669 $this->task->timespent_duration = $duration;
670 $this->task->timespent_fk_product = $product_id;
671 $this->task->timespent_fk_user = $user_id ?? DolibarrApiAccess::$user->id;
672 $this->task->timespent_note = $note;
673
674 $result = $this->task->updateTimeSpent(DolibarrApiAccess::$user, 0);
675 if ($result == 0) {
676 throw new RestException(304, 'Error nothing done.');
677 }
678 if ($result < 0) {
679 throw new RestException(500, 'Error when updating time spent: '.$this->task->error);
680 }
681
682 return array(
683 'success' => array(
684 'code' => 200,
685 'message' => 'Time spent updated'
686 )
687 );
688 }
689
702 public function deleteTimeSpent($id, $timespent_id)
703 {
704 if (!DolibarrApiAccess::$user->hasRight('projet', 'supprimer')) {
705 throw new RestException(403);
706 }
707 $this->timespentRecordChecks($id, $timespent_id);
708
709 if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
710 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
711 }
712
713 if ($this->task->delTimeSpent(DolibarrApiAccess::$user, 0) < 0) {
714 throw new RestException(500, 'Error when deleting time spent: '.$this->task->error);
715 }
716
717 return array(
718 'success' => array(
719 'code' => 200,
720 'message' => 'Time spent deleted'
721 )
722 );
723 }
724
734 private function timespentRecordChecks($id, $timespent_id)
735 {
736 dol_syslog("API Rest request::timespentRecordChecks", LOG_DEBUG);
737 if ($this->task->fetch($id) <= 0) {
738 throw new RestException(404, 'Task not found');
739 }
740 if ($this->task->fetchTimeSpent($timespent_id) <= 0) {
741 throw new RestException(404, 'Timespent not found');
742 } elseif ($this->task->id != $id) {
743 throw new RestException(404, 'Timespent not found in selected task');
744 }
745 }
746
747 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
758 protected function _cleanObjectDatas($object)
759 {
760 // phpcs:enable
761 $object = parent::_cleanObjectDatas($object);
762
763 unset($object->barcode_type);
764 unset($object->barcode_type_code);
765 unset($object->barcode_type_label);
766 unset($object->barcode_type_coder);
767 unset($object->cond_reglement_id);
768 unset($object->cond_reglement);
769 unset($object->fk_delivery_address);
770 unset($object->shipping_method_id);
771 unset($object->fk_account);
772 unset($object->note);
773 unset($object->fk_incoterms);
774 unset($object->label_incoterms);
775 unset($object->location_incoterms);
776 unset($object->name);
777 unset($object->lastname);
778 unset($object->firstname);
779 unset($object->civility_id);
780 unset($object->mode_reglement_id);
781 unset($object->country);
782 unset($object->country_id);
783 unset($object->country_code);
784
785 unset($object->weekWorkLoad);
786 unset($object->weekWorkLoad);
787
788 //unset($object->lines); // for task we use timespent_lines, but for project we use lines
789
790 unset($object->total_ht);
791 unset($object->total_tva);
792 unset($object->total_localtax1);
793 unset($object->total_localtax2);
794 unset($object->total_ttc);
795
796 unset($object->comments);
797
798 return $object;
799 }
800
801 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
813 {
814 if (!$object->note_private) {
815 $object->note_private = $object->note;
816 // unsure if we should use note_private or note_public, but note_private should be more secure
817 }
818 $saving_fk_element = $object->fk_element;
819 // because calling parent::_cleanObjectDatas clears fk_element
820
821 // phpcs:enable
822 $object = parent::_cleanObjectDatas($object);
823
824 unset($object->barcode_type);
825 unset($object->barcode_type_code);
826 unset($object->barcode_type_label);
827 unset($object->barcode_type_coder);
828 unset($object->cond_reglement_id);
829 unset($object->cond_reglement);
830 unset($object->fk_delivery_address);
831 unset($object->shipping_method_id);
832 unset($object->fk_account);
833 unset($object->fk_incoterms);
834 unset($object->label_incoterms);
835 unset($object->location_incoterms);
836 unset($object->name);
837 unset($object->lastname);
838 unset($object->firstname);
839 unset($object->civility_id);
840 unset($object->mode_reglement_id);
841 unset($object->country);
842 unset($object->country_id);
843 unset($object->country_code);
844
845 unset($object->weekWorkLoad);
846 unset($object->weekWorkLoad);
847
848 unset($object->actiontypecode);
849 unset($object->array_languages);
850 unset($object->array_options);
851 unset($object->canvas);
852 unset($object->civility_code);
853 unset($object->cond_reglement_supplier_id);
854 unset($object->contact_id);
855 unset($object->contacts_ids);
856 unset($object->contacts_ids_internal);
857 unset($object->date_cloture);
858 unset($object->date_validation);
859 unset($object->demand_reason_id);
860 unset($object->deposit_percent);
861 unset($object->entity);
862 unset($object->extraparams);
863 unset($object->fk_multicurrency);
864 unset($object->fk_project);
865 unset($object->fk_user_creat);
866 unset($object->fk_user_modif);
867 unset($object->last_main_doc);
868 unset($object->lines);
869 unset($object->linkedObjectsIds);
870 unset($object->module);
871 unset($object->multicurrency_code);
872 unset($object->multicurrency_total_ht);
873 unset($object->multicurrency_total_localtax1);
874 unset($object->multicurrency_total_localtax2);
875 unset($object->multicurrency_total_ttc);
876 unset($object->multicurrency_total_tva);
877 unset($object->multicurrency_tx);
878 unset($object->note_public);
879 unset($object->origin_id);
880 unset($object->origin_type);
881 unset($object->product);
882 unset($object->ref);
883 unset($object->region_id);
884 unset($object->retained_warranty_fk_cond_reglement);
885 unset($object->rowid);
886 unset($object->shipping_method);
887 unset($object->specimen);
888 unset($object->state_id);
889 unset($object->status);
890 unset($object->statut);
891 unset($object->totalpaid);
892 unset($object->transport_mode_id);
893 unset($object->user);
894 unset($object->user_author);
895 unset($object->user_closing_id);
896 unset($object->user_creation);
897 unset($object->user_creation_id);
898 unset($object->user_modification);
899 unset($object->user_modification_id);
900 unset($object->user_valid);
901 unset($object->user_validation);
902 unset($object->user_validation_id);
903 unset($object->warehouse_id);
904
905 unset($object->total_ht);
906 unset($object->total_tva);
907 unset($object->total_localtax1);
908 unset($object->total_localtax2);
909 unset($object->total_ttc);
910
911 unset($object->comments);
912
913 if (!$object->date_creation) {
914 $object->date_creation = $object->datec;
915 }
916 if (!$object->date_modification) {
917 $object->date_modification = $object->tms;
918 }
919 if (!$object->fk_element) {
920 $object->fk_element = $saving_fk_element;
921 // because calling parent::_cleanObjectDatas clears fk_element
922 }
923
924 return $object;
925 }
926
934 private function _validate($data)
935 {
936 if ($data === null) {
937 $data = array();
938 }
939 $object = array();
940 foreach (self::$FIELDS as $field) {
941 if (!isset($data[$field])) {
942 throw new RestException(400, "$field field missing");
943 }
944 $object[$field] = $data[$field];
945 }
946 return $object;
947 }
948}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
Class for API REST v1.
Definition api.class.php:33
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Definition api.class.php:98
Class to manage tasks.
_cleanObjectDatas($object)
Clean sensitive object data @phpstan-template T of Object.
_validate($data)
Validate fields before create or update object.
post($request_data=null)
Create task object.
put($id, $request_data=null)
Add a task to given project.
_cleanTimeSpentObjectDatas($object)
Clean sensitive object data @phpstan-template T of Object.
getRoles($id, $userid=0)
Get time spent of a task.
addTimeSpent($id, $date, $duration, $product_id=null, $user_id=0, $note='')
Add time spent to a task of a project.
__construct()
Constructor.
putTimeSpent($id, $timespent_id, $date, $duration, $product_id=null, $user_id=0, $note='')
Update time spent for a task of a project.
getTimeSpent($id, $timespent_id)
Get time spent of a task.
timespentRecordChecks($id, $timespent_id)
Validate task & timespent IDs for timespent API methods.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
List tasks.
deleteTimeSpent($id, $timespent_id)
Delete time spent for a task of a project.
Class for TimeSpent.
Class to manage Dolibarr users.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:431
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79