dolibarr 21.0.0-alpha
box_validated_projects.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012-2014 Charles-François BENKE <charles.fr@benke.fr>
3 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
4 * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
5 * Copyright (C) 2016 Juan José Menent <jmenent@2byte.es>
6 * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
7 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
28include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
29
30
35{
36 public $boxcode = "validated_project";
37 public $boximg = "object_projectpub";
38 public $boxlabel;
39 //var $depends = array("projet");
40
41 public $enabled = 1;
42
49 public function __construct($db, $param = '')
50 {
51 global $conf, $user, $langs;
52
53 // Load translation files required by the page
54 $langs->loadLangs(array('boxes', 'projects'));
55
56 $this->db = $db;
57 $this->boxlabel = "ProjectTasksWithoutTimeSpent";
58
59 $this->hidden = !$user->hasRight('projet', 'lire');
60
61 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
62 $this->enabled = 0;
63 }
64 }
65
72 public function loadBox($max = 5)
73 {
74 global $conf, $user, $langs;
75
76 $this->max = $max;
77
78 $totalMnt = 0;
79 $totalnb = 0;
80 $totalnbTask = 0;
81
82 $textHead = $langs->trans("ProjectTasksWithoutTimeSpent");
83 $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
84
85 // list the summary of the orders
86 if ($user->hasRight('projet', 'lire')) {
87 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
88 $projectstatic = new Project($this->db);
89
90 $socid = 0;
91 //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignment.
92
93 // Get list of project id allowed to user (in a string list separated by coma)
94 $projectsListId = '';
95 if (!$user->hasRight('projet', 'all', 'lire')) {
96 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
97 }
98
99 // I tried to solve sql error and performance problem, rewriting sql request but it is not clear what we want.
100 // Count of tasks without time spent for tasks we are assigned too or
101 // Count of tasks without time spent for all tasks of projects we are allowed to read (what it does) ?
102 $sql = "SELECT p.rowid, p.ref, p.fk_soc, p.dateo as startdate,";
103 $sql .= " COUNT(DISTINCT t.rowid) as tasknumber";
104 $sql .= " FROM ".MAIN_DB_PREFIX."projet AS p";
105 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet_task AS t ON p.rowid = t.fk_projet";
106 // TODO Replace -1, -2, -3 with ID used for type of contact project_task into llx_c_type_contact. Once done, we can switch widget as stable.
107 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_contact as ec ON ec.element_id = t.rowid AND fk_c_type_contact IN (-1, -2, -3)";
108 $sql .= " WHERE p.fk_statut = 1"; // Only open projects
109 if ($projectsListId) {
110 $sql .= ' AND p.rowid IN ('.$this->db->sanitize($projectsListId).')'; // Only projects that are allowed
111 }
112 $sql .= " AND t.rowid NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX."element_time WHERE elementtype = 'task' AND fk_user = ".((int) $user->id).")";
113 $sql .= " GROUP BY p.rowid, p.ref, p.fk_soc, p.dateo";
114 $sql .= " ORDER BY p.dateo ASC";
115
116 $result = $this->db->query($sql);
117 if ($result) {
118 $num = $this->db->num_rows($result);
119 $i = 0;
120 $this->info_box_contents[$i][] = array(
121 'td' => 'class="nowraponall"',
122 'text' => "Reference projet",
123 );
124 $this->info_box_contents[$i][] = array(
125 'td' => 'class="center"',
126 'text' => 'Client',
127 );
128 $this->info_box_contents[$i][] = array(
129 'td' => 'class="center"',
130 'text' => 'Date debut de projet',
131 );
132 $this->info_box_contents[$i][] = array(
133 'td' => 'class="center"',
134 'text' => 'Nombre de mes tâches sans temps saisi',
135 );
136 $i++;
137
138 while ($i < min($num + 1, $max + 1)) {
139 $objp = $this->db->fetch_object($result);
140
141 $projectstatic->id = $objp->rowid;
142 $projectstatic->ref = $objp->ref;
143
144 $this->info_box_contents[$i][] = array(
145 'td' => 'class="nowraponall"',
146 'text' => $projectstatic->getNomUrl(1),
147 'asis' => 1
148 );
149
150 if ($objp->fk_soc > 0) {
151 $sql = "SELECT rowid, nom as name FROM ".MAIN_DB_PREFIX."societe WHERE rowid = ".((int) $objp->fk_soc);
152 $resql = $this->db->query($sql);
153 //$socstatic = new Societe($this->db);
154 $obj2 = $this->db->fetch_object($resql);
155 $this->info_box_contents[$i][] = array(
156 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
157 'text' => $obj2->name,
158 'asis' => 1,
159 'url' => DOL_URL_ROOT.'/societe/card.php?socid='.urlencode($obj2->rowid)
160 );
161 } else {
162 $this->info_box_contents[$i][] = array(
163 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
164 'text' => '',
165 'asis' => 1,
166 'url' => ''
167 );
168 }
169
170 $this->info_box_contents[$i][] = array(
171 'td' => 'class="center"',
172 'text' => $objp->startDate,
173 );
174
175 $this->info_box_contents[$i][] = array(
176 'td' => 'class="center"',
177 'text' => $objp->tasknumber."&nbsp;".$langs->trans("Tasks"),
178 'asis' => 1,
179 );
180 $i++;
181 }
182 } else {
183 dol_print_error($this->db);
184 }
185 }
186 }
187
196 public function showBox($head = null, $contents = null, $nooutput = 0)
197 {
198 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
199 }
200}
Class ModeleBoxes.
Class to manage projects.
Class to manage the box to show last projet.
__construct($db, $param='')
Constructor.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...