19 use Luracast\Restler\RestException;
21 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
22 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
35 public static $FIELDS = array(
58 $this->project =
new Project($this->db);
59 $this->task =
new Task($this->db);
72 public function get($id)
74 if (!DolibarrApiAccess::$user->rights->projet->lire) {
75 throw new RestException(401);
78 $result = $this->project->fetch($id);
80 throw new RestException(404,
'Project not found');
84 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
87 $this->project->fetchObjectLinked();
108 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $category = 0, $sqlfilters =
'', $properties =
'')
110 if (!DolibarrApiAccess::$user->rights->projet->lire) {
111 throw new RestException(401);
117 $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
121 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
122 $search_sale = DolibarrApiAccess::$user->id;
125 $sql =
"SELECT t.rowid";
126 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
127 $sql .=
", sc.fk_soc, sc.fk_user";
129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as t";
130 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_extrafields AS ef ON ef.fk_object = t.rowid";
132 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_project as c";
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(
'project').
')';
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);
154 $sql .=
" AND c.fk_categorie = ".((int) $category).
" AND c.fk_project = t.rowid ";
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 $project_static =
new Project($this->db);
185 if ($project_static->fetch($obj->rowid)) {
191 throw new RestException(503,
'Error when retrieve project list : '.$this->db->lasterror());
203 public function post($request_data =
null)
205 if (!DolibarrApiAccess::$user->rights->projet->creer) {
206 throw new RestException(401,
"Insuffisant rights");
209 $result = $this->
_validate($request_data);
211 foreach ($request_data as $field => $value) {
212 if ($field ===
'caller') {
214 $this->project->context[
'caller'] = $request_data[
'caller'];
218 $this->project->$field = $value;
227 if ($this->project->create(DolibarrApiAccess::$user) < 0) {
228 throw new RestException(500,
"Error creating project", array_merge(array($this->project->error), $this->project->errors));
231 return $this->project->id;
244 public function getLines($id, $includetimespent = 0)
246 if (!DolibarrApiAccess::$user->rights->projet->lire) {
247 throw new RestException(401);
250 $result = $this->project->fetch($id);
252 throw new RestException(404,
'Project not found');
256 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
258 $this->project->getLinesArray(DolibarrApiAccess::$user);
260 foreach ($this->project->lines as $line) {
261 if ($includetimespent == 1) {
262 $timespent = $line->getSummaryOfTimeSpent(0);
264 if ($includetimespent == 2) {
265 $timespent = $line->fetchTimeSpentOnTask();
286 if (!DolibarrApiAccess::$user->rights->projet->lire) {
287 throw new RestException(401);
290 $result = $this->project->fetch($id);
292 throw new RestException(404,
'Project not found');
296 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
299 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
300 $taskstatic =
new Task($this->db);
301 $userp = DolibarrApiAccess::$user;
303 $userp =
new User($this->db);
304 $userp->fetch($userid);
306 $this->project->roles = $taskstatic->getUserRolesForProjectsOrTasks($userp,
null, $id, 0);
308 foreach ($this->project->roles as $line) {
455 public function put($id, $request_data =
null)
457 if (!DolibarrApiAccess::$user->rights->projet->creer) {
458 throw new RestException(401);
461 $result = $this->project->fetch($id);
463 throw new RestException(404,
'Project not found');
467 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
469 foreach ($request_data as $field => $value) {
470 if ($field ==
'id') {
473 if ($field ===
'caller') {
475 $this->project->context[
'caller'] = $request_data[
'caller'];
479 $this->project->$field = $value;
482 if ($this->project->update(DolibarrApiAccess::$user) >= 0) {
483 return $this->
get($id);
485 throw new RestException(500, $this->project->error);
496 public function delete($id)
498 if (!DolibarrApiAccess::$user->rights->projet->supprimer) {
499 throw new RestException(401);
501 $result = $this->project->fetch($id);
503 throw new RestException(404,
'Project not found');
507 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
510 if (!$this->project->delete(DolibarrApiAccess::$user)) {
511 throw new RestException(500,
'Error when delete project : '.$this->project->error);
517 'message' =>
'Project deleted'
542 if (!DolibarrApiAccess::$user->rights->projet->creer) {
543 throw new RestException(401);
545 $result = $this->project->fetch($id);
547 throw new RestException(404,
'Project not found');
551 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
554 $result = $this->project->setValid(DolibarrApiAccess::$user, $notrigger);
556 throw new RestException(304,
'Error nothing done. May be object is already validated');
559 throw new RestException(500,
'Error when validating Project: '.$this->project->error);
565 'message' =>
'Project validated'
581 $object = parent::_cleanObjectDatas($object);
583 unset($object->datec);
584 unset($object->datem);
585 unset($object->barcode_type);
586 unset($object->barcode_type_code);
587 unset($object->barcode_type_label);
588 unset($object->barcode_type_coder);
589 unset($object->cond_reglement_id);
590 unset($object->cond_reglement);
591 unset($object->fk_delivery_address);
592 unset($object->shipping_method_id);
593 unset($object->fk_account);
594 unset($object->note);
595 unset($object->fk_incoterms);
596 unset($object->label_incoterms);
597 unset($object->location_incoterms);
598 unset($object->name);
599 unset($object->lastname);
600 unset($object->firstname);
601 unset($object->civility_id);
602 unset($object->mode_reglement_id);
603 unset($object->country);
604 unset($object->country_id);
605 unset($object->country_code);
607 unset($object->weekWorkLoad);
608 unset($object->weekWorkLoad);
612 unset($object->total_ht);
613 unset($object->total_tva);
614 unset($object->total_localtax1);
615 unset($object->total_localtax2);
616 unset($object->total_ttc);
618 unset($object->comments);
633 foreach (self::$FIELDS as $field) {
634 if (!isset($data[$field])) {
635 throw new RestException(400,
"$field field missing");
637 $object[$field] = $data[$field];
_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.
Class to manage projects.
post($request_data=null)
Create project object.
getLines($id, $includetimespent=0)
Get tasks of a project.
validate($id, $notrigger=0)
Validate a project.
_validate($data)
Validate fields before create or update object.
_cleanObjectDatas($object)
Clean sensible object datas.
__construct()
Constructor.
put($id, $request_data=null)
Add a task to given project.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $category=0, $sqlfilters='', $properties='')
List projects.
getRoles($id, $userid=0)
Get roles a user is assigned to a project with.
Class to manage Dolibarr users.
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.