NEW : new param on load_board() function in ActionComm class to avoid duplicate code
This commit is contained in:
parent
d270a8e009
commit
1694737e0b
@ -912,18 +912,24 @@ class ActionComm extends CommonObject
|
|||||||
* Load indicators for dashboard (this->nbtodo and this->nbtodolate)
|
* Load indicators for dashboard (this->nbtodo and this->nbtodolate)
|
||||||
*
|
*
|
||||||
* @param User $user Objet user
|
* @param User $user Objet user
|
||||||
|
* @param int $load_state_board Charge indicateurs this->nb de tableau de bord
|
||||||
* @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK
|
* @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK
|
||||||
*/
|
*/
|
||||||
function load_board($user)
|
function load_board($user, $load_state_board=0)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
$sql = "SELECT a.id, a.datep as dp";
|
if(empty($load_state_board)) $sql = "SELECT a.id, a.datep as dp";
|
||||||
|
else {
|
||||||
|
$this->nb=array();
|
||||||
|
$sql = "SELECT count(a.id) as nb";
|
||||||
|
}
|
||||||
$sql.= " FROM (".MAIN_DB_PREFIX."actioncomm as a";
|
$sql.= " FROM (".MAIN_DB_PREFIX."actioncomm as a";
|
||||||
$sql.= ")";
|
$sql.= ")";
|
||||||
if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
|
if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
|
||||||
$sql.= " WHERE a.percent >= 0 AND a.percent < 100";
|
$sql.= " WHERE 1";
|
||||||
|
if(empty($load_state_board)) $sql.= " AND a.percent >= 0 AND a.percent < 100";
|
||||||
$sql.= " AND a.entity IN (".getEntity('agenda').")";
|
$sql.= " AND a.entity IN (".getEntity('agenda').")";
|
||||||
if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
|
if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
|
||||||
if ($user->societe_id) $sql.=" AND a.fk_soc = ".$user->societe_id;
|
if ($user->societe_id) $sql.=" AND a.fk_soc = ".$user->societe_id;
|
||||||
@ -932,69 +938,28 @@ class ActionComm extends CommonObject
|
|||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
|
if(empty($load_state_board)) {
|
||||||
$agenda_static = new ActionComm($this->db);
|
$agenda_static = new ActionComm($this->db);
|
||||||
|
|
||||||
$response = new WorkboardResponse();
|
$response = new WorkboardResponse();
|
||||||
$response->warning_delay = $conf->agenda->warning_delay/60/60/24;
|
$response->warning_delay = $conf->agenda->warning_delay/60/60/24;
|
||||||
$response->label = $langs->trans("ActionsToDo");
|
$response->label = $langs->trans("ActionsToDo");
|
||||||
$response->url = DOL_URL_ROOT.'/comm/action/listactions.php?status=todo&mainmenu=agenda';
|
$response->url = DOL_URL_ROOT.'/comm/action/listactions.php?status=todo&mainmenu=agenda';
|
||||||
if ($user->rights->agenda->allactions->read) $response->url.='&filtert=-1';
|
if ($user->rights->agenda->allactions->read) $response->url.='&filtert=-1';
|
||||||
$response->img = img_object('',"action",'class="inline-block valigntextmiddle"');
|
$response->img = img_object('',"action",'class="inline-block valigntextmiddle"');
|
||||||
|
}
|
||||||
// This assignment in condition is not a bug. It allows walking the results.
|
// This assignment in condition is not a bug. It allows walking the results.
|
||||||
while ($obj=$this->db->fetch_object($resql))
|
while ($obj=$this->db->fetch_object($resql))
|
||||||
{
|
{
|
||||||
|
if(empty($load_state_board)) {
|
||||||
$response->nbtodo++;
|
$response->nbtodo++;
|
||||||
|
|
||||||
$agenda_static->datep = $this->db->jdate($obj->dp);
|
$agenda_static->datep = $this->db->jdate($obj->dp);
|
||||||
|
if ($agenda_static->hasDelay()) $response->nbtodolate++;
|
||||||
if ($agenda_static->hasDelay()) {
|
} else $this->nb["actionscomm"]=$obj->nb;
|
||||||
$response->nbtodolate++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->error=$this->db->error();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Charge indicateurs this->nb de tableau de bord
|
|
||||||
*
|
|
||||||
* @return int <0 if ko, >0 if ok
|
|
||||||
*/
|
|
||||||
function load_state_board()
|
|
||||||
{
|
|
||||||
global $user;
|
|
||||||
|
|
||||||
$this->nb=array();
|
|
||||||
|
|
||||||
$sql = "SELECT count(a.id) as nb";
|
|
||||||
$sql.= " FROM (".MAIN_DB_PREFIX."actioncomm as a";
|
|
||||||
$sql.= ")";
|
|
||||||
if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
|
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
|
|
||||||
$sql.= " WHERE a.entity IN (".getEntity('agenda').")";
|
|
||||||
if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
|
|
||||||
if ($user->societe_id) $sql.=" AND a.fk_soc = ".$user->societe_id;
|
|
||||||
if (! $user->rights->agenda->allactions->read) $sql.= " AND (a.fk_user_author = ".$user->id . " OR a.fk_user_action = ".$user->id . " OR a.fk_user_done = ".$user->id . ")";
|
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$agenda_static = new ActionComm($this->db);
|
|
||||||
|
|
||||||
while ($obj=$this->db->fetch_object($resql))
|
|
||||||
{
|
|
||||||
$this->nb["actionscomm"]=$obj->nb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
return 1;
|
if(empty($load_state_board)) return $response;
|
||||||
|
else return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -377,7 +377,7 @@ if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->read)
|
|||||||
$board=new ActionComm($db);
|
$board=new ActionComm($db);
|
||||||
$wb_res = $board->load_board($user);
|
$wb_res = $board->load_board($user);
|
||||||
if(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
|
if(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
|
||||||
$board->load_state_board();
|
$board->load_board($user, 1);
|
||||||
$wb_res->nbtotal = (int)$board->nb['actionscomm'];
|
$wb_res->nbtotal = (int)$board->nb['actionscomm'];
|
||||||
}
|
}
|
||||||
$dashboardlines[] = $wb_res;
|
$dashboardlines[] = $wb_res;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user