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(
 
   53     $this->task = 
new Task($this->
db);
 
   66   public function get($id)
 
   68     if (!DolibarrApiAccess::$user->rights->projet->lire) {
 
   69       throw new RestException(401);
 
   72     $result = $this->project->fetch($id);
 
   74       throw new RestException(404, 
'Project not found');
 
   78       throw new RestException(401, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
   81     $this->project->fetchObjectLinked();
 
  101   public function index($sortfield = 
"t.rowid", $sortorder = 
'ASC', $limit = 100, $page = 0, $thirdparty_ids = 
'', $category = 0, $sqlfilters = 
'')
 
  105     if (!DolibarrApiAccess::$user->rights->projet->lire) {
 
  106       throw new RestException(401);
 
  112     $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
 
  116     if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
 
  117       $search_sale = DolibarrApiAccess::$user->id;
 
  120     $sql = 
"SELECT t.rowid";
 
  121     if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
 
  122       $sql .= 
", sc.fk_soc, sc.fk_user"; 
 
  124     $sql .= 
" FROM ".MAIN_DB_PREFIX.
"projet as t";
 
  126       $sql .= 
", ".MAIN_DB_PREFIX.
"categorie_project as c";
 
  128     if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
 
  129       $sql .= 
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc"; 
 
  132     $sql .= 
' WHERE t.entity IN ('.getEntity(
'project').
')';
 
  133     if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
 
  134       $sql .= 
" AND t.fk_soc = sc.fk_soc";
 
  137       $sql .= 
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
 
  139     if ($search_sale > 0) {
 
  140       $sql .= 
" AND t.rowid = sc.fk_soc"; 
 
  143     if ($search_sale > 0) {
 
  144       $sql .= 
" AND sc.fk_user = ".((int) $search_sale);
 
  148       $sql .= 
" AND c.fk_categorie = ".((int) $category).
" AND c.fk_project = t.rowid ";
 
  154         throw new RestException(503, 
'Error when validating parameter sqlfilters -> '.$errormessage);
 
  156       $regexstring = 
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
 
  157       $sql .= 
" AND (".preg_replace_callback(
'/'.$regexstring.
'/', 
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
 
  160     $sql .= $this->
db->order($sortfield, $sortorder);
 
  165       $offset = $limit * $page;
 
  167       $sql .= $this->
db->plimit($limit + 1, $offset);
 
  171     $result = $this->
db->query($sql);
 
  174       $num = $this->
db->num_rows($result);
 
  175       $min = min($num, ($limit <= 0 ? $num : $limit));
 
  178         $obj = $this->
db->fetch_object($result);
 
  179         $project_static = 
new Project($this->
db);
 
  180         if ($project_static->fetch($obj->rowid)) {
 
  186       throw new RestException(503, 
'Error when retrieve project list : '.$this->
db->lasterror());
 
  188     if (!count($obj_ret)) {
 
  189       throw new RestException(404, 
'No project found');
 
  200   public function post($request_data = 
null)
 
  202     if (!DolibarrApiAccess::$user->rights->projet->creer) {
 
  203       throw new RestException(401, 
"Insuffisant rights");
 
  206     $result = $this->
_validate($request_data);
 
  208     foreach ($request_data as $field => $value) {
 
  209       $this->project->$field = $value;
 
  218     if ($this->project->create(DolibarrApiAccess::$user) < 0) {
 
  219       throw new RestException(500, 
"Error creating project", array_merge(array($this->project->error), $this->project->errors));
 
  222     return $this->project->id;
 
  235   public function getLines($id, $includetimespent = 0)
 
  237     if (!DolibarrApiAccess::$user->rights->projet->lire) {
 
  238       throw new RestException(401);
 
  241     $result = $this->project->fetch($id);
 
  243       throw new RestException(404, 
'Project not found');
 
  247       throw new RestException(401, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  249     $this->project->getLinesArray(DolibarrApiAccess::$user);
 
  251     foreach ($this->project->lines as $line) {      
 
  252       if ($includetimespent == 1) {
 
  253         $timespent = $line->getSummaryOfTimeSpent(0);
 
  255       if ($includetimespent == 2) {
 
  256         $timespent = $line->fetchTimeSpentOnTask();
 
  277     if (!DolibarrApiAccess::$user->rights->projet->lire) {
 
  278       throw new RestException(401);
 
  281     $result = $this->project->fetch($id);
 
  283       throw new RestException(404, 
'Project not found');
 
  287       throw new RestException(401, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  290     require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
 
  291     $taskstatic = 
new Task($this->
db);
 
  292     $userp = DolibarrApiAccess::$user;
 
  294       $userp = 
new User($this->
db);
 
  295       $userp->fetch($userid);
 
  297     $this->project->roles = $taskstatic->getUserRolesForProjectsOrTasks($userp, 
null, $id, 0);
 
  299     foreach ($this->project->roles as $line) {
 
  446   public function put($id, $request_data = 
null)
 
  448     if (!DolibarrApiAccess::$user->rights->projet->creer) {
 
  449       throw new RestException(401);
 
  452     $result = $this->project->fetch($id);
 
  454       throw new RestException(404, 
'Project not found');
 
  458       throw new RestException(401, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  460     foreach ($request_data as $field => $value) {
 
  461       if ($field == 
'id') {
 
  464       $this->project->$field = $value;
 
  467     if ($this->project->update(DolibarrApiAccess::$user) >= 0) {
 
  468       return $this->
get($id);
 
  470       throw new RestException(500, $this->project->error);
 
  481   public function delete($id)
 
  483     if (!DolibarrApiAccess::$user->rights->projet->supprimer) {
 
  484       throw new RestException(401);
 
  486     $result = $this->project->fetch($id);
 
  488       throw new RestException(404, 
'Project not found');
 
  492       throw new RestException(401, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  495     if (!$this->project->delete(DolibarrApiAccess::$user)) {
 
  496       throw new RestException(500, 
'Error when delete project : '.$this->project->error);
 
  502         'message' => 
'Project deleted' 
  527     if (!DolibarrApiAccess::$user->rights->projet->creer) {
 
  528       throw new RestException(401);
 
  530     $result = $this->project->fetch($id);
 
  532       throw new RestException(404, 
'Project not found');
 
  536       throw new RestException(401, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  539     $result = $this->project->setValid(DolibarrApiAccess::$user, $notrigger);
 
  541       throw new RestException(304, 
'Error nothing done. May be object is already validated');
 
  544       throw new RestException(500, 
'Error when validating Project: '.$this->project->error);
 
  550         'message' => 
'Project validated' 
  566     $object = parent::_cleanObjectDatas($object);
 
  568     unset($object->datec);
 
  569     unset($object->datem);
 
  570     unset($object->barcode_type);
 
  571     unset($object->barcode_type_code);
 
  572     unset($object->barcode_type_label);
 
  573     unset($object->barcode_type_coder);
 
  574     unset($object->cond_reglement_id);
 
  575     unset($object->cond_reglement);
 
  576     unset($object->fk_delivery_address);
 
  577     unset($object->shipping_method_id);
 
  578     unset($object->fk_account);
 
  579     unset($object->note);
 
  580     unset($object->fk_incoterms);
 
  581     unset($object->label_incoterms);
 
  582     unset($object->location_incoterms);
 
  583     unset($object->name);
 
  584     unset($object->lastname);
 
  585     unset($object->firstname);
 
  586     unset($object->civility_id);
 
  587     unset($object->mode_reglement_id);
 
  588     unset($object->country);
 
  589     unset($object->country_id);
 
  590     unset($object->country_code);
 
  592     unset($object->weekWorkLoad);
 
  593     unset($object->weekWorkLoad);
 
  597     unset($object->total_ht);
 
  598     unset($object->total_tva);
 
  599     unset($object->total_localtax1);
 
  600     unset($object->total_localtax2);
 
  601     unset($object->total_ttc);
 
  603     unset($object->comments);
 
  618     foreach (self::$FIELDS as $field) {
 
  619       if (!isset($data[$field])) {
 
  620         throw new RestException(400, 
"$field field missing");
 
  622       $object[$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.
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid.
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.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $category=0, $sqlfilters='')
List projects.
__construct()
Constructor.
put($id, $request_data=null)
Add a task to given project.
getRoles($id, $userid=0)
Get roles a user is assigned to a project with.
Class to manage Dolibarr users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.