Mage_Poll_Block_ActivePoll Class Reference

Inheritance diagram for Mage_Poll_Block_ActivePoll:

Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 __construct ()
 setPollTemplate ($template, $type)

Protected Member Functions

 _toHtml ()

Protected Attributes

 $_templates
 $_voted


Detailed Description

Definition at line 34 of file ActivePoll.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor

By default is looking for first argument as array and assignes it as object attributes This behaviour may change in child classes

Reimplemented from Varien_Object.

Definition at line 38 of file ActivePoll.php.

00039     {
00040         parent::__construct();
00041 
00042         $pollModel = Mage::getModel('poll/poll');
00043         // get last voted poll (from session only)
00044         $pollId = Mage::getSingleton('core/session')->getJustVotedPoll();
00045         if (empty($pollId)) {
00046             // get random not voted yet poll
00047             $votedIds = $pollModel->getVotedPollsIds();
00048             $pollId = $pollModel->setExcludeFilter($votedIds)
00049                 ->setStoreFilter(Mage::app()->getStore()->getId())
00050                 ->getRandomId();
00051         }
00052         if (empty($pollId)) {
00053             return false;
00054         }
00055         $poll = $pollModel->load($pollId);
00056 
00057         $pollAnswers = Mage::getModel('poll/poll_answer')
00058             ->getResourceCollection()
00059             ->addPollFilter($pollId)
00060             ->load()
00061             ->countPercent($poll);
00062 
00063         // correct rounded percents to be always equal 100
00064         $percentsSorted = array();
00065         $answersArr = array();
00066         foreach ($pollAnswers as $key => $answer) {
00067             $percentsSorted[$key] = $answer->getPercent();
00068             $answersArr[$key] = $answer;
00069         }
00070         asort($percentsSorted);
00071         $total = 0;
00072         foreach ($percentsSorted as $key => $value) {
00073             $total += $value;
00074         }
00075         // change the max value only
00076         if ($total > 0 && $total !== 100) {
00077             $answersArr[$key]->setPercent($value + 100 - $total);
00078         }
00079 
00080         $this->assign('poll', $poll)
00081              ->assign('poll_answers', $pollAnswers)
00082              ->assign('action', Mage::getUrl('poll/vote/add', array('poll_id' => $pollId)));
00083 
00084         $this->_voted = Mage::getModel('poll/poll')->isVoted($pollId);
00085         Mage::getSingleton('core/session')->setJustVotedPoll(false);
00086     }


Member Function Documentation

_toHtml (  )  [protected]

Render block HTML

Returns:
string

Reimplemented from Mage_Core_Block_Template.

Definition at line 94 of file ActivePoll.php.

00095     {
00096         if( $this->_voted === true ) {
00097             $this->setTemplate($this->_templates['results']);
00098         } else {
00099             $this->setTemplate($this->_templates['poll']);
00100         }
00101         return parent::_toHtml();
00102     }

setPollTemplate ( template,
type 
)

Definition at line 88 of file ActivePoll.php.

00089     {
00090         $this->_templates[$type] = $template;
00091         return $this;
00092     }


Member Data Documentation

$_templates [protected]

Definition at line 36 of file ActivePoll.php.

$_voted [protected]

Definition at line 36 of file ActivePoll.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:34 2009 for Magento by  doxygen 1.5.8