Merge pull request #23342 from daraelmin/daraelmin-box-adh-tags
NEW Add widget box_members_by_tags.php
This commit is contained in:
commit
8675abeec8
@ -171,4 +171,82 @@ class AdherentStats extends Stats
|
||||
|
||||
return $this->_getAllByYear($sql);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return count of member by status group by adh type, total and average
|
||||
*
|
||||
* @param int $numberYears Years to scan
|
||||
* @return array Array with total of draft, pending, uptodate, expired, resiliated for each member tag
|
||||
*/
|
||||
public function countMembersByTagAndStatus($numberYears = 2)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$now = dol_now();
|
||||
$endYear = date('Y');
|
||||
$startYear = $endYear - $numberYears;
|
||||
|
||||
$sql = "SELECT c.rowid as fk_categorie, c.label as label";
|
||||
$sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft";
|
||||
$sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')", "'members_pending'", 'NULL').") as members_pending";
|
||||
$sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)", "'members_uptodate'", 'NULL').") as members_uptodate";
|
||||
$sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)", "'members_expired'", 'NULL').") as members_expired";
|
||||
$sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED, "'members_excluded'", 'NULL').") as members_excluded";
|
||||
$sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED, "'members_resiliated'", 'NULL').") as members_resiliated";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."categorie as c";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as ct ON c.rowid = ct.fk_categorie";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON d.rowid = ct.fk_member";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_type as t ON t.rowid = d.fk_adherent_type";
|
||||
$sql .= " WHERE c.entity IN (".getEntity('member_type').")";
|
||||
$sql .= " AND d.entity IN (" . getEntity('adherent') . ")";
|
||||
$sql .= " AND t.entity IN (" . getEntity('adherent') . ")";
|
||||
$sql .= " AND d.datefin > '".$this->db->idate(dol_get_first_day($startYear))."'";
|
||||
$sql .= " AND c.fk_parent = 0";
|
||||
$sql .= " GROUP BY c.rowid";
|
||||
|
||||
dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
if ($result) {
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
$MembersCountArray = [];
|
||||
$totalstatus = array(
|
||||
'label' => 'Total',
|
||||
'members_draft' => 0,
|
||||
'members_pending' => 0,
|
||||
'members_uptodate' => 0,
|
||||
'members_expired' => 0,
|
||||
'members_excluded' => 0,
|
||||
'members_resiliated' => 0
|
||||
);
|
||||
while ($i < $num) {
|
||||
$objp = $this->db->fetch_object($result);
|
||||
$MembersCountArray[$objp->fk_categorie] = array(
|
||||
'label' => $objp->label,
|
||||
'members_draft' => (int) $objp->members_draft,
|
||||
'members_pending' => (int) $objp->members_pending,
|
||||
'members_uptodate' => (int) $objp->members_uptodate,
|
||||
'members_expired' => (int) $objp->members_expired,
|
||||
'members_excluded' => (int) $objp->members_excluded,
|
||||
'members_resiliated' => (int) $objp->members_resiliated
|
||||
);
|
||||
$totalrow = 0;
|
||||
foreach ($MembersCountArray[$objp->fk_categorie] as $key=>$nb) {
|
||||
if ($key!='label') {
|
||||
$totalrow += $nb;
|
||||
$totalstatus[$key] += $nb;
|
||||
}
|
||||
}
|
||||
$MembersCountArray[$objp->fk_categorie]['total_adhtype'] = $totalrow;
|
||||
$i++;
|
||||
}
|
||||
$this->db->free($result);
|
||||
$MembersCountArray['total'] = $totalstatus;
|
||||
$MembersCountArray['total']['all'] = array_sum($totalstatus);
|
||||
}
|
||||
return $MembersCountArray;
|
||||
}
|
||||
}
|
||||
|
||||
278
htdocs/core/boxes/box_members_by_tags.php
Normal file
278
htdocs/core/boxes/box_members_by_tags.php
Normal file
@ -0,0 +1,278 @@
|
||||
<?php
|
||||
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2015-2020 Frederic France <frederic.france@netlogic.fr>
|
||||
* Copyright (C) 2021-2022 Waël Almoman <info@almoman.com>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/boxes/box_members_by_tags.php
|
||||
* \ingroup adherent
|
||||
* \brief Module to show box of members
|
||||
*/
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
|
||||
|
||||
|
||||
/**
|
||||
* Class to manage the box to show last modofied members
|
||||
*/
|
||||
class box_members_by_tags extends ModeleBoxes
|
||||
{
|
||||
public $boxcode = "box_members_by_tags";
|
||||
public $boximg = "object_user";
|
||||
public $boxlabel = "BoxTitleMembersByTags";
|
||||
public $depends = array("adherent", "categorie");
|
||||
|
||||
/**
|
||||
* @var DoliDB Database handler.
|
||||
*/
|
||||
public $db;
|
||||
|
||||
public $param;
|
||||
public $enabled = 1;
|
||||
|
||||
public $info_box_head = array();
|
||||
public $info_box_contents = array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
* @param string $param More parameters
|
||||
*/
|
||||
public function __construct($db, $param = '')
|
||||
{
|
||||
global $conf, $user;
|
||||
|
||||
$this->db = $db;
|
||||
|
||||
// disable module for such cases
|
||||
$listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
|
||||
if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) {
|
||||
$this->enabled = 0; // disabled for external users
|
||||
}
|
||||
|
||||
$this->hidden = !(isModEnabled('adherent') && $user->rights->adherent->lire);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data into info_box_contents array to show array later.
|
||||
*
|
||||
* @param int $max Maximum number of records to load
|
||||
* @return void
|
||||
*/
|
||||
public function loadBox($max = 5)
|
||||
{
|
||||
global $user, $langs, $conf;
|
||||
$langs->load("boxes");
|
||||
|
||||
$this->max = $max;
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
|
||||
$staticmember = new Adherent($this->db);
|
||||
|
||||
$year = date('Y');
|
||||
$numberyears = empty(getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH")) ? 2 : getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH");
|
||||
|
||||
$this->info_box_head = array('text' => $langs->trans("BoxTitleMembersByTags").' ('.$year-$numberyears.' - '.$year.')');
|
||||
|
||||
if ($user->rights->adherent->lire) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
$stats = new AdherentStats($this->db, $user->socid, $user->id);
|
||||
|
||||
// Show array
|
||||
$sumMembers= $stats->countMembersByTagAndStatus($numberyears);
|
||||
if ($sumMembers) {
|
||||
$line = 0;
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class=""',
|
||||
'text' => '',
|
||||
);
|
||||
// Members Status To Valid
|
||||
$labelstatus = $staticmember->LibStatut($staticmember::STATUS_DRAFT, 0, 0, 1);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
|
||||
'text' => $labelstatus
|
||||
);
|
||||
// Waiting for subscription
|
||||
$labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, 0, 1);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
|
||||
'text' => $labelstatus,
|
||||
);
|
||||
// Up to date
|
||||
$labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, dol_now() + 86400, 1);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
|
||||
'text' => $labelstatus,
|
||||
);
|
||||
// Expired
|
||||
$labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, dol_now() - 86400, 1);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
|
||||
'text' => $labelstatus
|
||||
);
|
||||
// Excluded
|
||||
$labelstatus = $staticmember->LibStatut($staticmember::STATUS_EXCLUDED, 0, 0, 1);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
|
||||
'text' => $labelstatus
|
||||
);
|
||||
// Resiliated
|
||||
$labelstatus = $staticmember->LibStatut($staticmember::STATUS_RESILIATED, 0, 0, 1);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"',
|
||||
'text' => $labelstatus
|
||||
);
|
||||
// Total row
|
||||
$labelstatus = $staticmember->LibStatut($staticmember::STATUS_RESILIATED, 0, 0, 1);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($langs->trans("Total")).'"',
|
||||
'text' => $langs->trans("Total")
|
||||
);
|
||||
$line++;
|
||||
foreach ($sumMembers as $key => $data) {
|
||||
$adhtype = new AdherentType($this->db);
|
||||
$adhtype->id = $key;
|
||||
|
||||
if ($key=='total') {
|
||||
break;
|
||||
}
|
||||
$adhtype->label = $data['label'];
|
||||
$AdherentType[$key] = $adhtype;
|
||||
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
|
||||
'text' => $adhtype->getNomUrl(1, dol_size(32)),
|
||||
'asis' => 1,
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right"',
|
||||
'text' => (isset($data['members_draft']) && $data['members_draft'] > 0 ? $data['members_draft'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3),
|
||||
'asis' => 1,
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right"',
|
||||
'text' => (isset($data['members_pending']) && $data['members_pending'] > 0 ? $data['members_pending'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3),
|
||||
'asis' => 1,
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right"',
|
||||
'text' => (isset($data['members_uptodate']) && $data['members_uptodate'] > 0 ? $data['members_uptodate'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 0, 0, 3),
|
||||
'asis' => 1,
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right"',
|
||||
'text' => (isset($data['members_expired']) && $data['members_expired'] > 0 ? $data['members_expired'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3),
|
||||
'asis' => 1,
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right"',
|
||||
'text' => (isset($data['members_excluded']) && $data['members_excluded'] > 0 ? $data['members_excluded'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, $now, 3),
|
||||
'asis' => 1,
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right"',
|
||||
'text' => (isset($data['members_resiliated']) && $data['members_resiliated'] > 0 ? $data['members_resiliated'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3),
|
||||
'asis' => 1,
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="right"',
|
||||
'text' => (isset($data['total_adhtype']) && $data['total_adhtype'] > 0 ? $data['total_adhtype'] : ''),
|
||||
'asis' => 1,
|
||||
);
|
||||
$line++;
|
||||
}
|
||||
|
||||
if (count($sumMembers) == 0) {
|
||||
$this->info_box_contents[$line][0] = array(
|
||||
'td' => 'class="center" colspan="6"',
|
||||
'text' => $langs->trans("NoRecordedMembersByType")
|
||||
);
|
||||
} else {
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'tr' => 'class="liste_total"',
|
||||
'td' => 'class="liste_total"',
|
||||
'text' => $langs->trans("Total")
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="liste_total right"',
|
||||
'text' => $sumMembers['total']['members_draft'].' '.$staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3),
|
||||
'asis' => 1
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="liste_total right"',
|
||||
'text' => $sumMembers['total']['members_pending'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3),
|
||||
'asis' => 1
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="liste_total right"',
|
||||
'text' => $sumMembers['total']['members_uptodate'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 0, 0, 3),
|
||||
'asis' => 1
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="liste_total right"',
|
||||
'text' => $sumMembers['total']['members_expired'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3),
|
||||
'asis' => 1
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="liste_total right"',
|
||||
'text' => $sumMembers['total']['members_excluded'].' '.$staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, 0, 3),
|
||||
'asis' => 1
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="liste_total right"',
|
||||
'text' => $sumMembers['total']['members_resiliated'].' '.$staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3),
|
||||
'asis' => 1
|
||||
);
|
||||
$this->info_box_contents[$line][] = array(
|
||||
'td' => 'class="liste_total right"',
|
||||
'text' => $sumMembers['total']['all'],
|
||||
'asis' => 1
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->info_box_contents[0][0] = array(
|
||||
'td' => '',
|
||||
'maxlength' => 500,
|
||||
'text' => ($this->db->error() . ' sql=' . $sql)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->info_box_contents[0][0] = array(
|
||||
'td' => 'class="nohover opacitymedium left"',
|
||||
'text' => $langs->trans("ReadPermissionNotAllowed")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to show box
|
||||
*
|
||||
* @param array $head Array with properties of box title
|
||||
* @param array $contents Array with properties of box lines
|
||||
* @param int $nooutput No print, only return string
|
||||
* @return string
|
||||
*/
|
||||
public function showBox($head = null, $contents = null, $nooutput = 0)
|
||||
{
|
||||
return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
|
||||
}
|
||||
}
|
||||
@ -464,6 +464,7 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" box
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
//echo "<pre>";print_r($modules);echo "</pre>";
|
||||
|
||||
asort($orders);
|
||||
|
||||
|
||||
@ -198,6 +198,7 @@ class modAdherent extends DolibarrModules
|
||||
4 => array('file'=>'box_members_last_subscriptions.php', 'enabledbydefaulton'=>'membersindex'),
|
||||
5 => array('file'=>'box_members_subscriptions_by_year.php', 'enabledbydefaulton'=>'membersindex'),
|
||||
6 => array('file'=>'box_members_by_type.php', 'enabledbydefaulton'=>'membersindex'),
|
||||
7 => array('file'=>'box_members_by_tags.php', 'enabledbydefaulton'=>'membersindex'),
|
||||
);
|
||||
|
||||
// Permissions
|
||||
|
||||
@ -24,6 +24,7 @@ BoxFicheInter=Latest interventions
|
||||
BoxCurrentAccounts=Open accounts balance
|
||||
BoxTitleMemberNextBirthdays=Birthdays of this month (members)
|
||||
BoxTitleMembersByType=Members by type and status
|
||||
BoxTitleMembersByTags=Members by tags and status
|
||||
BoxTitleMembersSubscriptionsByYear=Members Subscriptions by year
|
||||
BoxTitleLastRssInfos=Latest %s news from %s
|
||||
BoxTitleLastProducts=Products/Services: last %s modified
|
||||
|
||||
Loading…
Reference in New Issue
Block a user