Poll Display portlet

From VYRE

Jump to: navigation, search
Poll Display portlet
module: Content module
supplier: VYRE Ltd.


The Poll Display portlet is used to display the polls in websites so as to allow web users to cast their vote.

Usage

This portlet can be found under Polling portlets section in Portlet Types page.

Example of generated XML output
<poll total="1" id="158"> 
 <name>Poll with Strategy 'IP Address'</name>
 <question>Poll with Strategy 'IP Address'</question>
 <strategy>IpAddress</strategy>
 <creation-date>16.09.2009 14:32</creation-date>
 <answers>    
  <answer percentage="100.0" id="160" index="0" count="1">         
   <name>A1</name>         
   <description>A1</description>     
  </answer>     
  <answer percentage="0.0" id="161" index="1" count="0">          
   <name>A2</name>         
   <description>A2</description>     
  </answer>  
 </answers>
</poll>

Configuration

In the edit mode of the portlet, following fields are listed and user has to enter values for these fields while adding the portlet:

File:Poll Display Portlet Edit Mode.JPG

Poll

Select the poll created using Poll Edit portlet.

XSL stylesheet

Select the XSL file created under Publishing > XSL > Others to display the poll.

Sample XSL file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet>
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">  
  <xsl:output method="html" encoding="iso-8859-1"/>  
 
  <!-- Remove for Vyre 4.3 and lower -->  
  <xsl:param name="current_path"/>  
  <xsl:param name="context_path"/>  
  <xsl:param name="action_url"/>  
  <xsl:param name="ajax"/>  
  <xsl:param name="canVote"/>  
  <!--                               -->  
 
  <xsl:template match="/">     
    <h2>Can I vote in this poll? 
      <xsl:value-of select="$canVote"/>
    </h2>  
    <xsl:apply-templates select="poll"/> 
  </xsl:template>  
 
  <xsl:template match="poll"> 
    <h3>
      <xsl:value-of select="question"/>
    </h3>  
    <xsl:apply-templates select="answers" mode="graph"/>  
    <xsl:apply-templates select="answers" mode="table"/> 
  </xsl:template>  
  <xsl:template match="answer" mode="graph"> 
    <div style="width:{@percentage*10}px; color:#fff; margin-bottom:20px; background:#{position()*124577}"> 
      <xsl:value-of select="name"/>  
      <xsl:value-of select="@percentage"/> 
    </div> 
  </xsl:template>  
  <xsl:template match="answers" mode="table"> 
    <table cellspacing="0" cellpadding="0" border="0"> 
      <thead> 
        <tr> 
          <th class="first">Answer</th>  
          <th class="second">Description</th>  
          <th class="third">Count</th>  
          <th class="forth">Percentage</th>  
          <th class="fifth">Vote</th> 
        </tr> 
      </thead>  
      <tbody> 
        <xsl:apply-templates select="answer"/> 
      </tbody> 
    </table> 
  </xsl:template>  
  <xsl:template match="answer"> 
    <tr> 
      <td>
        <xsl:value-of select="name"/>
      </td>  
      <td>
        <xsl:value-of select="description"/>
      </td>  
      <td>
        <xsl:value-of select="@count"/>
      </td>  
      <td>
        <xsl:value-of select="@percentage"/>
      </td>  
      <xsl:choose> 
        <xsl:when test="$ajax='true'"> 
          <td>
            <a href="#" onclick="poll.vote({@id}); return false;">vote</a>
          </td> 
        </xsl:when>  
        <xsl:otherwise> 
          <td>
            <a href="{$action_url}&amp;pollId={//poll/@id}&amp;answerId={@id}">vote</a>
          </td> 
        </xsl:otherwise> 
      </xsl:choose> 
    </tr> 
  </xsl:template> 
</xsl:stylesheet>
Sample XSL file display as radio buttons
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE xsl:stylesheet  [
<!ENTITY nbsp   "&#160;">
<!ENTITY copy   "&#169;">
<!ENTITY reg    "&#174;">
<!ENTITY trade  "&#8482;">
<!ENTITY mdash  "&#8212;">
<!ENTITY ldquo  "&#8220;">
<!ENTITY rdquo  "&#8221;">
<!ENTITY pound  "&#163;">
<!ENTITY yen    "&#165;">
<!ENTITY euro   "&#8364;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="iso-8859-1"/>
 
  <!-- Remove for Vyre 4.3 and lower -->
  <xsl:param name="current_path" ></xsl:param>
  <xsl:param name="context_path" ></xsl:param>
  <!--                               -->
 
  <xsl:template match="/">    
  	<xsl:apply-templates select="poll"/>
  </xsl:template>
 
  <xsl:template match="poll">
	<div class="module poll" style="width:300px;">
		<h2>
			<span>Daily Poll</span>
		</h2>
		<xsl:variable name="pollQ">
			<xsl:value-of select="question"/>
		</xsl:variable>
		<div class="container">
 
			<p class="info">
				<xsl:value-of select="question"/>
			</p>
			<ul>
				<xsl:apply-templates select="answers/answer"/>
			</ul>
			<p id="submit-poll" class="cta red-up">
				<a href="#" onclick="poll.voteByRadio(); return false; ">Vote now</a>
			</p>
			<div class="clearer"></div>
		</div>
	</div>  
  </xsl:template>
 
  <xsl:template match="answer">
	<li class="radio">
		<label for="answer{@id}"><xsl:value-of select="name"/></label><input id="answer{@id}" name="answerId" value="{@id}" type="radio" class="radio"/>
		<div>
			<xsl:value-of select="description"/>
		</div>
	</li>   
  </xsl:template>
</xsl:stylesheet>

Detect incoming poll

When this checkbox is selected, poll id parameter is obtained from the URL: http://mysite:4510/poll_display/?pollId=32 and used by Poll Display portlet to display the poll. In order for the poll id parameter to be appended to the URL, Send Poll Id checkbox must be selected in Poll Edit portlet.

See Also

Personal tools