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