From dc80e6b0298a85665e69bfc0ac0c107cf234e313 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 Mar 2023 11:29:44 +0100 Subject: [PATCH] Fix look and feel v18 --- htdocs/core/lib/member.lib.php | 38 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/htdocs/core/lib/member.lib.php b/htdocs/core/lib/member.lib.php index 71a9849dc16..83b936a9b0b 100644 --- a/htdocs/core/lib/member.lib.php +++ b/htdocs/core/lib/member.lib.php @@ -126,16 +126,38 @@ function member_prepare_head(Adherent $object) $h++; // Show agenda tab - if (isModEnabled('agenda')) { - $head[$h][0] = DOL_URL_ROOT."/adherents/agenda.php?id=".$object->id; - $head[$h][1] = $langs->trans("Events"); - if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { - $head[$h][1] .= '/'; - $head[$h][1] .= $langs->trans("Agenda"); + $head[$h][0] = DOL_URL_ROOT.'/adherents/agenda.php?id='.$object->id; + $head[$h][1] = $langs->trans("Events"); + if (isModEnabled('agenda')&& (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { + $nbEvent = 0; + // Enable caching of thirdparty count actioncomm + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $cachekey = 'count_events_member_'.$object->id; + $dataretrieved = dol_getcache($cachekey); + if (!is_null($dataretrieved)) { + $nbEvent = $dataretrieved; + } else { + $sql = "SELECT COUNT(id) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm"; + $sql .= " WHERE elementtype = 'member' AND fk_element = ".((int) $object->id); + $resql = $db->query($sql); + if ($resql) { + $obj = $db->fetch_object($resql); + $nbEvent = $obj->nb; + } else { + dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR); + } + dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result. + } + + $head[$h][1] .= '/'; + $head[$h][1] .= $langs->trans("Agenda"); + if ($nbEvent > 0) { + $head[$h][1] .= ''.$nbEvent.''; } - $head[$h][2] = 'agenda'; - $h++; } + $head[$h][2] = 'agenda'; + $h++; complete_head_from_modules($conf, $langs, $object, $head, $h, 'member', 'add', 'external');