dolibarr 19.0.3
box_project.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 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
27include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
28
33{
34 public $boxcode = "project";
35 public $boximg = "object_projectpub";
36 public $boxlabel;
37 //var $depends = array("projet");
38
42 public $db;
43
44 public $param;
45
46 public $info_box_head = array();
47 public $info_box_contents = array();
48
55 public function __construct($db, $param = '')
56 {
57 global $user, $langs;
58
59 // Load translation files required by the page
60 $langs->loadLangs(array('boxes', 'projects'));
61
62 $this->db = $db;
63 $this->boxlabel = "OpenedProjects";
64
65 $this->hidden = empty($user->rights->projet->lire);
66 }
67
74 public function loadBox($max = 5)
75 {
76 global $conf, $user, $langs;
77
78 $this->max = $max;
79
80 $totalMnt = 0;
81 $totalnb = 0;
82 $totalnbTask = 0;
83
84 $textHead = $langs->trans("OpenedProjects");
85 $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
86
87 $i = 0;
88 // list the summary of the orders
89 if ($user->hasRight('projet', 'lire')) {
90 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
91 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
92 $projectstatic = new Project($this->db);
93 $companystatic = new Societe($this->db);
94
95 $socid = 0;
96 //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 assignement.
97
98 // Get list of project id allowed to user (in a string list separated by coma)
99 $projectsListId = '';
100 if (!$user->hasRight('projet', 'all', 'lire')) {
101 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
102 }
103
104 $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut as status, p.public, p.fk_soc,";
105 $sql .= " s.nom as name, s.name_alias";
106 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
107 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
108 $sql .= " WHERE p.entity IN (".getEntity('project').")"; // Only current entity or severals if permission ok
109 $sql .= " AND p.fk_statut = ".((int) $projectstatic::STATUS_VALIDATED); // Only open projects
110 if (!$user->hasRight('projet', 'all', 'lire')) {
111 $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
112 }
113
114 $sql .= " ORDER BY p.datec DESC";
115 //$sql.= $this->db->plimit($max, 0);
116
117 $result = $this->db->query($sql);
118
119 if ($result) {
120 $num = $this->db->num_rows($result);
121 while ($i < min($num, $max)) {
122 $objp = $this->db->fetch_object($result);
123
124 $projectstatic->id = $objp->rowid;
125 $projectstatic->ref = $objp->ref;
126 $projectstatic->title = $objp->title;
127 $projectstatic->public = $objp->public;
128 $projectstatic->statut = $objp->status;
129
130 $companystatic->id = $objp->fk_soc;
131 $companystatic->name = $objp->name;
132 $companystatic->name_alias = $objp->name_alias;
133
134 $this->info_box_contents[$i][] = array(
135 'td' => 'class="nowraponall"',
136 'text' => $projectstatic->getNomUrl(1),
137 'asis' => 1
138 );
139
140 $this->info_box_contents[$i][] = array(
141 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
142 'text' => $objp->title,
143 );
144
145 $this->info_box_contents[$i][] = array(
146 'td' => 'class="tdoverflowmax100"',
147 'text' => ($objp->fk_soc > 0 ? $companystatic->getNomUrl(1) : ''),
148 'asis' => 1
149 );
150
151 $sql = "SELECT count(*) as nb, sum(progress) as totprogress";
152 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
153 $sql .= " WHERE p.entity IN (".getEntity('project').')';
154 $sql .= " AND p.rowid = ".((int) $objp->rowid);
155
156 $resultTask = $this->db->query($sql);
157 if ($resultTask) {
158 $objTask = $this->db->fetch_object($resultTask);
159 $this->info_box_contents[$i][] = array(
160 'td' => 'class="right"',
161 'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
162 );
163 if ($objTask->nb > 0) {
164 $this->info_box_contents[$i][] = array(
165 'td' => 'class="right"',
166 'text' => round($objTask->totprogress / $objTask->nb, 0)."%",
167 );
168 } else {
169 $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
170 }
171 $totalnbTask += $objTask->nb;
172 } else {
173 $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => round(0));
174 $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
175 }
176 $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => $projectstatic->getLibStatut(3));
177
178 $i++;
179 }
180 if ($max < $num) {
181 $this->info_box_contents[$i][] = array('td' => 'colspan="6"', 'text' => '...');
182 $i++;
183 }
184 }
185 }
186
187
188 // Add the sum à the bottom of the boxes
189 $this->info_box_contents[$i][] = array(
190 'tr' => 'class="liste_total_wrap"',
191 'td' => 'class="liste_total"',
192 'text' => $langs->trans("Total")."&nbsp;".$textHead,
193 );
194 $this->info_box_contents[$i][] = array(
195 'td' => 'class="right liste_total" ',
196 'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
197 );
198 $this->info_box_contents[$i][] = array(
199 'td' => 'class="right liste_total" ',
200 'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
201 );
202 $this->info_box_contents[$i][] = array(
203 'td' => 'class="liste_total"',
204 'text' => "&nbsp;",
205 );
206 $this->info_box_contents[$i][] = array(
207 'td' => 'class="liste_total"',
208 'text' => "&nbsp;",
209 );
210 $this->info_box_contents[$i][] = array(
211 'td' => 'class="liste_total"',
212 'text' => "&nbsp;",
213 );
214 }
215
224 public function showBox($head = null, $contents = null, $nooutput = 0)
225 {
226 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
227 }
228}
Class ModeleBoxes.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last project.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.