dolibarr  17.0.4
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 
27 include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
28 
32 class box_project extends ModeleBoxes
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->rights->projet->lire) {
90  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
91  $projectstatic = new Project($this->db);
92 
93  $socid = 0;
94  //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.
95 
96  // Get list of project id allowed to user (in a string list separated by coma)
97  $projectsListId = '';
98  if (empty($user->rights->projet->all->lire)) {
99  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
100  }
101 
102  $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut as status, p.public";
103  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
104  $sql .= " WHERE p.entity IN (".getEntity('project').")"; // Only current entity or severals if permission ok
105  $sql .= " AND p.fk_statut = 1"; // Only open projects
106  if (empty($user->rights->projet->all->lire)) {
107  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
108  }
109 
110  $sql .= " ORDER BY p.datec DESC";
111  //$sql.= $this->db->plimit($max, 0);
112 
113  $result = $this->db->query($sql);
114 
115  if ($result) {
116  $num = $this->db->num_rows($result);
117  while ($i < min($num, $max)) {
118  $objp = $this->db->fetch_object($result);
119 
120  $projectstatic->id = $objp->rowid;
121  $projectstatic->ref = $objp->ref;
122  $projectstatic->title = $objp->title;
123  $projectstatic->public = $objp->public;
124  $projectstatic->statut = $objp->status;
125 
126  $this->info_box_contents[$i][] = array(
127  'td' => 'class="nowraponall"',
128  'text' => $projectstatic->getNomUrl(1),
129  'asis' => 1
130  );
131 
132  $this->info_box_contents[$i][] = array(
133  'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
134  'text' => $objp->title,
135  );
136 
137  $sql = "SELECT count(*) as nb, sum(progress) as totprogress";
138  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
139  $sql .= " WHERE p.entity IN (".getEntity('project').')';
140  $sql .= " AND p.rowid = ".((int) $objp->rowid);
141 
142  $resultTask = $this->db->query($sql);
143  if ($resultTask) {
144  $objTask = $this->db->fetch_object($resultTask);
145  $this->info_box_contents[$i][] = array(
146  'td' => 'class="right"',
147  'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
148  );
149  if ($objTask->nb > 0) {
150  $this->info_box_contents[$i][] = array(
151  'td' => 'class="right"',
152  'text' => round($objTask->totprogress / $objTask->nb, 0)."%",
153  );
154  } else {
155  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
156  }
157  $totalnbTask += $objTask->nb;
158  } else {
159  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => round(0));
160  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
161  }
162  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => $projectstatic->getLibStatut(3));
163 
164  $i++;
165  }
166  if ($max < $num) {
167  $this->info_box_contents[$i][] = array('td' => 'colspan="5"', 'text' => '...');
168  $i++;
169  }
170  }
171  }
172 
173 
174  // Add the sum à the bottom of the boxes
175  $this->info_box_contents[$i][] = array(
176  'td' => 'class="liste_total"',
177  'text' => $langs->trans("Total")."&nbsp;".$textHead,
178  );
179  $this->info_box_contents[$i][] = array(
180  'td' => 'class="right liste_total" ',
181  'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
182  );
183  $this->info_box_contents[$i][] = array(
184  'td' => 'class="right liste_total" ',
185  'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
186  );
187  $this->info_box_contents[$i][] = array(
188  'td' => 'class="liste_total"',
189  'text' => "&nbsp;",
190  );
191  $this->info_box_contents[$i][] = array(
192  'td' => 'class="liste_total"',
193  'text' => "&nbsp;",
194  );
195  }
196 
205  public function showBox($head = null, $contents = null, $nooutput = 0)
206  {
207  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
208  }
209 }
Class ModeleBoxes.
Class to manage projects.
Class to manage the box to show last projet.
Definition: box_project.php:33
loadBox($max=5)
Load data for box to show them later.
Definition: box_project.php:74
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
Definition: box_project.php:55
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
$conf db
API class for accounts.
Definition: inc.php:41