Browse Source

Merge pull request #675 from Arantor/release-2.1

! If gender is disabled, hide the item from the stats page - and don't b...
Arantor 11 years ago
parent
commit
5b0960d60f
2 changed files with 42 additions and 35 deletions
  1. 38 34
      Sources/Stats.php
  2. 4 1
      Themes/default/Stats.template.php

+ 38 - 34
Sources/Stats.php

@@ -149,43 +149,47 @@ function DisplayStats()
 	$context['latest_member'] = &$context['common_stats']['latest_member'];
 
 	// Male vs. female ratio - let's calculate this only every four minutes.
-	if (($context['gender'] = cache_get_data('stats_gender', 240)) == null)
+	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
+	if (!in_array('gender', $disabled_fields))
 	{
-		$result = $smcFunc['db_query']('', '
-			SELECT COUNT(*) AS total_members, gender
-			FROM {db_prefix}members
-			GROUP BY gender',
-			array(
-			)
-		);
-		$context['gender'] = array();
-		while ($row = $smcFunc['db_fetch_assoc']($result))
+		if (($context['gender'] = cache_get_data('stats_gender', 240)) == null)
 		{
-			// Assuming we're telling... male or female?
-			if (!empty($row['gender']))
-				$context['gender'][$row['gender'] == 2 ? 'females' : 'males'] = $row['total_members'];
+			$result = $smcFunc['db_query']('', '
+				SELECT COUNT(*) AS total_members, gender
+				FROM {db_prefix}members
+				GROUP BY gender',
+				array(
+				)
+			);
+			$context['gender'] = array();
+			while ($row = $smcFunc['db_fetch_assoc']($result))
+			{
+				// Assuming we're telling... male or female?
+				if (!empty($row['gender']))
+					$context['gender'][$row['gender'] == 2 ? 'females' : 'males'] = $row['total_members'];
+			}
+			$smcFunc['db_free_result']($result);
+
+			// Set these two zero if the didn't get set at all.
+			if (empty($context['gender']['males']))
+				$context['gender']['males'] = 0;
+			if (empty($context['gender']['females']))
+				$context['gender']['females'] = 0;
+
+			// Try and come up with some "sensible" default states in case of a non-mixed board.
+			if ($context['gender']['males'] == $context['gender']['females'])
+				$context['gender']['ratio'] = '1:1';
+			elseif ($context['gender']['males'] == 0)
+				$context['gender']['ratio'] = '0:1';
+			elseif ($context['gender']['females'] == 0)
+				$context['gender']['ratio'] = '1:0';
+			elseif ($context['gender']['males'] > $context['gender']['females'])
+				$context['gender']['ratio'] = round($context['gender']['males'] / $context['gender']['females'], 1) . ':1';
+			elseif ($context['gender']['females'] > $context['gender']['males'])
+				$context['gender']['ratio'] = '1:' . round($context['gender']['females'] / $context['gender']['males'], 1);
+
+			cache_put_data('stats_gender', $context['gender'], 240);
 		}
-		$smcFunc['db_free_result']($result);
-
-		// Set these two zero if the didn't get set at all.
-		if (empty($context['gender']['males']))
-			$context['gender']['males'] = 0;
-		if (empty($context['gender']['females']))
-			$context['gender']['females'] = 0;
-
-		// Try and come up with some "sensible" default states in case of a non-mixed board.
-		if ($context['gender']['males'] == $context['gender']['females'])
-			$context['gender']['ratio'] = '1:1';
-		elseif ($context['gender']['males'] == 0)
-			$context['gender']['ratio'] = '0:1';
-		elseif ($context['gender']['females'] == 0)
-			$context['gender']['ratio'] = '1:0';
-		elseif ($context['gender']['males'] > $context['gender']['females'])
-			$context['gender']['ratio'] = round($context['gender']['males'] / $context['gender']['females'], 1) . ':1';
-		elseif ($context['gender']['females'] > $context['gender']['males'])
-			$context['gender']['ratio'] = '1:' . round($context['gender']['females'] / $context['gender']['males'], 1);
-
-		cache_put_data('stats_gender', $context['gender'], 240);
 	}
 
 	$date = strftime('%Y-%m-%d', forum_time(false));

+ 4 - 1
Themes/default/Stats.template.php

@@ -69,7 +69,10 @@ function template_main()
 							<dt>', $txt['latest_member'], ':</dt>
 							<dd>', $context['common_stats']['latest_member']['link'], '</dd>
 							<dt>', $txt['average_online'], ':</dt>
-							<dd>', $context['average_online'], '</dd>
+							<dd>', $context['average_online'], '</dd>';
+
+	if (!empty($context['gender']))
+		echo '
 							<dt>', $txt['gender_ratio'], ':</dt>
 							<dd>', $context['gender']['ratio'], '</dd>';