We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22815
    • 1,097 Posts
    This is a very rough snippet, created as an additional resource for someone I was helping out.

    This is an Extra for Polls Module.

    The idea is to create an "archive" of past polls.

    I’d like to polish it a bit before I bung it in the Repository; I just thought I’d share it here and see what suggestions for improvements people have. Should I go for a template route like Ditto, or let people configure the styles / html tags in some other way? Frankly it’s such a simple snippet it’s probably easiest to just hack the code to suit - it’s more of a starting point than anything.

    There are no parameters, so you can just call it using [[PollArchive]] (or [!PollArchive!]).

    // <?php
    /* 
    PollArchive 0.1 - 21Aug06
    Snippet by Paul Gregory for MODx
    Initial development sponsored by Deep Ganatra - Web1 Solutions (www.web1.in)
    Requires "Polls Module" by garryn
    
    Changelog
    21Aug06: Created.
    */
    
    // Stylable Things
    // h2 - Poll Number
    // h3 - Poll Question
    // .poll_answers - Answers Section
    // strong - Percentage
    // Wrap the whole thing around a div.
    
    $polltable = $modx->getFullTableName("polls");
    $choicetable = $modx->getFullTableName("poll_choices");
    
    $rs = $modx->db->select("*", $polltable, '', "id ASC", "");
    $limit = $modx->db->getRecordCount($rs);
    for ($j = 0; $j < $limit; $j++) {
    	$poll = $modx->db->getRow($rs);
    	$pollid = $poll['id'];
    	$where = "pollid=" . $pollid;
    	$choices_rs = $modx->db->select("*", $choicetable, $where, "id ASC", "");
    	$limit2 = $modx->db->getRecordCount($choices_rs);
    	$output .= '<h2>Poll Number: '.$pollid.'</h2>';
    	$output .= '<h3>' . stripslashes($poll['question']) . '</h3><div class="poll_answers">';		
    	$totalvotes = $poll['votes'];
    	// loop through choice results to build total
    	for ($i = 0; $i < $limit2; $i++) {
    		$row = $modx->db->getRow($choices_rs);
    		$votes = $row['votes'];
    		if (($votes < 1) || ($totalvotes < 1)) {
    			$percent = 0;
    		} else {
    			$percent = ($votes / $totalvotes) * 100;
    		}
    		$output .= stripslashes($row['choice']) . ': <strong>' . number_format($percent, $decimal, '.', '') . '%</strong> ';
    	}
    	$output .= '</div><br />';}	
    return $output;
    
      No, I don&#39;t know what OpenGeek&#39;s saying half the time either.
      MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
      Forum: Where to post threads about add-ons | Forum Rules
      Like MODx? donate (and/or share your resources)
      Like me? See my Amazon wishlist
      MODx "Most Promising CMS" - so appropriate!