Umfrageoptionen nach Anzahl Stimmen im Ampelsystem färben

Support zu den Modifikationen (MODs) von Entwickler OXPUS für das phpBB 3.0.x
Antworten
Benutzeravatar
oxpus
Chief handy-man
Beiträge: 2660
Registriert: Do 13. Dez 2007, 23:06
Wohnort: Irgendwo im I-Net
Kontaktdaten:

Umfrageoptionen nach Anzahl Stimmen im Ampelsystem färben

Beitrag von oxpus »

Dieses Snippet färbt zumindest im Style prosilver und allen darauf basierenden weiteren Styles die Umfrageoptionen im Ampelsystem nach den abgegebenen Stimmen.
Dabei erhält die höchste Anzahl Stimmen grüne, die zweithöchste Anzahl Stimmen orange und alle anderen Optionen rote Balken.

Code: Alles auswählen

#
#-----[ OPEN ]-----
#
viewtopic.php

#
#-----[ FIND ]-----
#
	while ($row = $db->sql_fetchrow($result))
	{
		$poll_info[] = $row;
	}
	$db->sql_freeresult($result);

#
#-----[ AFTER, ADD ]-----
#
	// Poll max information system - OXPUS
	$sql = 'SELECT poll_option_total FROM ' . POLL_OPTIONS_TABLE . "
		WHERE topic_id = $topic_id
		GROUP BY poll_option_total
		ORDER BY poll_option_total DESC
		LIMIT 2";
	$result = $db->sql_query($sql);

	$poll_max_color = array();
	while ($row = $db->sql_fetchrow($result))
	{
		$poll_max_color[] = $row['poll_option_total'];
	}
	$db->sql_freeresult($result);
	// Poll max information system - OXPUS

#
#-----[ FIND ]-----
#
	foreach ($poll_info as $poll_option)
	{
		$option_pct = ($poll_total > 0) ? $poll_option['poll_option_total'] / $poll_total : 0;
		$option_pct_txt = sprintf("%.1d%%", round($option_pct * 100));

#
#-----[ AFTER, ADD ]-----
#
		// Poll max information system - OXPUS
		if ($poll_max_color[0] == $poll_option['poll_option_total'])
		{
			$poll_option_color = 'green';
		}
		else if ($poll_max_color[1] == $poll_option['poll_option_total'])
		{
			$poll_option_color = 'orange';
		}
		else
		{
			$poll_option_color = 'red';
		}
		// Poll max information system - OXPUS

#
#-----[ FIND ]-----
#
			'POLL_OPTION_PERCENT' 	=> $option_pct_txt,

#
#-----[ AFTER, ADD ]-----
#
			'POLL_OPTION_COLOR'		=> $poll_option_color,

#
#-----[ OPEN ]-----
#
styles/prosilver/template/viewtopic_body.html

#
#-----[ FIND ]-----
#
					<!-- IF S_DISPLAY_RESULTS --><dd class="resultbar"><div class="<!-- IF poll_option.POLL_OPTION_PCT < 20 -->pollbar1<!-- ELSEIF poll_option.POLL_OPTION_PCT < 40 -->pollbar2<!-- ELSEIF poll_option.POLL_OPTION_PCT < 60 -->pollbar3<!-- ELSEIF poll_option.POLL_OPTION_PCT < 80 -->pollbar4<!-- ELSE -->pollbar5<!-- ENDIF -->" style="width:{poll_option.POLL_OPTION_PERCENT};">{poll_option.POLL_OPTION_RESULT}</div></dd>

#
#-----[ IN-LINE FIND ]-----
#
pollbar5<!-- ENDIF -->" style="width:{poll_option.POLL_OPTION_PERCENT};

#
#-----[ IN-LINE AFTER, ADD ]-----
#
 background-color: {poll_option.POLL_OPTION_COLOR}; border: none;
In subsilver2 und ähnlichen Styles ist das weniger zu empfehlen, da hier Images für die Balken verwendet werden und man mehr oder weniger nur den kompletten Hintergrund dessen färben würde.

Dieses Snippet ist auf diesem Forum installiert und als Beispiel dient diese Umfrage: http://phpbb3.oxpus.net/viewtopic.php?f=5&t=47
Karsten Ude
Kein Support per Messenger, Email oder PN! Unaufgeforderte Nachrichten werden ignoriert!
No support per Messenger, Email or PM. Each unasked message will be ignored!
Antworten