2014-06-18 21:36:00 +02:00
< ? php
/* Copyright ( C ) 2012 - 2014 Charles - François BENKE < charles . fr @ benke . fr >
2014-12-23 16:37:53 +01:00
* Copyright ( C ) 2014 Marcos García < marcosgdf @ gmail . com >
2015-01-25 01:20:58 +01:00
* Copyright ( C ) 2015 Frederic France < frederic . france @ free . fr >
2016-10-04 16:51:44 +02:00
* Copyright ( C ) 2016 Juan José Menent < jmenent @ 2 byte . es >
2015-01-25 01:20:58 +01:00
*
2014-06-18 21:36:00 +02:00
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
2015-01-06 17:54:36 +01:00
* \file htdocs / core / boxes / box_activite . php
* \ingroup projet
* \brief Module to show Projet activity of the current Year
2014-06-18 21:36:00 +02:00
*/
include_once ( DOL_DOCUMENT_ROOT . " /core/boxes/modules_boxes.php " );
2014-06-20 23:19:57 +02:00
/**
* Class to manage the box to show last projet
*/
2014-06-20 23:56:03 +02:00
class box_project extends ModeleBoxes
2014-06-20 23:19:57 +02:00
{
var $boxcode = " project " ;
2014-06-18 21:36:00 +02:00
var $boximg = " object_projectpub " ;
var $boxlabel ;
//var $depends = array("projet");
var $db ;
var $param ;
var $info_box_head = array ();
var $info_box_contents = array ();
2015-01-06 17:54:36 +01:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
* @ param string $param More parameters
*/
function __construct ( $db , $param = '' )
{
2017-06-12 14:09:00 +02:00
global $user , $langs ;
2015-01-06 17:54:36 +01:00
$langs -> load ( " boxes " );
$langs -> load ( " projects " );
$this -> db = $db ;
$this -> boxlabel = " Projects " ;
2017-06-12 14:09:00 +02:00
$this -> hidden =! ( $user -> rights -> projet -> lire );
2015-01-06 17:54:36 +01:00
}
2014-06-18 21:36:00 +02:00
/**
2014-06-20 23:56:03 +02:00
* Load data for box to show them later
*
2015-01-06 17:54:36 +01:00
* @ param int $max Maximum number of records to load
* @ return void
2014-06-20 23:56:03 +02:00
*/
2014-06-18 21:36:00 +02:00
function loadBox ( $max = 5 )
{
global $conf , $user , $langs , $db ;
2014-07-08 01:02:30 +02:00
2014-06-18 21:36:00 +02:00
$this -> max = $max ;
2014-07-08 01:02:30 +02:00
2014-06-18 21:36:00 +02:00
$totalMnt = 0 ;
$totalnb = 0 ;
$totalnbTask = 0 ;
2014-07-08 01:02:30 +02:00
2017-03-21 13:38:00 +01:00
$textHead = $langs -> trans ( " OpenedProjects " );
2014-06-18 21:36:00 +02:00
$this -> info_box_head = array ( 'text' => $textHead , 'limit' => dol_strlen ( $textHead ));
// list the summary of the orders
2015-01-06 17:54:36 +01:00
if ( $user -> rights -> projet -> lire ) {
2017-06-12 14:09:00 +02:00
2017-03-21 13:38:00 +01:00
include_once ( DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' );
$projectstatic = new Project ( $this -> db );
2017-06-12 14:09:00 +02:00
2017-03-21 13:38:00 +01:00
$socid = $user -> societe_id ;
2017-06-12 14:09:00 +02:00
2017-03-21 13:38:00 +01:00
// Get list of project id allowed to user (in a string list separated by coma)
$projectsListId = '' ;
if ( ! $user -> rights -> projet -> all -> lire ) $projectsListId = $projectstatic -> getProjectsAuthorizedForUser ( $user , 0 , 1 , $socid );
2017-06-12 14:09:00 +02:00
2017-03-21 13:38:00 +01:00
$sql = " SELECT p.rowid, p.ref, p.title, p.fk_statut, p.public " ;
2014-08-14 13:25:54 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p " ;
2016-10-04 16:51:44 +02:00
if ( $user -> socid ) $sql .= " INNER JOIN " . MAIN_DB_PREFIX . " societe as s ON s.rowid=p.fk_soc " ;
2017-05-30 18:50:54 +02:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'project' ) . ')' ;
2017-03-21 13:38:00 +01:00
if ( ! $user -> rights -> projet -> all -> lire ) $sql .= " AND p.rowid IN ( " . $projectsListId . " ) " ; // public and assigned to, or restricted to company for external users
if ( $user -> socid ) $sql .= " AND s.rowid = " . $user -> socid ;
2016-10-04 16:51:44 +02:00
$sql .= " AND p.fk_statut = 1 " ; // Seulement les projets ouverts
2017-03-21 13:38:00 +01:00
if ( $socid ) $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . " ) " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id . " ) OR (s.rowid IS NULL)) " ;
2017-06-12 14:09:00 +02:00
2017-03-21 13:38:00 +01:00
$sql .= " ORDER BY p.datec DESC " ;
//$sql.= $db->plimit($max, 0);
2014-06-18 21:36:00 +02:00
2015-01-06 17:54:36 +01:00
$result = $db -> query ( $sql );
2014-06-18 21:36:00 +02:00
2015-01-06 17:54:36 +01:00
if ( $result ) {
$num = $db -> num_rows ( $result );
$i = 0 ;
2017-03-21 13:38:00 +01:00
while ( $i < min ( $num , $max )) {
2015-01-06 17:54:36 +01:00
$objp = $db -> fetch_object ( $result );
2014-12-23 16:37:53 +01:00
2017-11-11 00:28:00 +01:00
$projectstatic -> id = $objp -> rowid ;
$projectstatic -> ref = $objp -> ref ;
$projectstatic -> title = $objp -> title ;
$projectstatic -> public = $objp -> public ;
2014-07-08 01:02:30 +02:00
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array (
2017-03-10 11:22:27 +01:00
'td' => '' ,
2017-11-11 00:28:00 +01:00
'text' => $projectstatic -> getNomUrl ( 1 ),
'asis' => 1
2015-01-06 17:54:36 +01:00
);
2014-06-18 21:36:00 +02:00
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array (
2017-03-10 11:22:27 +01:00
'td' => '' ,
2015-01-24 15:36:47 +01:00
'text' => $objp -> title ,
2015-01-06 17:54:36 +01:00
);
2014-07-08 01:02:30 +02:00
2014-06-20 23:19:57 +02:00
$sql = " SELECT count(*) as nb, sum(progress) as totprogress " ;
2014-08-14 13:25:54 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p LEFT JOIN " . MAIN_DB_PREFIX . " projet_task as pt on pt.fk_projet = p.rowid " ;
2017-05-30 18:50:54 +02:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'project' ) . ')' ;
2017-03-21 13:38:00 +01:00
$sql .= " AND p.rowid = " . $objp -> rowid ;
2014-06-18 21:36:00 +02:00
$resultTask = $db -> query ( $sql );
2015-01-06 17:54:36 +01:00
if ( $resultTask ) {
2014-06-18 21:36:00 +02:00
$objTask = $db -> fetch_object ( $resultTask );
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array (
2017-03-10 11:22:27 +01:00
'td' => 'class="right"' ,
2017-03-21 13:01:32 +01:00
'text' => $objTask -> nb . " " . $langs -> trans ( " Tasks " ),
2015-01-24 15:36:47 +01:00
);
2017-03-21 13:01:32 +01:00
if ( $objTask -> nb > 0 )
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array (
2017-03-10 11:22:27 +01:00
'td' => 'class="right"' ,
2017-03-21 13:01:32 +01:00
'text' => round ( $objTask -> totprogress / $objTask -> nb , 0 ) . " % " ,
2015-01-24 15:36:47 +01:00
);
2014-06-18 22:19:28 +02:00
else
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array ( 'td' => 'class="right"' , 'text' => " N/A " );
2014-06-18 21:36:00 +02:00
$totalnbTask += $objTask -> nb ;
2015-01-06 17:54:36 +01:00
} else {
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array ( 'td' => 'class="right"' , 'text' => round ( 0 ));
$this -> info_box_contents [ $i ][] = array ( 'td' => 'class="right"' , 'text' => " N/A " );
2014-06-18 21:36:00 +02:00
}
$i ++ ;
}
2017-03-21 13:38:00 +01:00
if ( $max < $num )
{
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array ( 'td' => 'colspan="5"' , 'text' => '...' );
2017-03-21 13:38:00 +01:00
$i ++ ;
}
2014-06-18 21:36:00 +02:00
}
}
// Add the sum à the bottom of the boxes
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array (
2015-01-24 15:36:47 +01:00
'td' => '' ,
'text' => $langs -> trans ( " Total " ) . " " . $textHead ,
'text' => " " ,
);
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array (
2015-01-24 15:36:47 +01:00
'td' => 'align="right" ' ,
2017-03-21 13:38:00 +01:00
'text' => round ( $num , 0 ) . " " . $langs -> trans ( " Projects " ),
2015-01-24 15:36:47 +01:00
);
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array (
2015-01-24 15:36:47 +01:00
'td' => 'align="right" ' ,
2017-03-21 13:38:00 +01:00
'text' => (( $max < $num ) ? '' : ( round ( $totalnbTask , 0 ) . " " . $langs -> trans ( " Tasks " ))),
2015-01-24 15:36:47 +01:00
);
2017-11-11 00:28:00 +01:00
$this -> info_box_contents [ $i ][] = array (
2015-01-24 15:36:47 +01:00
'td' => '' ,
'text' => " " ,
);
2014-07-08 01:02:30 +02:00
2014-06-18 21:36:00 +02:00
}
2014-06-20 23:38:15 +02:00
/**
* Method to show box
*
* @ param array $head Array with properties of box title
* @ param array $contents Array with properties of box lines
2016-06-27 13:57:10 +02:00
* @ param int $nooutput No print , only return string
2017-06-12 14:09:00 +02:00
* @ return string
2014-06-20 23:38:15 +02:00
*/
2016-06-27 13:57:10 +02:00
function showBox ( $head = null , $contents = null , $nooutput = 0 )
{
2017-06-12 14:09:00 +02:00
return parent :: showBox ( $this -> info_box_head , $this -> info_box_contents , $nooutput );
2014-06-18 21:36:00 +02:00
}
}
2014-07-08 01:02:30 +02:00