Explorar o código

Merge pull request #21911 from ymollard/members-public-counters

NEW: Public counters feature
Laurent Destailleur %!s(int64=2) %!d(string=hai) anos
pai
achega
0a4514c785

+ 9 - 0
htdocs/adherents/admin/website.php

@@ -59,6 +59,7 @@ if ($action == 'update') {
 	$public = GETPOST('MEMBER_ENABLE_PUBLIC');
 	$amount = price2num(GETPOST('MEMBER_NEWFORM_AMOUNT'), 'MT', 2);
 	$editamount = GETPOST('MEMBER_NEWFORM_EDITAMOUNT');
+	$publiccounters = GETPOST('MEMBER_COUNTERS_ARE_PUBLIC');
 	$payonline = GETPOST('MEMBER_NEWFORM_PAYONLINE');
 	$forcetype = GETPOST('MEMBER_NEWFORM_FORCETYPE', 'int');
 	$forcemorphy = GETPOST('MEMBER_NEWFORM_FORCEMORPHY', 'aZ09');
@@ -66,6 +67,7 @@ if ($action == 'update') {
 	$res = dolibarr_set_const($db, "MEMBER_ENABLE_PUBLIC", $public, 'chaine', 0, '', $conf->entity);
 	$res = dolibarr_set_const($db, "MEMBER_NEWFORM_AMOUNT", $amount, 'chaine', 0, '', $conf->entity);
 	$res = dolibarr_set_const($db, "MEMBER_NEWFORM_EDITAMOUNT", $editamount, 'chaine', 0, '', $conf->entity);
+	$res = dolibarr_set_const($db, "MEMBER_COUNTERS_ARE_PUBLIC", $publiccounters, 'chaine', 0, '', $conf->entity);
 	$res = dolibarr_set_const($db, "MEMBER_NEWFORM_PAYONLINE", $payonline, 'chaine', 0, '', $conf->entity);
 	if ($forcetype < 0) {
 		$res = dolibarr_del_const($db, "MEMBER_NEWFORM_FORCETYPE", $conf->entity);
@@ -237,6 +239,13 @@ if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
 	print $form->selectyesno("MEMBER_NEWFORM_EDITAMOUNT", (!empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT) ? $conf->global->MEMBER_NEWFORM_EDITAMOUNT : 0), 1);
 	print "</td></tr>\n";
 
+	// SHow counter of validated members publicly
+	print '<tr class="oddeven" id="tredit"><td>';
+	print $langs->trans("MemberCountersArePublic");
+	print '</td><td>';
+	print $form->selectyesno("MEMBER_COUNTERS_ARE_PUBLIC", (!empty($conf->global->MEMBER_COUNTERS_ARE_PUBLIC) ? $conf->global->MEMBER_COUNTERS_ARE_PUBLIC : 0), 1);
+	print "</td></tr>\n";
+
 	// Jump to an online payment page
 	print '<tr class="oddeven" id="trpayment"><td>';
 	print $langs->trans("MEMBER_NEWFORM_PAYONLINE");

+ 1 - 0
htdocs/langs/en_US/members.lang

@@ -15,6 +15,7 @@ ErrorMemberIsAlreadyLinkedToThisThirdParty=Another member (name: <b>%s</b>, logi
 ErrorUserPermissionAllowsToLinksToItselfOnly=For security reasons, you must be granted permissions to edit all users to be able to link a member to a user that is not yours.
 SetLinkToUser=Link to a Dolibarr user
 SetLinkToThirdParty=Link to a Dolibarr third party
+MemberCountersArePublic=Counters of valid members are public
 MembersCards=Generation of cards for members
 MembersList=List of members
 MembersListToValid=List of draft members (to be validated)

+ 9 - 2
htdocs/public/members/new.php

@@ -770,10 +770,14 @@ if (!empty($conf->global->MEMBER_SKIP_TABLE) || !empty($conf->global->MEMBER_NEW
 	foreach ($measuringUnits->records as $lines)
 		$units[$lines->short_label] = $langs->trans(ucfirst($lines->label));
 
-	$sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.amount, d.caneditamount, d.vote, d.note, d.duration, d.statut as status, d.morphy";
+	$publiccounters = $conf->global->MEMBER_COUNTERS_ARE_PUBLIC;
+
+	$sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.amount, d.caneditamount, d.vote, d.note, d.duration, d.statut as status, d.morphy, COUNT(a.rowid) AS membercount";
 	$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
+	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as a";
+	$sql .= " ON d.rowid = a.fk_adherent_type AND a.statut>0";
 	$sql .= " WHERE d.entity IN (".getEntity('member_type').")";
-	$sql .= " AND d.statut=1";
+	$sql .= " AND d.statut=1 GROUP BY d.rowid";
 
 	$result = $db->query($sql);
 	if ($result) {
@@ -789,6 +793,7 @@ if (!empty($conf->global->MEMBER_SKIP_TABLE) || !empty($conf->global->MEMBER_NEW
 		print '<th class="center">'.$langs->trans("Amount").'</th>';
 		print '<th class="center">'.$langs->trans("MembersNature").'</th>';
 		print '<th class="center">'.$langs->trans("VoteAllowed").'</th>';
+		if ($publiccounters) print '<th class="center">'.$langs->trans("Members").'</th>';
 		print '<th class="center">'.$langs->trans("NewSubscription").'</th>';
 		print "</tr>\n";
 
@@ -828,6 +833,8 @@ if (!empty($conf->global->MEMBER_SKIP_TABLE) || !empty($conf->global->MEMBER_NEW
 			}
 			print '</td>';
 			print '<td class="center">'.yn($objp->vote).'</td>';
+			$membercount = $objp->membercount>0? $objp->membercount: "–";
+			if ($publiccounters) print '<td class="center">'.$membercount.'</td>';
 			print '<td class="center"><button class="button button-save reposition" name="typeid" type="submit" name="submit" value="'.$objp->rowid.'">'.$langs->trans("GetMembershipButtonLabel").'</button></td>';
 			print "</tr>";
 			$i++;