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');